Merge branch 'master' of https://github.com/SemvdH/netwerk-programming-eindopdracht
This commit is contained in:
@@ -52,15 +52,12 @@ public class MainGame extends Game implements ClientCallback {
|
||||
private GlyphLayout layout;
|
||||
private GAMESTATE gamestate;
|
||||
private Faction chosenFaction;
|
||||
private Faction enemyFaction;
|
||||
private long lastTimeCounted = 0;
|
||||
private boolean gameOver = false;
|
||||
private int turn = 0;
|
||||
private boolean playersTurn = true;
|
||||
private String username;
|
||||
private boolean ready = false;
|
||||
private boolean enemyReady = false;
|
||||
private Texture texture;
|
||||
|
||||
private Map map;
|
||||
public MapRenderer mapRenderer;
|
||||
@@ -115,19 +112,14 @@ public class MainGame extends Game implements ClientCallback {
|
||||
camera.viewportHeight = screenHeight / 2;
|
||||
camera.update();
|
||||
setGamestate(GAMESTATE.SELECTING_FACTION);
|
||||
// this.tree.insert(new Hacker(,new BodySwap()));
|
||||
|
||||
|
||||
// playSong();
|
||||
|
||||
|
||||
connectToServer();
|
||||
}
|
||||
|
||||
public void initCharacters() {
|
||||
assets.load("core/assets/characters.png", Texture.class);
|
||||
assets.finishLoading();
|
||||
texture = assets.get("core/assets/characters.png", Texture.class);
|
||||
|
||||
Texture texture = assets.get("core/assets/characters.png", Texture.class);
|
||||
TextureRegion[][] characters = TextureRegion.split(texture, 32, 32);
|
||||
this.team = new Team();
|
||||
this.enemyTeam = new Team();
|
||||
@@ -153,6 +145,7 @@ public class MainGame extends Game implements ClientCallback {
|
||||
|
||||
this.setSelectedCharacter(this.team.get(0));
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -296,6 +289,7 @@ public class MainGame extends Game implements ClientCallback {
|
||||
textRenderer.dispose();
|
||||
assets.dispose();
|
||||
textRenderer.dispose();
|
||||
mapRenderer.dispose();
|
||||
}
|
||||
|
||||
public float getScreenWidth() {
|
||||
@@ -382,26 +376,22 @@ public class MainGame extends Game implements ClientCallback {
|
||||
|
||||
@Override
|
||||
public void onDataReceived(Data data) {
|
||||
// System.out.println("[MAINGAME" + this.username + "] Got data: " + data.toString());
|
||||
if (data instanceof NameData) {
|
||||
this.username = ((NameData) data).getName();
|
||||
// System.out.println("[MAINGAME" + this.username + "] username is: " + username);
|
||||
} else if (data instanceof TeamData) {
|
||||
// check if it is not our own message
|
||||
if (!((TeamData) data).getUsername().equals(this.username)) {
|
||||
// if we have already chosen a faction, so we were first
|
||||
TeamData teamData = (TeamData) data;
|
||||
enemyFaction = teamData.getFaction();
|
||||
Faction enemyFaction = teamData.getFaction();
|
||||
if (this.chosenFaction == null) {
|
||||
if (enemyFaction == Faction.HACKER) {
|
||||
this.chosenFaction = Faction.MEGACORPORATION;
|
||||
this.enemyReady = true;
|
||||
this.ready = true;
|
||||
} else {
|
||||
this.chosenFaction = Faction.HACKER;
|
||||
this.enemyReady = true;
|
||||
this.ready = true;
|
||||
}
|
||||
this.enemyReady = true;
|
||||
this.ready = true;
|
||||
}
|
||||
}
|
||||
} else if (data instanceof MoveData) {
|
||||
@@ -422,7 +412,6 @@ public class MainGame extends Game implements ClientCallback {
|
||||
}
|
||||
|
||||
public void chooseHacker() {
|
||||
System.out.println("chose HACKER");
|
||||
setChosenFaction(Faction.HACKER);
|
||||
send(new TeamData(Faction.MEGACORPORATION, getUsername()));
|
||||
|
||||
@@ -434,7 +423,6 @@ public class MainGame extends Game implements ClientCallback {
|
||||
}
|
||||
|
||||
public void chooseMegaCorp() {
|
||||
System.out.println("chose MEGA CORP");
|
||||
setChosenFaction(Faction.MEGACORPORATION);
|
||||
send(new TeamData(Faction.MEGACORPORATION, getUsername()));
|
||||
initCharacters();
|
||||
|
||||
@@ -36,6 +36,7 @@ public class MapRenderer implements Renderable {
|
||||
private GameTile[][] gameTiles;
|
||||
private List<GameTile> surroundedTilesOfCurrentCharacter;
|
||||
|
||||
public static int[][] directions = new int[][]{{-1, -1}, {-1, 0}, {-1, 1}, {0, 1}, {1, 1}, {1, 0}, {1, -1}, {0, -1}};
|
||||
|
||||
/**
|
||||
* makea a new mapRenderer object
|
||||
@@ -62,14 +63,15 @@ public class MapRenderer implements Renderable {
|
||||
mainGame.assets.load("square.png", Texture.class);
|
||||
mainGame.assets.load("square2.png", Texture.class);
|
||||
mainGame.assets.load(tilePath, Texture.class);
|
||||
mainGame.assets.load("hit.png",Texture.class);
|
||||
mainGame.assets.load("dead.png",Texture.class);
|
||||
mainGame.assets.load("hit.png", Texture.class);
|
||||
mainGame.assets.load("dead.png", Texture.class);
|
||||
mainGame.assets.finishLoading();
|
||||
square = mainGame.assets.get("square.png");
|
||||
square2 = mainGame.assets.get("square2.png");
|
||||
hitMarker = mainGame.assets.get("hit.png");
|
||||
tombStone = mainGame.assets.get("dead.png");
|
||||
|
||||
// load the texture file
|
||||
Texture texture = mainGame.assets.get(tilePath);
|
||||
TextureRegion[][] tileTextures = TextureRegion.split(texture, 32, 32);
|
||||
|
||||
@@ -77,8 +79,10 @@ public class MapRenderer implements Renderable {
|
||||
WALL_TILE = tileTextures[0][4];
|
||||
PATH_TILE = tileTextures[4][6];
|
||||
|
||||
// init the array
|
||||
this.gameTiles = new GameTile[map.getHeight()][map.getWidth()];
|
||||
|
||||
// for each game tile, put the corresponding tile image in the array
|
||||
for (int row = map.getHeight(); row >= 0; row--) {
|
||||
y += 32;
|
||||
x = 0;
|
||||
@@ -111,6 +115,9 @@ public class MapRenderer implements Renderable {
|
||||
this.map = map;
|
||||
}
|
||||
|
||||
/**
|
||||
* method that renders the whole map
|
||||
*/
|
||||
@Override
|
||||
public void render() {
|
||||
batch.begin();
|
||||
@@ -119,25 +126,28 @@ public class MapRenderer implements Renderable {
|
||||
for (GameTile[] gameTileRow : gameTiles) {
|
||||
for (int col = 0; col < gameTiles[0].length; col++) {
|
||||
GameTile cur = gameTileRow[col];
|
||||
//draw each tile
|
||||
batch.draw(cur.getTextureRegion(), cur.x, cur.y);
|
||||
|
||||
if (cur.containsCharacter()) {
|
||||
//draw each character on a tile
|
||||
GameCharacter character = cur.getCharacter();
|
||||
|
||||
if (!character.isDead()) {
|
||||
batch.draw(character.getTextureRegion(), cur.x, cur.y);
|
||||
// System.out.println("character " + character.getName() + " showing: " + character.isShowingAnimation());
|
||||
if (character.isShowingAnimation()) {
|
||||
// System.out.println("animation");
|
||||
|
||||
//if he's showing an animation, draw the hitmarker.
|
||||
if (character.isShowingAnimation())
|
||||
batch.draw(hitMarker, cur.x, cur.y);
|
||||
}
|
||||
|
||||
|
||||
if (cur.getCharacter().equals(mainGame.getSelectedCharacter())) {
|
||||
// if hes selected, draw the green square
|
||||
if (cur.getCharacter().equals(mainGame.getSelectedCharacter()))
|
||||
batch.draw(square, cur.x, cur.y);
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
batch.draw(tombStone,cur.x,cur.y);
|
||||
// if hes dead, draw a tombstone
|
||||
batch.draw(tombStone, cur.x, cur.y);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -153,10 +163,15 @@ public class MapRenderer implements Renderable {
|
||||
y = 0;
|
||||
}
|
||||
|
||||
public static int[][] directions = new int[][]{{-1, -1}, {-1, 0}, {-1, 1}, {0, 1}, {1, 1}, {1, 0}, {1, -1}, {0, -1}};
|
||||
|
||||
public List<GameTile> setSurroundedTilesOfCurrentCharacter(int x, int y) {
|
||||
List<GameTile> res = new ArrayList<GameTile>();
|
||||
|
||||
/**
|
||||
* gets the 8 surrounding tiles of the character, to see where he can move.
|
||||
* @param x the x position of the character
|
||||
* @param y the y position of the character
|
||||
*/
|
||||
public void setSurroundedTilesOfCurrentCharacter(int x, int y) {
|
||||
List<GameTile> res = new ArrayList<>();
|
||||
for (int[] direction : directions) {
|
||||
int cx = x + direction[0];
|
||||
int cy = y + direction[1];
|
||||
@@ -166,9 +181,13 @@ public class MapRenderer implements Renderable {
|
||||
res.add(gameTiles[cy][cx]);
|
||||
}
|
||||
surroundedTilesOfCurrentCharacter = res;
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* gets the game tile of the character.
|
||||
* @param character the character
|
||||
* @return the game tile of the character, null if it is not found
|
||||
*/
|
||||
public GameTile getTile(GameCharacter character) {
|
||||
for (GameTile[] tiles : this.gameTiles) {
|
||||
for (GameTile tile : tiles) {
|
||||
@@ -181,7 +200,19 @@ public class MapRenderer implements Renderable {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void dispose() {
|
||||
tombStone.dispose();
|
||||
square.dispose();
|
||||
square2.dispose();
|
||||
hitMarker.dispose();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* gets the position of the specified tile.
|
||||
* @param tile the tile to get the position of
|
||||
* @return the position of the tile, a point of -1,-1 if the tile is not found
|
||||
*/
|
||||
public Point getPos(GameTile tile) {
|
||||
for (int row = 0; row < this.gameTiles.length; row++) {
|
||||
for (int col = 0; col < this.gameTiles[0].length; col++) {
|
||||
@@ -193,6 +224,11 @@ public class MapRenderer implements Renderable {
|
||||
return new Point(-1, -1);
|
||||
}
|
||||
|
||||
/**
|
||||
* gets the game tile at the specified position.
|
||||
* @param pos the position of the tile
|
||||
* @return the game tile on the position, <code>null</code> if it is not found
|
||||
*/
|
||||
public GameTile getGameTile(Point pos) {
|
||||
for (int row = 0; row < this.gameTiles.length; row++) {
|
||||
for (int col = 0; col < this.gameTiles[0].length; col++) {
|
||||
@@ -204,11 +240,11 @@ public class MapRenderer implements Renderable {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(double deltaTime) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* resize the screen
|
||||
* @param screenWidth the width of the screen
|
||||
* @param screenHeight the height of the screen
|
||||
*/
|
||||
public void resize(int screenWidth, int screenHeight) {
|
||||
cam = new OrthographicCamera(screenWidth, screenHeight);
|
||||
cam.translate(screenWidth / 2f, screenHeight / 2f);
|
||||
@@ -216,10 +252,18 @@ public class MapRenderer implements Renderable {
|
||||
batch.setProjectionMatrix(cam.combined);
|
||||
}
|
||||
|
||||
/**
|
||||
* return the game tiles
|
||||
* @return the game tiles.
|
||||
*/
|
||||
public GameTile[][] getGameTiles() {
|
||||
return gameTiles;
|
||||
}
|
||||
|
||||
/**
|
||||
* get the surrounding tiles of character
|
||||
* @return the surrounding tiles of character
|
||||
*/
|
||||
public List<GameTile> getSurroundedTilesOfCurrentCharacter() {
|
||||
return surroundedTilesOfCurrentCharacter;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user