-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSpikeTile.java
More file actions
66 lines (53 loc) · 1.69 KB
/
Copy pathSpikeTile.java
File metadata and controls
66 lines (53 loc) · 1.69 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
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class SpikeTile here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class SpikeTile extends Tile
{
private GreenfootImage[] images;
private int act, period, countdown, activationTime = 45, cooldown = 10;
private boolean trapActive;
public SpikeTile(){
super("tile_spike0.png", 's');
images = new GreenfootImage[2];
images[0] = new GreenfootImage("tile_spike0.png");
images[1] = new GreenfootImage("tile_spike1.png");
act = 0;
period = 60 * cooldown;
trapActive = false;
countdown = activationTime;
}
/**
* Act - do whatever the SpikeTile wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
super.act();
act++;
if (act % period == 0){
trapActive = true;
setImage(images[1]);
}
if (trapActive){
//deal damage to intersecting hurtables
java.util.List<HurtableEntity> hurtables = getWorld().getObjects(HurtableEntity.class);
if (hurtables.size() != 0){
for (HurtableEntity h : hurtables){
if (h.getCollider().getIntersectingTiles().contains(this)){
h.takeDamage(1);
}
}
}
countdown--;
if (countdown == 0){
setImage(images[0]);
countdown = activationTime;
trapActive = false;
}
}
}
}