public Sprite(Bound bound, int bmp, float x, float y, int fps, String type, Resources res) throws GameException { this.bitmap = BitmapCache.getInstance().getBitmapFromCache(res, bmp); this.normalBitmap = bitmap; this.x = x; this.y = y; this.bound = bound; if (bound != null) { x = (bound.inBoundX(getX(), getWidth())); y = (bound.inBoundY(getY(), getHeight())); } this.framePeriod = 1000 / fps; this.frameTicker = 0l; // probably should get set by constructor I guess targetX = 0; targetY = 0; state = SPRITE_STATE.STOPPED; this.type = type; // create the flipped bitmap this.flipBitmap = BitmapCache.getInstance().getFlipBitmapFromCache(res, bmp); }
/** * Move toward a specific angle * * @param angle * @param gameTime * @param speed * @param override * @param axis */ public void moveTowardAngle( double angle, long gameTime, float speed, boolean override, MOVEMENT_AXIS axis) { state = SPRITE_STATE.MOVING; /* this means that the motion should increment * every cetain number of frames, not every * time the method is called. This is because * this method could be called faster or * slower than the requires FPS. * * This check can be overridden, but be careful! */ if ((gameTime > frameTicker + framePeriod) || override) { frameTicker = gameTime; float difX = speed * (float) Math.cos(angle); float difY = speed * (float) Math.sin(angle); // if axis is specified, move only on that axis if (MOVEMENT_AXIS.X.equals(axis)) { x += -difX; } else if (MOVEMENT_AXIS.Y.equals(axis)) { y += -difY; } else { x += -difX; y += -difY; } /* don't move past bounds. if we are * passed the bound, then move axis to * the edge of the bound */ if (bound != null) { x = (bound.inBoundX(getX(), getWidth())); y = (bound.inBoundY(getY(), getHeight())); } } }