public class PacPlayer extends Character
| Modifier and Type | Field | Description |
|---|---|---|
int |
direction |
|
static int |
MSPACMAN |
|
static int |
PACMAN |
|
int |
pacmanspeed |
|
static java.lang.String |
PATH_AUDIO |
|
static java.lang.String |
PATH_IMAGE_MSPACMAN |
|
static java.lang.String |
PATH_IMAGE_PACMAN |
| Constructor | Description |
|---|---|
PacPlayer(int x,
int y) |
Constructor for PacPlayer class
|
PacPlayer(int x,
int y,
int playerNum,
Grid grid) |
Constructor for PacPlayer class for use
when multiple players are playing the game
|
| Modifier and Type | Method | Description |
|---|---|---|
void |
death() |
Handles PacMan's death by taking away lives,
resetting the death timer, and resetting position
|
void |
doAnim() |
Animates the Pacman sprite's direction as well as mouth opening and closing
|
void |
draw(java.awt.Graphics2D g2d,
javax.swing.JComponent canvas) |
Calls the appropriate draw method for the direction Pacman is facing
|
java.awt.Image |
getLifeImage() |
Returns the image used for displaying remaining lives
|
void |
keyPressed(int key) |
Handles key presses for game controls
|
void |
keyReleased(int key) |
Handles the release of a key by the player
Functionality has been removed for having smoother gameplay
Releasing key no longer undoes current direction move command
|
void |
loadAudio() |
Load game audio from audio folder
|
void |
loadImages() |
Load game sprites from images folder
|
void |
move(Grid grid) |
Moves character's current position with the board's collision
|
void |
moveAI(Grid grid,
Character[] c) |
Moves character's current position while detecting for collision
within the board
|
void |
playAudio(int sound) |
Plays a sound from pacman audio array.
|
void |
resetPos() |
Resets the player's position
|
public static final java.lang.String PATH_IMAGE_PACMAN
public static final java.lang.String PATH_IMAGE_MSPACMAN
public static final java.lang.String PATH_AUDIO
public static final int PACMAN
public static final int MSPACMAN
public int pacmanspeed
public int direction
public PacPlayer(int x,
int y)
x - the starting x coordinate of pacmany - the starting y coordinate of pacmanpublic PacPlayer(int x,
int y,
int playerNum,
Grid grid)
x - the starting x-coordinate of pacmany - the starting y-coordinate of pacmanplayerNum - int representing who the player is controllinggrid - the grid in which PacPlayer is part of.public void resetPos()
public void death()
public void move(Grid grid)
public void draw(java.awt.Graphics2D g2d,
javax.swing.JComponent canvas)
public void moveAI(Grid grid, Character[] c)
public void doAnim()
public void keyPressed(int key)
keyPressed in class Characterkey - Integer representing the key pressedpublic void keyReleased(int key)
keyReleased in class Characterkey - int representing the key that was pressedpublic void loadImages()
loadImages in class Characterpublic void loadAudio()
public void playAudio(int sound)
sound - sound effect IDpublic java.awt.Image getLifeImage()
getLifeImage in class Character