Nana can't stop phasing through walls

Co-authored-by: r3cp3ct <45179536+r3cp3ct@users.noreply.github.com>
Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
main
unknown 3 years ago
parent a2b0648074
commit 7161b5ffc9
  1. BIN
      maps/world1.map
  2. 6
      src/sig/map/CollisionType.java
  3. 32
      src/sig/map/Tile.java
  4. 2
      src/sig/objects/LevelRenderer.java
  5. 24
      src/sig/objects/Player.java

Binary file not shown.

@ -0,0 +1,6 @@
package sig.map;
public enum CollisionType {
BLOCK,
NONE
}

@ -1,12 +1,12 @@
package sig.map;
public enum Tile {
VOID(0,0,true), //File is populated by 0s by default. This represents the void.
WALL(0,0),
FLOOR(1,0),
PLATFORM_LEDGE(2,0),
INVISIBLE_WALL(0,0,true),
HIGHLIGHTED_TILE(3,0),
VOID(0,0,true,CollisionType.NONE), //File is populated by 0s by default. This represents the void.
WALL(0,0,CollisionType.BLOCK),
FLOOR(1,0,CollisionType.BLOCK),
PLATFORM_LEDGE(2,0,CollisionType.BLOCK),
INVISIBLE_WALL(0,0,true,CollisionType.BLOCK),
HIGHLIGHTED_TILE(3,0,CollisionType.BLOCK),
;
final public static int TILE_WIDTH=32;
@ -14,7 +14,20 @@ public enum Tile {
int spriteSheetX,spriteSheetY;
boolean invisible;
CollisionType collision;
public boolean isInvisible() {
return invisible;
}
public void setInvisible(boolean invisible) {
this.invisible = invisible;
}
public CollisionType getCollision() {
return collision;
}
public void setCollision(CollisionType collision) {
this.collision = collision;
}
int tileWidth=TILE_WIDTH,tileHeight=TILE_HEIGHT;
/*Tile(int spriteSheetX,int spriteSheetY,int tileWidth,int tileHeight) {
this.spriteSheetX=spriteSheetX;
@ -22,13 +35,14 @@ public enum Tile {
this.tileWidth=tileWidth;
this.tileHeight=tileHeight;
}*/
Tile(int spriteSheetX,int spriteSheetY,boolean invisible) {
Tile(int spriteSheetX,int spriteSheetY,boolean invisible, CollisionType collision) {
this.spriteSheetX=spriteSheetX;
this.spriteSheetY=spriteSheetY;
this.invisible=invisible;
this.collision=collision;
}
Tile(int spriteSheetX,int spriteSheetY) {
this(spriteSheetX, spriteSheetY, false);
Tile(int spriteSheetX,int spriteSheetY, CollisionType collision) {
this(spriteSheetX, spriteSheetY, false, collision);
}
public int getSpriteSheetX() {

@ -45,7 +45,7 @@ public class LevelRenderer extends Object{
Map.SaveMap(RabiClone.CURRENT_MAP);
System.out.println("Map saved");
}
setY(RabiClone.player.getY());
setY(RabiClone.player.getY()-RabiClone.BASE_HEIGHT*(2/3d));
}
@Override

@ -4,12 +4,14 @@ import sig.RabiClone;
import sig.engine.Object;
import sig.engine.Panel;
import sig.engine.Sprite;
import sig.map.CollisionType;
import sig.map.Tile;
public class Player extends Object{
double y_acceleration = 20;
double y_acceleration = 15;
double x_acceleration = 0;
double x_velocity = 0;
double y_velocity = -4;
double y_velocity = 5;
public Player(Panel panel) {
super(panel);
@ -23,7 +25,23 @@ public class Player extends Object{
public void update(double updateMult) {
y_velocity += y_acceleration*updateMult;
double displacement = y_velocity*updateMult;
this.setY(this.getY()+displacement);
boolean is_collision = false;
for(int i=0;i<4;i++){
double check_distance = (displacement/4)*(i+1);
Tile checked_tile_top = RabiClone.CURRENT_MAP.getTile((int)getX()/Tile.TILE_WIDTH, (int)(getY()+check_distance)/Tile.TILE_HEIGHT);
Tile checked_tile_bottom = RabiClone.CURRENT_MAP.getTile((int)(getX()+getSprite().getWidth())/Tile.TILE_WIDTH, (int)(getY()+getSprite().getHeight()+check_distance)/Tile.TILE_HEIGHT);
//System.out.println((int)getX()/Tile.TILE_WIDTH);
if(checked_tile_bottom.getCollision()==CollisionType.BLOCK){
setY((getY()+check_distance)+getSprite().getHeight()/2);
y_acceleration = 0;
y_velocity = 0;
is_collision=true;
break;
}
}
if (!is_collision){
this.setY(this.getY()+displacement);
}
}
@Override

Loading…
Cancel
Save