-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
161 additions
and
46 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,6 +1,6 @@ | ||
name: "CI Build" | ||
|
||
on: [ push, pull_request ] | ||
on: [ push ] | ||
|
||
jobs: | ||
check: | ||
|
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
37 changes: 37 additions & 0 deletions
37
app-javafx/src/main/java/software/onepiece/javarcade/engine/GameLoop.java
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,37 @@ | ||
package software.onepiece.javarcade.engine; | ||
|
||
import java.util.concurrent.Executors; | ||
import java.util.concurrent.ScheduledExecutorService; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
public class GameLoop { | ||
|
||
private ScheduledExecutorService exec; | ||
private GameState gameState; | ||
|
||
|
||
public void run(GameState gameState) { | ||
this.gameState = gameState; | ||
exec = Executors.newSingleThreadScheduledExecutor(); | ||
exec.scheduleAtFixedRate(this::update, 0, 20, TimeUnit.MILLISECONDS); | ||
} | ||
|
||
private void update() { | ||
if (gameState.isUp()) { | ||
gameState.getPlayer().moveUp(gameState.state, gameState.inhabitants); | ||
} | ||
if (gameState.isDown()) { | ||
gameState.getPlayer().moveDown(gameState.state, gameState.inhabitants); | ||
} | ||
if (gameState.isLeft()) { | ||
gameState.getPlayer().moveLeft(gameState.state, gameState.inhabitants); | ||
} | ||
if (gameState.isRight()) { | ||
gameState.getPlayer().moveRight(gameState.state, gameState.inhabitants); | ||
} | ||
} | ||
|
||
public void stop() { | ||
exec.shutdown(); | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
app-javafx/src/main/java/software/onepiece/javarcade/engine/GameState.java
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,61 @@ | ||
package software.onepiece.javarcade.engine; | ||
|
||
import software.onepiece.javarcade.model.Inhabitant; | ||
import software.onepiece.javarcade.model.Spot; | ||
|
||
import java.util.LinkedHashMap; | ||
import java.util.LinkedList; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class GameState { | ||
|
||
private boolean up; | ||
private boolean down; | ||
private boolean left; | ||
private boolean right; | ||
|
||
private Spot player; | ||
public final Map<Character, Inhabitant> inhabitants = new LinkedHashMap<>(); | ||
public final List<Spot> state = new LinkedList<>(); | ||
|
||
public boolean isUp() { | ||
return up; | ||
} | ||
|
||
public void setUp(boolean up) { | ||
this.up = up; | ||
} | ||
|
||
public boolean isDown() { | ||
return down; | ||
} | ||
|
||
public void setDown(boolean down) { | ||
this.down = down; | ||
} | ||
|
||
public boolean isLeft() { | ||
return left; | ||
} | ||
|
||
public void setLeft(boolean left) { | ||
this.left = left; | ||
} | ||
|
||
public boolean isRight() { | ||
return right; | ||
} | ||
|
||
public void setRight(boolean right) { | ||
this.right = right; | ||
} | ||
|
||
public Spot getPlayer() { | ||
return player; | ||
} | ||
|
||
public void setPlayer(Spot player) { | ||
this.player = player; | ||
} | ||
} |
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