|
|
|
@ -362,70 +362,22 @@ public class Player extends AnimatedObject implements CollisionEntity { |
|
|
|
|
double displacement_x = x_velocity*updateMult; |
|
|
|
|
|
|
|
|
|
boolean sideCollision = false; |
|
|
|
|
for(int i=0;i<4;i++){ |
|
|
|
|
double check_distance_x = (displacement_x/4)*(i+1); |
|
|
|
|
|
|
|
|
|
Tile checked_tile_top_right = RabiClone.CURRENT_MAP.getTile((int)(getX()+getAnimatedSpr().getWidth()/2-4+check_distance_x)/Tile.TILE_WIDTH, (int)(getY()+getAnimatedSpr().getHeight()/2)/Tile.TILE_HEIGHT); |
|
|
|
|
Tile checked_tile_top_left = RabiClone.CURRENT_MAP.getTile((int)(getX()-getAnimatedSpr().getWidth()/2+4+check_distance_x)/Tile.TILE_WIDTH, (int)(getY()+getAnimatedSpr().getHeight()/2)/Tile.TILE_HEIGHT); |
|
|
|
|
Tile checked_tile_bottom_center = RabiClone.CURRENT_MAP.getTile((int)(getX())/Tile.TILE_WIDTH, (int)(getY()+getAnimatedSpr().getHeight()/2)/Tile.TILE_HEIGHT); |
|
|
|
|
|
|
|
|
|
if(checked_tile_top_right.getCollision()==CollisionType.BLOCK||checked_tile_top_left.getCollision()==CollisionType.BLOCK){ |
|
|
|
|
//System.out.println(checked_tile_top_right.getCollision()+"//"+checked_tile_top_left.getCollision());
|
|
|
|
|
if(checked_tile_bottom_center.getCollision()==CollisionType.SLOPE){ |
|
|
|
|
} else { |
|
|
|
|
if (checked_tile_top_right.getCollision()==CollisionType.BLOCK) { |
|
|
|
|
setX(((int)(getX()-getAnimatedSpr().getWidth()/2)/Tile.TILE_WIDTH)*Tile.TILE_WIDTH+Tile.TILE_WIDTH/2+3+check_distance_x); |
|
|
|
|
} else { |
|
|
|
|
setX(((int)(getX()+getAnimatedSpr().getWidth())/Tile.TILE_WIDTH)*Tile.TILE_WIDTH-Tile.TILE_WIDTH/2-3+check_distance_x); |
|
|
|
|
} |
|
|
|
|
double startingX=getX(); |
|
|
|
|
if (displacement_x>0) { |
|
|
|
|
for (int x=(int)getX();x<startingX+displacement_x;x++) { |
|
|
|
|
if (x==getX()) { |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
if (RabiClone.COLLISION[(int)((getY()-RabiClone.level_renderer.getY())*RabiClone.BASE_WIDTH+(x-RabiClone.level_renderer.getX()+getCollisionBox().getX2()-getSprite().getWidth()/2))]) { |
|
|
|
|
x_acceleration = 0; |
|
|
|
|
x_velocity = Math.signum(x_velocity)*0.000001; |
|
|
|
|
sideCollision=true; |
|
|
|
|
} |
|
|
|
|
setX(x-1); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (y_velocity==0) { |
|
|
|
|
Tile checked_tile_bottom_right = RabiClone.CURRENT_MAP.getTile((int)(getX()+getAnimatedSpr().getWidth()/2-4)/Tile.TILE_WIDTH, (int)(getY()+getAnimatedSpr().getHeight()/2+1)/Tile.TILE_HEIGHT); |
|
|
|
|
Tile checked_tile_bottom_left = RabiClone.CURRENT_MAP.getTile((int)(getX()-getAnimatedSpr().getWidth()/2+4)/Tile.TILE_WIDTH, (int)(getY()+getAnimatedSpr().getHeight()/2+1)/Tile.TILE_HEIGHT); |
|
|
|
|
Tile checked_tile_bottom_center = RabiClone.CURRENT_MAP.getTile((int)(getX())/Tile.TILE_WIDTH, (int)(getY()+getAnimatedSpr().getHeight()/2)/Tile.TILE_HEIGHT); |
|
|
|
|
|
|
|
|
|
if (!(checked_tile_bottom_right.getCollision()==CollisionType.BLOCK |
|
|
|
|
||checked_tile_bottom_left.getCollision()==CollisionType.BLOCK |
|
|
|
|
||checked_tile_bottom_center.getCollision()==CollisionType.SLOPE)) { |
|
|
|
|
groundCollision=false; |
|
|
|
|
} else { |
|
|
|
|
if(checked_tile_bottom_center.getCollision()==CollisionType.SLOPE){ |
|
|
|
|
moveUpSlope(checked_tile_bottom_center); |
|
|
|
|
} |
|
|
|
|
groundCollision=true; |
|
|
|
|
jumpCount=maxJumpCount; |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
//System.out.println(x_velocity);
|
|
|
|
|
//System.out.println(((int)(getX()+getAnimatedSpr().getWidth()/2+displacement_x)/Tile.TILE_WIDTH)+"//"+((int)(getY()+getAnimatedSpr().getHeight()/2)/Tile.TILE_HEIGHT));
|
|
|
|
|
boolean collisionOccured=false; |
|
|
|
|
for(int i=0;i<4;i++){ |
|
|
|
|
double check_distance_y = (displacement_y/4)*(i+1); |
|
|
|
|
Tile checked_tile_bottom_right = RabiClone.CURRENT_MAP.getTile((int)(getX()+getAnimatedSpr().getWidth()/2-4)/Tile.TILE_WIDTH, (int)(getY()+getAnimatedSpr().getHeight()/2+check_distance_y)/Tile.TILE_HEIGHT); |
|
|
|
|
Tile checked_tile_bottom_left = RabiClone.CURRENT_MAP.getTile((int)(getX()-getAnimatedSpr().getWidth()/2+4)/Tile.TILE_WIDTH, (int)(getY()+getAnimatedSpr().getHeight()/2+check_distance_y)/Tile.TILE_HEIGHT); |
|
|
|
|
Tile checked_tile_bottom_center = RabiClone.CURRENT_MAP.getTile((int)(getX())/Tile.TILE_WIDTH, (int)(getY()+getAnimatedSpr().getHeight()/2)/Tile.TILE_HEIGHT); |
|
|
|
|
if(checked_tile_bottom_center.getCollision()==CollisionType.SLOPE |
|
|
|
|
&& getY()+check_distance_y>ySlopeCollisionPoint(checked_tile_bottom_center)) |
|
|
|
|
{ |
|
|
|
|
moveUpSlope(checked_tile_bottom_center); |
|
|
|
|
collisionOccured = groundCollision(0); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
//System.out.println((int)getX()/Tile.TILE_WIDTH);
|
|
|
|
|
if(checked_tile_bottom_right.getCollision()==CollisionType.BLOCK||checked_tile_bottom_left.getCollision()==CollisionType.BLOCK){ |
|
|
|
|
collisionOccured = groundCollision(check_distance_y); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (!collisionOccured) { |
|
|
|
|
groundCollision=false; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
groundCollision=true; |
|
|
|
|
if (!groundCollision){ |
|
|
|
|
this.setY(this.getY()+displacement_y); |
|
|
|
|
y_acceleration = GRAVITY; |
|
|
|
|