xpos = Player Xposition
ypos = Player Yposition
PlayingState.xOffset = map x
PlayingState.xOffset = map y
Speed fields
private double runningSpeed = 6;
private double normalSpeed = 4;
public double speed;
Player width and height are 30
and blocks are 32
if you need something else just ask!
this is where i move map and check for collision
private void EntityMovement(double deltaTime) {
if(canMove){
if(isLeft()){
if(!Collision.PlayerBlock(
//LEFT DOWN
new Point( (int) xpos + PlayingState.xOffset ,
(int) (ypos + PlayingState.yOffset - height)),
//LEFT UP
new Point( (int) (xpos + PlayingState.xOffset),
(int) (ypos + PlayingState.yOffset)))){
if(PlayingState.xOffset > 1){
//MOVE MAP
PlayingState.xOffset -= speed * deltaTime;
}
}
}
if(isRight()) {
if(!Collision.PlayerBlock(
// RIGHT DOWN
new Point( (int) xpos + PlayingState.xOffset + width ,
(int) (ypos + PlayingState.yOffset - height)),
// RIGHT UP
new Point( (int) (xpos + PlayingState.xOffset + width),
(int) (ypos + PlayingState.yOffset)))){
if(PlayingState.xOffset < 5110){
//MOVE MAP
PlayingState.xOffset += speed * deltaTime;
}
}
}
if(isUp()){
if(!Collision.PlayerBlock(
//UP LEFT
new Point( (int) xpos + PlayingState.xOffset ,
(int) (ypos + PlayingState.yOffset)),
//UP RIGHT
new Point( (int) (xpos + PlayingState.xOffset + width),
(int) (ypos + PlayingState.yOffset)))){
if(PlayingState.yOffset > 20){
//MOVE MAP
PlayingState.yOffset -= speed * deltaTime;
}
}
}
if(isDown()) {
if(!Collision.PlayerBlock(
//DOWN RIGHT
new Point( (int) xpos + PlayingState.xOffset ,
(int) (ypos + PlayingState.yOffset + height)),
//DOWN LEFT
new Point( (int) (xpos + PlayingState.xOffset + width),
(int) (ypos + PlayingState.yOffset + height)))){
if(PlayingState.yOffset < 5700){
//MOVE MAP
PlayingState.yOffset += speed * deltaTime;
}
}
}
if(isRunning()){
if(getStamina() > 2){
speed = runningSpeed;
setAnimationSpeed(50);
}
if(getStamina() < 2){
speed = normalSpeed;
setAnimationSpeed(200);
}
LoseStamina(deltaTime);
}else{
addStamina(deltaTime);
setAnimationSpeed(200);
speed = normalSpeed;
}
}
}
this is the collision Class
public static boolean PlayerBlock(Point pt1, Point pt2) {
for(Block b : PlayingState.blocks){
if(b.isSolid()){
if(b.contains(pt1) || b.contains(pt2)){
return true;
}
}
}
return false;
}
but what ever i do he always goes a small bit in to the block and prevent me from moving other ways
so if i walk right he goes little in to the block that prevents me from moving up and down!
how do i make so he does not go in to the block?
and sometimes he goes different jumps in to the block!!!