vooga.engine.core
Class BetterSprite

java.lang.Object
  extended by com.golden.gamedev.object.Sprite
      extended by vooga.engine.core.BetterSprite
Direct Known Subclasses:
Background, BallSprite, BasicAds, BlackHole, BlockadeSprite, BlockSprite, Bonus, Bonus, Bullet, Bullet, Bullet, Button, CharacterSprite, CyclePlayer, DoodleSprite, DoodleSprite, Enemy, Enemy, Enemy, EnemyGenerator, EnemyShip, EnemyShot, EnemySprite, Explosion, Explosion, FlyingMonster, GrayPlatform, Item, Item, Item, JigglingFlyingMonster, JigglingMonster, JumpingMonster, Laser, LevelParserExample.MySprite, LightBluePlatform, MarioSprite, Missile, MouseFollower, MovingMonster, Planetoid, PlanetSprite, Player, Player, PlayerExample, PlayerShip, PlayerShot, Ship, Ship, Shooter, Shooter, StarSprite, Tower, TowerShot, TronPlayer, ZipsterLaser, Zombie, Zombie

public class BetterSprite
extends com.golden.gamedev.object.Sprite

The vooga.engine.core.Sprite class can represent any renderable object in the game environment. The vooga.engine.core.Sprite class extends the com.golden.gamedev.object.Sprite class but provides two additional useful features: the option to switch between renderable images and the capacity to contain any attributes in the form of a Stat. Like the Golden T Sprite class, the Vooga Sprite class supports update and render behaviors for a Sprite object. In addition, the Sprite class contains all the images and attributes that a Sprite object needs. The functionalities supported by the Sprite class include rendering image animation, setting Sprite location and velocity, switching to a different image, and allows for the updating of Sprite attributes. Code Example:

Sprite robertDuvall = new Sprite(normal, "robertDuvall.jpg"); robertDuvall.addSprite(yelling, new Sprite("robertDuvallYelling.jpg")); BufferedImage[] duvallLaughing = Resources.getImages("robertDuvallLaughing")); robertDuvall.addAnimatedImages("laughing", duvallLaughing); robertDuvall.setAsRenderedSprite("laughing"); Stat<String> unhappyprojectResponse = new Stat("Well, this person obviously doesn't know how to code..."); Stat<Double> understandability = new Stat(0.0); robertDuvall.setStat("unhappyprojectResponse", unhappyprojectResponse); robertDuvall.setStat("understandability", understandability); Stat<Double> intelligible = robertDuvall.getStat("understandability"); long timeExisted = robertDuvall.getTimeInExistence(); robertDuvall.update(timeExisted); robertDvuall.render(g);


Constructor Summary
BetterSprite()
          Constructs an entity with null image and 0, 0 position and the default label.
BetterSprite(java.awt.image.BufferedImage image)
          Constructs an entity with the image and 0, 0 position
BetterSprite(java.awt.image.BufferedImage[] images)
          Construct an animated entity from an array of images
BetterSprite(java.awt.image.BufferedImage image, double x, double y)
          Constructs an entity with an image located at the specified coordinates and the default label.
BetterSprite(double x, double y)
          Constructs an entity with null image located at the specified coordinates with the default label.
BetterSprite(java.lang.String label, java.awt.image.BufferedImage image, double x, double y)
          Constructs an entity with given image located at specified coordinates AND labels the image so that you can switch to this initial sprite if other sprites are added to this entity later.
