-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBoss.java
More file actions
106 lines (102 loc) · 2.82 KB
/
Boss.java
File metadata and controls
106 lines (102 loc) · 2.82 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
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.util.List;
/**
* Write a description of class Boss here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Boss extends ScrollingActor
{
/**
* Act - do whatever the Boss wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
int health = 100;
int speed = 5;
int mobbyDist = 1000;
boolean changeDir;
private int timer;
private static final int TIMER = 130;
boolean dead = false;
int size = 1;
private double runningFrameTime = 0;
int runningFrameSpeed = 18;
private GreenfootSound gunshot = new GreenfootSound("gunshot.mp3");
GreenfootImage Img2 = new GreenfootImage("bossRun.png");
GreenfootImage Img1 = new GreenfootImage("bossStill.png");
public Boss()
{
timer = TIMER;
}
public void act()
{
// Add your action code here.
checkHit();
if (!dead) checkMobby();
}
public void checkMobby()
{
List<Mobby> list; // takes the actor Mobby into the list
list = getObjectsInRange(mobbyDist, Mobby.class);
if (!list.isEmpty())
{
pace();
shoot();
}
}
public void checkHit()
{
GlassDebris glassHit = (GlassDebris) getOneIntersectingObject(GlassDebris.class);
if (glassHit != null)
{
getWorld().removeObject(glassHit);
health -= 20;
if (health == 0)
{
dead = true;
getWorld().removeObject(this);
YouWin win = new YouWin();
Greenfoot.setWorld(win);
}
}
}
public void pace()
{
if (timer != 0)
{
move(speed);
if (runningFrameTime == runningFrameSpeed)
{
runningFrameTime = 0;
}
if (runningFrameTime == 0) {
setImage(Img1);
}
if (runningFrameTime == runningFrameSpeed / 2) {
setImage(Img2);
}
runningFrameTime++;
timer--;
}
if (timer == 0)
{
speed = speed * -1;
timer = TIMER;
}
}
int shotTimer = 120;
int shotTime = 120;
public void shoot()
{
Bullet bullet = new Bullet(size);
shotTimer--;
if (shotTimer <= 0)
{
getWorld().addObject(bullet, getX() - 125, getY() + 55 + size*6);
gunshot.play();
bullet.setRotation(180);
shotTimer = shotTime;
}
}
}