android.gameengine.icadroids.objects
Class MoveableGameObject

java.lang.Object
  extended by android.gameengine.icadroids.objects.GameObject
      extended by android.gameengine.icadroids.objects.MoveableGameObject

public class MoveableGameObject
extends GameObject

MoveableGameObject represents a moveable object in the game. Make sure to add the MoveableGameObject to the object list, else it won't update.
The game engine does collision detection for MoveableGameItems. This is very time consuming, so make sure you only extend this class when the items are really moving! note: Tile collision only works when the object is moving!

Author:
Edward van Raak,Bas van der Zandt, Roel van Bergen

Field Summary
 
Fields inherited from class android.gameengine.icadroids.objects.GameObject
position, xlocation, ylocation
 
Constructor Summary
MoveableGameObject()
           
 
Method Summary
 void bounce(boolean horizontal)
          Bounces the object , what this does is reversing the horizontal or vertical direction.
 void bounce(TileCollision tc)
          Bounce at the tile this object has just collided into.
<T> boolean
collidedWith(java.lang.Class<T> objectClass)
          Checks if your object has collided with another object of a certain class.
 java.util.ArrayList<GameObject> getCollidedObjects()
          Checks wether or not this gameObject has collided with one or multiple GameObjects or MovableGameObjects.
 CollidingObject getCollidingObject()
          Get the colliding object if you want to make use of the methods that are in there
 double getDirection()
          Gets the direction of the objects movement in degrees.
 double getDirectionRadians()
          Gets the direction of the objects movement in radians.
 double getFriction()
          Gets the friction of this object
 double getPrevCenterX()
          Gets the previous centerX position of this object, which is saved every loop.
 double getPrevCenterY()
          Gets the previous centerY position of this object, which is saved every loop.
 double getPrevX()
          Gets the previous X position of this object, which is saved every loop.
 double getPrevY()
          Gets the previous Y position of this object, which is saved every loop.
 double getSpeed()
          Gets the speed of this object.
 Tile getTileOnPosition(int xPosition, int yPosition)
          Get a tile on a specific x and y position in the game world.
 double getxSpeed()
          Gets the X speed of this object.
 double getySpeed()
          Gets the Y speed of this object.
 void movePlayer(int x_movement, int y_movement)
          This function allows you to move this object by specifying the x and y.
 boolean movesDown()
           
 boolean movesLeft()
           
 boolean movesRight()
           
 boolean movesUp()
           
 void moveTowardsAPoint(double x, double y)
          Sets the objects direction to move towards target point.
 void moveUpToTileSide(TileCollision tc)
          Move as close as possible to the side of tile, as specified in the TileCollision object, using the direction that the GameObject already has Note: Using Tiles that are not involved in a collision or are not close to the object can cause strange behaviour: The GameObject is moved to the extended line that passes through the specified side of the tile, using the original direction of the object's speed.
 void outsideWorld()
          Triggered when the MoveableGameObject moves outside of the world.
 void reverseHorizontalDirection()
          Reverses the horizontal direction of the objects movement.
 void reverseVerticalDirection()
          Reverses the vertical direction of the objects movement.
 void setDirection(double direction)
          Sets the direction of this object in degrees Direction 0 points up, directions go clockwise, so 90 is right, etc.
 void setDirectionRadians(double Direction)
          Sets the current direction of this object in radians Direction 0 points up, directions go clockwise, so 0.5*pi is right, etc.
 void setDirectionSpeed(double direction, double speed)
          Sets both the direction and the speed of this object.
 void setFriction(double friction)
          Sets the friction of this object, that is the amount of speed reduction.
 void setSpeed(double speed)
          Sets the speed of this object
 void setxSpeed(double xSpeed)
          Sets the x speed of this object.
 void setySpeed(double ySpeed)
          Sets the y speed of this object.
 void undoMove()
          This function will reset this object to its previous Position. the Previous Position will is set every loop.
 void update()
          The update-method will be called every cycle of the game loop.
 
