-
Notifications
You must be signed in to change notification settings - Fork 0
/
Crabby.java
96 lines (81 loc) · 2.57 KB
/
Crabby.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package entities;
import static utilz.Constants.EnemyConstants.*;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.geom.Rectangle2D;
import static utilz.Constants.Directions.*;
import main.Game;
import main.ScoreManager;
public class Crabby extends Enemy {
private int attackBoxOffsetX;
private ScoreManager scoreManager;
public Crabby(float x, float y, ScoreManager scoreManager) {
super(x, y, CRABBY_WIDTH, CRABBY_HEIGHT, CRABBY, scoreManager);
initHitbox(22, 19);
initAttackBox();
this.scoreManager = scoreManager;
}
private void initAttackBox() {
attackBox = new Rectangle2D.Float(x, y, (int) (82 * Game.SCALE), (int) (19 * Game.SCALE));
attackBoxOffsetX = (int) (Game.SCALE * 30);
}
public void update(int[][] lvlData, Player player) {
updateBehavior(lvlData, player);
updateAnimationTick();
updateAttackBox();
}
private void updateAttackBox() {
attackBox.x = hitbox.x - attackBoxOffsetX;
attackBox.y = hitbox.y;
}
private void updateBehavior(int[][] lvlData, Player player) {
if (firstUpdate) {
firstUpdateCheck(lvlData);
}
if (inAir) {
updateInAir(lvlData);
} else {
switch (state) {
case IDLE:
newState(RUNNING);
break;
case RUNNING:
if (canSeePlayer(lvlData, player)) {
turnTowardsPlayer(player);
if (isPlayerCloseForAttack(player)) {
newState(ATTACK);
}
}
move(lvlData);
break;
case ATTACK:
if (aniIndex == 0) {
attackChecked = false;
}
if (aniIndex == 3 && !attackChecked) {
checkPlayerHit(attackBox, player);
scoreManager.addToTotalScore(10);
attackChecked = true;
}
break;
case HIT:
break;
}
}
}
// Os métodos flipX e flipW podem ser úteis para determinar a orientação do inimigo
public int flipX() {
if (walkDir == RIGHT) {
return width;
} else {
return 0;
}
}
public int flipW() {
if (walkDir == RIGHT) {
return -1;
} else {
return 1;
}
}
}