Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Map.java
- public List<BoundingBox> getBoundingBoxes() {
- List<BoundingBox> boxes = new ArrayList<BoundingBox>();
- int i, j;
- for(int x = 0; x < this.size.x; x++) {
- for(int y = 0; y < this.size.y; y++) {
- if(this.getTile(x, y).collide()) {
- boxes.add(new BoundingBox(new Vec2(i = x * 16, j = y * 16), new Vec2(i + 16, j + 16)));
- }
- }
- }
- return boxes;
- }
- // Player.java
- public void handleInput() {
- BoundingBox last = this.pos.clone();
- if(Keys.A.state) {
- this.pos.offset(new Vec2(-1, 0));
- }
- if(Keys.D.state) {
- this.pos.offset(new Vec2(1, 0));
- }
- if(Keys.W.state) {
- this.pos.offset(new Vec2(0, -1));
- }
- if(Keys.S.state) {
- this.pos.offset(new Vec2(0, 1));
- }
- List<BoundingBox> boxes = Crawler.INSTANCE.map.getBoundingBoxes();
- for(BoundingBox box : boxes) {
- box.collide(last, this.pos);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment