-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBogdan.java
More file actions
158 lines (135 loc) · 4.91 KB
/
Bogdan.java
File metadata and controls
158 lines (135 loc) · 4.91 KB
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
import java.awt.*;
import java.net.*;
// This contains the images of Bogdan and all the methods to do with him.
public class Bogdan extends MovableWithDir
{
private Image[] sleepingImages = new Image[2];
private Image[][] sleepingImagesStore = new Image[4][2];
private Thread sleepingThread;
private BogdanBinThread bogdanbinthread;
private int sleepingIndex = 0;
private int noiseCount = 0;
private Boolean sleeping = true;
private Play play;
private int sleepingWait;
// The constructor loads all the images which will be used. It then sets
// up the images we want to run first and starts him sleeping.
Bogdan( Play obj )
{
play = obj;
loadImages("bogdan");
sleepingImagesStore[0][0] = readImage("img/bogdan/bogdansleep1.png");
sleepingImagesStore[0][1] = readImage("img/bogdan/bogdansleep2.png");
sleepingImagesStore[1][0] = readImage("img/bogdan/bogdanangry1a.png");
sleepingImagesStore[1][1] = readImage("img/bogdan/bogdanangry1b.png");
sleepingImagesStore[2][0] = readImage("img/bogdan/bogdanangry2a.png");
sleepingImagesStore[2][1] = readImage("img/bogdan/bogdanangry2b.png");
sleepingImagesStore[3][0] = readImage("img/bogdan/bogdanangry3a.png");
sleepingImagesStore[3][1] = readImage("img/bogdan/bogdanangry3b.png");
startSleeping();
}
// This starts Bogdan sleeping. It sets his co-ordinates, the images he will
// need and then starts the thread which will call the changes to his
// images as he sleeps.
private void startSleeping()
{
// Set up co-ordinates
xPos = 65;
yPos = 180;
// Set up images
setSleepingImages(0);
myimage = sleepingImages[0];
setImageSize();
makeTheMove();
// Start the thread
sleepingThread = new BogdanThread( this );
sleepingThread.start();
}
// This is called when someone in the game makes a noise. Bogdan doesnt like
// noises, so it adds one to the counter and takes the appropriate action if
// the counter is at specific places.
public void noise()
{
// The noises only count is Bogdan is sleeping
if ( !sleeping )
return;
noiseCount++;
// Change his images to get more angier at a count of 2, 4 and 6.
if ( noiseCount == 3 )
setSleepingImages(1);
else if ( noiseCount == 6 )
setSleepingImages(2);
else if ( noiseCount == 9 )
setSleepingImages(3);
// If it is 8, he should walk up and knock all the bins over.
else if ( noiseCount == 12 )
{
sleeping = false;
setLoadedImage(2,0,65,180);
MovementDetails details = new MovementDetails();
details.addEntry( 65, 250, 20 );
details.addEntry( 90, 250, 20 );
moveObject( details );
bogdanbinthread = new BogdanBinThread(this, play);
bogdanbinthread.start();
}
}
// This is called when all the bins have been knocked over. The method makes
// him walk back to where he was sleeping.
public void walkBack()
{
MovementDetails details = new MovementDetails();
details.addEntry( 65, 250, 20 );
details.addEntry( 65, 180, 20 );
moveObject(details);
}
// This is called when he reaches where he sleeps. The method sets
// everything up for him to sleep and count noises again.
public void sitBackDown()
{
sleepingImages[0] = sleepingImagesStore[0][0];
sleepingImages[1] = sleepingImagesStore[0][1];
sleeping = true;
startSleeping();
noiseCount = 0;
}
// This is called by his sleeping thread. Everytime it is called, Bogdans
// image flips back and forth between the images
public void changeSleepingImage()
{
if ( sleepingIndex == 0 )
{
myimage = sleepingImages[0];
sleepingIndex = 1;
}else{
myimage = sleepingImages[1];
sleepingIndex = 0;
}
makeTheMove();
}
// This is the getter for sleeping.
public Boolean keepSleeping()
{
return sleeping;
}
// This returns the image "img/bogdan/bogdan" + name + ".png".
private Image grabBogdanSleeping( String name )
{
String url = "img/bogdan/bogdan" + name + ".png";
return readImage( url );
}
// This changes the images of him sleeping
private void setSleepingImages( int level )
{
sleepingImages[0] = sleepingImagesStore[level][0];
sleepingImages[1] = sleepingImagesStore[level][1];
// This is the amount of time which the thread waits between changing
// the images.
sleepingWait = ( 4 - level ) * 269;
}
// This is the getter for sleepWait.
public int getSleepingWait()
{
return sleepingWait;
}
}