update moving

This commit is contained in:
Sem van der Hoeven
2020-06-07 16:09:16 +02:00
parent fd6d91b7ed
commit 6ac66d8311
3 changed files with 21 additions and 20 deletions

View File

@@ -376,38 +376,26 @@ public class MainGame extends Game implements ClientCallback {
} else if (data instanceof TeamData) { } else if (data instanceof TeamData) {
// check if it is not our own message // check if it is not our own message
if (!((TeamData) data).getUsername().equals(this.username)) { if (!((TeamData) data).getUsername().equals(this.username)) {
System.out.println(username + "got team data: " + ((TeamData) data).getFaction());
// if we have already chosen a faction, so we were first // if we have already chosen a faction, so we were first
TeamData teamData = (TeamData) data; TeamData teamData = (TeamData) data;
enemyFaction = teamData.getFaction(); enemyFaction = teamData.getFaction();
System.out.println("Got enemy faction: " + enemyFaction);
if (this.chosenFaction == null) { if (this.chosenFaction == null) {
if (enemyFaction == Faction.HACKER) { if (enemyFaction == Faction.HACKER) {
System.out.println("enemy is hacker");
this.chosenFaction = Faction.MEGACORPORATION; this.chosenFaction = Faction.MEGACORPORATION;
this.enemyReady = true; this.enemyReady = true;
this.ready = true; this.ready = true;
} else { } else {
System.out.println("enemy is mega corp");
this.chosenFaction = Faction.HACKER; this.chosenFaction = Faction.HACKER;
this.enemyReady = true; this.enemyReady = true;
this.ready = true; this.ready = true;
} }
} }
} }
} else if (data instanceof ReadyData) {
ReadyData readyData = (ReadyData) data;
if (!readyData.getUsername().equals(this.username)) {
this.enemyReady = true;
System.out.println("enemy is ready");
}
} else if (data instanceof MoveData) { } else if (data instanceof MoveData) {
MoveData moveData = (MoveData) data; MoveData moveData = (MoveData) data;
if (moveData.getUsername().equals(this.username)) { if (!moveData.getUsername().equals(this.username)) {
moveData.getTile().visit(team.get(moveData.getCharacterName())); GameTile tile = mapRenderer.getGameTile(moveData.getPos());
} else { tile.visit(enemyTeam.get(moveData.getCharacterName()));
moveData.getTile().visit(enemyTeam.get(moveData.getCharacterName()));
} }
} else if (data instanceof DamageData) { } else if (data instanceof DamageData) {
DamageData damageData = (DamageData) data; DamageData damageData = (DamageData) data;

View File

@@ -193,6 +193,17 @@ public class MapRenderer implements Renderable {
return new Point(-1, -1); return new Point(-1, -1);
} }
public GameTile getGameTile(Point pos) {
for (int row = 0; row < this.gameTiles.length; row++) {
for (int col = 0; col < this.gameTiles[0].length; col++) {
if (row == pos.y && col == pos.x) {
return this.gameTiles[row][col];
}
}
}
return null;
}
@Override @Override
public void update(double deltaTime) { public void update(double deltaTime) {

View File

@@ -3,17 +3,19 @@ package netwerkprog.game.util.data.character;
import netwerkprog.game.client.game.map.GameTile; import netwerkprog.game.client.game.map.GameTile;
import netwerkprog.game.util.data.Data; import netwerkprog.game.util.data.Data;
import java.awt.*;
public class MoveData extends Data { public class MoveData extends Data {
private final String username; private final String username;
private final String characterName; private final String characterName;
private final GameTile tile; private final Point pos;
public MoveData(String username, String characterName, GameTile tile) { public MoveData(String username, String characterName, Point pos) {
super("Move"); super("Move");
super.setPayload(this); super.setPayload(this);
this.username = username; this.username = username;
this.characterName = characterName; this.characterName = characterName;
this.tile = tile; this.pos = pos;
} }
public String getUsername() { public String getUsername() {
@@ -24,7 +26,7 @@ public class MoveData extends Data {
return characterName; return characterName;
} }
public GameTile getTile() { public Point getPos() {
return tile; return pos;
} }
} }