Skip to content

Commit

Permalink
fixed player collisions
Browse files Browse the repository at this point in the history
  • Loading branch information
Oshan96 committed Aug 25, 2019
1 parent 802ed51 commit 432c117
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
4 changes: 4 additions & 0 deletions src/main/java/io/github/oshan96/openfighting/world/World.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ public class World {

FighterKree p1 = new FighterKree(-2.5f,-4.7f,64,64, 0, 0);
FighterBee p2 = new FighterBee(2.5f,-4.7f,64,64, 0, 0);
p1.setFacingLeft(false);

p1.setEnemy(p2);
p2.setEnemy(p1);

playerOne = p1;
playerTwo = p2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public abstract class AbstractFighter extends BasicGameObject implements Fighter
protected int health = 100;
protected long lastPowerTime = 0;

protected AbstractFighter enemy = null;

protected boolean isFacingLeft = true;

protected boolean isDefeated = false;
Expand Down Expand Up @@ -192,21 +194,22 @@ public int getHealth() {
return health;
}

public AbstractFighter getEnemy() {
return enemy;
}

public void setEnemy(AbstractFighter enemy) {
this.enemy = enemy;
}

@Override
public void move(boolean isMovingRight) {
float xIn = 0;
if(isFacingLeft) {
if(isMovingRight) {
xIn++;
} else {
xIn--;
}

if(isMovingRight) {
xIn++;
} else {
if(isMovingRight) {
xIn++;
} else {
xIn--;
}
xIn--;
}

x += xIn * movementSpeed * GameLoop.getDelta();
Expand All @@ -225,6 +228,10 @@ public void collided() {
x = (Renderer.tileSize / 2 + 0.5f);
} else if (x> (Renderer.tileSize / 2 - 0.5f)) {
x = (Renderer.tileSize / 2 - 0.5f);
}else if((x+charWidth/3f) - (enemy.getX()) > 0 && !isFacingLeft ) {
x = enemy.getX()-enemy.charWidth/3;
}else if((x-charWidth/3f) - (enemy.getX()) < 0 && isFacingLeft ) {
x = enemy.getX()+enemy.charWidth/3;
}

if(y< -(Renderer.vTileSize)/2 + 1.5f) {
Expand Down

0 comments on commit 432c117

Please sign in to comment.