11package com .redomar .game .entities ;
22
3- import javax .swing .JOptionPane ;
4-
53import com .redomar .game .Game ;
64import com .redomar .game .gfx .Colours ;
75import com .redomar .game .gfx .Screen ;
@@ -11,83 +9,25 @@ public class Dummy extends Mob{
119
1210 private int colour , shirtCol , faceCol ; //= Colours.get(-1, 111, 240, 310);
1311 private int tickCount = 0 ;
14- private int tick = 0 ;
1512 private int xa = 0 ;
1613 private int ya = 0 ;
17- private int xes = 0 ;
1814
1915 public Dummy (LevelHandler level , String name , int x , int y , int shirtCol , int faceCol ) {
2016 super (level , "h" , x , y , 1 );
2117 this .faceCol = faceCol ;
2218 this .shirtCol = shirtCol ;
2319 this .colour = Colours .get (-1 , 111 , shirtCol , faceCol );
2420 }
25-
26- public boolean hasCollided (int xa , int ya ) {
27- int xMin = 0 ;
28- int xMax = 7 ;
29- int yMin = 3 ;
30- int yMax = 7 ;
31-
32- for (int x = xMin ; x < xMax ; x ++) {
33- if (isSolid (xa , ya , x , yMin )) {
34- return true ;
35- }
36- }
37-
38- for (int x = xMin ; x < xMax ; x ++) {
39- if (isSolid (xa , ya , x , yMax )) {
40- return true ;
41- }
42- }
43-
44- for (int y = yMin ; y < yMax ; y ++) {
45- if (isSolid (xa , ya , xMin , y )) {
46- return true ;
47- }
48- }
49-
50- for (int y = yMin ; y < yMax ; y ++) {
51- if (isSolid (xa , ya , xMax , y )) {
52- return true ;
53- }
54- }
55-
56- return false ;
57- }
5821
5922 public void tick () {
60- tick ++;
61- if (tick % (random .nextInt (50 ) +30 ) == 0 ){
62- xa = random .nextInt (3 ) -1 ;
63- ya = random .nextInt (3 ) -1 ;
64- if (random .nextInt (4 ) == 0 ){
65- xa = 0 ;
66- ya = 0 ;
67- }
68- }
6923
70- if (Game .getPlayer ().x == x && Game .getPlayer ().y == y && xes == 0 ){
71- JOptionPane .showMessageDialog (Game .getGame (), "Zombie Eat You @" +x +" " +y , "Zombie" , 1 );
72- xes ++;
73- }
74-
75- if (xa != 0 || ya != 0 ) {
76- move (xa , ya );
77- isMoving = true ;
78-
79- // Packet02Move packet = new Packet02Move(this.getUsername(), this.x, this.y, this.numSteps, this.isMoving, this.movingDir);
80- // packet.writeData(Game.getGame().getSocketClient());
81-
82- } else {
83- isMoving = false ;
84- }
24+ followMovementAI (getX (), getY (), Game .getPlayer ().getX (), Game .getPlayer ().getY (), xa , ya , this );
8525
86- if (level .getTile (this .x >> 3 , this .y >> 3 ).getId () == 4 ) {
26+ if (level .getTile (this .getX () >> 3 , this .getY () >> 3 ).getId () == 4 ) {
8727 isSwimming = true ;
8828 }
8929
90- if (isSwimming && level .getTile (this .x >> 3 , this .y >> 3 ).getId () != 4 ) {
30+ if (isSwimming && level .getTile (this .getX () >> 3 , this .getY () >> 3 ).getId () != 4 ) {
9131 isSwimming = false ;
9232 }
9333
@@ -110,8 +50,8 @@ public void render(Screen screen) {
11050 }
11151
11252 int modifier = 8 * scale ;
113- int xOffset = x - modifier / 2 ;
114- int yOffset = y - modifier / 2 - 4 ;
53+ int xOffset = getX () - modifier / 2 ;
54+ int yOffset = getY () - modifier / 2 - 4 ;
11555
11656 if (isSwimming ) {
11757 int waterColour = 0 ;
@@ -152,4 +92,36 @@ public void render(Screen screen) {
15292 }
15393 }
15494
95+ public boolean hasCollided (int xa , int ya ) {
96+ int xMin = 0 ;
97+ int xMax = 7 ;
98+ int yMin = 3 ;
99+ int yMax = 7 ;
100+
101+ for (int x = xMin ; x < xMax ; x ++) {
102+ if (isSolid (xa , ya , x , yMin )) {
103+ return true ;
104+ }
105+ }
106+
107+ for (int x = xMin ; x < xMax ; x ++) {
108+ if (isSolid (xa , ya , x , yMax )) {
109+ return true ;
110+ }
111+ }
112+
113+ for (int y = yMin ; y < yMax ; y ++) {
114+ if (isSolid (xa , ya , xMin , y )) {
115+ return true ;
116+ }
117+ }
118+
119+ for (int y = yMin ; y < yMax ; y ++) {
120+ if (isSolid (xa , ya , xMax , y )) {
121+ return true ;
122+ }
123+ }
124+
125+ return false ;
126+ }
155127}
0 commit comments