Class Player
[ Source
| Index
| Back to Nelzan ]
- class Player
- extends Object
Nelzan - Handles all information dealing with the player
Controls Player Movement, shields, weapons, lives, score, painting,
and collisions.
-
activeWeapon
-
-
comp
- Instance of Applet, for call backs.
-
count
-
-
dir
-
-
direction
- Array for storing directions.
-
fire
-
-
fireX
-
-
fireY
-
-
invincible
-
-
level
- Level Player is on.
-
lives
- Number of lives the player has.
-
myImages
-
-
myX
-
-
myY
-
-
originalX
-
-
originalY
-
-
prevX
-
-
prevY
-
-
score
- Player Score.
-
shieldColor
- Array of colors used for drawing Shields and weapons.
-
shields
- Current Level of shields.
-
weapon
-
-
weaponDamage
-
-
weaponRange
-
-
weaponSpeed
-
-
Player(Image[], int, int, Applet)
- Creates a player at and an x, y location with specified images.
-
addLife()
- Addes one life to the player.
-
addShield(int)
- Addes power back to the player's shields.
-
addWeapon(int)
- Addes one level to a Weapon.
-
buildShieldColor()
- Builds an array of shield colors for later use.
-
checkAttack(int, int, int, int, int)
- Checks to see if the Enemy's weapon is hitting the player.
-
checkBounds()
- Makes sure the player doesn't leave the playing area.
-
damage(int, int, int, int, int, int)
- This fuction handles collisions.
-
fire()
- Tells the player to fire it's weapon if it can.
-
getActiveWeapon()
- Gets the number of the current weapon.
-
getWeaponLevel()
- Gets the currently selected Weapons level.
-
getYMovement(int)
- Function allows enemy weapons to home in on players location.
-
givePowerUp(int)
- Function handles giving the player powerup's like shields, weapons,
and extra lives.
-
killFire(int)
- Removes a fired weapon from the array.
-
killMe()
- Kills the player.
-
move(int)
- Tells the player to move in direction i.
-
paint(Graphics)
- Used to paint the player and weapons.
-
setActiveWeapon(int)
- Sets players weapon to inputed value.
-
setMoveFalse(int)
- Sets direction[i] to false.
-
setMoveTrue(int)
- Sets direction[i] to true.
-
update()
- Updates player and fired ammo location.
myImages
private Image myImages[]
myX
private int myX
myY
private int myY
dir
private int dir
prevX
private int prevX[]
prevY
private int prevY[]
activeWeapon
private int activeWeapon
weapon
private int weapon[]
weaponDamage
private static final int weaponDamage[]
weaponRange
private static final int weaponRange[]
weaponSpeed
private static final int weaponSpeed[]
fire
private int fire[]
fireX
private int fireX[]
fireY
private int fireY[]
count
private int count
invincible
private int invincible
originalX
private int originalX
originalY
private int originalY
score
public int score
- Player Score.
lives
public int lives
- Number of lives the player has.
shields
public int shields
- Current Level of shields.
level
public int level
- Level Player is on.
direction
boolean direction[]
- Array for storing directions.
shieldColor
public Color shieldColor[]
- Array of colors used for drawing Shields and weapons.
comp
Applet comp
- Instance of Applet, for call backs.
Player
Player(Image img[],
int startX,
int startY,
Applet c)
- Creates a player at and an x, y location with specified images.
- Parameters:
- img - Images that represent the player.
- startX - Players starting X location.
- startY - Players starting Y location.
- c - Instance of an Applet, for call backs.
paint
public void paint(Graphics g)
- Used to paint the player and weapons.
- Parameters:
- g - Graphics to paint to.
update
public void update()
- Updates player and fired ammo location.
getActiveWeapon
public int getActiveWeapon()
- Gets the number of the current weapon.
- Returns:
- an
int based on the selected weapon.
getWeaponLevel
public int getWeaponLevel()
- Gets the currently selected Weapons level.
- Returns:
- an
int based on the selected weapon's level.
setActiveWeapon
public void setActiveWeapon(int i)
- Sets players weapon to inputed value. It only does this if the
level of the weapon is greater than 0.
- Parameters:
- i - Weapon number to set to.
fire
public void fire()
- Tells the player to fire it's weapon if it can.
setMoveTrue
public void setMoveTrue(int i)
- Sets direction[i] to true. This is used so the player will continually
move in the selected direction until setMoveFalse(i) is called.
- Parameters:
- i - The direction to set.
- See Also:
- setMoveFalse
setMoveFalse
public void setMoveFalse(int i)
- Sets direction[i] to false. This is used so the player will stop
moving in the selected direction.
- Parameters:
- i - The direction to set.
move
public void move(int i)
- Tells the player to move in direction i.
- Parameters:
- i - The Direction to move.
getYMovement
public int getYMovement(int y)
- Function allows enemy weapons to home in on players location. Depending
on the weapons location, the function will return a positive, negative,
or zero.
- Parameters:
- y - Fired weapons y location.
- Returns:
-
2 if y > player Y, -2
otherwise.
damage
public int damage(int x,
int y,
int w,
int h,
int t,
int d)
- This fuction handles collisions. If the player or the players'
weapons hit the an enemy object, this function will return the
damage that is done, and cause damage when needed.
- Parameters:
- x - Enemy x location.
- y - Enemy y location.
- w - Enemy's width.
- h - Enemy's height.
- t - Enemy's Type.
- d - Enemy's Shield level.
- Returns:
-
WeaponDamage if getting hit by weapon,
d if coliding with player,
0 otherwise.
checkAttack
public boolean checkAttack(int x,
int y,
int w,
int h,
int d)
- Checks to see if the Enemy's weapon is hitting the player.
- Parameters:
- x - Enemy x location.
- y - Enemy y location.
- w - Enemy's width.
- h - Enemy's height.
- d - How much damage the weapon will cause.
- Returns:
-
true if the weapon hits,
false otherwise.
givePowerUp
private void givePowerUp(int t)
- Function handles giving the player powerup's like shields, weapons,
and extra lives.
- Parameters:
- i - Type of power up to give.
addShield
private void addShield(int a)
- Addes power back to the player's shields. Shields cannot exceed 200,
so proper checks are in place.
- Parameters:
- a - Value to add to current shield levels.
addWeapon
private void addWeapon(int i)
- Addes one level to a Weapon. Weapons cannot exceed a level of 10,
so proper checks are in place.
- Parameters:
- i - Weapon number to add 1 to.
addLife
private void addLife()
- Addes one life to the player. Lives cannot exceed 7, so proper
checks are in place.
checkBounds
private boolean checkBounds()
- Makes sure the player doesn't leave the playing area.
- Returns:
-
true if the player is out of bounds,
false otherwise.
killFire
private void killFire(int w)
- Removes a fired weapon from the array. Because weapons can move at
different speeds this is a little more complex, but it gets the job done.
- Parameters:
- w - Weapon to kill.
killMe
public void killMe()
- Kills the player. Causes them to move back to the original starting x,
y, and will give them about 2 second "free" play.
buildShieldColor
private void buildShieldColor()
- Builds an array of shield colors for later use. This Array and function
is designed to save speed at runtime.
|