[Change] Smoother Movement
[Fix] FPS bug.
This commit is contained in:
parent
97b1e857b0
commit
0ba6a9dcc0
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -2,6 +2,8 @@ package tfg;
|
||||
|
||||
import org.jsfml.graphics.RenderWindow;
|
||||
import org.jsfml.system.Vector2i;
|
||||
import org.jsfml.window.Keyboard;
|
||||
import org.jsfml.window.Keyboard.Key;
|
||||
import org.jsfml.window.VideoMode;
|
||||
import org.jsfml.window.event.Event;
|
||||
|
||||
@ -32,6 +34,8 @@ public class Game {
|
||||
public void handleInitialization() {
|
||||
renderWindow.create(new VideoMode(renderWindowDimensions.x,
|
||||
renderWindowDimensions.y), renderWindowTitle);
|
||||
|
||||
renderWindow.setFramerateLimit(60);
|
||||
|
||||
player = new Player();
|
||||
|
||||
@ -60,40 +64,26 @@ public class Game {
|
||||
case CLOSED:
|
||||
renderWindow.close();
|
||||
break;
|
||||
case KEY_PRESSED:
|
||||
switch(event.asKeyEvent().key) {
|
||||
case ESCAPE:
|
||||
renderWindow.close();
|
||||
break;
|
||||
case W:
|
||||
case UP:
|
||||
player.move(Direction.NORTH);
|
||||
break;
|
||||
case S:
|
||||
case DOWN:
|
||||
player.move(Direction.SOUTH);
|
||||
break;
|
||||
case A:
|
||||
case LEFT:
|
||||
player.move(Direction.WEST);
|
||||
break;
|
||||
case D:
|
||||
case RIGHT:
|
||||
player.move(Direction.EAST);
|
||||
break;
|
||||
case N:
|
||||
player.resetLocation();
|
||||
player.changeMap(getRandomMap());
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(Keyboard.isKeyPressed(Key.W)) {
|
||||
player.move(Direction.NORTH);
|
||||
} else if(Keyboard.isKeyPressed(Key.S)) {
|
||||
player.move(Direction.SOUTH);
|
||||
} else if(Keyboard.isKeyPressed(Key.A)) {
|
||||
player.move(Direction.WEST);
|
||||
} else if(Keyboard.isKeyPressed(Key.D)) {
|
||||
player.move(Direction.EAST);
|
||||
} else if(Keyboard.isKeyPressed(Key.ESCAPE)) {
|
||||
renderWindow.close();
|
||||
}
|
||||
|
||||
if(Keyboard.isKeyPressed(Key.N)) {
|
||||
player.resetLocation();
|
||||
player.changeMap(getRandomMap());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -48,6 +48,7 @@ public class Map implements Drawable {
|
||||
}
|
||||
|
||||
public void draw(RenderTarget target, RenderStates states) {
|
||||
mapVertexArray.clear();
|
||||
final int tileSize = Tile.getSize();
|
||||
for(int i = 0; i < mapDimensions.x; i++) {
|
||||
for(int j = 0; j < mapDimensions.y; j++) {
|
||||
|
@ -28,7 +28,7 @@ public class Player implements Drawable {
|
||||
private PlayerAction currentAction = PlayerAction.NONE;
|
||||
private Location newPlayerLoc;
|
||||
private int frameCounter = 0;
|
||||
private final float animationSpeed = 20.f;
|
||||
private final float animationSpeed = 15.f;
|
||||
private int animationFrame = 0;
|
||||
private SoundBuffer cannotMoveBuffer = new SoundBuffer();
|
||||
private Sound cannotMove = new Sound();
|
||||
|
Loading…
Reference in New Issue
Block a user