package sample.game.model; import java.util.ArrayList; import library.core.debug.CoreLog; import library.core.listener.OnCoreCollisionListener; import library.core.listener.OnCoreTouchDownListener; import library.core.model.CoreAnimation; import library.core.model.CoreAnimationModel; import library.core.model.CoreModel; import sample.game.controller.GameController; public class CharaModel extends CoreAnimationModel implements Cloneable,OnCoreCollisionListener,OnCoreTouchDownListener{ public enum TARGET_TYPE{ MINISTART, WOLF, CATTLE, CABBAGE, } private TARGET_TYPE type; private boolean canMove; private boolean nowTarget; private boolean canTouch; private GameController controller; //レイアウトで使用するID private int layoutXId=0; private int layoutYId=0; //ターゲットのID識別用 セレクトボタンのIDに使用 private int targetId=0; public CharaModel(GameController controller,TARGET_TYPE type,ArrayList<CoreAnimation> animations, int startTargetAnimIndex, float centerX, float centerY, float width, float height) { super(animations, startTargetAnimIndex, centerX, centerY, width, height); this.type=type; this.canMove=true; this.canTouch=true; this.nowTarget=false; this.controller=controller; this.targetId=0; } @Override public CharaModel clone(){ CharaModel c=null; c=(CharaModel) super.clone(); return c; } /** * リスタート時などのゲームの再設定に使用 */ public void reset(){ this.canMove=true; this.canTouch=true; this.nowTarget=false; } /** *リセットかけたときにゲームコントローラーのインスタンスが変わっているので入れなおす * @param g */ public void setGameController(GameController g){ this.controller=g; } public TARGET_TYPE getType(){ return type; } public boolean isCanMove() { return canMove; } public void setCanMove(boolean canMove) { this.canMove = canMove; } public boolean isNowTarget() { return nowTarget; } public void setNowTarget(boolean nowTarget) { this.nowTarget = nowTarget; } public void setLayoutId(int x,int y){ this.layoutXId=x; this.layoutYId=y; } public int getLayoutXId() { return layoutXId; } public int getLayoutYId() { return layoutYId; } public void setTargetId(int id){ this.targetId=id; } public int getTargetId(){ return targetId; } public boolean isCanTouch() { return canTouch; } public void setCanTouch(boolean canTouch) { this.canTouch = canTouch; } @Override public void onTouchDown() { if(!canTouch) return; //タッチできない if(nowTarget){ controller.removeTarget(this); nowTarget=false; }else{ if(controller.addTarget(this)){ nowTarget=true; } } CoreLog.debug("touch chara"); } @Override public void onCollisionEnter(CoreModel model) { } @Override public void onCollisionOut(CoreModel model) { } @Override public void onCollisionIn(CoreModel model) { } @Override public void endAnimationEvent(CoreAnimation endAnim) { } }