diff --git a/src/main/java/core/general/Master.java b/src/main/java/core/general/Master.java index 7c7ecf8..8141b56 100644 --- a/src/main/java/core/general/Master.java +++ b/src/main/java/core/general/Master.java @@ -206,8 +206,7 @@ public class Master extends JPanel { * @return True if it collides with something, false if it doesn't - Should return a Collision */ public Collision doesCollide(Collidable collidable) { - long time = System.nanoTime(); - Collision collides = null; + Collision collision = null; for (Collidable other : collidables) { @@ -217,13 +216,17 @@ public class Master extends JPanel { if (other != collidable && (distance < other.getHitbox().getSize() + collidable.getHitbox().getSize())) { if (other.getHitbox().collidesWith(collidable.getHitbox())) { - collides = new Collision(collidable, other); - collidable.onCollision(); + collision = new Collision(collidable, other); + if(collision.isTrigger()){ + collidable.onTrigger(); + } else { + collidable.onCollision(); + } } } } } - return collides; + return collision; } public int getW() { diff --git a/src/main/java/core/math/Coordinates.java b/src/main/java/core/math/Coordinates.java index 62297d1..a935958 100644 --- a/src/main/java/core/math/Coordinates.java +++ b/src/main/java/core/math/Coordinates.java @@ -6,7 +6,7 @@ import core.objects.core.GameObject; /** * This class provides everything about the local coordinate system the game uses - *
In this system, the screen is always 100 high and 100 * the screen ration wide. + *
In this system, the screen is always 100 high and 100 * the screen ratio wide. * This class is the used to convert these coordinates into the true Java 2D coordinates for the drawing
*/ public class Coordinates { diff --git a/src/main/java/core/objects/core/CollGameObject.java b/src/main/java/core/objects/core/CollGameObject.java index 3213694..b345994 100644 --- a/src/main/java/core/objects/core/CollGameObject.java +++ b/src/main/java/core/objects/core/CollGameObject.java @@ -3,6 +3,7 @@ package core.objects.core; import core.math.Vector2D; import core.objects.core.GameObject; import core.physics.Collidable; +import core.physics.Collision; import core.physics.hitboxes.Hitbox; import java.util.ArrayList; @@ -38,7 +39,8 @@ public abstract class CollGameObject extends GameObject implements Collidable { this.position = target; ((Collidable) this).getHitbox().moveTo(position, size); - if (master.doesCollide(this) != null) { + Collision coll = master.doesCollide(this); + if (coll != null && !coll.isTrigger()) { this.position = oldPos; ((Collidable) this).getHitbox().moveTo(oldPos, size); } @@ -63,6 +65,10 @@ public abstract class CollGameObject extends GameObject implements Collidable { public void onCollision() { } + @Override + public void onTrigger() { + } + @Override public ArrayList