update moving
This commit is contained in:
@@ -376,38 +376,26 @@ public class MainGame extends Game implements ClientCallback {
|
||||
} else if (data instanceof TeamData) {
|
||||
// check if it is not our own message
|
||||
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
|
||||
TeamData teamData = (TeamData) data;
|
||||
enemyFaction = teamData.getFaction();
|
||||
System.out.println("Got enemy faction: " + enemyFaction);
|
||||
if (this.chosenFaction == null) {
|
||||
if (enemyFaction == Faction.HACKER) {
|
||||
System.out.println("enemy is hacker");
|
||||
this.chosenFaction = Faction.MEGACORPORATION;
|
||||
this.enemyReady = true;
|
||||
this.ready = true;
|
||||
} else {
|
||||
System.out.println("enemy is mega corp");
|
||||
this.chosenFaction = Faction.HACKER;
|
||||
this.enemyReady = 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) {
|
||||
MoveData moveData = (MoveData) data;
|
||||
if (moveData.getUsername().equals(this.username)) {
|
||||
moveData.getTile().visit(team.get(moveData.getCharacterName()));
|
||||
} else {
|
||||
moveData.getTile().visit(enemyTeam.get(moveData.getCharacterName()));
|
||||
if (!moveData.getUsername().equals(this.username)) {
|
||||
GameTile tile = mapRenderer.getGameTile(moveData.getPos());
|
||||
tile.visit(enemyTeam.get(moveData.getCharacterName()));
|
||||
}
|
||||
} else if (data instanceof DamageData) {
|
||||
DamageData damageData = (DamageData) data;
|
||||
|
||||
@@ -193,6 +193,17 @@ public class MapRenderer implements Renderable {
|
||||
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
|
||||
public void update(double deltaTime) {
|
||||
|
||||
|
||||
@@ -3,17 +3,19 @@ package netwerkprog.game.util.data.character;
|
||||
import netwerkprog.game.client.game.map.GameTile;
|
||||
import netwerkprog.game.util.data.Data;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class MoveData extends Data {
|
||||
private final String username;
|
||||
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.setPayload(this);
|
||||
this.username = username;
|
||||
this.characterName = characterName;
|
||||
this.tile = tile;
|
||||
this.pos = pos;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
@@ -24,7 +26,7 @@ public class MoveData extends Data {
|
||||
return characterName;
|
||||
}
|
||||
|
||||
public GameTile getTile() {
|
||||
return tile;
|
||||
public Point getPos() {
|
||||
return pos;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user