Player being stuck in walls/floors -bug fixed.

This commit is contained in:
Jeasonfire 2015-05-08 21:58:40 +03:00
parent d961bd21de
commit 9c70a7326b
4 changed files with 22 additions and 15 deletions

View File

@ -86,7 +86,8 @@ public class GladiatorBrawler extends ApplicationAdapter {
renderedObject.addSequence("Idle", sequence);
renderedObject.playAnimation("Idle");
player.add(renderedObject);
player.add(new CPhysics().setSize(player1.getRegionWidth() * Global.SPRITE_SCALE, player1.getRegionHeight() * Global.SPRITE_SCALE));
player.add(new CPhysics().setSize(player1.getRegionWidth() * Global.SPRITE_SCALE,
player1.getRegionHeight() * Global.SPRITE_SCALE).setPosition(0, 5));
engine.addEntity(player);
@ -99,7 +100,7 @@ public class GladiatorBrawler extends ApplicationAdapter {
Sprite groundSprite = SpriteLoader.loadSprite(Name.GROUNDIMG, 0, 0, 256, 64);
CRenderedObject renderedObject = new CRenderedObject(groundSprite);
ground.add(renderedObject);
CPhysics physics = new CPhysics().setMovable(false).setGravityApplied(false)
CPhysics physics = new CPhysics().setMovable(false).setGravityApplied(false).setDynamic(false)
.setSize(groundSprite.getRegionWidth() * Global.SPRITE_SCALE,
groundSprite.getRegionHeight() * Global.SPRITE_SCALE);
physics.position.set(new Vector2(0, -4));
@ -109,7 +110,7 @@ public class GladiatorBrawler extends ApplicationAdapter {
Entity wall0 = new Entity();
CRenderedObject wall0RenderedObject = new CRenderedObject(wallSprite);
CPhysics wall0Physics = new CPhysics().setMovable(false).setGravityApplied(false)
CPhysics wall0Physics = new CPhysics().setMovable(false).setGravityApplied(false).setDynamic(false)
.setSize(wallSprite.getRegionWidth() * Global.SPRITE_SCALE,
wallSprite.getRegionHeight() * Global.SPRITE_SCALE);
wall0Physics.position.set(new Vector2(6, 0));
@ -118,7 +119,7 @@ public class GladiatorBrawler extends ApplicationAdapter {
Entity wall1 = new Entity();
CRenderedObject wall1RenderedObject = new CRenderedObject(wallSprite);
CPhysics wall1Physics = new CPhysics().setMovable(false).setGravityApplied(false)
CPhysics wall1Physics = new CPhysics().setMovable(false).setGravityApplied(false).setDynamic(false)
.setSize(wallSprite.getRegionWidth() * Global.SPRITE_SCALE,
wallSprite.getRegionHeight() * Global.SPRITE_SCALE);
wall1Physics.position.set(new Vector2(-6, 0));

View File

@ -43,4 +43,9 @@ public class CPhysics extends Component {
return this;
}
public CPhysics setPosition(float x, float y) {
this.position.set(x, y);
return this;
}
}

View File

@ -80,29 +80,30 @@ public class PhysicsSystem extends EntitySystem {
return;
}
if (x00 <= x11 && Math.abs(x00 - x11) < (cp0.size.x + cp1.size.x) / 4) {
if (x00 <= x11 && Math.abs(x00 - x11) < (cp0.size.x + cp1.size.x) / 16) {
// cp0's left side is colliding with cp1's right side
if (cp0.velocity.x < 0) {
// cp0 is going left, stop
cp0.velocity.x = 0;
}
}
if (x01 > x10 && Math.abs(x01 - x10) < (cp0.size.x + cp1.size.x) / 4) {
if (x01 > x10 && Math.abs(x01 - x10) < (cp0.size.x + cp1.size.x) / 16) {
// cp0's right side is colliding with cp1's left side
if (cp0.velocity.x > 0) {
// cp0 is going right, stop
cp0.velocity.x = 0;
}
}
if (y00 <= y11 && Math.abs(y00 - y11) < (cp0.size.y + cp1.size.y) / 4) {
if (y00 <= y11 && Math.abs(y00 - y11) < (cp0.size.y + cp1.size.y) / 16) {
// cp0's bottom side is colliding with cp1's top side
if (cp0.velocity.y < 0) {
// cp0 is going down, stop
cp0.velocity.y = 0;
}
cp0.grounded = true;
//cp0.position.y -= Math.abs(y00 - y11);
}
if (y01 > y10 && Math.abs(y01 - y10) < (cp0.size.y + cp1.size.y) / 4) {
if (y01 > y10 && Math.abs(y01 - y10) < (cp0.size.y + cp1.size.y) / 16) {
// cp0's top side is colliding with cp1's bottom side
if (cp0.velocity.y > 0) {
// cp0 is going up, stop

View File

@ -1,13 +1,13 @@
package com.saltosion.gladiator.util;
package com.saltosion.gladiator.util;
import com.badlogic.ashley.core.Entity;
import com.badlogic.gdx.math.Vector2;
public class AppUtil {
public static Entity player;
public static final int VPHEIGHT_CONST = 14;
public static final Vector2 JUMP_FORCE = new Vector2(0, 12000);
public static Entity player;
public static final int VPHEIGHT_CONST = 24;
public static final Vector2 JUMP_FORCE = new Vector2(0, 12000);
}