-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVampire.java
More file actions
117 lines (109 loc) · 3.32 KB
/
Copy pathVampire.java
File metadata and controls
117 lines (109 loc) · 3.32 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
107
108
109
110
111
112
113
114
115
116
117
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Vampire here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Vampire extends Enemy
{
private GreenfootImage[] vampireUp = {
new GreenfootImage("vampire/vu1.png"),
new GreenfootImage("vampire/vu2.png"),
new GreenfootImage("vampire/vu3.png"),
new GreenfootImage("vampire/vu4.png"),
};
private GreenfootImage[] vampireDown = {
new GreenfootImage("vampire/vd1.png"),
new GreenfootImage("vampire/vd2.png"),
new GreenfootImage("vampire/vd3.png"),
new GreenfootImage("vampire/vd4.png"),
};
private GreenfootImage[] vampireRight = {
new GreenfootImage("vampire/vr1.png"),
new GreenfootImage("vampire/vr2.png"),
new GreenfootImage("vampire/vr3.png"),
new GreenfootImage("vampire/vr4.png"),
};
private GreenfootImage[] vampireLeft = {
new GreenfootImage("vampire/vl1.png"),
new GreenfootImage("vampire/vl2.png"),
new GreenfootImage("vampire/vl3.png"),
new GreenfootImage("vampire/vl4.png"),
};
private int frame = 0;
public Vampire(){
super(2, 1);
}
public void act()
{
super.act();
super.enemyDead(this, 5);
getImage().scale(22,22);
animation();
frame++;
}
private void animation(){
if (this.getRotation() >= 316 || this.getRotation() <= 45){
rightAnimation();
}else if(this.getRotation() >= 46 && this.getRotation() <= 135){
upAnimation();
}else if(this.getRotation() >= 136 && this.getRotation() <= 225){
leftAnimation();
}else if(this.getRotation() >= 226 && this.getRotation() <= 315){
downAnimation();
}
}
private void upAnimation()
{
if(frame == 0) {
this.setImage(vampireUp[0]);
}else if(frame == 10) {
this.setImage(vampireUp[1]);
}else if(frame == 20) {
this.setImage(vampireUp[2]);
}else if(frame == 30) {
this.setImage(vampireUp[3]);
frame = 0;
}
}
private void downAnimation()
{
if(frame == 0) {
this.setImage(vampireDown[0]);
}else if(frame == 10) {
this.setImage(vampireDown[1]);
}else if(frame == 20) {
this.setImage(vampireDown[2]);
}else if(frame == 30) {
this.setImage(vampireDown[3]);
frame = 0;
}
}
private void rightAnimation()
{
if(frame == 0) {
this.setImage(vampireRight[0]);
}else if(frame == 10) {
this.setImage(vampireRight[1]);
}else if(frame == 20) {
this.setImage(vampireRight[2]);
}else if(frame == 30) {
this.setImage(vampireRight[3]);
frame = 0;
}
}
private void leftAnimation()
{
if(frame == 0) {
this.setImage(vampireLeft[0]);
}else if(frame == 10) {
this.setImage(vampireLeft[1]);
}else if(frame == 20) {
this.setImage(vampireLeft[2]);
}else if(frame == 30) {
this.setImage(vampireLeft[3]);
frame = 0;
}
}
}