Game Development Reference
In-Depth Information
3.2 Main Character
The main character class Hero extends the base class Sprite and overrides its method move() .
Building the Constructor
The Constructor creates a Hero instance based on the specified typeID and position of main
character:
//Constructor: creates a Hero instance based on
//the specified TypeID and position
//Parameters:
// type - the TypeID of the specified sprite. 0-hero
// col - the column# of the position
// row - the row# of the position
// gv - the reference to GameView
public Hero( int type, int col, int row, GameView gv){
super (type, col, row);
this .gv = gv;
}
Overriding move() Method
Called to move the hero object when the user taps the D-Pad arrows on the screen.
//Called to move a Hero object when the user taps
//the D-Pad arrows on the screen.
//Returns:
// true - succeeded, false - failed
//Parameters:
// dir - the direction to be headed for
@Override
public boolean move( int dir){
boolean ret = true ;
//Screen bounds check
if (gv.checkScreenOut(dir)) return false ;
switch (dir){
case DIR_UP:
Search WWH ::




Custom Search