Item pickup
This commit is contained in:
@@ -27,7 +27,7 @@ public class AssetSetter {
|
||||
|
||||
panel.obj[3] = new DoorObj();
|
||||
panel.obj[3].worldX = 10 * panel.tileSize;
|
||||
panel.obj[3].worldY = 9 * panel.tileSize;
|
||||
panel.obj[3].worldY = 11 * panel.tileSize;
|
||||
|
||||
panel.obj[4] = new DoorObj();
|
||||
panel.obj[4].worldX = 8 * panel.tileSize;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package de.miaurizius.jgame2d.core;
|
||||
|
||||
import de.miaurizius.jgame2d.entity.Entity;
|
||||
import de.miaurizius.jgame2d.object.SuperObject;
|
||||
|
||||
public class CollisionHandler {
|
||||
|
||||
@@ -51,4 +52,57 @@ public class CollisionHandler {
|
||||
}
|
||||
}
|
||||
|
||||
public int checkObject(Entity entity, boolean player) {
|
||||
int index = 999;
|
||||
int c = -1;
|
||||
|
||||
for(SuperObject obj : panel.obj) {
|
||||
c++;
|
||||
if (obj != null) {
|
||||
|
||||
entity.solidArea.x += entity.worldX;
|
||||
entity.solidArea.y += entity.worldY;
|
||||
|
||||
obj.solidArea.x += obj.worldX;
|
||||
obj.solidArea.y += obj.worldY;
|
||||
|
||||
switch (entity.direction) {
|
||||
case UP:
|
||||
entity.solidArea.y -= entity.speed;
|
||||
if (entity.solidArea.intersects(obj.solidArea)) {
|
||||
if (obj.collision) entity.collisionOn = true;
|
||||
if (player) index = c;
|
||||
}
|
||||
break;
|
||||
case DOWN:
|
||||
entity.solidArea.y += entity.speed;
|
||||
if (entity.solidArea.intersects(obj.solidArea)) {
|
||||
if (obj.collision) entity.collisionOn = true;
|
||||
if (player) index = c;
|
||||
}
|
||||
break;
|
||||
case LEFT:
|
||||
entity.solidArea.x -= entity.speed;
|
||||
if (entity.solidArea.intersects(obj.solidArea)) {
|
||||
if (obj.collision) entity.collisionOn = true;
|
||||
if (player) index = c;
|
||||
}
|
||||
break;
|
||||
case RIGHT:
|
||||
entity.solidArea.x += entity.speed;
|
||||
if (entity.solidArea.intersects(obj.solidArea)) {
|
||||
if (obj.collision) entity.collisionOn = true;
|
||||
if (player) index = c;
|
||||
}
|
||||
break;
|
||||
}
|
||||
entity.solidArea.x = entity.solidAreaDefaultX;
|
||||
entity.solidArea.y = entity.solidAreaDefaultY;
|
||||
obj.solidArea.x = obj.solidAreaDefaultX;
|
||||
obj.solidArea.y = obj.solidAreaDefaultY;
|
||||
}
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user