-
Notifications
You must be signed in to change notification settings - Fork 1
/
Erik.java
90 lines (80 loc) · 2.61 KB
/
Erik.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
import java.util.Random;
import java.net.*;
// This contains the images of Erik and all the methods to do with her.
public class Erik extends MovableWithDir
{
Play play;
int offDir;
ErikThread thethread;
// At the start, Erik's images and location are set. Then the thred which
// controls him throwing rubbish at ian is started
Erik( Play parent )
{
play = parent;
// Load images and set location
loadImages("erik");
setImage( 1, 580, 440 );
setImageSize();
makeTheMove();
// Start the thread
thethread = new ErikThread( this );
}
// This is the getter for getOffDir.
public int getOffDir()
{
return offDir;
}
//This throws a peice of rubbish to ian.
public void throwRubbish()
{
play.getMaster().newErik();
play.getMaster().getErik().beThrown();
}
// This method makes erik walk from a random position of frame on to the
// frame, throw a peice of rubbish and then walk off.
public void walkToThrow()
{
Random randomGenerator = new Random();
int xTarget;
int yTarget;
MovementDetails details = new MovementDetails();
switch( randomGenerator.nextInt() % 3 )
{
case 0:
yTarget = 335 + Math.abs(randomGenerator.nextInt() % 91 );
setLoadedImage( 1, 0, -100, yTarget );
details.addEntry(000, yTarget, 15);
addThrow( details );
details.addEntry( -100, yTarget, 20 );
offDir = 3;
break;
case 1:
xTarget = 700;
yTarget = 195 + Math.abs(randomGenerator.nextInt() % 100 );
setLoadedImage( 1, 0, 830, yTarget );
details.addEntry(700, yTarget, 15);
addThrow( details );
details.addEntry( 830, yTarget, 20 );
offDir = 1;
break;
case 2:
default:
xTarget = 230 + Math.abs(randomGenerator.nextInt() % 340);//570
yTarget = 500;
setLoadedImage( 1, 0, xTarget, 600 );
details.addEntry(xTarget, 485, 15);
addThrow( details );
details.addEntry( xTarget, 600, 20 );
offDir = 2;
break;
}
play.getIan().erikWalking(offDir);
moveObject( details );
}
private void addThrow( MovementDetails details )
{
details.addEntry( 250 );
details.addEntry( this );
details.addEntry( 250 );
}
}