This repository has been archived by the owner on Nov 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDeadlyShard.java
79 lines (74 loc) · 1.87 KB
/
DeadlyShard.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
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.util.*;
/**
* Write a description of class DeadlyShard here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class DeadlyShard extends Bullet
{
boolean moving;
String prefix;
int frame;
int id;
public final double frameChangeChance=.4;
public DeadlyShard(Trap t) {
super(t.getCreator());
distance=12;
moving=true;
id=t.getID();
try {
id=t.getID();
prefix="Tank"+id+"p5f";
}
catch(NullPointerException npe) {
prefix="Tank0p5f";
}
setImage(prefix+"0.png");
distance=5;
}
@Override
public void addedToWorld(World w) {
super.addedToWorld(w);
setRotation((int)(Math.random()*360));
}
/**
* Act - do whatever the Shard wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
@Override
public void act()
{
if(moving){
turn(-45);
if(blocked()) {
moving=false;
}
else {
move();
}
turn(45);
}
if(Math.random()<frameChangeChance) {
frame++;
if(frame>11) {
getWorld().removeObject(this);
}
else {
setImage(prefix+frame+".png");
}
}
if(getWorld()!=null) {
List<Tank>neighboring=getIntersectingObjects(Tank.class);
for(Tank a:neighboring) {
if(debug) {
System.out.println("Destroying "+a.toString()+".");
}
if(a.killed()==-1) {
a.destroyed(this);
}
}
}
}
}