public class Vec { public float _x, _y; Vec(){ _x = _y = 0; } Vec( float x, float y ){ _x = x; _y = y; } //角度を取得する float getAngle(){ return (float)Math.atan2(_y, _x); } //大きさを取得する float getLength(){ return (float)Math.sqrt( _x*_x + _y*_y ); } }
public class Circle { public float _x, _y, _r; Circle(){ _x = _y = _r = 0; } Circle(float x, float y, float r){ _x = x; _y = y; _r = r; } }
public class Player extends Task { private final static float SIZE = 20; //自機の大きさ private Circle _cir = null; //自機の円 private Paint _paint = new Paint(); //描画設定 private Vec _vec = new Vec(); //自機の移動ベクトル public Player(){ _cir = new Circle( 240, 0, SIZE );//(240,0)の位置にSIZEの大きさの円を作る _paint.setColor(Color.BLUE); //色を青に設定 _paint.setAntiAlias(true); //エイリアスをオン _vec._y = 2; //移動ベクトルを下に向ける } @Override public boolean onUpdate(){ _cir._x += _vec._x; //移動ベクトル_vecが指す方向に移動させる _cir._y += _vec._y; return true; } @Override public void onDraw( Canvas c ){ c.drawCircle(_cir._x, _cir._y, _cir._r, _paint); } }
public class GameMgr { private LinkedList<Task> _taskList = new LinkedList<Task>();//タスクリスト GameMgr(){ _taskList.add( new Player() ); _taskList.add( new FpsController() ); } public boolean onUpdate() { for(int i=0; i<_taskList.size(); i++){ if(_taskList.get(i).onUpdate() == false){ //更新失敗なら _taskList.remove(i); //そのタスクを消す i--; } } return true; } public void onDraw(Canvas c) { c.drawColor(Color.WHITE); //白で塗りつぶす for(int i=0; i<_taskList.size(); i++){ _taskList.get(i).onDraw(c);//描画 } } }
Portions of this page are modifications
based on work created and shared by Google and used according to terms
described in the Creative Commons 3.0 Attribution License.
- Remical Soft -