diff --git a/bin/tfg/Game.class b/bin/tfg/Game.class index 7e40da1..c4a3087 100644 Binary files a/bin/tfg/Game.class and b/bin/tfg/Game.class differ diff --git a/bin/tfg/Map.class b/bin/tfg/Map.class index c409f3e..d96b208 100644 Binary files a/bin/tfg/Map.class and b/bin/tfg/Map.class differ diff --git a/bin/tfg/Player.class b/bin/tfg/Player.class index ce74f69..cfb5828 100644 Binary files a/bin/tfg/Player.class and b/bin/tfg/Player.class differ diff --git a/src/tfg/Game.java b/src/tfg/Game.java index d9b1aa4..ab9a6dd 100644 --- a/src/tfg/Game.java +++ b/src/tfg/Game.java @@ -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()); } } diff --git a/src/tfg/Map.java b/src/tfg/Map.java index 729361c..0e5a37b 100644 --- a/src/tfg/Map.java +++ b/src/tfg/Map.java @@ -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++) { diff --git a/src/tfg/Player.java b/src/tfg/Player.java index cf091a9..f31bc24 100644 --- a/src/tfg/Player.java +++ b/src/tfg/Player.java @@ -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();