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
/
Shard.java
74 lines (67 loc) · 1.56 KB
/
Shard.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
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Shard here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Shard extends myActor
{
boolean moving;
String prefix;
int frame;
Tank parent;
public final double frameChangeChance=1;
public Shard() {
this(null);
}
public Shard(Tank t) {
super(new myList<Actor>(t));
moving=true;
int id=Math.abs(t.getID()%4);
try {
prefix="Tank"+id+"p5f";
}
catch(NullPointerException npe) {
prefix="Tank0p5f";
}
setImage(prefix+"0.png");
distance=5;
parent=t;
}
@Override
public void addedToWorld(World w) {
setRotation((int)(Math.random()*360));
}
@Override
public boolean intersectsTanks() {
return true;
}
/**
* 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");
}
}
}
}