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 <sigonasr2@gmail.com>
main
sigonasr2 3 years ago
parent b0be363293
commit a982df2063
  1. 4
      src/sig/RabiClone.java
  2. 13
      src/sig/objects/LevelRenderer.java
  3. 8
      src/sig/objects/Player.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();

@ -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) {

@ -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) {}
}

Loading…
Cancel
Save