Local Game: Added support for mobile players

master
EmaMaker 2020-05-03 14:26:13 +02:00
parent 96b134c3df
commit 607bf7b91e
11 changed files with 536 additions and 326 deletions

View File

@ -12,6 +12,6 @@ public class AndroidLauncher extends AndroidApplication {
super.onCreate(savedInstanceState);
AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
config.useImmersiveMode = true;
initialize(new AMazeIng(), config);
initialize(new AMazeIng(AMazeIng.Platform.ANDROID), config);
}
}

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

View File

@ -31,21 +31,27 @@ public class AMazeIng extends Game {
/* Local manager for local games and server host in multiplayer games */
public GameServer server;
public GameClient client;
static AMazeIng game;
public static Platform PLATFORM;
public AMazeIng(Platform p) {
PLATFORM = p;
}
@Override
public void create() {
game = this;
// Bullet init for physics
Bullet.init();
// Set windowed resolution
Gdx.graphics.setWindowedMode(1280, 720);
//Enable on-screen keyboard for mobile devices
//Gdx.input.setOnscreenKeyboardVisible(true);
// Enable on-screen keyboard for mobile devices
// Gdx.input.setOnscreenKeyboardVisible(true);
// Voxel engine init. Call everything after this
world.init(this);
@ -111,9 +117,12 @@ public class AMazeIng extends Game {
public void resume() {
world.resume();
}
public static AMazeIng getMain() {
return game;
}
public static enum Platform {
DESKTOP, ANDROID, IOS
}
}

View File

@ -1,19 +1,26 @@
package com.emamaker.amazeing.manager;
import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.math.Plane.PlaneSide;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.utils.viewport.ScreenViewport;
import com.emamaker.amazeing.AMazeIng;
import com.emamaker.amazeing.AMazeIng.Platform;
import com.emamaker.amazeing.maze.MazeGenerator;
import com.emamaker.amazeing.maze.settings.MazeSettings;
import com.emamaker.amazeing.player.MazePlayer;
import com.emamaker.amazeing.player.MazePlayerLocal;
import com.emamaker.amazeing.ui.screens.PreGameScreen;
import com.emamaker.voxelengine.block.CellId;
import com.emamaker.voxelengine.player.Player;
import java.util.ArrayList;
import java.util.Random;
import java.util.Set;
import com.badlogic.gdx.Game;
import com.badlogic.gdx.math.Vector3;
import com.emamaker.amazeing.AMazeIng;
import com.emamaker.amazeing.maze.MazeGenerator;
import com.emamaker.amazeing.maze.settings.MazeSettings;
import com.emamaker.amazeing.player.MazePlayer;
import com.emamaker.amazeing.ui.screens.PreGameScreen;
import com.emamaker.voxelengine.block.CellId;
import com.emamaker.voxelengine.player.Player;
public class GameManager {
AMazeIng main;
@ -23,6 +30,8 @@ public class GameManager {
public boolean showGame = true;
public boolean anyoneWon = false;
public Stage stage;
Random rand = new Random();
GameType type = GameType.LOCAL;
@ -32,39 +41,51 @@ public class GameManager {
public GameManager(Game main_, GameType t) {
main = (AMazeIng) main_;
gameStarted = false;
// Maze Generation
type = t;
setShowGame(type != GameType.SERVER);
mazeGen = new MazeGenerator(main, MazeSettings.MAZEX, MazeSettings.MAZEZ);
stage = new Stage(new ScreenViewport());
}
ArrayList<MazePlayer> toDelete = new ArrayList<MazePlayer>();
public void generateMaze(Set<MazePlayer> pl, int todraw[][]) {
main.setScreen(null);
AMazeIng.getMain().multiplexer.removeProcessor(stage);
anyoneWon = false;
if (pl != null) {
for (MazePlayer p : players)
if (!pl.contains(p))
toDelete.add(p);
if(AMazeIng.PLATFORM == Platform.DESKTOP) {
if (pl != null) {
for (MazePlayer p : players)
if (!pl.contains(p))
toDelete.add(p);
// Check if new players have to be added
for (MazePlayer p : pl)
if (!players.contains(p))
players.add(p);
// Check if new players have to be added
for (MazePlayer p : pl)
if (!players.contains(p))
players.add(p);
// Fianlly delete players. A separated step is needed to remove the risk of a
// ConcurrentModificationException
for (MazePlayer p : toDelete) {
p.dispose();
players.remove(p);
// Fianlly delete players. A separated step is needed to remove the risk of a
// ConcurrentModificationException
for (MazePlayer p : toDelete) {
p.dispose();
players.remove(p);
}
toDelete.clear();
}
toDelete.clear();
}else{
for (MazePlayer p : players) {
p.dispose();
}
players.clear();
players.addAll(pl);
}
for (int i = 0; i < MazeSettings.MAZEX; i++) {
for (int j = 0; j < 2; j++) {
for (int k = 0; k < MazeSettings.MAZEZ; k++) {
@ -88,9 +109,19 @@ public class GameManager {
resetCamera();
gameStarted = true;
stage.clear();
if (AMazeIng.PLATFORM == Platform.ANDROID)
for (MazePlayer p : players) {
if (p instanceof MazePlayerLocal)
stage.addActor(((MazePlayerLocal) p).tctrl);
}
AMazeIng.getMain().multiplexer.addProcessor(stage);
}
public void update() {
if (gameStarted && !anyoneWon) {
if (getShowGame()) {
@ -98,6 +129,10 @@ public class GameManager {
resetCamera();
setCamera(new Vector3(mazeGen.w / 2, (MazeSettings.MAZEX + MazeSettings.MAZEZ) * 0.45f, mazeGen.h / 2),
new Vector3(0, -90, 0));
stage.act();
stage.draw();
}
main.world.modelBatch.begin(main.world.cam);
@ -123,12 +158,13 @@ public class GameManager {
main.setScreen(main.uiManager.playersScreen);
} else if (type == GameType.SERVER) {
((PreGameScreen)main.uiManager.preGameScreen)
.setGameType(GameType.SERVER);
((PreGameScreen) main.uiManager.preGameScreen).setGameType(GameType.SERVER);
main.setScreen(main.uiManager.preGameScreen);
}
}
main.world.modelBatch.end();
}
}

View File

@ -20,9 +20,14 @@ public class MazeSettings {
setDim = new MazeSettingDimension("MAZE DIMENSIONS:", new String[] {
"10x10", "20x20", "30x30"
}, 1, AMazeIng.getMain().uiManager);
setPlayers = new MazeSettingMaxPlayers("MAX NUMBER OF PLAYERS: ", new String[] {
"2", "4", "6", "8", "10", "15", "20"
}, AMazeIng.getMain().uiManager);
if(AMazeIng.PLATFORM == AMazeIng.Platform.DESKTOP)
setPlayers = new MazeSettingMaxPlayers("MAX NUMBER OF PLAYERS: ", new String[] {
"2", "4", "6", "8", "10", "15", "20"
}, AMazeIng.getMain().uiManager);
else
setPlayers = new MazeSettingMaxPlayers("MAX NUMBER OF PLAYERS: ", new String[] {
"2", "4"
}, AMazeIng.getMain().uiManager);
settings.add(setDim);
settings.add(setPlayers);

View File

@ -2,6 +2,7 @@ package com.emamaker.amazeing.player;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.controllers.Controller;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Matrix4;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.physics.bullet.collision.btBoxShape;
@ -11,186 +12,295 @@ import com.badlogic.gdx.physics.bullet.collision.btConvexShape;
import com.badlogic.gdx.physics.bullet.collision.btPairCachingGhostObject;
import com.badlogic.gdx.physics.bullet.dynamics.btDiscreteDynamicsWorld;
import com.badlogic.gdx.physics.bullet.dynamics.btKinematicCharacterController;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.InputListener;
import com.badlogic.gdx.scenes.scene2d.ui.Touchpad;
import com.emamaker.amazeing.AMazeIng;
public class MazePlayerLocal extends MazePlayer {
/*
* Player controlled on local machine with mouse and kbd, touch or controller
* (in a remote future=
*/
/*
* Player controlled on local machine with mouse and kbd, touch or controller
* (in a remote future=
*/
btConvexShape ghostShape;
public btPairCachingGhostObject ghostObject;
public btKinematicCharacterController characterController;
Matrix4 characterTransform;
Vector3 characterDirection = new Vector3();
Vector3 walkDirection = new Vector3();
public Controller ctrl;
btConvexShape ghostShape;
public btPairCachingGhostObject ghostObject;
public btKinematicCharacterController characterController;
Matrix4 characterTransform;
Vector3 characterDirection = new Vector3();
Vector3 walkDirection = new Vector3();
public Controller ctrl;
public Touchpad tctrl;
public int tctrlPosition;
// Physics using LibGDX's bullet wrapper
public int kup, kdown, ksx, kdx;
float startx, starty, startz;
boolean touchpadPressed = false;
float oldAngle = 0, angle;
// Give keys in up, down, left, right order
public MazePlayerLocal(int... keys) {
this(keys[0], keys[1], keys[2], keys[3]);
}
// Physics using LibGDX's bullet wrapper
public int kup, kdown, ksx, kdx;
float startx, starty, startz;
public MazePlayerLocal(int up_, int down_, int sx_, int dx_) {
this(up_, down_, sx_, dx_, 0, 0, 0);
}
// Give keys in up, down, left, right order
public MazePlayerLocal(int... keys) {
this(keys[0], keys[1], keys[2], keys[3]);
}
public MazePlayerLocal(int up_, int down_, int sx_, int dx_, String name) {
this(up_, down_, sx_, dx_, 0, 0, 0, name);
}
public MazePlayerLocal(int up_, int down_, int sx_, int dx_) {
this(up_, down_, sx_, dx_, 0, 0, 0);
}
public MazePlayerLocal(int up_, int down_, int sx_, int dx_, float startx, float starty, float startz) {
this(up_, down_, sx_, dx_, startx, starty, startz, String.valueOf((char) (65 + rand.nextInt(26))));
}
public MazePlayerLocal(int up_, int down_, int sx_, int dx_, String name) {
this(up_, down_, sx_, dx_, 0, 0, 0, name);
}
public MazePlayerLocal(int up_, int down_, int sx_, int dx_, float startx, float starty, float startz,
String name) {
super(name, true);
this.kup = up_;
this.kdown = down_;
this.ksx = sx_;
this.kdx = dx_;
public MazePlayerLocal(int up_, int down_, int sx_, int dx_, float startx, float starty, float startz) {
this(up_, down_, sx_, dx_, startx, starty, startz, String.valueOf((char) (65 + rand.nextInt(26))));
}
this.startx = startx;
this.starty = starty;
this.startz = startz;
public MazePlayerLocal(int up_, int down_, int sx_, int dx_, float startx, float starty, float startz,
String name) {
super(name, true);
this.kup = up_;
this.kdown = down_;
this.ksx = sx_;
this.kdx = dx_;
initPhysics();
}
this.startx = startx;
this.starty = starty;
this.startz = startz;
public MazePlayerLocal(Controller ctrl_) {
this(ctrl_, 0, 0, 0);
}
initPhysics();
}
public MazePlayerLocal(Controller ctrl_, String name) {
this(ctrl_, 0, 0, 0, name);
}
public MazePlayerLocal(Controller ctrl_) {
this(ctrl_, 0, 0, 0);
}
public MazePlayerLocal(Controller crtl_, float startx, float starty, float startz) {
this(crtl_, startx, starty, startz, String.valueOf((char) (65 + rand.nextInt(26))));
}
public MazePlayerLocal(Controller ctrl_, String name) {
this(ctrl_, 0, 0, 0, name);
}
public MazePlayerLocal(Controller ctrl_, float startx, float starty, float startz, String name) {
super(true);
this.ctrl = ctrl_;
public MazePlayerLocal(Controller crtl_, float startx, float starty, float startz) {
this(crtl_, startx, starty, startz, String.valueOf((char) (65 + rand.nextInt(26))));
}
this.startx = startx;
this.starty = starty;
this.startz = startz;
public MazePlayerLocal(Controller ctrl_, float startx, float starty, float startz, String name) {
super(true);
this.ctrl = ctrl_;
initPhysics();
}
this.startx = startx;
this.starty = starty;
this.startz = startz;
public void initPhysics() {
characterTransform = instance.transform; // Set by reference
characterTransform.set(startx, starty, startz, 0, 0, 0, 0);
initPhysics();
}
// Create the physics representation of the character
ghostObject = new btPairCachingGhostObject();
ghostObject.setWorldTransform(characterTransform);
ghostShape = new btBoxShape(new Vector3(0.3f, 0.3f, 0.3f));
ghostObject.setCollisionShape(ghostShape);
ghostObject.setCollisionFlags(btCollisionObject.CollisionFlags.CF_CHARACTER_OBJECT);
characterController = new btKinematicCharacterController(ghostObject, ghostShape, .05f, Vector3.Y);
public MazePlayerLocal(Touchpad ctrl_, int p) {
this(ctrl_, p, 0, 0, 0);
}
// And add it to the physics world
main.world.dynamicsWorld.addCollisionObject(ghostObject,
(short) btBroadphaseProxy.CollisionFilterGroups.CharacterFilter,
(short) (btBroadphaseProxy.CollisionFilterGroups.StaticFilter
| btBroadphaseProxy.CollisionFilterGroups.DefaultFilter));
((btDiscreteDynamicsWorld) (main.world.dynamicsWorld)).addAction(characterController);
}
public MazePlayerLocal(Touchpad ctrl_, int p, String name) {
this(ctrl_, p, 0, 0, 0, name);
}
boolean pressed = false;
public MazePlayerLocal(Touchpad crtl_, int p, float startx, float starty, float startz) {
this(crtl_, p, startx, starty, startz, String.valueOf((char) (65 + rand.nextInt(26))));
}
public void inputs() {
pressed = false;
// If the left or right key is pressed, rotate the character and update its
// physics update accordingly.
if (Gdx.input.isKeyPressed(ksx)) {
pressed = true;
characterTransform.rotate(0, 1, 0, 2.5f);
ghostObject.setWorldTransform(characterTransform);
}
if (Gdx.input.isKeyPressed(kdx)) {
pressed = true;
characterTransform.rotate(0, 1, 0, -2.5f);
ghostObject.setWorldTransform(characterTransform);
}
// Fetch which direction the character is facing now
characterDirection.set(-1, 0, 0).rot(characterTransform).nor();
// Set the walking direction accordingly (either forward or backward)
walkDirection.set(0, 0, 0);
public MazePlayerLocal(Touchpad ctrl_, int p, float startx, float starty, float startz, String name) {
super(true);
this.tctrl = ctrl_;
if (Gdx.input.isKeyPressed(kup)) {
pressed = true;
walkDirection.add(characterDirection);
}
if (Gdx.input.isKeyPressed(kdown)) {
pressed = false;
walkDirection.add(-characterDirection.x, -characterDirection.y, -characterDirection.z);
}
walkDirection.scl(3f * Gdx.graphics.getDeltaTime());
// And update the character controller
characterController.setWalkDirection(walkDirection);
// Now we can update the world as normally
// And fetch the new transformation of the character (this will make the model
// be rendered correctly)
ghostObject.getWorldTransform(characterTransform);
this.startx = startx;
this.starty = starty;
this.startz = startz;
this.tctrlPosition = p;
if (pressed)
main.client.updateLocalPlayer(this);
}
tctrl.setResetOnTouchUp(true);
@Override
public void update() {
inputs();
}
oldAngle = 0;
angle = 0;
touchpadPressed = false;
@Override
public Vector3 getPos() {
if (!disposing) {
return ghostObject.getWorldTransform().getTranslation(new Vector3());
}
return null;
}
tctrl.setSize(Gdx.graphics.getHeight() / 6f, Gdx.graphics.getHeight() / 6f);
@Override
public void setPos(Vector3 v) {
this.setPos(v.x, v.y, v.z);
}
tctrl.addListener(new InputListener() {
@Override
public void setPos(float x, float y, float z) {
if (!disposing)
setTransform(x, y, z, 0, 0, 0, 0);
}
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
return true;
}
@Override
public void setTransform(float x, float y, float z, float i, float j, float k, float l) {
if (!disposing) {
characterTransform.set(x, y, z, i, j, k, l);
ghostObject.setWorldTransform(characterTransform);
}
}
@Override
public void touchDragged(InputEvent event, float x, float y, int pointer) {
oldAngle = angle;
angle = MathUtils.atan2(-tctrl.getKnobPercentY(), -tctrl.getKnobPercentX()) * 180f / MathUtils.PI;
@Override
public void dispose() {
super.dispose();
disposing = true;
if(!isDisposed()) {
main.world.dynamicsWorld.removeAction(characterController);
main.world.dynamicsWorld.removeCollisionObject(ghostObject);
characterController.dispose();
ghostObject.dispose();
ghostShape.dispose();
}
disposing = false;
}
touchpadPressed = true;
//System.out.println(angle);
}
@Override
public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
touchpadPressed = false;
}
});
if (tctrlPosition == 0)
tctrl.setPosition(tctrl.getWidth() / 2, tctrl.getHeight() / 2);
else if (tctrlPosition == 1)
tctrl.setPosition(Gdx.graphics.getWidth() - tctrl.getWidth() * 1.5f, tctrl.getHeight() / 2);
else if (tctrlPosition == 2)
tctrl.setPosition(Gdx.graphics.getWidth() - tctrl.getWidth() * 1.5f, Gdx.graphics.getHeight() - tctrl.getHeight() * 1.5f);
else if (tctrlPosition == 3)
tctrl.setPosition(tctrl.getWidth() / 2, Gdx.graphics.getHeight() - tctrl.getHeight() * 1.5f);
initPhysics();
}
public void initPhysics() {
characterTransform = instance.transform; // Set by reference
characterTransform.set(startx, starty, startz, 0, 0, 0, 0);
// Create the physics representation of the character
ghostObject = new btPairCachingGhostObject();
ghostObject.setWorldTransform(characterTransform);
ghostShape = new btBoxShape(new Vector3(0.3f, 0.3f, 0.3f));
ghostObject.setCollisionShape(ghostShape);
ghostObject.setCollisionFlags(btCollisionObject.CollisionFlags.CF_CHARACTER_OBJECT);
characterController = new btKinematicCharacterController(ghostObject, ghostShape, .05f, Vector3.Y);
// And add it to the physics world
main.world.dynamicsWorld.addCollisionObject(ghostObject,
(short) btBroadphaseProxy.CollisionFilterGroups.CharacterFilter,
(short) (btBroadphaseProxy.CollisionFilterGroups.StaticFilter
| btBroadphaseProxy.CollisionFilterGroups.DefaultFilter));
((btDiscreteDynamicsWorld) (main.world.dynamicsWorld)).addAction(characterController);
}
boolean pressed = false;
public void inputs() {
//Update for touchscreen controller is done in touchpad listener
if(AMazeIng.PLATFORM == AMazeIng.Platform.DESKTOP){
if (ctrl != null) {
}else{
pressed = false;
// If the left or right key is pressed, rotate the character and update its
// physics update accordingly.
if (Gdx.input.isKeyPressed(ksx)) {
pressed = true;
characterTransform.rotate(0, 1, 0, 2.5f);
ghostObject.setWorldTransform(characterTransform);
}
if (Gdx.input.isKeyPressed(kdx)) {
pressed = true;
characterTransform.rotate(0, 1, 0, -2.5f);
ghostObject.setWorldTransform(characterTransform);
}
// Fetch which direction the character is facing now
characterDirection.set(-1, 0, 0).rot(characterTransform).nor();
// Set the walking direction accordingly (either forward or backward)
walkDirection.set(0, 0, 0);
if (Gdx.input.isKeyPressed(kup)) {
pressed = true;
walkDirection.add(characterDirection);
}
if (Gdx.input.isKeyPressed(kdown)) {
pressed = false;
walkDirection.add(-characterDirection.x, -characterDirection.y, -characterDirection.z);
}
walkDirection.scl(3f * Gdx.graphics.getDeltaTime());
// And update the character controller
characterController.setWalkDirection(walkDirection);
// Now we can update the world as normally
// And fetch the new transformation of the character (this will make the model
// be rendered correctly)
ghostObject.getWorldTransform(characterTransform);
}
}else{
if(touchpadPressed) {
//characterTransform.rotate(0, 1, 0, angle-oldAngle);
//ghostObject.setWorldTransform(characterTransform);
// Fetch which direction the character is facing now
characterDirection.set(-1, 0, 0).rotate(angle, 0, 1, 0).nor();
// characterDirection.set(-1, 0, 0).rot(characterTransform).nor();
// Set the walking direction accordingly (either forward or backward)
walkDirection.set(0, 0, 0);
walkDirection.add(characterDirection);
walkDirection.scl(3f * Gdx.graphics.getDeltaTime());
// And update the character controller
characterController.setWalkDirection(walkDirection);
// Now we can update the world as normally
// And fetch the new transformation of the character (this will make the model
// be rendered correctly)
ghostObject.getWorldTransform(characterTransform);
oldAngle = angle;
pressed = true;
}
}
if (pressed)
main.client.updateLocalPlayer(this);
}
@Override
public void update() {
inputs();
}
@Override
public Vector3 getPos() {
if (!disposing) {
return ghostObject.getWorldTransform().getTranslation(new Vector3());
}
return null;
}
@Override
public void setPos(Vector3 v) {
this.setPos(v.x, v.y, v.z);
}
@Override
public void setPos(float x, float y, float z) {
if (!disposing)
setTransform(x, y, z, 0, 0, 0, 0);
}
@Override
public void setTransform(float x, float y, float z, float i, float j, float k, float l) {
if (!disposing) {
characterTransform.set(x, y, z, i, j, k, l);
ghostObject.setWorldTransform(characterTransform);
}
}
@Override
public void dispose() {
super.dispose();
disposing = true;
if (!isDisposed()) {
main.world.dynamicsWorld.removeAction(characterController);
main.world.dynamicsWorld.removeCollisionObject(ghostObject);
characterController.dispose();
ghostObject.dispose();
ghostShape.dispose();
disposed = true;
}
disposing = false;
}
}

View File

@ -1,185 +1,226 @@
package com.emamaker.amazeing.ui.screens;
import java.util.ArrayList;
import java.util.HashSet;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.InputListener;
import com.badlogic.gdx.scenes.scene2d.ui.CheckBox;
import com.badlogic.gdx.scenes.scene2d.ui.Container;
import com.badlogic.gdx.scenes.scene2d.ui.Dialog;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.ui.Touchpad;
import com.emamaker.amazeing.AMazeIng;
import com.emamaker.amazeing.AMazeIng.Platform;
import com.emamaker.amazeing.maze.settings.MazeSettings;
import com.emamaker.amazeing.player.MazePlayer;
import com.emamaker.amazeing.player.MazePlayerLocal;
import com.emamaker.amazeing.player.PlayerUtils;
import com.emamaker.amazeing.ui.UIManager;
import java.util.ArrayList;
import java.util.HashSet;
public class PlayerChooseScreen extends MyScreen {
Label[] labels;
int currentLabel = 0;
ArrayList<MazePlayer> players = new ArrayList<MazePlayer>();
Label[] labels;
CheckBox[] buttons;
int currentLabel = 0;
ArrayList<MazePlayer> players = new ArrayList<MazePlayer>();
MyScreen thisScreen;
MyScreen thisScreen;
Container<Table> firstRowContainer;
Table firstRowTable;
Container<Table> firstRowContainer;
Table firstRowTable;
Label instLab, helpDlgText;
TextButton backBtn, setBtn, helpBtn, playBtn, helpDlgOkBtn;
Dialog helpDlg;
Label instLab, helpDlgText;
TextButton backBtn, setBtn, helpBtn, playBtn, helpDlgOkBtn;
Dialog helpDlg;
public PlayerChooseScreen(UIManager uiManager_) {
super(uiManager_);
int totalPlayers = 0;
chmult = 0.8f;
}
public PlayerChooseScreen(UIManager uiManager_) {
super(uiManager_);
@Override
public void createTable() {
super.createTable();
thisScreen = this;
chmult = 0.8f;
}
firstRowContainer = new Container<Table>();
firstRowTable = new Table();
@Override
public void createTable() {
super.createTable();
thisScreen = this;
firstRowContainer.setActor(firstRowTable);
firstRowContainer = new Container<Table>();
firstRowTable = new Table();
instLab = new Label("Use WASD, ARROWS, or button on controller to join the match", uiManager.skin);
backBtn = new TextButton("<", uiManager.skin);
setBtn = new TextButton("Settings", uiManager.skin);
helpBtn = new TextButton("?", uiManager.skin);
playBtn = new TextButton("Play!", uiManager.skin);
/* HELP DIALOG */
helpDlg = new Dialog("Help", uiManager.skin);
firstRowContainer.setActor(firstRowTable);
instLab = new Label(
AMazeIng.PLATFORM == Platform.DESKTOP ? "Use WASD, ARROWS, or button on controller to join the match"
: "Tap the buttons below to join the match",
uiManager.skin);
backBtn = new TextButton("<", uiManager.skin);
setBtn = new TextButton("Settings", uiManager.skin);
helpBtn = new TextButton("?", uiManager.skin);
playBtn = new TextButton("Play!", uiManager.skin);
/* HELP DIALOG */
helpDlg = new Dialog("Help", uiManager.skin);
// helpDlg.setResizable(true);
helpDlgText = new Label("Here you can start a singleplayer or multiplayer game on the local machine:\n"
+ "For keyboard players, pressing W,A,S,D or the directional arrows will toggle two different players.\n"
+ "Pressing a button on a controller will toggle a player.\n"
+ "You can edit game settings from the \"Settings\" menu or use the \"<\" button to go back to the main menu\n"
+ "Press the \"Play!\" button to start the game with the players that have currently joined.\n"
+ "Once a game is finished you will go back to this menu", uiManager.skin);
helpDlg.text(helpDlgText);
helpDlgOkBtn = new TextButton("OK", uiManager.skin);
helpDlg.button(helpDlgOkBtn);
helpDlgOkBtn.addListener(new InputListener() {
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
helpDlg.hide();
helpDlgText = new Label("Here you can start a singleplayer or multiplayer game on the local machine:\n"
+ "For keyboard players, pressing W,A,S,D or the directional arrows will toggle two different players.\n"
+ "Pressing a button on a controller will toggle a player.\n"
+ "Mobile players can tap the buttons below to join the game.\n"
+ "You can edit game settings from the \"Settings\" menu or use the \"<\" button to go back to the main menu\n"
+ "Press the \"Play!\" button to start the game with the players that have currently joined.\n"
+ "Once a game is finished you will go back to this menu", uiManager.skin);
helpDlg.text(helpDlgText);
helpDlgOkBtn = new TextButton("OK", uiManager.skin);
helpDlg.button(helpDlgOkBtn);
helpDlgOkBtn.addListener(new InputListener() {
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
helpDlg.hide();
// hideDialog();
return true;
}
});
return true;
}
});
// Add actions to the buttons
backBtn.addListener(new InputListener() {
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
hide();
uiManager.main.setScreen(uiManager.titleScreen);
return true;
}
});
playBtn.addListener(new InputListener() {
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
if (!players.isEmpty()) {
hide();
uiManager.main.gameManager.generateMaze(new HashSet<>(players));
}
return true;
}
});
setBtn.addListener(new InputListener() {
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
hide();
uiManager.setScreen.setPrevScreen(thisScreen);
uiManager.main.setScreen(uiManager.setScreen);
return true;
}
});
helpBtn.addListener(new InputListener() {
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
helpDlg.show(stage);
buildTable();
return true;
}
});
// Add actions to the buttons
backBtn.addListener(new InputListener() {
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
hide();
uiManager.main.setScreen(uiManager.titleScreen);
return true;
}
});
playBtn.addListener(new InputListener() {
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
if (AMazeIng.PLATFORM != Platform.DESKTOP) {
for (MazePlayer p : players)
p.dispose();
players.clear();
for (int i = 0; i < buttons.length; i++)
if (buttons[i].isChecked())
players.add(new MazePlayerLocal(new Touchpad(0f, uiManager.skin), i));
}
if (!players.isEmpty()) {
uiManager.main.gameManager.generateMaze(new HashSet<>(players));
}
}
return true;
}
});
setBtn.addListener(new InputListener() {
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
hide();
uiManager.setScreen.setPrevScreen(thisScreen);
uiManager.main.setScreen(uiManager.setScreen);
return true;
}
});
helpBtn.addListener(new InputListener() {
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
helpDlg.show(stage);
buildTable();
return true;
}
});
@Override
public void buildTable() {
super.buildTable();
firstRowTable.clear();
}
labels = new Label[MazeSettings.MAXPLAYERS];
// Labels to know if players joined
for (int i = 0; i < labels.length; i++) {
labels[i] = new Label("-- empty slot --", uiManager.skin);
}
@Override
public void buildTable() {
super.buildTable();
firstRowTable.clear();
float d = containerDiagonal();
float labScale = d * .00090f;
float buttonDim = d * 0.05f;
totalPlayers = 0;
firstRowContainer.setSize(cw, ch * 0.2f);
firstRowContainer.setPosition(tableContainer.getX(), ch * 0.1f);
firstRowContainer.fill();
if (AMazeIng.PLATFORM == Platform.DESKTOP) {
labels = new Label[MazeSettings.MAXPLAYERS];
// Labels to know if players joined
for (int i = 0; i < labels.length; i++) {
labels[i] = new Label("-- empty slot --", uiManager.skin);
}
} else {
buttons = new CheckBox[MazeSettings.MAXPLAYERS];
// Labels to know if players joined
for (int i = 0; i < buttons.length; i++) {
buttons[i] = new CheckBox("-- empty slot --", uiManager.skin);
}
}
helpDlg.setSize(cw*0.7f, ch*0.3f);
helpDlg.setPosition((sw-helpDlg.getWidth())/2, (sh-helpDlg.getHeight())/2);
helpDlgText.setFontScale(labScale*0.8f);
helpDlgOkBtn.getLabel().setFontScale(labScale*0.8f);
instLab.setFontScale(labScale);
backBtn.getLabel().setFontScale(labScale);
setBtn.getLabel().setFontScale(labScale);
helpBtn.getLabel().setFontScale(labScale);
playBtn.getLabel().setFontScale(labScale);
float d = containerDiagonal();
float labScale = d * .00090f;
float buttonDim = d * 0.05f;
firstRowTable.add(backBtn).fillX().expandX().space(cw * 0.005f).width(buttonDim).height(buttonDim);
firstRowTable.add(instLab).space(cw * 0.25f).width(cw / 2);
firstRowTable.add(setBtn).fillX().expandX().space(cw * 0.005f).height(buttonDim);
firstRowTable.add(helpBtn).fillX().expandX().space(cw * 0.005f).width(buttonDim).height(buttonDim);
firstRowContainer.setSize(cw, ch * 0.2f);
firstRowContainer.setPosition(tableContainer.getX(), ch * 0.1f);
firstRowContainer.fill();
table.row().colspan(MazeSettings.MAXPLAYERS == 2 ? 2 : 4);
helpDlg.setSize(cw * 0.7f, ch * 0.3f);
helpDlg.setPosition((sw - helpDlg.getWidth()) / 2, (sh - helpDlg.getHeight()) / 2);
helpDlgText.setFontScale(labScale * 0.8f);
helpDlgOkBtn.getLabel().setFontScale(labScale * 0.8f);
table.add(firstRowContainer);
instLab.setFontScale(labScale);
backBtn.getLabel().setFontScale(labScale);
setBtn.getLabel().setFontScale(labScale);
helpBtn.getLabel().setFontScale(labScale);
playBtn.getLabel().setFontScale(labScale);
for (int i = 0; i < labels.length; i++) {
labels[i].setFontScale(labScale);
if (i % 4 == 0)
table.row().expandY().fillY();
table.add(labels[i]).space(1);
}
table.row().colspan(MazeSettings.MAXPLAYERS == 2 ? 2 : 4);
firstRowTable.add(backBtn).fillX().expandX().space(cw * 0.005f).width(buttonDim).height(buttonDim);
firstRowTable.add(instLab).space(cw * 0.25f).width(cw / 2);
firstRowTable.add(setBtn).fillX().expandX().space(cw * 0.005f).height(buttonDim);
firstRowTable.add(helpBtn).fillX().expandX().space(cw * 0.005f).width(buttonDim).height(buttonDim);
table.row().colspan(MazeSettings.MAXPLAYERS == 2 ? 2 : 4);
table.add(firstRowContainer);
if (AMazeIng.PLATFORM == Platform.DESKTOP) {
for (int i = 0; i < labels.length; i++) {
labels[i].setFontScale(labScale);
if (i % 4 == 0)
table.row().expandY().fillY();
table.add(labels[i]).space(1);
}
} else {
for (int i = 0; i < buttons.length; i++) {
buttons[i].getLabel().setFontScale(labScale);
if (i % 4 == 0)
table.row().expandY().fillY();
table.add(buttons[i]).space(1);
}
}
table.row().colspan(MazeSettings.MAXPLAYERS == 2 ? 2 : 4);
// table.add(playBtn).fillX().width(buttonDim*2f).height(buttonDim);
table.add(playBtn).fillX().expandX().height(buttonDim);
}
table.add(playBtn).fillX().expandX().height(buttonDim);
}
MazePlayerLocal p;
MazePlayerLocal p;
@Override
public void update() {
// Consantly search for new players to be added
// First search for keyboard players (WASD and ARROWS)
if (Gdx.input.isKeyJustPressed(Keys.W) || Gdx.input.isKeyJustPressed(Keys.A)
|| Gdx.input.isKeyJustPressed(Keys.S) || Gdx.input.isKeyJustPressed(Keys.D))
PlayerUtils.togglePlayerWithKeys(players, Keys.W, Keys.S, Keys.A, Keys.D);
if (Gdx.input.isKeyJustPressed(Keys.UP) || Gdx.input.isKeyJustPressed(Keys.LEFT)
|| Gdx.input.isKeyJustPressed(Keys.DOWN) || Gdx.input.isKeyJustPressed(Keys.RIGHT))
PlayerUtils.togglePlayerWithKeys(players, Keys.UP, Keys.DOWN, Keys.LEFT, Keys.RIGHT);
@Override
public void update() {
// Consantly search for new players to be added
// First search for keyboard players (WASD and ARROWS)
if (Gdx.input.isKeyJustPressed(Keys.W) || Gdx.input.isKeyJustPressed(Keys.A)
|| Gdx.input.isKeyJustPressed(Keys.S) || Gdx.input.isKeyJustPressed(Keys.D))
PlayerUtils.togglePlayerWithKeys(players, Keys.W, Keys.S, Keys.A, Keys.D);
if (Gdx.input.isKeyJustPressed(Keys.UP) || Gdx.input.isKeyJustPressed(Keys.LEFT)
|| Gdx.input.isKeyJustPressed(Keys.DOWN) || Gdx.input.isKeyJustPressed(Keys.RIGHT))
PlayerUtils.togglePlayerWithKeys(players, Keys.UP, Keys.DOWN, Keys.LEFT, Keys.RIGHT);
// for (Controller c : Controllers.getControllers()) {
// System.out.println(c.getButton(Xbox.A));
// if (c.getButton(Xbox.Y)) {
// if (c.getButton(Xbox.Y)) {
// p = getPlayerWithCtrl(c);
// if (p == null)
// p = new MazePlayerLocal(uiManager.main, c);
@ -187,10 +228,16 @@ public class PlayerChooseScreen extends MyScreen {
// }
// }
// Update labels
for (int i = 0; i < labels.length; i++) {
labels[i].setText(i < players.size() ? "-- Player Ready! --" : "-- empty slot --");
}
}
// Update labels
if (AMazeIng.PLATFORM == Platform.DESKTOP) {
for (int i = 0; i < labels.length; i++) {
labels[i].setText(i < players.size() ? "-- Player Ready! --" : "-- empty slot --");
}
} else {
for (int i = 0; i < buttons.length; i++) {
buttons[i].setText(buttons[i].isChecked() ? " -- Player Ready -- " : " -- empty slot -- ");
}
}
}
}

View File

@ -142,6 +142,7 @@ public class ServerJoinScreen extends MyScreen {
failDlgOkBtn.getLabel().setFontScale(labScale*0.9f);
instLab.setFontScale(labScale);
srvIpL.setFontScale(labScale);
backBtn.getLabel().setFontScale(labScale);
helpBtn.getLabel().setFontScale(labScale);
connectBtn.getLabel().setFontScale(labScale);

View File

@ -154,6 +154,7 @@ public class ServerLaunchScreen extends MyScreen {
instLab.setFontScale(labScale);
backBtn.getLabel().setFontScale(labScale);
srvPortL.setFontScale(labScale);
helpBtn.getLabel().setFontScale(labScale);
connectBtn.getLabel().setFontScale(labScale);

View File

@ -3,10 +3,11 @@ package com.emamaker.amazeing.desktop;
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
import com.emamaker.amazeing.AMazeIng;
import com.emamaker.amazeing.AMazeIng.Platform;
public class DesktopLauncher {
public static void main (String[] arg) {
LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
new LwjglApplication(new AMazeIng(), config);
new LwjglApplication(new AMazeIng(Platform.DESKTOP), config);
}
}