diff --git a/core/assets/hit.png b/core/assets/hit.png new file mode 100644 index 0000000..ce2d65d Binary files /dev/null and b/core/assets/hit.png differ diff --git a/core/assets/sound/earrape.mp3 b/core/assets/sound/earrape.mp3 new file mode 100644 index 0000000..8b017b3 Binary files /dev/null and b/core/assets/sound/earrape.mp3 differ diff --git a/core/assets/sound/hit.mp3 b/core/assets/sound/hit.mp3 new file mode 100644 index 0000000..ff586b9 Binary files /dev/null and b/core/assets/sound/hit.mp3 differ diff --git a/core/assets/music.mp3 b/core/assets/sound/music.mp3 similarity index 100% rename from core/assets/music.mp3 rename to core/assets/sound/music.mp3 diff --git a/core/src/netwerkprog/game/client/MainGame.java b/core/src/netwerkprog/game/client/MainGame.java index b22b32f..63e3bbf 100644 --- a/core/src/netwerkprog/game/client/MainGame.java +++ b/core/src/netwerkprog/game/client/MainGame.java @@ -12,6 +12,7 @@ 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.TextureRegion; +import com.badlogic.gdx.utils.TimeUtils; import netwerkprog.game.client.game.GAMESTATE; import netwerkprog.game.client.game.characters.Agent; import netwerkprog.game.client.game.characters.Hacker; @@ -44,6 +45,7 @@ public class MainGame extends ApplicationAdapter { private GlyphLayout layout; private GAMESTATE gamestate; private Faction chosenFaction; + private long lastTimeCounted = 0; private Map map; public MapRenderer mapRenderer; @@ -76,13 +78,13 @@ public class MainGame extends ApplicationAdapter { String[] strings = new String[]{ "#########################", - "#xxxx #", - "# x #", - "# xxxx xxxxx #", - "# xxxx xxxxx #", - "# xxxx xx xx #", - "# x xxxxx #", - "# x xxxx #", + "#xxxx # #", + "# x # #", + "# xxxx #xxxx #", + "# xxxx #xxxx #", + "# xxxx #x xx #", + "# x #xxxx #", + "# x #xxx #", "# x #", "# xxxxxx #", "# x #", @@ -113,22 +115,31 @@ public class MainGame extends ApplicationAdapter { Texture texture = assets.get("core/assets/characters.png"); TextureRegion[][] characters = TextureRegion.split(texture, 32, 32); this.team = new Team(); + this.enemyTeam = new Team(); + + System.out.println(this.chosenFaction); 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); + + GameCharacter temp2 = new Agent("Agent" + i, characters[11][0], new BodySwap("Test")); + int width = mapRenderer.getGameTiles()[0].length; + mapRenderer.getGameTiles()[3][width - (i + 1)].visit(temp2); + if (chosenFaction == Faction.HACKER) { + System.out.println("adding " + temp); this.team.addMember(temp); + this.enemyTeam.addMember(temp2); + } if (chosenFaction == Faction.MEGACORPORATION) { + System.out.println("adding " + temp2); + this.team.addMember(temp2); + this.enemyTeam.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); - } - } + System.out.println(this.team); + System.out.println(this.enemyTeam); this.setSelectedCharacter(this.team.get(0)); } @@ -136,12 +147,11 @@ public class MainGame extends ApplicationAdapter { private void playSong() { // play music - Music music = Gdx.audio.newMusic(Gdx.files.getFileHandle("core/assets/music.mp3", Files.FileType.Internal)); + Music music = Gdx.audio.newMusic(Gdx.files.getFileHandle("core/assets/earrape.mp3", Files.FileType.Internal)); music.setVolume(.1f); music.play(); music.setLooping(true); - connectToServer(); } @@ -195,9 +205,12 @@ public class MainGame extends ApplicationAdapter { * update method that does all calculation before something is being drawn */ public void update() { + frameRate.update(); camera.update(); this.gameInputProcessor.update(); + this.team.update(Gdx.graphics.getDeltaTime()); + this.enemyTeam.update(Gdx.graphics.getDeltaTime()); } @Override diff --git a/core/src/netwerkprog/game/client/game/characters/Team.java b/core/src/netwerkprog/game/client/game/characters/Team.java index daa3a01..c419d3d 100644 --- a/core/src/netwerkprog/game/client/game/characters/Team.java +++ b/core/src/netwerkprog/game/client/game/characters/Team.java @@ -54,6 +54,12 @@ public class Team { return null; } + public void update(double deltaTime) { + for (GameCharacter character : this.members) { + character.update(deltaTime); + } + } + public boolean isDead() { int dead = 0; for (GameCharacter character : this.members) { @@ -61,4 +67,11 @@ public class Team { } return dead >= this.members.getSize(); } + + @Override + public String toString() { + return "Team{" + + "members=" + members + + '}'; + } } diff --git a/core/src/netwerkprog/game/client/game/map/GameInputProcessor.java b/core/src/netwerkprog/game/client/game/map/GameInputProcessor.java index 65c6ae6..b5ce136 100644 --- a/core/src/netwerkprog/game/client/game/map/GameInputProcessor.java +++ b/core/src/netwerkprog/game/client/game/map/GameInputProcessor.java @@ -46,6 +46,7 @@ public class GameInputProcessor implements InputProcessor { camera.zoom = MathUtils.clamp(camera.zoom, 1.5f, 1.8f); + } public boolean isWPressed() { @@ -124,8 +125,10 @@ public class GameInputProcessor implements InputProcessor { System.out.println("HACKER"); mainGame.setChosenFaction(Faction.HACKER); mainGame.initCharacters(); + camera.translate(-400, 0); mainGame.setGamestate(GAMESTATE.PLAYING); } + } return false; } @@ -148,21 +151,31 @@ public class GameInputProcessor implements InputProcessor { GameTile gameTile = mainGame.mapRenderer.getGameTiles()[row][col]; if (gameTile.contains(touchPoint.x, touchPoint.y)) { if (button == Input.Buttons.LEFT) { -// System.out.println(gameTile + " row: " + row + ", col: " + col); + + // moving selected character if (mainGame.hasCharacterSelected() && !gameTile.containsCharacter()) { -// System.out.println(mainGame.getSelectedCharacter()); + if (gameTile.getSymbol() != '#' && mainGame.mapRenderer.getSurroundedTilesOfCurrentCharacter().contains(gameTile)) { removeCharacterFromTile(mainGame.getSelectedCharacter()); gameTile.visit(mainGame.getSelectedCharacter()); mainGame.mapRenderer.setSurroundedTilesOfCurrentCharacter(col, row); } } +// clicking on enemy + if (mainGame.hasCharacterSelected() && gameTile.containsCharacter() && gameTile.getCharacter().getFaction() != mainGame.getChosenFaction()) { + if (mainGame.mapRenderer.getSurroundedTilesOfCurrentCharacter().contains(gameTile)) { + gameTile.getCharacter().damage(10); + + } + } + // set selected character if (!mainGame.hasCharacterSelected() && gameTile.containsCharacter()) { if (gameTile.getCharacter().getFaction() == mainGame.getChosenFaction()) { mainGame.setSelectedCharacter(gameTile.getCharacter()); mainGame.mapRenderer.setSurroundedTilesOfCurrentCharacter(col, row); } } + // switch character if (gameTile.containsCharacter() && !mainGame.getSelectedCharacter().equals(gameTile.getCharacter()) && gameTile.getCharacter().getFaction() == mainGame.getChosenFaction()) { diff --git a/core/src/netwerkprog/game/client/game/map/MapRenderer.java b/core/src/netwerkprog/game/client/game/map/MapRenderer.java index 5b0cd29..ada9960 100644 --- a/core/src/netwerkprog/game/client/game/map/MapRenderer.java +++ b/core/src/netwerkprog/game/client/game/map/MapRenderer.java @@ -26,6 +26,7 @@ public class MapRenderer implements Renderable { private MainGame mainGame; private Texture square; private Texture square2; + private Texture hitMarker; public static TextureRegion FLOOR_TILE; @@ -61,9 +62,11 @@ 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.finishLoading(); square = mainGame.assets.get("square.png"); square2 = mainGame.assets.get("square2.png"); + hitMarker = mainGame.assets.get("hit.png"); Texture texture = mainGame.assets.get(tilePath); TextureRegion[][] tileTextures = TextureRegion.split(texture, 32, 32); @@ -117,10 +120,17 @@ public class MapRenderer implements Renderable { batch.draw(cur.getTextureRegion(), cur.x, cur.y); if (cur.containsCharacter()) { - batch.draw(cur.getCharacter().getTextureRegion(), cur.x, cur.y); + GameCharacter character = cur.getCharacter(); + batch.draw(character.getTextureRegion(), cur.x, cur.y); +// System.out.println("character " + character.getName() + " showing: " + character.isShowingAnimation()); + if (character.isShowingAnimation()) { +// System.out.println("animation"); + batch.draw(hitMarker,cur.x,cur.y); + } + + if (cur.getCharacter().equals(mainGame.getSelectedCharacter())) { batch.draw(square, cur.x, cur.y); - } } } diff --git a/core/src/netwerkprog/game/util/application/Timer.java b/core/src/netwerkprog/game/util/application/Timer.java deleted file mode 100644 index 11d61fb..0000000 --- a/core/src/netwerkprog/game/util/application/Timer.java +++ /dev/null @@ -1,102 +0,0 @@ -package netwerkprog.game.util.application; - -public class Timer implements Updatable { - private double wait; - private double time; - private boolean loop; - private int timeout; - - /** - * makes a new timer that doesnt start automatically and doesnt loop - * @param wait the time in ms to wait - */ - public Timer(double wait) { - this(wait, false, false); - } - - /** - * makes a new timer with the given parameters - * @param wait the wait time in ms - * @param autoStart whether the timer should start automatically - */ - public Timer(double wait, boolean autoStart) { - this(wait, autoStart, false); - } - - /** - * makes a new timer with the given parameters - * @param wait the wait time in ms - * @param autoStart wether the timer should start automatically - * @param loop if this timer should loop - */ - public Timer(double wait, boolean autoStart, boolean loop) { - this.wait = wait; - this.loop = loop; - this.time = 0.0; - this.timeout = autoStart ? 0 : -1; - } - - public void start() { - this.timeout = 0; - } - - public void stop() { - this.timeout = -1; - } - - /** - * Get whether the timer has timed out. - * Timeouts will stack and will not be reset when this method has been called, - * instead the timeout will decrease by one. - * - * @return timeout occurred - */ - public boolean timeout() { - if (this.timeout == -1) { - // timeout has occurred and is not looped - return false; - } - - if (this.timeout - 1 < 0) { - // timeout has not occurred - this.timeout = 0; - return false; - } - - if (this.loop) { - // when looped, decrease by one - this.timeout -= 1; - } else { - // else abort the timer - this.timeout = -1; - } - - return true; - } - - /** - * sets the time until the timeout. - * @param wait the new timeout time - */ - public void setWait(double wait) { - this.wait = wait; - } - - - public double getWait() { - return this.wait; - } - - @Override - public void update(double deltaTime) { - if (this.timeout != -1) { - // Only update when timer is not aborted - this.time += deltaTime; - if (this.time >= this.wait) { - // timeout occurred - this.time -= this.wait; - this.timeout++; - } - } - } -} diff --git a/core/src/netwerkprog/game/util/game/GameCharacter.java b/core/src/netwerkprog/game/util/game/GameCharacter.java index 4715e86..34fbd67 100644 --- a/core/src/netwerkprog/game/util/game/GameCharacter.java +++ b/core/src/netwerkprog/game/util/game/GameCharacter.java @@ -1,6 +1,7 @@ package netwerkprog.game.util.game; +import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.g2d.TextureRegion; import com.badlogic.gdx.scenes.scene2d.Actor; import netwerkprog.game.client.game.map.GameTile; @@ -19,6 +20,8 @@ public abstract class GameCharacter extends Actor implements Comparable allowedToMove; + protected boolean damageAnimation; + protected double hitTimout = 0; public GameCharacter(String name, Faction faction, TextureRegion textureRegion, Ability... abilities) { super(); @@ -28,6 +31,7 @@ public abstract class GameCharacter extends Actor implements Comparable(); } @@ -58,7 +62,13 @@ public abstract class GameCharacter extends Actor implements Comparable= 0.4) { + this.damageAnimation = false; + this.hitTimout = 0; + } + + } + @Override public int hashCode() { return Objects.hash(name, faction, abilities, override); @@ -96,7 +117,7 @@ public abstract class GameCharacter extends Actor implements Comparable> extends AbstractTree { protected TreeNode root; protected int size = 0; @@ -323,6 +325,19 @@ public class BST> extends AbstractTree { size = 0; } + @Override + public String toString() { + String res = ""; + for (E e : this) { + res += e.toString(); + } + return "BST{" + + "root=" + root + + ", size=" + size + + ", " + res + + '}'; + } + // if (tree == null) { // return false; // }