Methods inherited from class android.gameengine.icadroids.objects.GameObject
clearActive, deleteThisGameObject, drawCustomObjects, drawGameObject, getAngle, getCenterX, getCenterY, getDepth, getFrameHeight, getFrameWidth, getFullX, getFullY, getPosition, getSprite, getX, getY, intialize, intializeGameObject, isActive, isVisible, jumpToStartPosition, setAnimationSpeed, setDepth, setFrameNumber, setPosition, setSprite, setSprite, setSprite, setStartPosition, setVisibility, setX, setY, startAnimate, stopAnimate, updatePlayerFramePosition
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MoveableGameObject

public MoveableGameObject()
Method Detail

update

public void update()
The update-method will be called every cycle of the game loop. Override this method to give an object any time driven behaviour.
Note: Always call super.update() first in your overrides, because the default update does some important actions, like moving the object.

Overrides:
update in class GameObject
See Also:
GameObject.update()

moveTowardsAPoint

public final void moveTowardsAPoint(double x,
                                    double y)
Sets the objects direction to move towards target point.

Parameters:
x - The x coordinate of your point.
y - The y coordinate of your point.

setDirection

public final void setDirection(double direction)
Sets the direction of this object in degrees Direction 0 points up, directions go clockwise, so 90 is right, etc.

Parameters:
direction - the direction in degrees.

setSpeed

public final void setSpeed(double speed)
Sets the speed of this object

Parameters:
speed - the speed to give this object.

setDirectionSpeed

public final void setDirectionSpeed(double direction,
                                    double speed)
Sets both the direction and the speed of this object. Direction 0 points up, directions go clockwise, so 90 is right, etc.

Parameters:
direction - the direction you want to set in the degrees
speed - the speed you want to set.

setxSpeed

public final void setxSpeed(double xSpeed)
Sets the x speed of this object.

Parameters:
xSpeed - the xSpeed.

setySpeed

public final void setySpeed(double ySpeed)
Sets the y speed of this object.

Parameters:
ySpeed - the ySpeed.

setDirectionRadians

public final void setDirectionRadians(double Direction)
Sets the current direction of this object in radians Direction 0 points up, directions go clockwise, so 0.5*pi is right, etc.

Parameters:
Direction - the direction in radians.

movePlayer

public final void movePlayer(int x_movement,
                             int y_movement)
This function allows you to move this object by specifying the x and y. Each successive call in one loop will increase the amount of movement this object should perform at the end of the loop.

Parameters:
x_movement - the amount of X pixels this object should move.
y_movement - the amount of Y pixels this object should move.

movesLeft

public final boolean movesLeft()
Returns:
returns true if this object is moving to the left, returns false otherwise.

movesRight

public final boolean movesRight()
Returns:
returns true if this object is moving to the right, returns false otherwise.

movesUp

public final boolean movesUp()
Returns:
returns true if this object is moving up, returns false otherwise.

movesDown

public final boolean movesDown()
Returns:
returns true if this object is moving down, returns false otherwise.

bounce

public final void bounce(boolean horizontal)
Bounces the object , what this does is reversing the horizontal or vertical direction.

Parameters:
horizontal - Put this on TRUE if you want to bounce Horizontal, FALSE if you want to bounce vertical.

setFriction

public final void setFriction(double friction)
Sets the friction of this object, that is the amount of speed reduction.
The decrease in speed is measured as a fraction, if you want a 5% decrease in speed per cycle of the game loop, use 0.05.

Parameters:
friction - the fraction of decrease in speed per cycle of the game loop. Must be a number between 0 and 1

getFriction

public final double getFriction()
Gets the friction of this object

Returns:
the friction.

getDirection

public final double getDirection()
Gets the direction of the objects movement in degrees. Direction 0 points up, directions go clockwise, so 90 is right, etc.

Returns:
the direction(angle) in degrees.

getDirectionRadians

