-
Notifications
You must be signed in to change notification settings - Fork 1
/
BasicZombieWaiting.java
84 lines (69 loc) · 2.28 KB
/
BasicZombieWaiting.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
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Class to define a basic (non-bucket-wearing) "waiting zombie" that appears
* at the beginning of the stage
*
* TODO: Take redundant/common code from this class and move it to
* the ZombieWaiting superclass
*
* @author bcanada
* @version 2014.01.17
*/
public class BasicZombieWaiting extends ZombieWaiting
{
private GreenfootImage[] imgFrames; // <-- should this be part of the superclass?
private int numFrames = 16; // <-- make this a constant?
private int currentImgNum;
private int cycleCount;
/**
* Initialize stationary zombie object
*/
public BasicZombieWaiting()
{
// setup array of images
imgFrames = new GreenfootImage[ numFrames ];
// initialize current image animation frame number to zero
currentImgNum = Greenfoot.getRandomNumber( 16 );
// initialize cycle count (consider making this a constant?)
cycleCount = 1;
// initialize animation frames for this object
for ( int i = 0 ; i < imgFrames.length; i++ )
{
imgFrames[ i ] = new GreenfootImage("basicZombieWaiting" + i + ".png");
} // end for
} // end no-arg constructor
/**
* Act - do whatever the Peashooter 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 % 5 == 0 ) {
updateImage();
cycleCount = 1;
}
else
{
cycleCount++;
} // end if/else
} // end method act
/**
* Updates the image for the next pass through the game loop
*/
public void updateImage()
{
setImage( imgFrames[ currentImgNum ] );
if ( currentImgNum == (numFrames - 1) )
{
currentImgNum = 0;
}
else
{
currentImgNum++;
} // end if/else
} // end method updateImage
} // end class BasicZombieWaiting