Damage character #11

Merged
SemvdH merged 5 commits from damage-character into master 2020-06-06 20:43:07 +00:00
5 changed files with 26 additions and 13 deletions
Showing only changes of commit bbfa59ab7f - Show all commits

BIN
core/assets/earrape.mp3 Normal file

Binary file not shown.

View File

@@ -76,13 +76,13 @@ public class MainGame extends ApplicationAdapter {
String[] strings = new String[]{ String[] strings = new String[]{
"#########################", "#########################",
"#xxxx #", "#xxxx # #",
"# x #", "# x # #",
"# xxxx xxxxx #", "# xxxx #xxxx #",
"# xxxx xxxxx #", "# xxxx #xxxx #",
"# xxxx xx xx #", "# xxxx #x xx #",
"# x xxxxx #", "# x #xxxx #",
"# x xxxx #", "# x #xxx #",
"# x #", "# x #",
"# xxxxxx #", "# xxxxxx #",
"# x #", "# x #",
@@ -101,7 +101,7 @@ public class MainGame extends ApplicationAdapter {
// this.tree.insert(new Hacker(,new BodySwap())); // this.tree.insert(new Hacker(,new BodySwap()));
// playSong(); playSong();
// connectToServer(); // connectToServer();
@@ -124,7 +124,8 @@ public class MainGame extends ApplicationAdapter {
for (int i = 1; i <= 5; i++) { for (int i = 1; i <= 5; i++) {
GameCharacter temp = new Agent("Agent" + i, characters[11][0], new BodySwap("Test")); GameCharacter temp = new Agent("Agent" + i, characters[11][0], new BodySwap("Test"));
mapRenderer.getGameTiles()[3][i].visit(temp); int width = mapRenderer.getGameTiles()[0].length;
mapRenderer.getGameTiles()[3][width-(i+1)].visit(temp);
if (chosenFaction == Faction.MEGACORPORATION) { if (chosenFaction == Faction.MEGACORPORATION) {
this.team.addMember(temp); this.team.addMember(temp);
} }
@@ -136,7 +137,7 @@ public class MainGame extends ApplicationAdapter {
private void playSong() { private void playSong() {
// play music // 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.setVolume(.1f);
music.play(); music.play();
music.setLooping(true); music.setLooping(true);

View File

@@ -46,6 +46,7 @@ public class GameInputProcessor implements InputProcessor {
camera.zoom = MathUtils.clamp(camera.zoom, 1.5f, 1.8f); camera.zoom = MathUtils.clamp(camera.zoom, 1.5f, 1.8f);
} }
public boolean isWPressed() { public boolean isWPressed() {
@@ -124,8 +125,10 @@ public class GameInputProcessor implements InputProcessor {
System.out.println("HACKER"); System.out.println("HACKER");
mainGame.setChosenFaction(Faction.HACKER); mainGame.setChosenFaction(Faction.HACKER);
mainGame.initCharacters(); mainGame.initCharacters();
camera.translate(-400,0);
mainGame.setGamestate(GAMESTATE.PLAYING); mainGame.setGamestate(GAMESTATE.PLAYING);
} }
} }
return false; return false;
} }
@@ -148,21 +151,28 @@ public class GameInputProcessor implements InputProcessor {
GameTile gameTile = mainGame.mapRenderer.getGameTiles()[row][col]; GameTile gameTile = mainGame.mapRenderer.getGameTiles()[row][col];
if (gameTile.contains(touchPoint.x, touchPoint.y)) { if (gameTile.contains(touchPoint.x, touchPoint.y)) {
if (button == Input.Buttons.LEFT) { if (button == Input.Buttons.LEFT) {
// System.out.println(gameTile + " row: " + row + ", col: " + col);
// moving selected character
if (mainGame.hasCharacterSelected() && !gameTile.containsCharacter()) { if (mainGame.hasCharacterSelected() && !gameTile.containsCharacter()) {
// System.out.println(mainGame.getSelectedCharacter());
if (gameTile.getSymbol() != '#' && mainGame.mapRenderer.getSurroundedTilesOfCurrentCharacter().contains(gameTile)) { 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); mainGame.mapRenderer.setSurroundedTilesOfCurrentCharacter(col, row);
} }
} }
// clicking on enemy
if (mainGame.hasCharacterSelected() && gameTile.containsCharacter() && gameTile.getCharacter().getFaction() != mainGame.getChosenFaction()) {
gameTile.getCharacter().damage(10);
}
// set selected character
if (!mainGame.hasCharacterSelected() && gameTile.containsCharacter()) { if (!mainGame.hasCharacterSelected() && gameTile.containsCharacter()) {
if (gameTile.getCharacter().getFaction() == mainGame.getChosenFaction()) { if (gameTile.getCharacter().getFaction() == mainGame.getChosenFaction()) {
mainGame.setSelectedCharacter(gameTile.getCharacter()); mainGame.setSelectedCharacter(gameTile.getCharacter());
mainGame.mapRenderer.setSurroundedTilesOfCurrentCharacter(col, row); mainGame.mapRenderer.setSurroundedTilesOfCurrentCharacter(col, row);
} }
} }
// switch character
if (gameTile.containsCharacter() if (gameTile.containsCharacter()
&& !mainGame.getSelectedCharacter().equals(gameTile.getCharacter()) && !mainGame.getSelectedCharacter().equals(gameTile.getCharacter())
&& gameTile.getCharacter().getFaction() == mainGame.getChosenFaction()) { && gameTile.getCharacter().getFaction() == mainGame.getChosenFaction()) {

View File

@@ -6,6 +6,7 @@ import com.badlogic.gdx.graphics.Texture;
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.MainGame; import netwerkprog.game.client.MainGame;
import netwerkprog.game.util.application.Timer;
import netwerkprog.game.util.game.GameCharacter; import netwerkprog.game.util.game.GameCharacter;
import netwerkprog.game.util.graphics.Renderable; import netwerkprog.game.util.graphics.Renderable;
@@ -118,9 +119,9 @@ public class MapRenderer implements Renderable {
if (cur.containsCharacter()) { if (cur.containsCharacter()) {
batch.draw(cur.getCharacter().getTextureRegion(), cur.x, cur.y); batch.draw(cur.getCharacter().getTextureRegion(), cur.x, cur.y);
if (cur.getCharacter().equals(mainGame.getSelectedCharacter())) { if (cur.getCharacter().equals(mainGame.getSelectedCharacter())) {
batch.draw(square, cur.x, cur.y); batch.draw(square, cur.x, cur.y);
} }
} }
} }

View File

@@ -59,6 +59,7 @@ public abstract class GameCharacter extends Actor implements Comparable<GameChar
public void damage(int amount) { public void damage(int amount) {
this.health -= amount; this.health -= amount;
if (this.health < 0) this. health = 0; if (this.health < 0) this. health = 0;
System.out.println("OUCH character " + name + " was damaged for " + amount);
} }
public boolean isDead() { public boolean isDead() {