-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
created InputManager class to handle inputs and changed the inputlist…
… to be type KeyCode instead of string.
- Loading branch information
1 parent
949587c
commit d316c2f
Showing
7 changed files
with
100 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,42 @@ | ||
package bomberman; | ||
|
||
import bomberman.constants.GlobalConstants; | ||
import bomberman.entity.Entity; | ||
import bomberman.gamecontroller.InputManager; | ||
import bomberman.scenes.Sandbox; | ||
import javafx.animation.AnimationTimer; | ||
import javafx.scene.canvas.GraphicsContext; | ||
|
||
public class GameLoop { | ||
|
||
|
||
public class GameLoop | ||
{ | ||
static double tickDuration; | ||
final static long startNanoTime = System.nanoTime(); | ||
static double tickDuration; | ||
final static long startNanoTime = System.nanoTime(); | ||
|
||
public static double getTickDuration() { | ||
return tickDuration; | ||
} | ||
|
||
public static void start(GraphicsContext gc) | ||
{ | ||
public static void start(GraphicsContext gc) { | ||
GameState.gameStatus=GlobalConstants.GameStatus.Running; | ||
new AnimationTimer() { | ||
public void handle(long currentNanoTime) { | ||
tickDuration = (currentNanoTime - startNanoTime) / 1000000000.0; | ||
gc.clearRect(0, 0, 512, 512); | ||
//TODO This will have to be something like, currentScene.getEntities() | ||
for(Entity e : Sandbox.getEntities()) | ||
e.draw(); | ||
updateGame(); | ||
renderGame(); | ||
} | ||
}.start(); | ||
} | ||
} | ||
|
||
public static void updateGame() { | ||
InputManager.handlePlayerMovements(); | ||
} | ||
|
||
public static void renderGame() { | ||
for (Entity e : Sandbox.getEntities()) { | ||
e.draw(); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,5 +10,5 @@ | |
* @author ashish.padalkar | ||
*/ | ||
public class GameVariables { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* To change this license header, choose License Headers in Project Properties. | ||
* To change this template file, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
package bomberman.gamecontroller; | ||
|
||
import bomberman.constants.Direction; | ||
import bomberman.entity.player.Player; | ||
import bomberman.scenes.Sandbox; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import javafx.scene.input.KeyCode; | ||
/** | ||
* | ||
* @author Ashish | ||
*/ | ||
public class InputManager { | ||
|
||
public static void handlePlayerMovements(){ | ||
List keyboardInputs = EventHandler.getInputList(); | ||
Player player = Sandbox.getPlayer(); | ||
if(keyboardInputs.contains(KeyCode.UP) || keyboardInputs.contains(KeyCode.W)){ | ||
player.move(5,Direction.UP); | ||
} | ||
if(keyboardInputs.contains(KeyCode.DOWN) || keyboardInputs.contains(KeyCode.S)){ | ||
player.move(5,Direction.DOWN); | ||
} | ||
if(keyboardInputs.contains(KeyCode.LEFT) || keyboardInputs.contains(KeyCode.A)){ | ||
player.move(5,Direction.LEFT); | ||
} | ||
if(keyboardInputs.contains(KeyCode.RIGHT) || keyboardInputs.contains(KeyCode.D)){ | ||
player.move(5,Direction.RIGHT); | ||
} | ||
if( !keyboardInputs.contains(KeyCode.LEFT) && | ||
!keyboardInputs.contains(KeyCode.RIGHT) && | ||
!keyboardInputs.contains(KeyCode.UP) && | ||
!keyboardInputs.contains(KeyCode.DOWN) && | ||
!keyboardInputs.contains(KeyCode.W) && | ||
!keyboardInputs.contains(KeyCode.A) && | ||
!keyboardInputs.contains(KeyCode.S) && | ||
!keyboardInputs.contains(KeyCode.D) | ||
) | ||
{ | ||
player.move(0, Direction.DOWN); | ||
} | ||
} | ||
|
||
} |