|
@@ -1,72 +1,61 @@
|
|
|
package me.hammerle.supersnuvi.entity;
|
|
|
|
|
|
-import java.util.List;
|
|
|
import me.hammerle.supersnuvi.entity.components.ai.Controller;
|
|
|
import me.hammerle.supersnuvi.entity.components.Energy;
|
|
|
import me.hammerle.supersnuvi.entity.components.Health;
|
|
|
import me.hammerle.supersnuvi.entity.components.ItemCollector;
|
|
|
import me.hammerle.supersnuvi.entity.components.Movement;
|
|
|
import me.hammerle.supersnuvi.tiles.Tile;
|
|
|
-import me.hammerle.supersnuvi.util.CollisionObject;
|
|
|
import me.hammerle.supersnuvi.util.Face;
|
|
|
import me.hammerle.supersnuvi.util.Utils;
|
|
|
import me.hammerle.supersnuvi.gamelogic.Level;
|
|
|
+import me.hammerle.supersnuvi.math.Vector;
|
|
|
+import me.hammerle.supersnuvi.entity.components.IDespawn;
|
|
|
|
|
|
public final class Entity
|
|
|
{
|
|
|
public static final float GRAVITY = 8.0f * Tile.SIZE_SCALE;
|
|
|
public static final float STEP = 0.0625f;
|
|
|
// this one is a little bit bigger to prevent wrong calculation
|
|
|
- // while joing upwars
|
|
|
+ // while going upwards
|
|
|
public static final float UP_STEP = STEP + 0.00390625f;
|
|
|
|
|
|
// the last position is used for interpolation during rendering
|
|
|
- private float lastPosX;
|
|
|
- private float lastPosY;
|
|
|
+ private final Vector lastPos = new Vector();
|
|
|
// the current position of the entity
|
|
|
- private float posX;
|
|
|
- private float posY;
|
|
|
-
|
|
|
- // the collision box of the entity
|
|
|
- private final CollisionObject box;
|
|
|
-
|
|
|
- // the motion before the movement collision check
|
|
|
- private float preMotionX;
|
|
|
- private float preMotionY;
|
|
|
- // the motion after the movement collision check
|
|
|
- private float motionX;
|
|
|
- private float motionY;
|
|
|
-
|
|
|
+ private final Vector pos = new Vector();
|
|
|
+ // the width of the entity
|
|
|
+ private final float width;
|
|
|
+ // the height of the entity
|
|
|
+ private final float height;
|
|
|
+ // own force used by the controller component
|
|
|
+ private final Vector ownForce = new Vector();
|
|
|
+ // the motion, reduced by the movement collision check
|
|
|
+ private final Vector motion = new Vector();
|
|
|
+ // the friction reducing motion each tick
|
|
|
+ private final Vector friction = new Vector(0.0f, 1.0f);
|
|
|
// a flag indicating that the entity is on the ground
|
|
|
private boolean onGround = true;
|
|
|
-
|
|
|
// entity components
|
|
|
- protected Controller controller = Controller.NULL;
|
|
|
- protected Health health = Health.NULL;
|
|
|
- protected Energy energy = Energy.NULL;
|
|
|
- protected Movement move = Movement.NULL;
|
|
|
- protected ItemCollector itemCollector = ItemCollector.NULL;
|
|
|
-
|
|
|
- // face
|
|
|
- private Face face = Face.RIGHT;
|
|
|
-
|
|
|
+ private final Controller controller;
|
|
|
+ private final Health health;
|
|
|
+ private final Energy energy;
|
|
|
+ private final Movement move;
|
|
|
+ private final ItemCollector itemCollector;
|
|
|
+ private final IDespawn onDespawn;
|
|
|
+ // the type of the entity, used by snuvi script
|
|
|
private final String type;
|
|
|
|
|
|
- protected Entity(String type, float x, float y, CollisionObject box)
|
|
|
+ protected Entity(float width, float height, Controller c, Health h, Energy e, Movement m, ItemCollector ic, IDespawn d, String type)
|
|
|
{
|
|
|
- lastPosX = x;
|
|
|
- lastPosY = y;
|
|
|
- posX = x;
|
|
|
- posY = y;
|
|
|
-
|
|
|
- // ensure the box cannot be modified from the outside
|
|
|
- this.box = box.copy().offset(x, y);
|
|
|
-
|
|
|
- preMotionX = 0.0f;
|
|
|
- preMotionY = 0.0f;
|
|
|
- motionX = 0.0f;
|
|
|
- motionY = 0.0f;
|
|
|
-
|
|
|
+ this.width = width;
|
|
|
+ this.height = height;
|
|
|
+ this.controller = c;
|
|
|
+ this.health = h;
|
|
|
+ this.energy = e;
|
|
|
+ this.move = m;
|
|
|
+ this.itemCollector = ic;
|
|
|
+ this.onDespawn = d;
|
|
|
this.type = type;
|
|
|
}
|
|
|
|
|
@@ -109,119 +98,126 @@ public final class Entity
|
|
|
return itemCollector;
|
|
|
}
|
|
|
|
|
|
+ public void onDespawn()
|
|
|
+ {
|
|
|
+ onDespawn.onDespawn(this);
|
|
|
+ }
|
|
|
+
|
|
|
//--------------------------------------------------------------------------
|
|
|
// basic stuff
|
|
|
//--------------------------------------------------------------------------
|
|
|
|
|
|
public float getSquaredDistance(Entity e)
|
|
|
{
|
|
|
- return Utils.getSquaredDistance(
|
|
|
- posX + box.getWidth() * 0.5f, posY + box.getHeight() * 0.5f,
|
|
|
- e.posX + e.box.getWidth() * 0.5f, e.posY + e.box.getHeight() * 0.5f);
|
|
|
- }
|
|
|
-
|
|
|
- public CollisionObject getBox()
|
|
|
- {
|
|
|
- return box;
|
|
|
+ return Utils.getSquaredDistance(getCenterX(), getCenterY(), e.getCenterX(), e.getCenterY());
|
|
|
}
|
|
|
|
|
|
public float getX()
|
|
|
{
|
|
|
- return posX;
|
|
|
+ return pos.getX();
|
|
|
}
|
|
|
|
|
|
public float getY()
|
|
|
{
|
|
|
- return posY;
|
|
|
+ return pos.getY();
|
|
|
}
|
|
|
|
|
|
public void setPosition(float x, float y)
|
|
|
{
|
|
|
- lastPosX = x;
|
|
|
- lastPosY = y;
|
|
|
- posX = x;
|
|
|
- posY = y;
|
|
|
- box.reset().offset(posX, posY);
|
|
|
+ lastPos.set(x, y);
|
|
|
+ pos.set(x, y);
|
|
|
}
|
|
|
|
|
|
public float getLastX()
|
|
|
{
|
|
|
- return lastPosX;
|
|
|
+ return lastPos.getX();
|
|
|
}
|
|
|
|
|
|
public float getLastY()
|
|
|
{
|
|
|
- return lastPosY;
|
|
|
+ return lastPos.getY();
|
|
|
}
|
|
|
|
|
|
public float getCenterX()
|
|
|
{
|
|
|
- return posX + box.getWidth() * 0.5f;
|
|
|
+ return pos.getX() + width * 0.5f;
|
|
|
}
|
|
|
|
|
|
public float getCenterY()
|
|
|
{
|
|
|
- return posY + box.getHeight() * 0.5f;
|
|
|
+ return pos.getY() + height * 0.5f;
|
|
|
}
|
|
|
|
|
|
public float getWidth()
|
|
|
{
|
|
|
- return box.getWidth();
|
|
|
+ return width;
|
|
|
}
|
|
|
|
|
|
public float getHeight()
|
|
|
{
|
|
|
- return box.getHeight();
|
|
|
+ return height;
|
|
|
+ }
|
|
|
+
|
|
|
+ public float getMotionX()
|
|
|
+ {
|
|
|
+ return motion.getX();
|
|
|
}
|
|
|
|
|
|
- public Face getFace()
|
|
|
+ public float getMotionY()
|
|
|
{
|
|
|
- if(motionX == 0.0f)
|
|
|
- {
|
|
|
- return face;
|
|
|
- }
|
|
|
- face = motionX < 0.0f ? Face.LEFT : Face.RIGHT;
|
|
|
- return face;
|
|
|
+ return motion.getY();
|
|
|
}
|
|
|
|
|
|
- public void updateFace()
|
|
|
+ public float getOwnForceX()
|
|
|
{
|
|
|
-
|
|
|
+ return ownForce.getX();
|
|
|
}
|
|
|
|
|
|
- public float getMotionX()
|
|
|
+ public float getOwnForceY()
|
|
|
{
|
|
|
- return motionX;
|
|
|
+ return ownForce.getY();
|
|
|
+ }
|
|
|
+
|
|
|
+ public void applyOwnForce(float x, float y)
|
|
|
+ {
|
|
|
+ ownForce.add(x, y);
|
|
|
}
|
|
|
|
|
|
- public void setMotionX(float motionX)
|
|
|
+ public void applyForce(float x, float y)
|
|
|
{
|
|
|
- this.motionX = motionX;
|
|
|
+ motion.add(x, y);
|
|
|
}
|
|
|
|
|
|
- public float getMotionY()
|
|
|
+ public void setFriction(float fx, float fy)
|
|
|
{
|
|
|
- return motionY;
|
|
|
+ friction.set(fx, fy);
|
|
|
}
|
|
|
|
|
|
- public void setMotionY(float motionY)
|
|
|
+ public boolean isAt(float x, float y)
|
|
|
{
|
|
|
- this.motionY = motionY;
|
|
|
+ return Math.abs(x - pos.getX()) < STEP && Math.abs(y - pos.getY()) < STEP;
|
|
|
}
|
|
|
|
|
|
- public float getPreMotionX()
|
|
|
+ public boolean isColliding(float minX, float minY, float maxX, float maxY)
|
|
|
{
|
|
|
- return preMotionX;
|
|
|
+ return maxX > getX() && getX() + width > minX && maxY > getY() && getY() + height > minY;
|
|
|
}
|
|
|
|
|
|
- public float getPreMotionY()
|
|
|
+ private Face getCollidingFace(Entity o)
|
|
|
{
|
|
|
- return preMotionY;
|
|
|
+ return Utils.getCollidingFace(
|
|
|
+ o.getX(), o.getY(), o.getX() + o.getWidth(), o.getY() + o.getHeight(),
|
|
|
+ getX(), getY(), getX() + getWidth(), getY() + getHeight());
|
|
|
}
|
|
|
|
|
|
- public boolean isAt(float x, float y)
|
|
|
+ public boolean jump()
|
|
|
{
|
|
|
- return Math.abs(x - posX) < STEP && Math.abs(y - posY) < STEP;
|
|
|
+ if(onGround)
|
|
|
+ {
|
|
|
+ ownForce.addY(-move.getJumpPower());
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
}
|
|
|
|
|
|
//--------------------------------------------------------------------------
|
|
@@ -230,175 +226,257 @@ public final class Entity
|
|
|
|
|
|
public void tick(Level level)
|
|
|
{
|
|
|
- lastPosX = posX;
|
|
|
- lastPosY = posY;
|
|
|
+ // reset own force
|
|
|
+ ownForce.set(0.0f, 0.0f);
|
|
|
|
|
|
- controller.tick(level);
|
|
|
- energy.tick();
|
|
|
+ // remeber last position for rendering
|
|
|
+ lastPos.set(pos);
|
|
|
|
|
|
- preMotionX = motionX;
|
|
|
- preMotionY = motionY;
|
|
|
+ // update onGround before controller tick
|
|
|
+ // ToDo: does not work for ramps
|
|
|
+ onGround = isOnTileGround(level);
|
|
|
|
|
|
- if(move.hasGravity())
|
|
|
+ // tick components
|
|
|
+ controller.tick(this, level);
|
|
|
+ energy.tick(this);
|
|
|
+ health.tick();
|
|
|
+
|
|
|
+ // apply gravity if needed
|
|
|
+ if(move.hasGravity(this))
|
|
|
{
|
|
|
- preMotionY += GRAVITY * move.getGravityFactor();
|
|
|
+ motion.addY(GRAVITY * move.getGravityFactor());
|
|
|
}
|
|
|
|
|
|
+ // apply friction
|
|
|
+ motion.mul(friction);
|
|
|
+
|
|
|
+ // modify current motion by own force
|
|
|
+ motion.add(ownForce);
|
|
|
+
|
|
|
+ // (entity <-> tile) collision
|
|
|
+ doTileCollision(level);
|
|
|
+ // (entity <-> entity) collision
|
|
|
+ level.forEachCollidingEntity(this, (ent) ->
|
|
|
+ {
|
|
|
+ controller.onCollideWithEntity(this, ent, getCollidingFace(ent));
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ public void move(Level level)
|
|
|
+ {
|
|
|
+ reduceMotionByTiles(level);
|
|
|
+ reduceMotionByEntities(level);
|
|
|
+ pos.add(motion);
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean isOnTileGround(Level level)
|
|
|
+ {
|
|
|
+ float minX = pos.getX();
|
|
|
+ float minY = pos.getY() + height;
|
|
|
+ float maxX = pos.getX() + width;
|
|
|
+ float maxY = pos.getY() + height + STEP * 2;
|
|
|
+ int startX = Utils.toBlock(minX);
|
|
|
+ int startY = Utils.toBlock(minY);
|
|
|
+ int endX = Utils.toBlock(maxX);
|
|
|
+ int endY = Utils.toBlock(maxY);
|
|
|
+
|
|
|
+ for(int x = startX; x <= endX; x++)
|
|
|
+ {
|
|
|
+ for(int y = startY; y <= endY; y++)
|
|
|
+ {
|
|
|
+ Tile t = level.getInteractionTile(x, y);
|
|
|
+ if(t.isMoveColliding(minX, minY, maxX, maxY, x, y, level))
|
|
|
+ {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void doTileCollision(Level level)
|
|
|
+ {
|
|
|
+ float minX = pos.getX() - STEP;
|
|
|
+ float minY = pos.getY() - STEP;
|
|
|
+ float maxX = pos.getX() + width + STEP;
|
|
|
+ float maxY = pos.getY() + height + STEP;
|
|
|
+ int startX = Utils.toBlock(minX);
|
|
|
+ int startY = Utils.toBlock(minY);
|
|
|
+ int endX = Utils.toBlock(maxX);
|
|
|
+ int endY = Utils.toBlock(maxY);
|
|
|
+
|
|
|
+ for(int x = startX; x <= endX; x++)
|
|
|
+ {
|
|
|
+ for(int y = startY; y <= endY; y++)
|
|
|
+ {
|
|
|
+ Tile t = level.getInteractionTile(x, y);
|
|
|
+ if(t.isColliding(minX, minY, maxX, maxY, x, y, level))
|
|
|
+ {
|
|
|
+ Face f = t.getCollidingFace(minX, minY, maxX, maxY, x, y, level);
|
|
|
+ controller.onCollideWithTile(this, x, y, level, t, f);
|
|
|
+ t.onEntityCollide(this, x, y, f.getOpposite(), level);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void reduceMotionByEntities(Level level)
|
|
|
+ {
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean isCollidingWithTiles(int startX, int startY, int endX, int endY, Level level)
|
|
|
+ {
|
|
|
+ float minX = getX();
|
|
|
+ float minY = getY();
|
|
|
+ float maxX = minX + width;
|
|
|
+ float maxY = minY + height;
|
|
|
+ for(int x = startX; x <= endX; x++)
|
|
|
+ {
|
|
|
+ for(int y = startY; y <= endY; y++)
|
|
|
+ {
|
|
|
+ if(level.getInteractionTile(x, y).isMoveColliding(minX, minY, maxX, maxY, x, y, level))
|
|
|
+ {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void reduceMotionByTiles(Level level)
|
|
|
+ {
|
|
|
if(move.canMoveEverywhere())
|
|
|
{
|
|
|
- motionX = preMotionX;
|
|
|
- motionY = preMotionY;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ float mx = motion.getX();
|
|
|
+ float my = motion.getY();
|
|
|
+
|
|
|
+ if(mx == 0.0f && my == 0.0f)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ int startX;
|
|
|
+ int endX;
|
|
|
+ if(mx < 0.0f)
|
|
|
+ {
|
|
|
+ startX = Utils.toBlock(pos.getX() + mx);
|
|
|
+ endX = Utils.toBlock(pos.getX() + width);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- CollisionObject testBox = box.copy().expand(preMotionX, preMotionY).expand(0.0f, -UP_STEP);
|
|
|
- List<CollisionObject> boxes = level.getMovementBoxesAt(testBox, this);
|
|
|
- if(!boxes.isEmpty())
|
|
|
+ startX = Utils.toBlock(pos.getX());
|
|
|
+ endX = Utils.toBlock(pos.getX() + width + mx);
|
|
|
+ }
|
|
|
+
|
|
|
+ int startY;
|
|
|
+ int endY;
|
|
|
+ if(my < 0.0f)
|
|
|
+ {
|
|
|
+ startY = Utils.toBlock(pos.getY() + my);
|
|
|
+ endY = Utils.toBlock(pos.getY() + height);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ startY = Utils.toBlock(pos.getY());
|
|
|
+ endY = Utils.toBlock(pos.getY() + height + my);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ float oldPosX = pos.getX();
|
|
|
+ float oldPosY = pos.getY();
|
|
|
+
|
|
|
+ while(mx != 0.0 || my != 0.0)
|
|
|
+ {
|
|
|
+ if(mx != 0.0f)
|
|
|
{
|
|
|
- float mx = preMotionX;
|
|
|
- float my = preMotionY;
|
|
|
-
|
|
|
- testBox.reset();
|
|
|
-
|
|
|
- float oldX = testBox.getMinX();
|
|
|
- float oldY = testBox.getMinY();
|
|
|
-
|
|
|
- while(mx != 0.0 || my != 0.0)
|
|
|
+ float oldX = pos.getX();
|
|
|
+ if(mx < 0.0)
|
|
|
{
|
|
|
- testBox.save();
|
|
|
-
|
|
|
- if(mx < 0.0)
|
|
|
+ if(mx > -STEP)
|
|
|
{
|
|
|
- if(mx > -STEP)
|
|
|
- {
|
|
|
- testBox.offsetX(mx);
|
|
|
- mx = 0.0f;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- testBox.offsetX(-STEP);
|
|
|
- mx += STEP;
|
|
|
- }
|
|
|
+ pos.addX(mx);
|
|
|
+ mx = 0.0f;
|
|
|
}
|
|
|
- else if(mx > 0.0)
|
|
|
+ else
|
|
|
{
|
|
|
- if(mx < STEP)
|
|
|
- {
|
|
|
- testBox.offsetX(mx);
|
|
|
- mx = 0.0f;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- testBox.offsetX(STEP);
|
|
|
- mx -= STEP;
|
|
|
- }
|
|
|
+ pos.addX(-STEP);
|
|
|
+ mx += STEP;
|
|
|
}
|
|
|
-
|
|
|
- for(CollisionObject cb : boxes)
|
|
|
- {
|
|
|
- if(cb.isColliding(testBox))
|
|
|
- {
|
|
|
- testBox.offsetY(-UP_STEP);
|
|
|
- for(CollisionObject cb2 : boxes)
|
|
|
- {
|
|
|
- if(cb2.isColliding(testBox))
|
|
|
- {
|
|
|
- mx = 0.0f;
|
|
|
- testBox.reset();
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- testBox.save();
|
|
|
-
|
|
|
- if(my < 0.0)
|
|
|
+ }
|
|
|
+ else if(mx > 0.0)
|
|
|
+ {
|
|
|
+ if(mx < STEP)
|
|
|
{
|
|
|
- if(my > -STEP)
|
|
|
- {
|
|
|
- testBox.offsetY(my);
|
|
|
- my = 0.0f;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- testBox.offsetY(-STEP);
|
|
|
- my += STEP;
|
|
|
- }
|
|
|
+ pos.addX(mx);
|
|
|
+ mx = 0.0f;
|
|
|
}
|
|
|
- else if(my > 0.0)
|
|
|
+ else
|
|
|
{
|
|
|
- if(my < STEP)
|
|
|
- {
|
|
|
- testBox.offsetY(my);
|
|
|
- my = 0.0f;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- testBox.offsetY(STEP);
|
|
|
- my -= STEP;
|
|
|
- }
|
|
|
+ pos.addX(STEP);
|
|
|
+ mx -= STEP;
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- for(CollisionObject cb : boxes)
|
|
|
+ if(isCollidingWithTiles(startX, startY, endX, endY, level))
|
|
|
+ {
|
|
|
+ pos.addY(-UP_STEP);
|
|
|
+ if(isCollidingWithTiles(startX, startY, endX, endY, level))
|
|
|
{
|
|
|
- if(cb.isColliding(testBox))
|
|
|
- {
|
|
|
- my = 0.0f;
|
|
|
- testBox.reset();
|
|
|
- break;
|
|
|
- }
|
|
|
+ pos.addY(UP_STEP);
|
|
|
+ pos.setX(oldX);
|
|
|
+ mx = 0.0f;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- motionX = testBox.getMinX() - oldX;
|
|
|
- motionY = testBox.getMinY() - oldY;
|
|
|
}
|
|
|
- else
|
|
|
+ if(my != 0.0f)
|
|
|
{
|
|
|
- motionX = preMotionX;
|
|
|
- motionY = preMotionY;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- posX += motionX;
|
|
|
- posY += motionY;
|
|
|
- box.reset().offset(posX, posY);
|
|
|
-
|
|
|
- if(!move.canMoveEverywhere())
|
|
|
- {
|
|
|
- //onGround = preMotionY > 0.0f && motionY == 0;
|
|
|
- onGround = !level.getMovementBoxesAt(box.copy().expand(0.0f, STEP * 2), this).isEmpty();
|
|
|
+ float oldY = pos.getY();
|
|
|
|
|
|
- move.setInWater(false);
|
|
|
- move.setFrictionFactor(0.6f);
|
|
|
- // apply collision
|
|
|
- CollisionObject cb = box.copy();
|
|
|
- for(Face f : Face.values())
|
|
|
- {
|
|
|
- cb.reset();
|
|
|
- cb.expand(f.getCollisionOffsetX(), f.getCollisionOffsetY());
|
|
|
- level.getEntitiesCollidingWith(this, cb).forEach(ent -> this.controller.onCollideWithEntity(ent, f));
|
|
|
- level.getCollisionBoxesAt(cb).forEach(loc ->
|
|
|
+ if(my < 0.0)
|
|
|
{
|
|
|
- controller.onCollideWithTile(loc, f);
|
|
|
- loc.getTile().onEntityCollide(this, loc.getX(), loc.getY(), f.getOpposite(), level);
|
|
|
- });
|
|
|
- }
|
|
|
+ if(my > -STEP)
|
|
|
+ {
|
|
|
+ pos.addY(my);
|
|
|
+ my = 0.0f;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ pos.addY(-STEP);
|
|
|
+ my += STEP;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if(my > 0.0)
|
|
|
+ {
|
|
|
+ if(my < STEP)
|
|
|
+ {
|
|
|
+ pos.addY(my);
|
|
|
+ my = 0.0f;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ pos.addY(STEP);
|
|
|
+ my -= STEP;
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- motionX *= move.getFrictionFactor();
|
|
|
- if(Math.abs(motionX) < 0.3)
|
|
|
- {
|
|
|
- motionX = 0.0f;
|
|
|
+ if(isCollidingWithTiles(startX, startY, endX, endY, level))
|
|
|
+ {
|
|
|
+ my = 0.0f;
|
|
|
+ pos.setY(oldY);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- health.tick();
|
|
|
+
|
|
|
+ motion.set(pos.getX() - oldPosX, pos.getY() - oldPosY);
|
|
|
+ pos.set(oldPosX, oldPosY);
|
|
|
}
|
|
|
|
|
|
public void renderTick(float lag)
|
|
|
{
|
|
|
- controller.renderTick(lag);
|
|
|
+ controller.renderTick(this, lag);
|
|
|
}
|
|
|
|
|
|
//--------------------------------------------------------------------------
|