Skip to content

Commit

Permalink
Keeping entities inside the map
Browse files Browse the repository at this point in the history
Fixes #13
  • Loading branch information
ronaldosvieira committed Mar 12, 2017
1 parent 878e7d3 commit a64a1a1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/entity/Entity.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package entity;

import assets.Assets;
import game.Game;
import org.joml.Matrix4f;
import org.joml.Vector2f;
import org.joml.Vector3f;
Expand Down Expand Up @@ -52,8 +53,16 @@ public void useAnimation(int index) {
}

public void move(Vector2f direction) {
World world = Game.getInstance().getWorld();

transform.pos.add(new Vector3f(direction, 0));


transform.pos.x = Math.max(0, transform.pos.x);
transform.pos.x = Math.min(transform.pos.x, world.getWidth());

transform.pos.y = Math.min(0, transform.pos.y);
transform.pos.y = Math.max(transform.pos.y, -world.getHeight());

boundingBox.getCenter().set(transform.pos.x, transform.pos.y);
}

Expand Down
3 changes: 3 additions & 0 deletions src/world/World.java
Original file line number Diff line number Diff line change
Expand Up @@ -198,4 +198,7 @@ public int getScale() {
}

public List<Entity> getEntities() {return this.entities;}

public int getWidth() {return this.width;}
public int getHeight() {return this.height;}
}

0 comments on commit a64a1a1

Please sign in to comment.