Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package kopako.entities.components;
- import kopako.collision.AABBbox;
- import kopako.entities.Entity;
- import kopako.utility.Component;
- import kopako.utility.EntityComponent;
- import kopako.utility.Location;
- import kopako.utility.graphics.Coordinates;
- public class Collidable extends EntityComponent {
- private AABBbox Box;
- private Location last;
- private AABBbox wtfTest;
- public Collidable(Entity e) {
- super(e);
- this.setID(Component.COLLIDABLE);
- last = getEntity().getLocation().clone();
- }
- @Override
- public void update(int delta) {
- // if (Box != null) {
- // float x = Coordinates.subtract(getEntity().getLocation().getX(),last.getX());
- // float y = Coordinates.subtract(getEntity().getLocation().getY(),last.getY());
- //System.out.println("X:" + x + " Y:" + y);
- // wtfTest = Box.clone();
- // Box.moveLocation(x, y);
- // System.out.println("Last:" + wtfTest.getLeft() + " Current:" + Box.getLeft());
- // last = getEntity().getLocation().clone();
- // }
- }
- public final void NewBoundingBox(Location l, float height, float width) {
- Box = new AABBbox(l,height,width);
- }
- public final AABBbox getBoundingBox() {
- return Box;
- }
- public final boolean isColliding(AABBbox test) {
- if (Box != null) {
- return Box.colliding(test);
- }
- return false;
- }
- public final boolean willCollide(AABBbox test, float moveX, float moveY) {
- if (Box != null) {
- AABBbox goTo = Box.clone();
- goTo.moveLocation(moveX, moveY);
- return goTo.colliding(test);
- }
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement