forked from scnerd/Purebread-Ninja
-
Notifications
You must be signed in to change notification settings - Fork 0
/
JamFisher.java
executable file
·118 lines (102 loc) · 2.87 KB
/
JamFisher.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import greenfoot.*;
import purebreadninja.*;
import static purebreadninja.CharacterAction.*;
public class JamFisher extends Enemy
{
private int alert_wait_time = 200;
private int aggresive_wait_time = 200;
private int wait_time = 0;
private double last_angle = 0;
private int DEFAULT_SHOOTING_TICKS = 20;
private int shooting_ticks = 0;
private int DEFAULT_DYING_TICKS = 35;
private int dying_ticks = 0;
@Animates(IDLE)
@DefaultAnimation
public Sprite idle = Sprite.ImageSheet("JamFisherIdle.png", 5);
@Animates(ATTACKING)
public Sprite attacking = Sprite.ImageSheet("JamFisherAttack.png", 3);
@Animates(DYING)
public Sprite dying = Sprite.ImageSheet("JamFisherDeath.png", 10);
private GreenfootSound shootSound = new GreenfootSound("sounds/pew.wav");
public JamFisher()
{
// VISION_RANGE = 400, PROXIMITY_RANGE = 200
super(380, 200);
}
public void act()
{
if (isDying)
{
if (dying_ticks-- <= 0)
{
getWorld().removeObject(this);
return;
}
}
else
{
if (shooting_ticks <= 0)
{
currentAction = IDLE;
}
else
shooting_ticks--;
if (playerInProximity() || playerInRange())
{
last_angle = getAngleToPlayer();
facePlayer();
aggresive();
}
else if (sawPlayer)
{
engagedPlayer = false;
alert();
}
}
super.act();
}
private void shootSeed()
{
try
{
currentAction = ATTACKING;
shooting_ticks = DEFAULT_SHOOTING_TICKS;
BulletSeed bullet = new BulletSeed(last_angle);
this.getWorld().addObject(bullet, this.getX(), this.getY() - 10);
shootSound.play();
} catch(Exception ex) {}
}
private void alert()
{
if (wait_time == alert_wait_time)
{
shootSeed();
}
else if (wait_time == alert_wait_time * (1/2.0))
{
last_angle = last_angle == 0 ? Math.PI : 0;
flipFrames = !flipFrames;
}
if (wait_time-- < 0) { wait_time = alert_wait_time; }
}
private void aggresive()
{
if (wait_time == aggresive_wait_time)
{
shootSeed();
}
else if (wait_time == aggresive_wait_time * (6/8.0))
{
shootSeed();
}
if (wait_time-- < 0) { wait_time = aggresive_wait_time; }
}
@Override
protected void die()
{
isDying = true;
dying_ticks = DEFAULT_DYING_TICKS;
currentAction = DYING;
}
}