From a982df2063422bd4c439743cd0d05b0dcbb9cf36 Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Tue, 31 May 2022 23:37:32 -0500 Subject: [PATCH] Do not allow jumps to be recovered from hitting the roof of blocks Co-authored-by: r3cp3ct <45179536+r3cp3ct@users.noreply.github.com> Co-authored-by: sigonasr2 --- src/sig/RabiClone.java | 4 +++- src/sig/objects/LevelRenderer.java | 13 +++++++++++-- src/sig/objects/Player.java | 8 ++++---- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/sig/RabiClone.java b/src/sig/RabiClone.java index 81c8335..f226ef3 100644 --- a/src/sig/RabiClone.java +++ b/src/sig/RabiClone.java @@ -29,7 +29,7 @@ public class RabiClone{ public static Point MOUSE_POS; public static LevelRenderer level_renderer; - public static Player player; + public static Player player,player2; public static Maps CURRENT_MAP = Maps.WORLD1; public static void main(String[] args) { @@ -53,6 +53,8 @@ public class RabiClone{ OBJ.add(level_renderer = new LevelRenderer(p)); OBJ.add(player = new Player(p)); + OBJ.add(player2 = new Player(p)); + player2.setX(64); p.render(); diff --git a/src/sig/objects/LevelRenderer.java b/src/sig/objects/LevelRenderer.java index 723bd85..9e63992 100644 --- a/src/sig/objects/LevelRenderer.java +++ b/src/sig/objects/LevelRenderer.java @@ -19,6 +19,7 @@ public class LevelRenderer extends Object{ public LevelRenderer(Panel panel) { super(panel); this.setSprite(Sprite.TILE_SHEET); + setY(Tile.TILE_HEIGHT*6); } @Override @@ -45,8 +46,6 @@ public class LevelRenderer extends Object{ Map.SaveMap(RabiClone.CURRENT_MAP); System.out.println("Map saved"); } - setX(RabiClone.player.getX()-RabiClone.BASE_WIDTH/2); - setY(RabiClone.player.getY()-RabiClone.BASE_HEIGHT*(2/3d)); } @Override @@ -78,6 +77,16 @@ public class LevelRenderer extends Object{ } } } + Draw_Object(RabiClone.player); + Draw_Object(RabiClone.player2); + } + + /** + * Draws an object where its sprite is centered among its position and drawn relative to the camera position. + * @param object + */ + protected void Draw_Object(Object object) { + super.Draw_Sprite(object.getX()-this.getX()-object.getSprite().getWidth()/2, object.getY()-this.getY()-object.getSprite().getHeight()/2, object.getSprite()); } private void DrawTile(double x, double y, Tile tile) { diff --git a/src/sig/objects/Player.java b/src/sig/objects/Player.java index 6182e65..56d85a8 100644 --- a/src/sig/objects/Player.java +++ b/src/sig/objects/Player.java @@ -71,6 +71,9 @@ public class Player extends Object{ //System.out.println((int)getX()/Tile.TILE_WIDTH); if(checked_tile_bottom_right.getCollision()==CollisionType.BLOCK||checked_tile_bottom_left.getCollision()==CollisionType.BLOCK){ setY((getY()-check_distance_y)); + if (y_velocity>0) { + jumpCount=maxJumpCount; + } y_acceleration = 0; y_velocity = 0; groundCollision=true; @@ -98,7 +101,6 @@ public class Player extends Object{ this.setX(this.getX()+displacement_x); } } else { - jumpCount=maxJumpCount; if (KeyHeld(KeyEvent.VK_SPACE)&&jumpCount>0) { jumpCount--; y_velocity = jump_velocity; @@ -130,8 +132,6 @@ public class Player extends Object{ } @Override - public void draw(byte[] p) { - Draw_Sprite(RabiClone.BASE_WIDTH/2-getSprite().getWidth()/2,RabiClone.BASE_HEIGHT*(2/3d)-getSprite().getHeight()/2, this.getSprite()); - } + public void draw(byte[] p) {} }