BetterSprite(java.lang.String label, com.golden.gamedev.object.Sprite s)
           
 
Method Summary
 void addAnimatedImages(java.lang.String label, java.awt.image.BufferedImage[] images)
          Adds a new Animatedsprite to the image map;
 void addHorizontalSpeed(long elapsedTime, double accel, double maxSpeed)
          Add an acceleration value to the sprite or change the horizontal speed of the sprite
 void addImage(java.lang.String label, java.awt.image.BufferedImage image)
          Adds a new Sprite made from the given image.
 void addSprite(java.lang.String label, com.golden.gamedev.object.Sprite sp)
           
 void addVerticalSpeed(long elapsedTime, double accel, double maxSpeed)
          Add an acceleration value to the sprite or change the vertical speed of the sprite
 void firstRun()
          Override this method to do any initializations necessary after the sprite is initialized by the level file.
 void forceX(double newx)
          Force myCurrentSprite to a specific X location newx on the screen
 void forceY(double newy)
          Force myCurrentSprite to a specific Y location newy on the screen
 com.golden.gamedev.object.Sprite getCurrentSprite()
          This method returns my currentSprite.
 double getDistance(com.golden.gamedev.object.Sprite other)
          Get the distance from mycurrentSprite
 Stat<java.lang.Double> getDoubleStat(java.lang.String statname)
           
 int getHeight()
           
 double getHorizontalSpeed()
           
 java.awt.image.BufferedImage getImage()
          Get the bitmap representation of myCurrentSprite
 Stat<java.lang.Integer> getIntStat(java.lang.String statname)
           
 Stat<?> getStat(java.lang.String statName)
          Returns the Stat associated with the given name.
 long getTimeInExistence()
           
 double getVerticalSpeed()
           
 int getWidth()
           
 double getX()
          Get the current X position of myCurrentSprite
 double getY()
          Get the current Y position of myCurrentSprite
 boolean isActive()
          check if myCurrentSprite is currently displayed
 boolean isOnScreen()
          Check whether the myCurrentSprite is on the screen
 void move(double newx, double newy)
          Move the current Sprite newx and newy
 boolean moveTo(long elapsedTime, double newx, double newy, double newspeed)
          Move myCurrentSprie to newx and newy and change the velocity to newSpeed
 void moveX(double dx)
           
 void moveY(double dy)
           
 void render(java.awt.Graphics2D g)
          Render the image onto the screen
 void setActive(boolean b)
          set whether myCurrentSprite will be visible on the screen
 void setAsRenderedSprite(java.lang.String spriteName)
          Modify GameEntity so that it is represented by the Sprite specified by spriteName.
 void setBackground(Background backgr)
          Set the background for the Golden T.
 void setDoubleStat(java.lang.String statname)
           
 void setHorizontalSpeed(double vx)
           
 void setImage(java.awt.image.BufferedImage Image)
          This method sets a new image to the current Image.
 void setImages(java.awt.image.BufferedImage[] images)
          This method sets a new image array to the current image array only if myCurrentSprite is an AnimatedSprite
 void setIntStat(java.lang.String statname, int stat)
           
 void setLayer(int i)
          Set all the sprites to the same
 void setLocation(double xs, double ys)
           
 void setMovement(double speed, double angleDir)
          set the magnitude of myCurrenttSprite with an initial angle
 void setSpeed(double vs, double vy)
           
 void setStat(java.lang.String name, Stat<?> t)
          Sets
 void setVerticalSpeed(double vy)
           
 void setX(double xs)
           
 void setY(double ys)
           
 void update(long elapsedTime)
          Specify how the GameEntity Object should be updated.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BetterSprite

public BetterSprite()
Constructs an entity with null image and 0, 0 position and the default label.


BetterSprite

public BetterSprite(java.awt.image.BufferedImage image)
Constructs an entity with the image and 0, 0 position

Parameters:
image -

BetterSprite

public BetterSprite(java.lang.String label,
                    com.golden.gamedev.object.Sprite s)
Parameters:
name - is any name you'd like to give to the object.
state - State name is the name you'd like to map to the following Sprite object. e.g."alive" to represent a sprite that's a live, or "dead" if the sprite represents the entity in a dead state, etc
this - is the default Sprite that will represent this Entity on the Screen.

BetterSprite

public BetterSprite(java.awt.image.BufferedImage[] images)
Construct an animated entity from an array of images

Parameters:
image -

BetterSprite

public BetterSprite(java.awt.image.BufferedImage image,
                    double x,
                    double y)
Constructs an entity with an image located at the specified coordinates and the default label.

Parameters:
image -
x - is the x position.
y - is the y position.

BetterSprite

public BetterSprite(double x,
                    double y)
Constructs an entity with null image located at the specified coordinates with the default label.

Parameters:
x - is the x position.
y - is the y position.

BetterSprite

public BetterSprite(java.lang.String label,
                    java.awt.image.BufferedImage image,
                    double x,
                    double y)
Constructs an entity with given image located at specified coordinates AND labels the image so that you can switch to this initial sprite if other sprites are added to this entity later.

Parameters:
label - is the label for this sprite representation.
image -
x - is the x position.
y - is the y position.
Method Detail

addSprite

public void addSprite(java.lang.String label,
                      com.golden.gamedev.object.Sprite sp)
Parameters:
label - is the name you'd like to use to represent the Sprite parameter. e.g. "alive" or "dead" or "shooting"
sp - is the Sprite you are mapping to the first parameter.

addImage

public void addImage(java.lang.String label,
                     java.awt.image.BufferedImage image)
Adds a new Sprite made from the given image.

Parameters:
label - is the name you'd like to use to represent the Sprite parameter. e.g. "alive" or "dead" or "shooting"
image - is the image from which the new Sprite will be constructed.

addAnimatedImages

public void addAnimatedImages(java.lang.String label,
                              java.awt.image.BufferedImage[] images)
