Ability to walk down and up slopes

Co-authored-by: r3cp3ct <45179536+r3cp3ct@users.noreply.github.com>
Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
main
sigonasr2 3 years ago
parent dac67fda41
commit c804490c7b
  1. BIN
      maps/world1.map
  2. 14
      src/sig/map/Map.java
  3. 54
      src/sig/objects/Player.java

Binary file not shown.

@ -114,14 +114,18 @@ public class Map {
public void ModifyTile(int x,int y,Tile t) {
Tile prevTile = Tile.values()[tiles[y*Map.MAP_WIDTH+x]];
boolean prevIsCollisionTile=prevTile.getCollision()==CollisionType.SOLID;
boolean newIsCollisionTile=t.getCollision()==CollisionType.SOLID;
if (prevIsCollisionTile!=newIsCollisionTile) {
if (prevTile!=t) {
byte[] tilesheet = Sprite.TILE_SHEET.getBi_array();
boolean setSolid = t.getCollision()==CollisionType.SOLID;
for (int yy=0;yy<Tile.TILE_HEIGHT;yy++) {
for (int xx=0;xx<Tile.TILE_WIDTH;xx++) {
RabiClone.COLLISION[(y*Tile.TILE_HEIGHT+yy)*(Map.MAP_WIDTH*Tile.TILE_WIDTH)+(x*Tile.TILE_WIDTH+xx)]=newIsCollisionTile;
if (tilesheet[(t.getSpriteSheetY()*Tile.TILE_HEIGHT+yy)*Sprite.TILE_SHEET.getCanvasWidth()+t.getSpriteSheetX()*Tile.TILE_WIDTH+xx]!=(byte)32) {
RabiClone.COLLISION[(y*Tile.TILE_HEIGHT+yy)*(Map.MAP_WIDTH*Tile.TILE_WIDTH)+(x*Tile.TILE_WIDTH+xx)]=setSolid;
} else {
RabiClone.COLLISION[(y*Tile.TILE_HEIGHT+yy)*(Map.MAP_WIDTH*Tile.TILE_WIDTH)+(x*Tile.TILE_WIDTH+xx)]=false;
}
}
}
}
}
tiles[y*Map.MAP_WIDTH+x]=(char)(t.ordinal());
//System.out.println("Tile "+(y*MAP_WIDTH+x)+" is now "+tiles[y*MAP_WIDTH+x]+".");

@ -369,13 +369,25 @@ public class Player extends AnimatedObject implements CollisionEntity {
continue;
}
if (checkCollision(x+getCollisionBox().getX2()-getSprite().getWidth()/2,(getY()-getSprite().getHeight()/2+getCollisionBounds().getY2()))||
checkCollision(x+getCollisionBox().getX2()-getSprite().getWidth()/2,(getY()-getSprite().getHeight()/2+getCollisionBounds().getY2()))) {
x_acceleration = 0;
x_velocity = 0.000001;
sideCollision=true;
setX(x-0.1);
break;
}
checkCollision(x+getCollisionBox().getX2()-getSprite().getWidth()/2,(getY()-getSprite().getHeight()/2+getCollisionBounds().getY()))) {
if (!(checkCollision(x+getCollisionBox().getX2()-getSprite().getWidth()/2,(getY()-getSprite().getHeight()/2+getCollisionBounds().getY2()-1))&&
checkCollision(x+getCollisionBox().getX2()-getSprite().getWidth()/2,(getY()-getSprite().getHeight()/2+getCollisionBounds().getY()-1)))) {
setY(getY()-1);
} else {
x_acceleration = 0;
x_velocity = 0.000001;
sideCollision=true;
setX(x-0.1);
break;
}
} else {
if (!checkCollision(x+getCollisionBox().getX()-getSprite().getWidth()/2,(getY()-getSprite().getHeight()/2+getCollisionBounds().getY2()+1))&&
checkCollision(x+getCollisionBox().getX()-getSprite().getWidth()/2,(getY()-getSprite().getHeight()/2+getCollisionBounds().getY2()+2))) {
//System.out.println("Performs check."+System.currentTimeMillis());
setY(getY()+1);
//x_velocity = ;
}
}
}
} else
if (displacement_x<-0.00001) {
@ -385,17 +397,29 @@ public class Player extends AnimatedObject implements CollisionEntity {
}
if (checkCollision((x+getCollisionBox().getX()-getSprite().getWidth()/2),getY()-getSprite().getHeight()/2+getCollisionBounds().getY2())||
checkCollision((x+getCollisionBox().getX()-getSprite().getWidth()/2),getY()-getSprite().getHeight()/2+getCollisionBounds().getY())) {
x_acceleration = 0;
x_velocity = -0.000001;
sideCollision=true;
setX(x+0.1);
break;
}
if (!(checkCollision(x+getCollisionBox().getX()-getSprite().getWidth()/2,(getY()-getSprite().getHeight()/2+getCollisionBounds().getY2()-1))&&
checkCollision(x+getCollisionBox().getX()-getSprite().getWidth()/2,(getY()-getSprite().getHeight()/2+getCollisionBounds().getY()-1)))) {
setY(getY()-1);
} else {
x_acceleration = 0;
x_velocity = -0.000001;
sideCollision=true;
setX(x+0.1);
break;
}
} else {
if (!checkCollision(x+getCollisionBox().getX2()-getSprite().getWidth()/2,(getY()-getSprite().getHeight()/2+getCollisionBounds().getY2()+1))&&
checkCollision(x+getCollisionBox().getX2()-getSprite().getWidth()/2,(getY()-getSprite().getHeight()/2+getCollisionBounds().getY2()+2))) {
//System.out.println("Performs check."+System.currentTimeMillis());
setY(getY()+1);
//x_velocity = ;
}
}
}
}
if (y_velocity==0) {
if (!(checkCollision(getX()-getSprite().getWidth()/2+getCollisionBox().getX2(),getY()-getSprite().getHeight()/2+getCollisionBounds().getY2()+1)||
checkCollision(getX()-getSprite().getWidth()/2+getCollisionBox().getX(),getY()-getSprite().getHeight()/2+getCollisionBounds().getY2()+1))) {
if (!(checkCollision(getX()-getSprite().getWidth()/2+getCollisionBox().getX2(),getY()-getSprite().getHeight()/2+getCollisionBounds().getY2()+2)||
checkCollision(getX()-getSprite().getWidth()/2+getCollisionBox().getX(),getY()-getSprite().getHeight()/2+getCollisionBounds().getY2()+2))) {
groundCollision=false;
} else {
groundCollision=true;

Loading…
Cancel
Save