Skip to content

Commit fa55aa8

Browse files
committed
Changed collisions for mobs
Seperated mob and player collision, now they have there own individual collision boundries Modified A* search algorithm so mobs can go diagonal freely Started expirimenting with javadocs
1 parent 416b7d5 commit fa55aa8

File tree

5 files changed

+23
-9
lines changed

5 files changed

+23
-9
lines changed

src/com/redomar/game/Game.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ public class Game extends Canvas implements Runnable {
8686
private GameServer socketServer;
8787
private Printing print = new Printing();
8888

89+
/**
90+
* @author Redomar
91+
* @version Alpha 1.7
92+
*/
8993
public Game() {
9094
setMinimumSize(new Dimension(WIDTH * SCALE, HEIGHT * SCALE));
9195
setMaximumSize(new Dimension(WIDTH * SCALE, HEIGHT * SCALE));

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@ public class Dummy extends Mob {
2020
private static double speed = 0.75;
2121
private List<Node> path = null;
2222
private int time = 0;
23+
private static int[] collisionBoders = {0, 7, 0, 7};
2324

2425
private Swim swim;
2526

2627
public Dummy(LevelHandler level, String name, int x, int y, int shirtCol,
2728
int faceCol) {
28-
super(level, "h", x, y, speed);
29+
super(level, "h", x, y, speed, collisionBoders);
2930
this.faceCol = faceCol;
3031
this.shirtCol = shirtCol;
3132
this.colour = Colours.get(-1, 111, shirtCol, faceCol);

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,21 @@ public abstract class Mob extends Entity {
2222
protected boolean isMuddy = false;
2323
protected boolean changeLevels = false;
2424
protected int ticker;
25-
26-
public Mob(LevelHandler level, String name, int x, int y, double speed) {
25+
/**
26+
* [0] Contains the <strong>xMin</strong><br>
27+
* [1] Contains the <strong>xMax</strong><br>
28+
* [2] Contains the <strong>yMin</strong><br>
29+
* [3] Contains the <strong>yMax
30+
*/
31+
protected int[] collisionBoders = new int[4];
32+
33+
public Mob(LevelHandler level, String name, int x, int y, double speed, int[] collisionBoders) {
2734
super(level);
2835
this.name = name;
2936
this.setX(x);
3037
this.setY(y);
3138
this.speed = speed;
39+
this.collisionBoders = collisionBoders;
3240
}
3341

3442
public void move(double xa, double ya) {
@@ -90,10 +98,10 @@ public void move(double xa, double ya) {
9098
}
9199

92100
public boolean hasCollided(double xa, double ya){
93-
int xMin = -2;
94-
int xMax = 8;
95-
int yMin = 0;
96-
int yMax = 7;
101+
int xMin = collisionBoders[0];
102+
int xMax = collisionBoders[1];
103+
int yMin = collisionBoders[2];
104+
int yMax = collisionBoders[3];
97105

98106
for (int x = xMin; x < xMax; x++) {
99107
if (isSolid((int) xa, (int) ya, x, yMin)) {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,13 @@ public class Player extends Mob {
2424
private String userName;
2525
private boolean[] swimType;
2626
private int[] swimColour;
27+
private static int[] collisionBoders = {-2, 8, 0, 7};
2728

2829
public static String guestPlayerName = customeName.setName("Player ");
2930

3031
public Player(LevelHandler level, int x, int y, InputHandler input,
3132
String userName, int shirtCol, int faceCol) {
32-
super(level, "Player", x, y, speed);
33+
super(level, "Player", x, y, speed, collisionBoders);
3334
this.input = input;
3435
this.userName = userName;
3536
this.faceCol = faceCol;

src/com/redomar/game/level/LevelHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ public List<Node> findPath(Vector2i start, Vector2i goal){
237237
if(at == null) continue;
238238
if(at.isSolid()) continue;
239239
Vector2i a = new Vector2i(x + xi, y + yi);
240-
double gCost = current.gCost + getDistance(current.tile, a);
240+
double gCost = current.gCost + (getDistance(current.tile, a) == 1 ? 1 : 0.95);
241241
double hCost = getDistance(a, goal);
242242
Node node = new Node(a, current, gCost, hCost);
243243
if(isVectorInList(closedList, a) && gCost >= node.gCost) continue;

0 commit comments

Comments
 (0)