Adds a new Animatedsprite to the image map;

Parameters:
label -
images -

getCurrentSprite

public com.golden.gamedev.object.Sprite getCurrentSprite()
This method returns my currentSprite. Beware that the currentSprite may change

Returns:
Sprite

getTimeInExistence

public long getTimeInExistence()
Returns:
length of time the GameEntity has existed

setAsRenderedSprite

public void setAsRenderedSprite(java.lang.String spriteName)
Modify GameEntity so that it is represented by the Sprite specified by spriteName.

Parameters:
spriteName - the "name" of the sprite that GameEntity will now be represented by.

getStat

public Stat<?> getStat(java.lang.String statName)
Returns the Stat associated with the given name.

Parameters:
statName - is the name used
Returns:

setStat

public void setStat(java.lang.String name,
                    Stat<?> t)
Sets


getIntStat

public Stat<java.lang.Integer> getIntStat(java.lang.String statname)

setIntStat

public void setIntStat(java.lang.String statname,
                       int stat)

getDoubleStat

public Stat<java.lang.Double> getDoubleStat(java.lang.String statname)

setDoubleStat

public void setDoubleStat(java.lang.String statname)

update

public void update(long elapsedTime)
Specify how the GameEntity Object should be updated.


firstRun

public void firstRun()
Override this method to do any initializations necessary after the sprite is initialized by the level file.


render

public void render(java.awt.Graphics2D g)
Render the image onto the screen

See Also:
com.golden.gamedev.object.Sprite#render(java.awt.Graphics2D)

getImage

public java.awt.image.BufferedImage getImage()
Get the bitmap representation of myCurrentSprite


setImage

public void setImage(java.awt.image.BufferedImage Image)
This method sets a new image to the current Image. This method is used by rotate Image;

Parameters:
Image -

setImages

public void setImages(java.awt.image.BufferedImage[] images)
This method sets a new image array to the current image array only if myCurrentSprite is an AnimatedSprite

Parameters:
images - the images to set on myCurrentSprite

isOnScreen

public boolean isOnScreen()
Check whether the myCurrentSprite is on the screen


setActive

public void setActive(boolean b)
set whether myCurrentSprite will be visible on the screen


isActive

public boolean isActive()
check if myCurrentSprite is currently displayed


setBackground

public void setBackground(Background backgr)
Set the background for the Golden T. This allows the sprites to be part of the playfield.


setLayer

public void setLayer(int i)
Set all the sprites to the same


addHorizontalSpeed

public void addHorizontalSpeed(long elapsedTime,
                               double accel,
                               double maxSpeed)
Add an acceleration value to the sprite or change the horizontal speed of the sprite

See Also:
com.golden.gamedev.object.Sprite#addHorizontalSpeed(long, double, double)

addVerticalSpeed

public void addVerticalSpeed(long elapsedTime,
                             double accel,
                             double maxSpeed)
Add an acceleration value to the sprite or change the vertical speed of the sprite

See Also:
com.golden.gamedev.object.Sprite#addVerticalSpeed(long, double, double)

forceX

public void forceX(double newx)
Force myCurrentSprite to a specific X location newx on the screen


forceY

public void forceY(double newy)
Force myCurrentSprite to a specific Y location newy on the screen


getX

public double getX()
Get the current X position of myCurrentSprite


getY

public double getY()
Get the current Y position of myCurrentSprite

See Also:
com.golden.gamedev.object.Sprite#getY()

getDistance

public double getDistance(com.golden.gamedev.object.Sprite other)
Get the distance from mycurrentSprite


getHeight

public int getHeight()

getWidth

public int getWidth()

getHorizontalSpeed

public double getHorizontalSpeed()

getVerticalSpeed

public double getVerticalSpeed()

setHorizontalSpeed

public void setHorizontalSpeed(double vx)

setVerticalSpeed

public void setVerticalSpeed(double vy)

setLocation

public void setLocation(double xs,
                        double ys)

setMovement

public void setMovement(double speed,
                        double angleDir)
set the magnitude of myCurrenttSprite with an initial angle


setSpeed

public void setSpeed(double vs,
                     double vy)

setX

public void setX(double xs)

setY

public void setY(double ys)

move

public void move(double newx,
                 double newy)
Move the current Sprite newx and newy

See Also:
com.golden.gamedev.object.Sprite#move(double, double)

moveTo

public boolean moveTo(long elapsedTime,
                      double newx,
                      double newy,
                      double newspeed)
Move myCurrentSprie to newx and newy and change the velocity to newSpeed


moveX

public void moveX(double dx)

moveY

public void moveY(double dy)