diff --git a/maps/world1.map b/maps/world1.map index 34e6161..1432afe 100644 Binary files a/maps/world1.map and b/maps/world1.map differ diff --git a/src/sig/objects/Erinoah.java b/src/sig/objects/Erinoah.java index 67fd0a3..3c4601b 100644 --- a/src/sig/objects/Erinoah.java +++ b/src/sig/objects/Erinoah.java @@ -9,10 +9,23 @@ import sig.objects.actor.RenderedObject; public class Erinoah extends PhysicsObject implements RenderedObject{ + double lastMoved = 0; + boolean moveDir = false; + double moveTimer = 0; + public Erinoah(double x, double y) { super(Sprite.ERINOAH,6.5,RabiClone.p); setX(x); setY(y); + setAccelerationLimits(100, 100); + setVelocityLimits(246, 500); + setGroundDrag(2000); + setGroundFriction(PhysicsObject.NORMAL_FRICTION); + setAirDrag(800); + setAirFriction(180); + setSlidingVelocity(164); + setSlidingAcceleration(120); + setJumpVelocity(PhysicsObject.NORMAL_JUMP_VELOCITY); } @Override @@ -23,6 +36,23 @@ public class Erinoah extends PhysicsObject implements RenderedObject{ @Override public void update(double updateMult) { super.update(updateMult); + lastMoved+=updateMult; + if (lastMoved>5) { + switch ((int)(Math.random()*3)) { + case 0:{ + moveDir=true; + moveTimer=Math.random()*3; + }break; + case 1:{ + moveDir=false; + moveTimer=Math.random()*3; + }break; + case 2:{ + lastMoved=0; + }break; + } + } + moveTimer-=updateMult; } @Override @@ -36,11 +66,11 @@ public class Erinoah extends PhysicsObject implements RenderedObject{ @Override public boolean rightKeyHeld() { - return false; + return moveTimer>0&&moveDir; } @Override public boolean leftKeyHeld() { - return false; + return moveTimer>0&&!moveDir; } } diff --git a/src/sig/objects/LevelRenderer.java b/src/sig/objects/LevelRenderer.java index 42a4d5b..5e8e5a4 100644 --- a/src/sig/objects/LevelRenderer.java +++ b/src/sig/objects/LevelRenderer.java @@ -73,7 +73,7 @@ public class LevelRenderer extends Object{ } } if (RabiClone.player!=null) { - Draw_Text(4,4,new String(RabiClone.player.y_velocity),Font.PROFONT_12); + Draw_Text(4,4,new String(RabiClone.player.getYVelocity()),Font.PROFONT_12); Draw_Text(4,4+Font.PROFONT_12.getGlyphHeight(),new String(RabiClone.scaleTime),Font.PROFONT_12); } } diff --git a/src/sig/objects/Player.java b/src/sig/objects/Player.java index d94220b..b0b10e4 100644 --- a/src/sig/objects/Player.java +++ b/src/sig/objects/Player.java @@ -21,34 +21,12 @@ public class Player extends PhysicsObject implements RenderedObject{ final static long slide_AnimationWaitTime = TimeUtils.millisToNanos(100); final static long slide_duration = TimeUtils.millisToNanos(700); - double y_acceleration = PhysicsObject.GRAVITY; - double y_acceleration_limit = 100; - double x_acceleration = 0; - double x_acceleration_limit = 100; - double x_velocity = 0; - double x_velocity_limit = 246; - double y_velocity = 5; - double y_velocity_limit = 500; - double sliding_velocity = 164; - double sliding_acceleration = 120; - - double horizontal_drag = 2000; - double horizontal_friction = PhysicsObject.NORMAL_FRICTION; - double horizontal_air_drag = 800; - double horizontal_air_friction = 180; - - double jump_velocity = PhysicsObject.NORMAL_JUMP_VELOCITY; - - int maxJumpCount = 2; - int jumpCount = maxJumpCount; - State state = State.IDLE; State prvState = state; final double viewBoundaryX = RabiClone.BASE_WIDTH / 3; final double viewBoundaryY = RabiClone.BASE_HEIGHT / 3; View lastCameraView = View.FIXED; - boolean groundCollision = false; boolean spacebarReleased = true; boolean facing_direction = RIGHT; @@ -66,6 +44,15 @@ public class Player extends PhysicsObject implements RenderedObject{ super(Sprite.ERINA, 5, panel); setX(RabiClone.BASE_WIDTH / 2 - getAnimatedSpr().getWidth() / 2); setY(RabiClone.BASE_HEIGHT * (2 / 3d) - getAnimatedSpr().getHeight() / 2); + setAccelerationLimits(100, 100); + setVelocityLimits(246, 500); + setGroundDrag(2000); + setGroundFriction(PhysicsObject.NORMAL_FRICTION); + setAirDrag(800); + setAirFriction(180); + setSlidingVelocity(164); + setSlidingAcceleration(120); + setJumpVelocity(PhysicsObject.NORMAL_JUMP_VELOCITY); } @Override @@ -76,7 +63,6 @@ public class Player extends PhysicsObject implements RenderedObject{ @Override public void update(double updateMult) { super.update(updateMult); - handleMovementPhysics(updateMult); handleCameraRoomMovement(); switch (state) { @@ -365,4 +351,8 @@ public class Player extends PhysicsObject implements RenderedObject{ public boolean leftKeyHeld() { return KeyHeld(Action.MOVE_LEFT); } + + public double getYVelocity() { + return y_velocity; + } } diff --git a/src/sig/objects/actor/PhysicsObject.java b/src/sig/objects/actor/PhysicsObject.java index 465108f..9fc6b93 100644 --- a/src/sig/objects/actor/PhysicsObject.java +++ b/src/sig/objects/actor/PhysicsObject.java @@ -13,16 +13,19 @@ public abstract class PhysicsObject extends AnimatedObject implements PhysicsObj final public static double NORMAL_JUMP_VELOCITY = -300; final public static double WALKING_SPEED_LIMIT = 164; - State state = State.IDLE; - double x_velocity,y_velocity; - double x_acceleration,y_acceleration; - double x_velocity_limit,y_velocity_limit; - boolean groundCollision; - byte maxJumpCount=2; - byte jumpCount=0; + protected State state = State.IDLE; + protected double x_velocity,y_velocity; + protected double x_acceleration,y_acceleration; + protected double x_velocity_limit,y_velocity_limit; + protected double x_acceleration_limit,y_acceleration_limit; + protected boolean groundCollision; + protected byte maxJumpCount=2; + protected byte jumpCount=0; + protected double jump_velocity; - double horizontal_air_friction,horizontal_air_drag; - double horizontal_friction,horizontal_drag; + protected double horizontal_air_friction,horizontal_air_drag; + protected double horizontal_friction,horizontal_drag; + protected double sliding_velocity,sliding_acceleration; protected PhysicsObject(AnimatedSprite spr, double animationSpd, Panel panel) { super(spr, animationSpd, panel); @@ -215,5 +218,59 @@ public abstract class PhysicsObject extends AnimatedObject implements PhysicsObj public Rectangle getCollisionBounds() { return getCollisionBox(); } + + + + @Override + public void setVelocityLimits(double x, double y) { + this.x_velocity_limit=x; + this.y_velocity_limit=y; + } + + @Override + public void setAccelerationLimits(double x, double y) { + this.x_acceleration_limit=x; + this.y_acceleration_limit=y; + } + + @Override + public void setMaxJumpCount(byte jumps) { + this.maxJumpCount=jumps; + } + + @Override + public void setGroundFriction(double x) { + this.horizontal_friction=x; + } + + @Override + public void setAirFriction(double x) { + this.horizontal_air_friction=x; + } + + @Override + public void setGroundDrag(double x) { + this.horizontal_drag=x; + } + + @Override + public void setAirDrag(double x) { + this.horizontal_air_drag=x; + } + + @Override + public void setSlidingVelocity(double x) { + this.sliding_velocity=x; + } + + @Override + public void setSlidingAcceleration(double x) { + this.sliding_acceleration=x; + } + + @Override + public void setJumpVelocity(double x) { + this.jump_velocity=x; + } } diff --git a/src/sig/objects/actor/PhysicsObjectRequirements.java b/src/sig/objects/actor/PhysicsObjectRequirements.java index fbfb612..a4482d3 100644 --- a/src/sig/objects/actor/PhysicsObjectRequirements.java +++ b/src/sig/objects/actor/PhysicsObjectRequirements.java @@ -7,4 +7,14 @@ public interface PhysicsObjectRequirements { boolean leftKeyHeld(); Rectangle getCollisionBounds(); Rectangle setCollisionBounds(); + void setVelocityLimits(double x,double y); + void setAccelerationLimits(double x,double y); + void setMaxJumpCount(byte jumps); + void setGroundFriction(double x); + void setAirFriction(double x); + void setGroundDrag(double x); + void setAirDrag(double x); + void setSlidingVelocity(double x); + void setSlidingAcceleration(double x); + void setJumpVelocity(double x); }