-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEntities.java
More file actions
128 lines (107 loc) · 3.56 KB
/
Copy pathEntities.java
File metadata and controls
128 lines (107 loc) · 3.56 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
118
119
120
121
122
123
124
125
126
127
128
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.geom.AffineTransform;
import java.awt.image.AffineTransformOp;
public class Entities {
public GamePanel gp;
public int Worldx, Worldy;
public int speed;
public int width, height;
public int maxLife, life;
public boolean isDead = false;
public Image image;
public StripAnimation anim;
public String direction;
public Rectangle boundingBox;
public int boundsX, boundsY;
public boolean collision = false;
public String dialogue = "";
// Animation
public int actionCounter = 0;
public String name;
public Entities(GamePanel gp){
this.gp = gp;
getDirection();
}
public void setAction(){
actionCounter++;
}
public void update(){
setAction();
collision = false;
gp.cc.checkTile(this);
gp.cc.checkBoat(this, collision);
gp.cc.checkPlayer(this);
gp.cc.checkEntity(this, gp.hostile);
gp.cc.checkEntity(this, gp.neutral);
if (!collision) {
switch (direction) {
case "up":
Worldy -= speed;
break;
case "down":
Worldy += speed;
break;
case "left":
Worldx -= speed;
break;
case "right":
Worldx += speed;
break;
}
}
}
public void draw(Graphics2D g2){
int ScreenX = Worldx - gp.player.Worldx + gp.player.screenX;
int ScreenY = Worldy - gp.player.Worldy + gp.player.screenY;
int size = gp.getTileSize();
anim = getAnim();
if(Worldx + gp.getTileSize() > gp.player.Worldx - gp.player.screenX &&
Worldx - gp.getTileSize() < gp.player.Worldx + gp.player.screenX &&
Worldy + gp.getTileSize() > gp.player.Worldy - gp.player.screenY &&
Worldy - gp.getTileSize() < gp.player.Worldy + gp.player.screenY){
switch(direction){
case "up":
anim.draw(g2, ScreenX, ScreenY, size, size);
break;
case "down":
anim.draw(g2, ScreenX, ScreenY, size, size);
break;
case "left":
anim.draw(g2, ScreenX, ScreenY, size, size);
break;
case "right":
anim.draw(g2, ScreenX, ScreenY, size, size);
break;
case "attack1":
anim.draw(g2, ScreenX, ScreenY, size, size);
break;
}
//g2.setColor(Color.RED);
//g2.drawRect(ScreenX, ScreenY, size, size);
}
}
public void attack(Entities e){
if (e instanceof Deer) {
Deer deer = (Deer) e;
deer.life -= 1; // Decrement the life of the deer
if (deer.life <= 0) {
// Remove the deer from the game or perform any other necessary actions
}
} else if (e instanceof Bear) {
Bear bear = (Bear) e;
bear.life -= 1; // Decrement the life of the bear
if (bear.life <= 0) {
// Remove the bear from the game or perform any other necessary actions
}
}
}
public StripAnimation getAnim() {
return anim;
}
public String getDirection() {
return direction;
}
}