Merge branch 'master' into Connections
* master: optimize imports fixed memory leaks made only possible to select own factions characters made character only able to move in some position added character squares he can move added stuff add square to selected character # Conflicts: # core/src/netwerkprog/game/client/MainGame.java # core/src/netwerkprog/game/util/game/GameCharacter.java
This commit is contained in:
BIN
core/assets/square.png
Normal file
BIN
core/assets/square.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 913 B |
BIN
core/assets/square2.png
Normal file
BIN
core/assets/square2.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 907 B |
@@ -3,24 +3,33 @@ package netwerkprog.game.client;
|
|||||||
import com.badlogic.gdx.ApplicationAdapter;
|
import com.badlogic.gdx.ApplicationAdapter;
|
||||||
import com.badlogic.gdx.Files;
|
import com.badlogic.gdx.Files;
|
||||||
import com.badlogic.gdx.Gdx;
|
import com.badlogic.gdx.Gdx;
|
||||||
|
import com.badlogic.gdx.assets.AssetManager;
|
||||||
import com.badlogic.gdx.audio.Music;
|
import com.badlogic.gdx.audio.Music;
|
||||||
import com.badlogic.gdx.graphics.GL20;
|
import com.badlogic.gdx.graphics.GL20;
|
||||||
import com.badlogic.gdx.graphics.OrthographicCamera;
|
import com.badlogic.gdx.graphics.OrthographicCamera;
|
||||||
import com.badlogic.gdx.graphics.Texture;
|
import com.badlogic.gdx.graphics.Texture;
|
||||||
|
import com.badlogic.gdx.graphics.g2d.BitmapFont;
|
||||||
|
import com.badlogic.gdx.graphics.g2d.GlyphLayout;
|
||||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||||
|
|
||||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||||
|
import netwerkprog.game.client.game.GAMESTATE;
|
||||||
|
import netwerkprog.game.client.game.characters.Agent;
|
||||||
import netwerkprog.game.client.game.characters.Hacker;
|
import netwerkprog.game.client.game.characters.Hacker;
|
||||||
import netwerkprog.game.client.game.characters.Team;
|
import netwerkprog.game.client.game.characters.Team;
|
||||||
import netwerkprog.game.client.game.characters.abilities.BodySwap;
|
import netwerkprog.game.client.game.characters.abilities.BodySwap;
|
||||||
import netwerkprog.game.client.game.connections.Client;
|
import netwerkprog.game.client.game.connections.Client;
|
||||||
|
import netwerkprog.game.client.game.map.GameInputProcessor;
|
||||||
|
import netwerkprog.game.client.game.map.GameTile;
|
||||||
import netwerkprog.game.client.game.map.Map;
|
import netwerkprog.game.client.game.map.Map;
|
||||||
import netwerkprog.game.client.game.map.MapRenderer;
|
import netwerkprog.game.client.game.map.MapRenderer;
|
||||||
import netwerkprog.game.client.game.map.GameInputProcessor;
|
|
||||||
import netwerkprog.game.util.data.Data;
|
import netwerkprog.game.util.data.Data;
|
||||||
import netwerkprog.game.util.data.DataCallback;
|
import netwerkprog.game.util.data.DataCallback;
|
||||||
|
import netwerkprog.game.util.game.Faction;
|
||||||
import netwerkprog.game.util.game.GameCharacter;
|
import netwerkprog.game.util.game.GameCharacter;
|
||||||
import netwerkprog.game.util.graphics.FrameRate;
|
import netwerkprog.game.util.graphics.FrameRate;
|
||||||
|
import netwerkprog.game.util.graphics.TextRenderer;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
public class MainGame extends ApplicationAdapter implements DataCallback {
|
public class MainGame extends ApplicationAdapter implements DataCallback {
|
||||||
SpriteBatch batch;
|
SpriteBatch batch;
|
||||||
@@ -32,11 +41,16 @@ public class MainGame extends ApplicationAdapter implements DataCallback {
|
|||||||
private GameInputProcessor gameInputProcessor;
|
private GameInputProcessor gameInputProcessor;
|
||||||
private GameCharacter selectedCharacter;
|
private GameCharacter selectedCharacter;
|
||||||
private Team team;
|
private Team team;
|
||||||
|
private Team enemyTeam;
|
||||||
|
private TextRenderer textRenderer;
|
||||||
|
private BitmapFont font;
|
||||||
|
private GlyphLayout layout;
|
||||||
|
private GAMESTATE gamestate;
|
||||||
|
private Faction chosenFaction;
|
||||||
|
|
||||||
private Map map;
|
private Map map;
|
||||||
public MapRenderer mapRenderer;
|
public MapRenderer mapRenderer;
|
||||||
|
public AssetManager assets;
|
||||||
public GameCharacter testCharacter;
|
|
||||||
|
|
||||||
private static MainGame INSTANCE;
|
private static MainGame INSTANCE;
|
||||||
|
|
||||||
@@ -58,17 +72,20 @@ public class MainGame extends ApplicationAdapter implements DataCallback {
|
|||||||
screenHeight = Gdx.graphics.getHeight();
|
screenHeight = Gdx.graphics.getHeight();
|
||||||
frameRate = new FrameRate();
|
frameRate = new FrameRate();
|
||||||
camera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
|
camera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
|
||||||
|
textRenderer = new TextRenderer();
|
||||||
|
font = new BitmapFont();
|
||||||
|
layout = new GlyphLayout();
|
||||||
|
assets = new AssetManager();
|
||||||
|
|
||||||
String[] strings = new String[]{
|
String[] strings = new String[]{
|
||||||
"#########################",
|
"#########################",
|
||||||
"#xxxx #",
|
"#xxxx #",
|
||||||
"# x #",
|
"# x #",
|
||||||
"# xxxx #",
|
"# xxxx xxxxx #",
|
||||||
"# xx #",
|
"# xxxx xxxxx #",
|
||||||
"# x #",
|
"# xxxx xx xx #",
|
||||||
"# x #",
|
"# x xxxxx #",
|
||||||
"# x #",
|
"# x xxxx #",
|
||||||
"# x #",
|
"# x #",
|
||||||
"# xxxxxx #",
|
"# xxxxxx #",
|
||||||
"# x #",
|
"# x #",
|
||||||
@@ -83,7 +100,7 @@ public class MainGame extends ApplicationAdapter implements DataCallback {
|
|||||||
camera.viewportWidth = screenWidth / 2;
|
camera.viewportWidth = screenWidth / 2;
|
||||||
camera.viewportHeight = screenHeight / 2;
|
camera.viewportHeight = screenHeight / 2;
|
||||||
camera.update();
|
camera.update();
|
||||||
initCharacters();
|
setGamestate(GAMESTATE.SELECTING_FACTION);
|
||||||
// this.tree.insert(new Hacker(,new BodySwap()));
|
// this.tree.insert(new Hacker(,new BodySwap()));
|
||||||
|
|
||||||
|
|
||||||
@@ -93,16 +110,29 @@ public class MainGame extends ApplicationAdapter implements DataCallback {
|
|||||||
connectToServer();
|
connectToServer();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initCharacters() {
|
public void initCharacters() {
|
||||||
Texture texture = new Texture(Gdx.files.internal("core/assets/characters.png"));
|
assets.load("core/assets/characters.png", Texture.class);
|
||||||
|
assets.finishLoading();
|
||||||
|
Texture texture = assets.get("core/assets/characters.png");
|
||||||
TextureRegion[][] characters = TextureRegion.split(texture, 32, 32);
|
TextureRegion[][] characters = TextureRegion.split(texture, 32, 32);
|
||||||
this.testCharacter = new Hacker("harry",characters[1][0], new BodySwap("test"));
|
|
||||||
GameCharacter character2 = new Hacker("test2",characters[2][0], new BodySwap("test"));
|
|
||||||
this.setSelectedCharacter(testCharacter);
|
|
||||||
mapRenderer.getGameTiles()[1][1].visit(testCharacter);
|
|
||||||
mapRenderer.getGameTiles()[1][2].visit(character2);
|
|
||||||
this.team = new Team();
|
this.team = new Team();
|
||||||
this.team.addMember(this.testCharacter, character2);
|
|
||||||
|
for (int i = 1; i <= 5; i++) {
|
||||||
|
GameCharacter temp = new Hacker("hacker" + i, characters[5][0], new BodySwap("test"));
|
||||||
|
mapRenderer.getGameTiles()[1][i].visit(temp);
|
||||||
|
if (chosenFaction == Faction.HACKER) {
|
||||||
|
this.team.addMember(temp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 1; i <= 5; i++) {
|
||||||
|
GameCharacter temp = new Agent("Agent" + i, characters[11][0], new BodySwap("Test"));
|
||||||
|
mapRenderer.getGameTiles()[3][i].visit(temp);
|
||||||
|
if (chosenFaction == Faction.MEGACORPORATION) {
|
||||||
|
this.team.addMember(temp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.setSelectedCharacter(this.team.get(0));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -132,12 +162,36 @@ public class MainGame extends ApplicationAdapter implements DataCallback {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void render() {
|
public void render() {
|
||||||
|
if (this.gamestate == GAMESTATE.PLAYING) {
|
||||||
update();
|
update();
|
||||||
// clear screen
|
// clear screen
|
||||||
Gdx.gl.glClearColor(0, 0, 0, 1);
|
Gdx.gl.glClearColor(0, 0, 0, 1);
|
||||||
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
|
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
|
||||||
mapRenderer.render();
|
mapRenderer.render();
|
||||||
frameRate.render();
|
frameRate.render();
|
||||||
|
renderText();
|
||||||
|
} else if (this.gamestate == GAMESTATE.SELECTING_FACTION) {
|
||||||
|
renderString("FACTION SELECT\nPress 1 for mega corporation, press 2 for hackers", Gdx.graphics.getWidth() / 2f, Gdx.graphics.getHeight() / 2f);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void renderText() {
|
||||||
|
String text = "FACION: " + chosenFaction;
|
||||||
|
text += "\nSelected character: " + selectedCharacter.getName();
|
||||||
|
text += "\nHealth: " + selectedCharacter.getHealth();
|
||||||
|
layout.setText(font, text);
|
||||||
|
textRenderer.render(text, Gdx.graphics.getWidth() - layout.width - 5, Gdx.graphics.getHeight() - 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void renderString(String text) {
|
||||||
|
layout.setText(font, text);
|
||||||
|
textRenderer.render(text, Gdx.graphics.getWidth() - layout.width - 5, Gdx.graphics.getHeight() - 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void renderString(String text, float x, float y) {
|
||||||
|
layout.setText(font, text);
|
||||||
|
textRenderer.render(text, x - layout.width / 2f, x - layout.height / 2f);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -156,6 +210,7 @@ public class MainGame extends ApplicationAdapter implements DataCallback {
|
|||||||
screenWidth = width;
|
screenWidth = width;
|
||||||
frameRate.resize(width, height);
|
frameRate.resize(width, height);
|
||||||
mapRenderer.resize(width, height);
|
mapRenderer.resize(width, height);
|
||||||
|
textRenderer.resize(width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -166,6 +221,8 @@ public class MainGame extends ApplicationAdapter implements DataCallback {
|
|||||||
@Override
|
@Override
|
||||||
public void dispose() {
|
public void dispose() {
|
||||||
batch.dispose();
|
batch.dispose();
|
||||||
|
textRenderer.dispose();
|
||||||
|
assets.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getScreenWidth() {
|
public float getScreenWidth() {
|
||||||
@@ -186,7 +243,25 @@ public class MainGame extends ApplicationAdapter implements DataCallback {
|
|||||||
|
|
||||||
public void setSelectedCharacter(GameCharacter character) {
|
public void setSelectedCharacter(GameCharacter character) {
|
||||||
this.selectedCharacter = character;
|
this.selectedCharacter = character;
|
||||||
System.out.println("selected character set to : " + character);
|
GameTile characterTile = mapRenderer.getTile(character);
|
||||||
|
Point pos = mapRenderer.getPos(characterTile);
|
||||||
|
mapRenderer.setSurroundedTilesOfCurrentCharacter(pos.x, pos.y);
|
||||||
|
}
|
||||||
|
|
||||||
|
public GAMESTATE getGamestate() {
|
||||||
|
return gamestate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGamestate(GAMESTATE gamestate) {
|
||||||
|
this.gamestate = gamestate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Faction getChosenFaction() {
|
||||||
|
return chosenFaction;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setChosenFaction(Faction chosenFaction) {
|
||||||
|
this.chosenFaction = chosenFaction;
|
||||||
}
|
}
|
||||||
|
|
||||||
public GameCharacter getSelectedCharacter() {
|
public GameCharacter getSelectedCharacter() {
|
||||||
|
|||||||
6
core/src/netwerkprog/game/client/game/GAMESTATE.java
Normal file
6
core/src/netwerkprog/game/client/game/GAMESTATE.java
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
package netwerkprog.game.client.game;
|
||||||
|
|
||||||
|
public enum GAMESTATE {
|
||||||
|
PLAYING,
|
||||||
|
SELECTING_FACTION
|
||||||
|
}
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
package netwerkprog.game.client.game;
|
|
||||||
|
|
||||||
import netwerkprog.game.util.application.Controller;
|
|
||||||
|
|
||||||
public class Game extends Controller {
|
|
||||||
|
|
||||||
|
|
||||||
public Game() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
package netwerkprog.game.client.game;
|
|
||||||
|
|
||||||
import netwerkprog.game.util.application.Controller;
|
|
||||||
|
|
||||||
public class Graphics extends Controller {
|
|
||||||
public Graphics() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -6,7 +6,7 @@ import netwerkprog.game.util.game.Faction;
|
|||||||
import netwerkprog.game.util.game.GameCharacter;
|
import netwerkprog.game.util.game.GameCharacter;
|
||||||
|
|
||||||
public class Agent extends GameCharacter {
|
public class Agent extends GameCharacter {
|
||||||
public Agent(TextureRegion textureRegion, Ability... abilities) {
|
public Agent(String name, TextureRegion textureRegion, Ability... abilities) {
|
||||||
super("Agent", Faction.MEGACORPORATION, textureRegion, abilities);
|
super(name, Faction.MEGACORPORATION, textureRegion, abilities);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package netwerkprog.game.client.game.characters;
|
package netwerkprog.game.client.game.characters;
|
||||||
|
|
||||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||||
import netwerkprog.game.util.game.GameCharacter;
|
|
||||||
import netwerkprog.game.util.game.Faction;
|
import netwerkprog.game.util.game.Faction;
|
||||||
|
import netwerkprog.game.util.game.GameCharacter;
|
||||||
|
|
||||||
public class DevTest1 extends GameCharacter {
|
public class DevTest1 extends GameCharacter {
|
||||||
public DevTest1() {
|
public DevTest1() {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package netwerkprog.game.client.game.characters;
|
package netwerkprog.game.client.game.characters;
|
||||||
|
|
||||||
import netwerkprog.game.util.game.GameCharacter;
|
|
||||||
import netwerkprog.game.util.game.Faction;
|
import netwerkprog.game.util.game.Faction;
|
||||||
|
import netwerkprog.game.util.game.GameCharacter;
|
||||||
|
|
||||||
public class DevTest2 extends GameCharacter {
|
public class DevTest2 extends GameCharacter {
|
||||||
public DevTest2() {
|
public DevTest2() {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package netwerkprog.game.client.game.characters;
|
package netwerkprog.game.client.game.characters;
|
||||||
|
|
||||||
import netwerkprog.game.util.game.GameCharacter;
|
|
||||||
import netwerkprog.game.util.game.Faction;
|
import netwerkprog.game.util.game.Faction;
|
||||||
|
import netwerkprog.game.util.game.GameCharacter;
|
||||||
|
|
||||||
public class DevTest3 extends GameCharacter {
|
public class DevTest3 extends GameCharacter {
|
||||||
public DevTest3() {
|
public DevTest3() {
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ import com.badlogic.gdx.math.MathUtils;
|
|||||||
import com.badlogic.gdx.math.Vector3;
|
import com.badlogic.gdx.math.Vector3;
|
||||||
import com.badlogic.gdx.utils.TimeUtils;
|
import com.badlogic.gdx.utils.TimeUtils;
|
||||||
import netwerkprog.game.client.MainGame;
|
import netwerkprog.game.client.MainGame;
|
||||||
|
import netwerkprog.game.client.game.GAMESTATE;
|
||||||
|
import netwerkprog.game.util.game.Faction;
|
||||||
import netwerkprog.game.util.game.GameCharacter;
|
import netwerkprog.game.util.game.GameCharacter;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -89,6 +91,8 @@ public class GameInputProcessor implements InputProcessor {
|
|||||||
@Override
|
@Override
|
||||||
public boolean keyUp(int keycode) {
|
public boolean keyUp(int keycode) {
|
||||||
// System.out.println(camera.position.x + " , " + camera.position.y);
|
// System.out.println(camera.position.x + " , " + camera.position.y);
|
||||||
|
if (mainGame.getGamestate() == GAMESTATE.PLAYING) {
|
||||||
|
|
||||||
if (keysList.contains(keycode)) {
|
if (keysList.contains(keycode)) {
|
||||||
if (keycode == keysList.get(0)) {
|
if (keycode == keysList.get(0)) {
|
||||||
this.isWPressed = false;
|
this.isWPressed = false;
|
||||||
@@ -109,6 +113,20 @@ public class GameInputProcessor implements InputProcessor {
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
} else if (mainGame.getGamestate() == GAMESTATE.SELECTING_FACTION) {
|
||||||
|
if (keycode == Input.Keys.NUM_1) {
|
||||||
|
System.out.println("MEGA CORP");
|
||||||
|
mainGame.setChosenFaction(Faction.MEGACORPORATION);
|
||||||
|
mainGame.initCharacters();
|
||||||
|
mainGame.setGamestate(GAMESTATE.PLAYING);
|
||||||
|
}
|
||||||
|
if (keycode == Input.Keys.NUM_2) {
|
||||||
|
System.out.println("HACKER");
|
||||||
|
mainGame.setChosenFaction(Faction.HACKER);
|
||||||
|
mainGame.initCharacters();
|
||||||
|
mainGame.setGamestate(GAMESTATE.PLAYING);
|
||||||
|
}
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -122,6 +140,8 @@ public class GameInputProcessor implements InputProcessor {
|
|||||||
|
|
||||||
Vector3 touchPoint = new Vector3(Gdx.input.getX(), Gdx.input.getY(), 0);
|
Vector3 touchPoint = new Vector3(Gdx.input.getX(), Gdx.input.getY(), 0);
|
||||||
camera.unproject(touchPoint);
|
camera.unproject(touchPoint);
|
||||||
|
if (mainGame.getGamestate() == GAMESTATE.PLAYING) {
|
||||||
|
|
||||||
|
|
||||||
for (int row = 0; row < mainGame.mapRenderer.getGameTiles().length; row++) {
|
for (int row = 0; row < mainGame.mapRenderer.getGameTiles().length; row++) {
|
||||||
for (int col = 0; col < mainGame.mapRenderer.getGameTiles()[0].length; col++) {
|
for (int col = 0; col < mainGame.mapRenderer.getGameTiles()[0].length; col++) {
|
||||||
@@ -131,20 +151,30 @@ public class GameInputProcessor implements InputProcessor {
|
|||||||
// System.out.println(gameTile + " row: " + row + ", col: " + col);
|
// System.out.println(gameTile + " row: " + row + ", col: " + col);
|
||||||
if (mainGame.hasCharacterSelected() && !gameTile.containsCharacter()) {
|
if (mainGame.hasCharacterSelected() && !gameTile.containsCharacter()) {
|
||||||
// System.out.println(mainGame.getSelectedCharacter());
|
// System.out.println(mainGame.getSelectedCharacter());
|
||||||
|
if (gameTile.getSymbol() != '#' && mainGame.mapRenderer.getSurroundedTilesOfCurrentCharacter().contains(gameTile)) {
|
||||||
removeCharacterFromTile(mainGame.getSelectedCharacter());
|
removeCharacterFromTile(mainGame.getSelectedCharacter());
|
||||||
gameTile.visit(mainGame.getSelectedCharacter());
|
gameTile.visit(mainGame.getSelectedCharacter());
|
||||||
|
mainGame.mapRenderer.setSurroundedTilesOfCurrentCharacter(col, row);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!mainGame.hasCharacterSelected() && gameTile.containsCharacter()) {
|
if (!mainGame.hasCharacterSelected() && gameTile.containsCharacter()) {
|
||||||
|
if (gameTile.getCharacter().getFaction() == mainGame.getChosenFaction()) {
|
||||||
mainGame.setSelectedCharacter(gameTile.getCharacter());
|
mainGame.setSelectedCharacter(gameTile.getCharacter());
|
||||||
|
mainGame.mapRenderer.setSurroundedTilesOfCurrentCharacter(col, row);
|
||||||
}
|
}
|
||||||
if (gameTile.containsCharacter() && !mainGame.getSelectedCharacter().equals(gameTile.getCharacter())) {
|
}
|
||||||
|
if (gameTile.containsCharacter()
|
||||||
|
&& !mainGame.getSelectedCharacter().equals(gameTile.getCharacter())
|
||||||
|
&& gameTile.getCharacter().getFaction() == mainGame.getChosenFaction()) {
|
||||||
mainGame.setSelectedCharacter(gameTile.getCharacter());
|
mainGame.setSelectedCharacter(gameTile.getCharacter());
|
||||||
|
mainGame.mapRenderer.setSurroundedTilesOfCurrentCharacter(col, row);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
package netwerkprog.game.client.game.map;
|
package netwerkprog.game.client.game.map;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Map class to hold a 2d array of tiles which will specify the map
|
* Map class to hold a 2d array of tiles which will specify the map
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -4,9 +4,14 @@ import com.badlogic.gdx.Gdx;
|
|||||||
import com.badlogic.gdx.graphics.OrthographicCamera;
|
import com.badlogic.gdx.graphics.OrthographicCamera;
|
||||||
import com.badlogic.gdx.graphics.Texture;
|
import com.badlogic.gdx.graphics.Texture;
|
||||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||||
import netwerkprog.game.client.MainGame;
|
|
||||||
import netwerkprog.game.util.graphics.Renderable;
|
|
||||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||||
|
import netwerkprog.game.client.MainGame;
|
||||||
|
import netwerkprog.game.util.game.GameCharacter;
|
||||||
|
import netwerkprog.game.util.graphics.Renderable;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class MapRenderer implements Renderable {
|
public class MapRenderer implements Renderable {
|
||||||
private final OrthographicCamera camera;
|
private final OrthographicCamera camera;
|
||||||
@@ -19,6 +24,8 @@ public class MapRenderer implements Renderable {
|
|||||||
private static int y = 0;
|
private static int y = 0;
|
||||||
|
|
||||||
private MainGame mainGame;
|
private MainGame mainGame;
|
||||||
|
private Texture square;
|
||||||
|
private Texture square2;
|
||||||
|
|
||||||
|
|
||||||
public static TextureRegion FLOOR_TILE;
|
public static TextureRegion FLOOR_TILE;
|
||||||
@@ -26,6 +33,7 @@ public class MapRenderer implements Renderable {
|
|||||||
public static TextureRegion PATH_TILE;
|
public static TextureRegion PATH_TILE;
|
||||||
|
|
||||||
private GameTile[][] gameTiles;
|
private GameTile[][] gameTiles;
|
||||||
|
private List<GameTile> surroundedTilesOfCurrentCharacter;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -50,7 +58,14 @@ public class MapRenderer implements Renderable {
|
|||||||
* loads all the images for the tiles and adds all the tiles to the array
|
* loads all the images for the tiles and adds all the tiles to the array
|
||||||
*/
|
*/
|
||||||
private void makeTiles() {
|
private void makeTiles() {
|
||||||
Texture texture = new Texture(Gdx.files.internal(tilePath));
|
mainGame.assets.load("square.png", Texture.class);
|
||||||
|
mainGame.assets.load("square2.png", Texture.class);
|
||||||
|
mainGame.assets.load(tilePath, Texture.class);
|
||||||
|
mainGame.assets.finishLoading();
|
||||||
|
square = mainGame.assets.get("square.png");
|
||||||
|
square2 = mainGame.assets.get("square2.png");
|
||||||
|
|
||||||
|
Texture texture = mainGame.assets.get(tilePath);
|
||||||
TextureRegion[][] tileTextures = TextureRegion.split(texture, 32, 32);
|
TextureRegion[][] tileTextures = TextureRegion.split(texture, 32, 32);
|
||||||
|
|
||||||
FLOOR_TILE = tileTextures[1][6];
|
FLOOR_TILE = tileTextures[1][6];
|
||||||
@@ -100,18 +115,67 @@ public class MapRenderer implements Renderable {
|
|||||||
for (int col = 0; col < gameTiles[0].length; col++) {
|
for (int col = 0; col < gameTiles[0].length; col++) {
|
||||||
GameTile cur = gameTileRow[col];
|
GameTile cur = gameTileRow[col];
|
||||||
batch.draw(cur.getTextureRegion(), cur.x, cur.y);
|
batch.draw(cur.getTextureRegion(), cur.x, cur.y);
|
||||||
|
|
||||||
if (cur.containsCharacter()) {
|
if (cur.containsCharacter()) {
|
||||||
batch.draw(cur.getCharacter().getTextureRegion(), cur.x, cur.y);
|
batch.draw(cur.getCharacter().getTextureRegion(), cur.x, cur.y);
|
||||||
// System.out.println("drawing character at " + cur.x + " " + cur.y);
|
if (cur.getCharacter().equals(mainGame.getSelectedCharacter())) {
|
||||||
|
batch.draw(square, cur.x, cur.y);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if (surroundedTilesOfCurrentCharacter != null && !surroundedTilesOfCurrentCharacter.isEmpty()) {
|
||||||
|
for (GameTile gameTile : surroundedTilesOfCurrentCharacter) {
|
||||||
|
batch.draw(square2, gameTile.x, gameTile.y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
batch.end();
|
batch.end();
|
||||||
x = 0;
|
x = 0;
|
||||||
y = 0;
|
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>();
|
||||||
|
for (int[] direction : directions) {
|
||||||
|
int cx = x + direction[0];
|
||||||
|
int cy = y + direction[1];
|
||||||
|
if (cy >= 0 && cy < gameTiles.length)
|
||||||
|
if (cx >= 0 && cx < gameTiles[cy].length)
|
||||||
|
if (gameTiles[cy][cx].getSymbol() != '#')
|
||||||
|
res.add(gameTiles[cy][cx]);
|
||||||
|
}
|
||||||
|
surroundedTilesOfCurrentCharacter = res;
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GameTile getTile(GameCharacter character) {
|
||||||
|
for (GameTile[] tiles : this.gameTiles) {
|
||||||
|
for (GameTile tile : tiles) {
|
||||||
|
if (tile.containsCharacter())
|
||||||
|
if (tile.getCharacter().equals(character)) {
|
||||||
|
return tile;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public Point getPos(GameTile tile) {
|
||||||
|
for (int row = 0; row < this.gameTiles.length; row++) {
|
||||||
|
for (int col = 0; col < this.gameTiles[0].length; col++) {
|
||||||
|
if (gameTiles[row][col].equals(tile)) {
|
||||||
|
return new Point(col, row);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new Point(-1, -1);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(double deltaTime) {
|
public void update(double deltaTime) {
|
||||||
|
|
||||||
@@ -127,4 +191,9 @@ public class MapRenderer implements Renderable {
|
|||||||
public GameTile[][] getGameTiles() {
|
public GameTile[][] getGameTiles() {
|
||||||
return gameTiles;
|
return gameTiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<GameTile> getSurroundedTilesOfCurrentCharacter() {
|
||||||
|
return surroundedTilesOfCurrentCharacter;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,10 +3,13 @@ package netwerkprog.game.util.game;
|
|||||||
|
|
||||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||||
import com.badlogic.gdx.scenes.scene2d.Actor;
|
import com.badlogic.gdx.scenes.scene2d.Actor;
|
||||||
|
import netwerkprog.game.client.game.map.GameTile;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
public abstract class GameCharacter extends Actor implements Comparable<GameCharacter>, Serializable {
|
public abstract class GameCharacter extends Actor implements Comparable<GameCharacter>, Serializable {
|
||||||
@@ -16,6 +19,7 @@ public abstract class GameCharacter extends Actor implements Comparable<GameChar
|
|||||||
protected boolean override;
|
protected boolean override;
|
||||||
protected TextureRegion textureRegion;
|
protected TextureRegion textureRegion;
|
||||||
protected int health;
|
protected int health;
|
||||||
|
protected List<GameTile> allowedToMove;
|
||||||
|
|
||||||
public GameCharacter(String name, Faction faction, TextureRegion textureRegion, Ability... abilities) {
|
public GameCharacter(String name, Faction faction, TextureRegion textureRegion, Ability... abilities) {
|
||||||
super();
|
super();
|
||||||
@@ -25,6 +29,7 @@ public abstract class GameCharacter extends Actor implements Comparable<GameChar
|
|||||||
this.override = false;
|
this.override = false;
|
||||||
this.textureRegion = textureRegion;
|
this.textureRegion = textureRegion;
|
||||||
this.health = 100;
|
this.health = 100;
|
||||||
|
this.allowedToMove = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
@@ -104,4 +109,16 @@ public abstract class GameCharacter extends Actor implements Comparable<GameChar
|
|||||||
", y=" + super.getY() +
|
", y=" + super.getY() +
|
||||||
'}';
|
'}';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<GameTile> getAllowedToMove() {
|
||||||
|
return allowedToMove;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAllowedToMove(List<GameTile> allowedToMove) {
|
||||||
|
this.allowedToMove = allowedToMove;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Faction getFaction() {
|
||||||
|
return faction;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
38
core/src/netwerkprog/game/util/graphics/TextRenderer.java
Normal file
38
core/src/netwerkprog/game/util/graphics/TextRenderer.java
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
package netwerkprog.game.util.graphics;
|
||||||
|
|
||||||
|
import com.badlogic.gdx.Gdx;
|
||||||
|
import com.badlogic.gdx.graphics.OrthographicCamera;
|
||||||
|
import com.badlogic.gdx.graphics.g2d.BitmapFont;
|
||||||
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||||
|
import com.badlogic.gdx.utils.Disposable;
|
||||||
|
|
||||||
|
public class TextRenderer implements Disposable {
|
||||||
|
private BitmapFont font;
|
||||||
|
private SpriteBatch batch;
|
||||||
|
private OrthographicCamera cam;
|
||||||
|
|
||||||
|
public TextRenderer() {
|
||||||
|
font = new BitmapFont();
|
||||||
|
batch = new SpriteBatch();
|
||||||
|
cam = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
|
||||||
|
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void dispose() {
|
||||||
|
font.dispose();
|
||||||
|
batch.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void resize(int screenWidth, int screenHeight) {
|
||||||
|
cam = new OrthographicCamera(screenWidth, screenHeight);
|
||||||
|
cam.translate(screenWidth / 2, screenHeight / 2);
|
||||||
|
cam.update();
|
||||||
|
batch.setProjectionMatrix(cam.combined);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void render(String text, float x, float y) {
|
||||||
|
batch.begin();
|
||||||
|
font.draw(batch, text, x, y);
|
||||||
|
batch.end();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,5 @@
|
|||||||
package netwerkprog.game.util.tree;
|
package netwerkprog.game.util.tree;
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
public class BST<E extends Comparable<E>> extends AbstractTree<E> {
|
public class BST<E extends Comparable<E>> extends AbstractTree<E> {
|
||||||
protected TreeNode<E> root;
|
protected TreeNode<E> root;
|
||||||
protected int size = 0;
|
protected int size = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user