Fixed collisions

~ Mike
This commit is contained in:
Armin Benz 2017-04-30 18:06:50 +02:00
parent 5fd5a60307
commit 1bac4713ed
8 changed files with 1673 additions and 1682 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,12 +1,12 @@
package de.samdev.colorrunner.game.world.entities;
import de.samdev.colorrunner.game.world.CRGameWorld;
import de.samdev.colorrunner.game.world.entities.gameentities.GetTriggerType;
import de.samdev.colorrunner.game.world.entities.gameentities.ControllingType;
public abstract class GravityEntity extends MovingEntity {
public float GRAVITY_FORCE = 700f;
public final static float TERMINAL_VELOCITY = 900f;
public GetTriggerType getType = GetTriggerType.RUNBOTTOM;
public ControllingType ctrlType = ControllingType.RUNBOTTOM;
public GravityEntity(CRGameWorld _owner, float width, float height) {
this(_owner, 0, 0, width, height);
@ -19,7 +19,7 @@ public abstract class GravityEntity extends MovingEntity {
@Override
public void update(float delta) {
switch (getType){
switch (ctrlType){
case RUNTOP:
GRAVITY_FORCE = -700;
break;

View File

@ -10,8 +10,8 @@ import de.samdev.colorrunner.game.world.CRGameWorld;
public abstract class MovingEntity extends CRGameEntity {
protected Vector2 velocity = new Vector2();
public final static float EPSILON = 1e-8f;
public final static float EPSILON_TOUCH = 5e-8f;
public final static float EPSILON = 1e-4f;
public final static float EPSILON_TOUCH = 5e-4f;
private boolean face_TOP_isTouching = false;
private boolean face_LEFT_isTouching = false;
@ -134,26 +134,29 @@ public abstract class MovingEntity extends CRGameEntity {
if (isTouching_LEFT() && ! isTouching_RIGHT()) {
next.width += add;
next.x -= add;
} else if (! isTouching_LEFT() && isTouching_RIGHT()) {
next.width += add;
next.x -= add;
next.x -= EPSILON;
} else {
next.width += add;
next.x -= add/2;
}
if (add < 0) {
bounds.set(next);
for (CRGameEntity ent2 : world.entities) { //TODO rem me
if (ent2 == this) continue;
if (CRGame.DEBUG) {
for (CRGameEntity ent2 : world.entities) {
if (ent2 == this) continue;
if (overlaps(next, ent2.bounds) && ent2.canCollide(false, this)) {
Gdx.app.log("Entity Hitbox", "Expand failed X- || WTF");
return false;
if (overlaps(next, ent2.bounds) && ent2.canCollide(false, this)) {
Gdx.app.log("Entity Hitbox", "Expand failed X- || WTF");
return false;
}
}
}
bounds.set(next);
return true;
} else {
for (CRGameEntity ent : world.entities) {
@ -206,24 +209,27 @@ public abstract class MovingEntity extends CRGameEntity {
next.height += add;
} else if (! isTouching_BOTTOM() && isTouching_TOP()) {
next.height += add;
next.y -= add - EPSILON;
next.y -= add;
next.y -= EPSILON;
} else {
next.height += add;
next.y -= add/2;
}
if (add < 0) {
bounds.set(next);
for (CRGameEntity ent2 : world.entities) { //TODO rem me
if (ent2 == this) continue;
if (CRGame.DEBUG) {
for (CRGameEntity ent2 : world.entities) {
if (ent2 == this) continue;
if (overlaps(next, ent2.bounds) && ent2.canCollide(false, this)) {
Gdx.app.log("Entity Hitbox", "Expand failed Y- || WTF");
return false;
if (overlaps(next, ent2.bounds) && ent2.canCollide(false, this)) {
Gdx.app.log("Entity Hitbox", "Expand failed Y- || WTF");
return false;
}
}
}
bounds.set(next);
return true;
} else {
for (CRGameEntity ent : world.entities) {

View File

@ -4,6 +4,6 @@ package de.samdev.colorrunner.game.world.entities.gameentities;
* Created by benza on 23.04.2017.
*/
public enum GetTriggerType {
public enum ControllingType {
RUNBOTTOM, RUNTOP, FLY, NOTHING
}

View File

@ -1,6 +1,5 @@
package de.samdev.colorrunner.game.world.entities.gameentities;
import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
@ -11,14 +10,10 @@ import de.samdev.colorrunner.game.world.entities.CRGameEntity;
import de.samdev.colorrunner.game.world.entities.GravityEntity;
import de.samdev.colorrunner.game.world.entities.gameentities.floor.FloorTileEntity;
import de.samdev.colorrunner.game.world.map.provider.TriggerType;
import de.samdev.colorrunner.screens.menu.MainMenu;
import static de.samdev.colorrunner.game.world.map.provider.TriggerType.RUNBOTTOM;
import static de.samdev.colorrunner.game.world.map.provider.TriggerType.RUNTOP;
public class PlayerEntity extends GravityEntity {
public final static float PLAYER_WIDTH = 32;
public final static float PLAYER_HEIGHT = 32;
public final static float PLAYER_WIDTH = 31.9f;
public final static float PLAYER_HEIGHT = 31.9f;
public final static float PLAYER_JUMP_FORCE = 356f;
public final static float PLAYER_FLY_FORCE = 250f;
@ -30,10 +25,7 @@ public class PlayerEntity extends GravityEntity {
private SwipeDirection phase = SwipeDirection.UP;
private boolean doFly = false;
private TriggerType triggerType;
public PlayerEntity(CRGameWorld _owner, float x, float y) {
super(_owner, x, y, PLAYER_WIDTH, PLAYER_HEIGHT);
@ -45,35 +37,33 @@ public class PlayerEntity extends GravityEntity {
velocity.x += PLAYER_SPEED_FORCE * delta;
if (doFly) {
if ( getType == GetTriggerType.RUNBOTTOM)
if ( ctrlType == ControllingType.RUNBOTTOM)
velocity.y += PLAYER_FLY_FORCE * delta;
else if(getType == GetTriggerType.RUNTOP)
else if(ctrlType == ControllingType.RUNTOP)
velocity.y += -PLAYER_FLY_FORCE * delta;
}
doFly = false;
updateRotation(delta);
triggerType = world.mapprovider.getTrigger((int)(bounds.x / FloorTileEntity.FLOORTILE_WIDTH), (int)(bounds.y / FloorTileEntity.FLOORTILE_HEIGHT));
switch (triggerType){
TriggerType trigger = world.mapprovider.getTrigger((int)((bounds.x + bounds.width/2f) / FloorTileEntity.FLOORTILE_WIDTH), (int)((bounds.y + bounds.height/2f) / FloorTileEntity.FLOORTILE_HEIGHT));
switch (trigger){
case RUNTOP:
getType = GetTriggerType.RUNTOP;
ctrlType = ControllingType.RUNTOP;
break;
case RUNBOTTOM:
getType = GetTriggerType.RUNBOTTOM;
ctrlType = ControllingType.RUNBOTTOM;
break;
case FLY:
getType = GetTriggerType.FLY;
ctrlType = ControllingType.FLY;
break;
}
super.update(delta);
}
private void updateRotation(float delta) {
boolean touch = false; //isTouching_ANY(); //TODO comment me to force bug
boolean touch = isTouching_ANY();
boolean aligned = (visualRotation % 90 == 0);
if (!touch)
@ -109,9 +99,9 @@ public class PlayerEntity extends GravityEntity {
}
public void jump() {
if (isTouching_BOTTOM() && getType == GetTriggerType.RUNBOTTOM)
if (isTouching_BOTTOM() && ctrlType == ControllingType.RUNBOTTOM)
velocity.y = PLAYER_JUMP_FORCE;
else if(isTouching_TOP() && getType == GetTriggerType.RUNTOP)
else if(isTouching_TOP() && ctrlType == ControllingType.RUNTOP)
velocity.y = -PLAYER_JUMP_FORCE;
}
@ -129,9 +119,9 @@ public class PlayerEntity extends GravityEntity {
}
public void fly() {
if (!isTouching_BOTTOM() && getType == GetTriggerType.RUNBOTTOM)
if (!isTouching_BOTTOM() && ctrlType == ControllingType.RUNBOTTOM)
doFly = true;
else if(isTouching_TOP() && getType == GetTriggerType.RUNTOP)
else if(isTouching_TOP() && ctrlType == ControllingType.RUNTOP)
doFly = true;
}

View File

@ -133,25 +133,25 @@ public class CRGameInputProcessor implements InputProcessor, GestureListener {
@Override
public boolean pan(float x, float y, float deltaX, float deltaY) {
// TODO Auto-generated method stub
// NOP
return false;
}
@Override
public boolean panStop(float x, float y, int pointer, int button) {
// TODO Auto-generated method stub
// NOP
return false;
}
@Override
public boolean zoom(float initialDistance, float distance) {
// TODO Auto-generated method stub
// NOP
return false;
}
@Override
public boolean pinch(Vector2 initialPointer1, Vector2 initialPointer2, Vector2 pointer1, Vector2 pointer2) {
// TODO Auto-generated method stub
// NOP
return false;
}

View File

@ -18,8 +18,6 @@ import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import de.samdev.colorrunner.screens.gameScreen.GameScreen;
public class OptionMenuScreen implements Screen{
private Preferences prefs = Gdx.app.getPreferences("settings");
@ -58,8 +56,7 @@ public class OptionMenuScreen implements Screen{
@Override
public void resize(int width, int height) {
// TODO Auto-generated method stub
// NOP
}
@Override
@ -116,13 +113,13 @@ public class OptionMenuScreen implements Screen{
@Override
public void pause() {
// TODO Auto-generated method stub
// NOP
}
@Override
public void resume() {
// TODO Auto-generated method stub
// NOP
}

View File

@ -9,8 +9,6 @@ import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.MathUtils;
import de.samdev.colorrunner.CRGame;
public class SplashScreen implements Screen {
@ -47,7 +45,7 @@ public class SplashScreen implements Screen {
@Override
public void resize(int width, int height) {
// TODO Auto-generated method stub
// NOP
}
@ -71,13 +69,13 @@ public class SplashScreen implements Screen {
@Override
public void pause() {
// TODO Auto-generated method stub
// NOP
}
@Override
public void resume() {
// TODO Auto-generated method stub
// NOP
}