Skip to content

Commit 88ecfe5

Browse files
committed
Fixed an issue with the facing of the player direction
Fixed an issue where the player is facing the last way they were before the encount a wall Moved around collision code
1 parent cf255b0 commit 88ecfe5

File tree

3 files changed

+49
-78
lines changed

3 files changed

+49
-78
lines changed

src/com/redomar/game/entities/Dummy.java

Lines changed: 5 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ public void tick() {
3333
if (players.size() > 0) {
3434
followMovementAI(getX(), getY(), Game.getPlayer().getX(), Game
3535
.getPlayer().getY(), xa, ya, this);
36+
}else{
37+
isMoving = false;
3638
}
3739

3840
setSwim(new Swim(level, getX(), getY()));
@@ -62,6 +64,9 @@ public void render(Screen screen) {
6264
} else if (movingDir > 1) {
6365
xTile += 4 + ((numSteps >> walkingSpeed) & 1) * 2;
6466
flipTop = (movingDir - 1) % 2;
67+
if(!isMoving){
68+
xTile = 4;
69+
}
6570
}
6671

6772
int modifier = 8 * scale;
@@ -109,39 +114,6 @@ public void render(Screen screen) {
109114
}
110115
}
111116

112-
public boolean hasCollided(int xa, int ya) {
113-
int xMin = 0;
114-
int xMax = 7;
115-
int yMin = 3;
116-
int yMax = 7;
117-
118-
for (int x = xMin; x < xMax; x++) {
119-
if (isSolid(xa, ya, x, yMin)) {
120-
return true;
121-
}
122-
}
123-
124-
for (int x = xMin; x < xMax; x++) {
125-
if (isSolid(xa, ya, x, yMax)) {
126-
return true;
127-
}
128-
}
129-
130-
for (int y = yMin; y < yMax; y++) {
131-
if (isSolid(xa, ya, xMin, y)) {
132-
return true;
133-
}
134-
}
135-
136-
for (int y = yMin; y < yMax; y++) {
137-
if (isSolid(xa, ya, xMax, y)) {
138-
return true;
139-
}
140-
}
141-
142-
return false;
143-
}
144-
145117
public Swim getSwim() {
146118
return swim;
147119
}

src/com/redomar/game/entities/Mob.java

Lines changed: 44 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,25 +43,57 @@ public void move(int xa, int ya) {
4343
//2 = Facing Left
4444
//3 = Facing Right
4545

46+
if (ya < 0) {
47+
movingDir = 0;
48+
}
49+
if (ya > 0) {
50+
movingDir = 1;
51+
}
52+
if (xa < 0) {
53+
movingDir = 2;
54+
}
55+
if (xa > 0) {
56+
movingDir = 3;
57+
}
58+
4659
if (!hasCollided(xa, ya)) {
47-
if (ya < 0) {
48-
movingDir = 0;
60+
setX(getX() + xa * (int) speed);
61+
setY(getY() + ya * (int) speed);
62+
}
63+
}
64+
65+
public boolean hasCollided(int xa, int ya){
66+
int xMin = 0;
67+
int xMax = 7;
68+
int yMin = 3;
69+
int yMax = 7;
70+
71+
for (int x = xMin; x < xMax; x++) {
72+
if (isSolid(xa, ya, x, yMin)) {
73+
return true;
4974
}
50-
if (ya > 0) {
51-
movingDir = 1;
75+
}
76+
77+
for (int x = xMin; x < xMax; x++) {
78+
if (isSolid(xa, ya, x, yMax)) {
79+
return true;
5280
}
53-
if (xa < 0) {
54-
movingDir = 2;
81+
}
82+
83+
for (int y = yMin; y < yMax; y++) {
84+
if (isSolid(xa, ya, xMin, y)) {
85+
return true;
5586
}
56-
if (xa > 0) {
57-
movingDir = 3;
87+
}
88+
89+
for (int y = yMin; y < yMax; y++) {
90+
if (isSolid(xa, ya, xMax, y)) {
91+
return true;
5892
}
59-
setX(getX() + xa * (int) speed);
60-
setY(getY() + ya * (int) speed);
6193
}
62-
}
6394

64-
public abstract boolean hasCollided(int xa, int ya);
95+
return false;
96+
}
6597

6698
protected boolean isSolid(int xa, int ya, int x, int y) {
6799

src/com/redomar/game/entities/Player.java

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -161,39 +161,6 @@ public void render(Screen screen) {
161161
}
162162
}
163163

164-
public boolean hasCollided(int xa, int ya) {
165-
int xMin = 0;
166-
int xMax = 7;
167-
int yMin = 3;
168-
int yMax = 7;
169-
170-
for (int x = xMin; x < xMax; x++) {
171-
if (isSolid(xa, ya, x, yMin)) {
172-
return true;
173-
}
174-
}
175-
176-
for (int x = xMin; x < xMax; x++) {
177-
if (isSolid(xa, ya, x, yMax)) {
178-
return true;
179-
}
180-
}
181-
182-
for (int y = yMin; y < yMax; y++) {
183-
if (isSolid(xa, ya, xMin, y)) {
184-
return true;
185-
}
186-
}
187-
188-
for (int y = yMin; y < yMax; y++) {
189-
if (isSolid(xa, ya, xMax, y)) {
190-
return true;
191-
}
192-
}
193-
194-
return false;
195-
}
196-
197164
public String getUsername() {
198165
if (this.userName.isEmpty()) {
199166
return guestPlayerName;

0 commit comments

Comments
 (0)