public class Ghost extends Character
| Modifier and Type | Field | Description |
|---|---|---|
static int |
defaultSpeed |
|
boolean |
edible |
|
int |
edibleTimer |
|
static int |
GHOST1 |
|
static int |
GHOST2 |
|
static java.lang.String |
IMAGE_PATH |
|
int |
prev_speed |
|
int |
type |
|
static int |
TYPE_PINK |
|
static int |
TYPE_RED |
| Constructor | Description |
|---|---|
Ghost(int x,
int y,
int speed,
int type) |
Ghost class constructor for singleplayer
|
Ghost(int x,
int y,
int speed,
int type,
int playerNum,
Grid grid) |
|
Ghost(int x,
int y,
int speed,
int playerNum,
Grid grid) |
Ghost class constructor for multiplayer
|
| Modifier and Type | Method | Description |
|---|---|---|
void |
death() |
Handles character's death
coordinates are reset to the coordinates that
the ghost initially started at and the ghost
becomes inedible
|
void |
death(int newX,
int newY) |
Handles character's death and allows specification of a new location
for the character to spawn at
|
void |
draw(java.awt.Graphics2D g,
javax.swing.JComponent canvas) |
Draws the ghost
|
java.awt.Image |
getLifeImage() |
Returns the image used for displaying remaining lives
|
void |
keyPressed(int key) |
Handles player keyboard input
|
void |
keyReleased(int key) |
Handles key releases for game controls
|
void |
loadImages() |
Load ghost sprites from images folder
|
void |
move(Grid grid) |
Moves character's current position with the board's collision
Handles logic pertaining to collision detection, movement, and standstill
|
void |
moveAI(Grid grid,
Character[] c) |
For ghosts that are close to pacman, have them follow pacman
with a specified probability
|
void |
moveRandom(Grid grid) |
Pick a random move from the list of available movement options
for the ghost to move in
|
Node |
pathFind(Grid grid,
int x,
int y) |
A* pathfinding algorithm
|
public static final java.lang.String IMAGE_PATH
public static final int TYPE_RED
public static final int TYPE_PINK
public static final int GHOST1
public static final int GHOST2
public static int defaultSpeed
public boolean edible
public int prev_speed
public int edibleTimer
public int type
public Ghost(int x,
int y,
int speed,
int type)
x - x-position of ghosty - y-position of ghostspeed - the ghost's initial movement speedtype - the type of ghostpublic Ghost(int x,
int y,
int speed,
int playerNum,
Grid grid)
x - x-positiony - y-positionspeed - initialplayerNum - a number to indicate which player is controlling this ghostgrid - the grid used to determine movement/collisionpublic Ghost(int x,
int y,
int speed,
int type,
int playerNum,
Grid grid)
public void death()
public void death(int newX,
int newY)
newX - the new x-coordinate that the ghost will respawn atnewY - the new y-coordinate that the ghost will respawn atpublic void draw(java.awt.Graphics2D g,
javax.swing.JComponent canvas)
public void loadImages()
loadImages in class Characterpublic java.awt.Image getLifeImage()
getLifeImage in class Characterpublic void keyPressed(int key)
keyPressed in class Characterkey - Integer representing the key pressedpublic void keyReleased(int key)
CharacterkeyReleased in class Characterkey - Integer representing the key releasedpublic void move(Grid grid)
public void moveAI(Grid grid, Character[] c)
public Node pathFind(Grid grid, int x, int y)
grid - the grid to be used for pathfindingx - target x coordinate in grid formy - target y coordinate in grid formpublic void moveRandom(Grid grid)
grid - The Grid to be used for collision