Skip to content

Commit

Permalink
fixed wall coordinates + removed players collision
Browse files Browse the repository at this point in the history
  • Loading branch information
bugy committed Nov 30, 2017
1 parent ac117b3 commit 1463381
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
4 changes: 4 additions & 0 deletions src/main/java/co/selim/gameserver/entity/GameEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@ enum Type {
void collided(GameEntity other);

Type getType();

default boolean shouldCollide(GameEntity other) {
return true;
}
}
9 changes: 9 additions & 0 deletions src/main/java/co/selim/gameserver/entity/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,15 @@ public void collided(GameEntity other) {
}
}

@Override
public boolean shouldCollide(GameEntity other) {
if (other instanceof Player) {
return false;
}

return true;
}

public String getId() {
return id;
}
Expand Down
23 changes: 17 additions & 6 deletions src/main/java/co/selim/gameserver/model/GameMap.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package co.selim.gameserver.model;

import co.selim.gameserver.entity.GameEntity;
import co.selim.gameserver.entity.Player;
import co.selim.gameserver.entity.Tree;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.Body;
import com.badlogic.gdx.physics.box2d.BodyDef;
Expand Down Expand Up @@ -37,10 +39,10 @@ public GameMap() {

float mapWidth = MAP_SIZE.x;
float mapHeight = MAP_SIZE.y;
createWall(0, 0, 0, mapHeight);
createWall(0, 0, mapWidth, 0);
createWall(mapWidth, 0, mapWidth, mapHeight);
createWall(0, mapHeight, mapWidth, mapHeight);
createWall(mapWidth, 0, mapWidth, 50); // top
createWall(0, mapHeight, 50, mapHeight); // left
createWall(mapWidth, mapHeight + 50, mapWidth, 50); // bottom
createWall(mapWidth + 50, mapHeight, 50, mapHeight); // right
createTree(mapWidth * 0.25f, mapHeight * 0.33f, Tree.TreeType.PINALE);
createTree(mapWidth * 0.85f, mapHeight * 0.5f, Tree.TreeType.BROADLEAF);
createTree(mapWidth * 0.5f, mapHeight * 0.75f, Tree.TreeType.BROADLEAF);
Expand All @@ -67,7 +69,16 @@ public void endContact(Contact contact) {

@Override
public void preSolve(Contact contact, Manifold oldManifold) {
GameEntity a = (GameEntity) contact.getFixtureA()
.getBody()
.getUserData();
GameEntity b = (GameEntity) contact.getFixtureB()
.getBody()
.getUserData();

if (!(a.shouldCollide(b) && b.shouldCollide(a))) {
contact.setEnabled(false);
}
}

@Override
Expand Down Expand Up @@ -130,10 +141,10 @@ public static Set<Tree> getTrees() {
return new HashSet<>(trees);
}

private void createWall(float x, float y, float w, float h) {
private void createWall(float rightX, float bottomY, float w, float h) {
// TODO: fix wall coordinates
BodyDef bodyDef = new BodyDef();
bodyDef.position.set(x - w / 2, y - h / 2);
bodyDef.position.set(rightX - w / 2, bottomY - h / 2);
bodyDef.type = BodyDef.BodyType.StaticBody;
PolygonShape edgeShape = new PolygonShape();
edgeShape.setAsBox(w / 2, h / 2);
Expand Down

0 comments on commit 1463381

Please sign in to comment.