public final double getDirectionRadians()
Gets the direction of the objects movement in radians. Direction 0 points up, directions go clockwise, so 0.5*pi is right, etc.

Returns:
the direction(angle) in radians

reverseHorizontalDirection

public final void reverseHorizontalDirection()
Reverses the horizontal direction of the objects movement.


reverseVerticalDirection

public final void reverseVerticalDirection()
Reverses the vertical direction of the objects movement.


getPrevX

public final double getPrevX()
Gets the previous X position of this object, which is saved every loop.

Returns:
the previous X position.

getPrevY

public final double getPrevY()
Gets the previous Y position of this object, which is saved every loop.

Returns:
the previous Y position.

getPrevCenterX

public final double getPrevCenterX()
Gets the previous centerX position of this object, which is saved every loop.

Returns:
the prevCenterX of this object

getPrevCenterY

public final double getPrevCenterY()
Gets the previous centerY position of this object, which is saved every loop.

Returns:
the prevCenterY of this object

getSpeed

public final double getSpeed()
Gets the speed of this object. Note that an object only has a speed if it first has been set with setSpeed(double), setxSpeed(double) or setySpeed(double)

Returns:
The speed.

getxSpeed

public final double getxSpeed()
Gets the X speed of this object. Note that an object only has a speed if it first has been set with setSpeed(double), setxSpeed(double) or setySpeed(double)

Returns:
The X speed.

getySpeed

public final double getySpeed()
Gets the Y speed of this object. Note that an object only has a speed if it first has been set with setSpeed(double),setxSpeed(double) or setySpeed(double)

Returns:
The Y speed.

undoMove

public final void undoMove()
This function will reset this object to its previous Position. the Previous Position will is set every loop.


outsideWorld

public void outsideWorld()
Triggered when the MoveableGameObject moves outside of the world. Override this method to take action when this happens!


getCollidedObjects

public final java.util.ArrayList<GameObject> getCollidedObjects()
Checks wether or not this gameObject has collided with one or multiple GameObjects or MovableGameObjects. It will return a list with the collided objects, it returns a null if there is no collision.
Call this method inside your update(), if you want to handle collisions.

Returns:
An arraylist of all objects that this object has collided with. Note that you will never get the object calling this function back.

collidedWith

public final <T> boolean collidedWith(java.lang.Class<T> objectClass)
Checks if your object has collided with another object of a certain class.

Parameters:
objectClass - Asks for any generic class, classes you should use are Gameobject,MoveableGameobject or any extensions of these two.
Returns:
returns true if this object has collided with an instance of the given class

moveUpToTileSide

public void moveUpToTileSide(TileCollision tc)
Move as close as possible to the side of tile, as specified in the TileCollision object, using the direction that the GameObject already has Note: Using Tiles that are not involved in a collision or are not close to the object can cause strange behaviour: The GameObject is moved to the extended line that passes through the specified side of the tile, using the original direction of the object's speed. If there wasn't any collision in the first place, this may be somewhere not very close to the tile!

Parameters:
tc - the TileCollision (usually provided by the the 'collisionOccurred' call )

bounce

public void bounce(TileCollision tc)
Bounce at the tile this object has just collided into. The TileCollision object will be provided by the tile-collision detection, so this method will typically be called at collision handling.
The object will be moved to the side of the tile and, according to the side of the tile it bounces on, x- or y-Speed will be reversed, so the object will move away in the next cycle of the game loop.

Parameters:
tc - The TileCollision (that is Tile plus side) you want to bounce onto

getTileOnPosition

public Tile getTileOnPosition(int xPosition,
                              int yPosition)
Get a tile on a specific x and y position in the game world.
ToDo Note: this method should not be here, but in class GameEngine. Change in next version!

Parameters:
xPosition - x position of the tile
yPosition - y position of the tile
Returns:
The Tile object at the given x and y position

getCollidingObject

public CollidingObject getCollidingObject()
Get the colliding object if you want to make use of the methods that are in there

Returns:
the collidingObject