-
Notifications
You must be signed in to change notification settings - Fork 1
/
ConeheadZombie.java
102 lines (84 loc) · 2.73 KB
/
ConeheadZombie.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Defines the attributes and behaviors of a traffic cone-wearing walking Zombie
*
* TODO: I should remove the cone (convert to basic zombie) after a certain number of hits
*
* @author bcanada
* @version 2014.01.17
*/
public class ConeheadZombie extends Zombie
{
/*
* Declare instance variables
*/
private GreenfootImage[] imgFrames;
private int numFrames = 51;
private int currentImgNum;
private int cycleCount;
/**
* Initialize coneheadZombie object
*/
public ConeheadZombie()
{
// setup array of images
imgFrames = new GreenfootImage[ numFrames ];
// initialize current image animation frame number to randomly selected value
currentImgNum = Greenfoot.getRandomNumber( numFrames );
// initialize cycle count
cycleCount = 1;
hitPoints = 10;
// initialize animation frames for this object
for ( int i = 0 ; i < imgFrames.length; i++ )
{
imgFrames[ i ] = new GreenfootImage("coneheadZombie" + i + ".png");
} // end for
width = imgFrames[ 0 ].getWidth();
height = imgFrames[ 0 ].getHeight();
} // end constructor for ConeheadZombie
/**
* Act - do whatever the BasicZombie wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
/*
* Assuming standard execution speed, update new animation frame
* every fifth cycle through the object's act() method
*/
if ( cycleCount % 3 == 0 ) // i.e., "if the current value of cycleCount is divisible by 5..."
{
updateImage();
cycleCount = 1;
}
else // otherwise, increment the value of cycleCount by 1
{
cycleCount++;
} // end if-else
checkForHit();
if ( !isDying )
{
move();
}
else // if dying, then...
{
super.animateDeath();
} // end if/else
} // end method act
/**
* Updates the object's image to the next animation frame in sequence
*/
public void updateImage()
{
setImage( imgFrames[ currentImgNum ] );
// Reset currentImgNum for the next animation cycle
if ( currentImgNum == (numFrames - 1) )
{
currentImgNum = 0;
}
else
{
currentImgNum++;
} // end if-else
} // end method updateImage
} // end class ConeheadZombie