Characters moving #9
BIN
core/assets/square2.png
Normal file
BIN
core/assets/square2.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 914 B |
@@ -8,16 +8,19 @@ import com.badlogic.gdx.graphics.GL20;
|
||||
import com.badlogic.gdx.graphics.OrthographicCamera;
|
||||
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.Sprite;
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||
import netwerkprog.game.client.game.GAMESTATE;
|
||||
import netwerkprog.game.client.game.characters.Hacker;
|
||||
import netwerkprog.game.client.game.characters.Team;
|
||||
import netwerkprog.game.client.game.characters.abilities.BodySwap;
|
||||
import netwerkprog.game.client.game.map.Map;
|
||||
import netwerkprog.game.client.game.map.MapRenderer;
|
||||
import netwerkprog.game.client.game.map.GameInputProcessor;
|
||||
import netwerkprog.game.util.game.Faction;
|
||||
import netwerkprog.game.util.game.GameCharacter;
|
||||
import netwerkprog.game.util.graphics.FrameRate;
|
||||
import netwerkprog.game.util.graphics.TextRenderer;
|
||||
@@ -35,11 +38,15 @@ public class MainGame extends ApplicationAdapter {
|
||||
private Team enemyTeam;
|
||||
private TextRenderer textRenderer;
|
||||
private BitmapFont font;
|
||||
private GlyphLayout layout;
|
||||
private GAMESTATE gamestate;
|
||||
private Faction chosenFaction;
|
||||
|
||||
|
||||
private Map map;
|
||||
public MapRenderer mapRenderer;
|
||||
|
||||
|
||||
public GameCharacter testCharacter;
|
||||
|
||||
private static MainGame INSTANCE;
|
||||
@@ -64,17 +71,17 @@ public class MainGame extends ApplicationAdapter {
|
||||
camera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
|
||||
textRenderer = new TextRenderer();
|
||||
font = new BitmapFont();
|
||||
|
||||
layout = new GlyphLayout();
|
||||
|
||||
String[] strings = new String[]{
|
||||
"#########################",
|
||||
"#xxxx #",
|
||||
"# x #",
|
||||
"# xxxx #",
|
||||
"# xx #",
|
||||
"# x #",
|
||||
"# x #",
|
||||
"# x #",
|
||||
"# xxxx xxxxx #",
|
||||
"# xxxx xxxxx #",
|
||||
"# xxxx xx xx #",
|
||||
"# x xxxxx #",
|
||||
"# x xxxx #",
|
||||
"# x #",
|
||||
"# xxxxxx #",
|
||||
"# x #",
|
||||
@@ -89,6 +96,7 @@ public class MainGame extends ApplicationAdapter {
|
||||
camera.viewportWidth = screenWidth / 2;
|
||||
camera.viewportHeight = screenHeight / 2;
|
||||
camera.update();
|
||||
setGamestate(GAMESTATE.SELECTING_FACTION);
|
||||
|
||||
initCharacters();
|
||||
// this.tree.insert(new Hacker(,new BodySwap()));
|
||||
@@ -103,8 +111,8 @@ public class MainGame extends ApplicationAdapter {
|
||||
private void initCharacters() {
|
||||
Texture texture = new Texture(Gdx.files.internal("core/assets/characters.png"));
|
||||
TextureRegion[][] characters = TextureRegion.split(texture, 32, 32);
|
||||
this.testCharacter = new Hacker("harryyyyyyyyyy",characters[1][0], new BodySwap("test"));
|
||||
GameCharacter character2 = new Hacker("test2",characters[2][0], new BodySwap("test"));
|
||||
this.testCharacter = new Hacker("harryyyyyyyyyy", 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);
|
||||
@@ -139,6 +147,7 @@ public class MainGame extends ApplicationAdapter {
|
||||
*/
|
||||
@Override
|
||||
public void render() {
|
||||
if (this.gamestate == GAMESTATE.PLAYING) {
|
||||
update();
|
||||
// clear screen
|
||||
Gdx.gl.glClearColor(0, 0, 0, 1);
|
||||
@@ -146,12 +155,28 @@ public class MainGame extends ApplicationAdapter {
|
||||
mapRenderer.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 = "Selected character: " + selectedCharacter.getName();
|
||||
textRenderer.render(text,Gdx.graphics.getWidth() - text.length() * 6.5f,Gdx.graphics.getHeight() - 3);
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -170,7 +195,7 @@ public class MainGame extends ApplicationAdapter {
|
||||
screenWidth = width;
|
||||
frameRate.resize(width, height);
|
||||
mapRenderer.resize(width, height);
|
||||
textRenderer.resize(width,height);
|
||||
textRenderer.resize(width, height);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -205,6 +230,22 @@ public class MainGame extends ApplicationAdapter {
|
||||
System.out.println("selected character set to : " + character);
|
||||
}
|
||||
|
||||
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() {
|
||||
return selectedCharacter;
|
||||
}
|
||||
@@ -216,4 +257,5 @@ public class MainGame extends ApplicationAdapter {
|
||||
public Team getTeam() {
|
||||
return team;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
@@ -8,6 +8,8 @@ import com.badlogic.gdx.math.MathUtils;
|
||||
import com.badlogic.gdx.math.Vector3;
|
||||
import com.badlogic.gdx.utils.TimeUtils;
|
||||
import netwerkprog.game.client.MainGame;
|
||||
import netwerkprog.game.client.game.GAMESTATE;
|
||||
import netwerkprog.game.util.game.Faction;
|
||||
import netwerkprog.game.util.game.GameCharacter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -89,6 +91,8 @@ public class GameInputProcessor implements InputProcessor {
|
||||
@Override
|
||||
public boolean keyUp(int keycode) {
|
||||
// System.out.println(camera.position.x + " , " + camera.position.y);
|
||||
if (mainGame.getGamestate() == GAMESTATE.PLAYING) {
|
||||
|
||||
if (keysList.contains(keycode)) {
|
||||
if (keycode == keysList.get(0)) {
|
||||
this.isWPressed = false;
|
||||
@@ -108,9 +112,17 @@ public class GameInputProcessor implements InputProcessor {
|
||||
}
|
||||
|
||||
return true;
|
||||
} else {
|
||||
if (keycode == Input.Keys.ENTER) {
|
||||
|
||||
}
|
||||
} else if (mainGame.getGamestate() == GAMESTATE.SELECTING_FACTION) {
|
||||
if (keycode == Input.Keys.NUM_1) {
|
||||
System.out.println("MEGA CORP");
|
||||
mainGame.setChosenFaction(Faction.MEGACORPORATION);
|
||||
mainGame.setGamestate(GAMESTATE.PLAYING);
|
||||
}
|
||||
if (keycode == Input.Keys.NUM_2) {
|
||||
System.out.println("HACKER");
|
||||
mainGame.setChosenFaction(Faction.HACKER);
|
||||
mainGame.setGamestate(GAMESTATE.PLAYING);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
@@ -126,6 +138,8 @@ public class GameInputProcessor implements InputProcessor {
|
||||
|
||||
Vector3 touchPoint = new Vector3(Gdx.input.getX(), Gdx.input.getY(), 0);
|
||||
camera.unproject(touchPoint);
|
||||
if (mainGame.getGamestate() == GAMESTATE.PLAYING) {
|
||||
|
||||
|
||||
for (int row = 0; row < mainGame.mapRenderer.getGameTiles().length; row++) {
|
||||
for (int col = 0; col < mainGame.mapRenderer.getGameTiles()[0].length; col++) {
|
||||
@@ -135,9 +149,11 @@ public class GameInputProcessor implements InputProcessor {
|
||||
// System.out.println(gameTile + " row: " + row + ", col: " + col);
|
||||
if (mainGame.hasCharacterSelected() && !gameTile.containsCharacter()) {
|
||||
// System.out.println(mainGame.getSelectedCharacter());
|
||||
if (gameTile.getSymbol() != '#') {
|
||||
removeCharacterFromTile(mainGame.getSelectedCharacter());
|
||||
if (gameTile.getSymbol() != '#')
|
||||
gameTile.visit(mainGame.getSelectedCharacter());
|
||||
mainGame.mapRenderer.setSurroundedTilesOfCurrentCharacter(col,row);
|
||||
}
|
||||
}
|
||||
if (!mainGame.hasCharacterSelected() && gameTile.containsCharacter()) {
|
||||
mainGame.setSelectedCharacter(gameTile.getCharacter());
|
||||
@@ -150,6 +166,7 @@ public class GameInputProcessor implements InputProcessor {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,9 @@ import netwerkprog.game.client.MainGame;
|
||||
import netwerkprog.game.util.graphics.Renderable;
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class MapRenderer implements Renderable {
|
||||
private final OrthographicCamera camera;
|
||||
private int tileWidth;
|
||||
@@ -25,6 +28,7 @@ public class MapRenderer implements Renderable {
|
||||
|
||||
private MainGame mainGame;
|
||||
private Texture square;
|
||||
private Texture square2;
|
||||
|
||||
|
||||
public static TextureRegion FLOOR_TILE;
|
||||
@@ -32,6 +36,7 @@ public class MapRenderer implements Renderable {
|
||||
public static TextureRegion PATH_TILE;
|
||||
|
||||
private GameTile[][] gameTiles;
|
||||
private List<GameTile> surroundedTilesOfCurrentCharacter;
|
||||
|
||||
|
||||
/**
|
||||
@@ -51,6 +56,7 @@ public class MapRenderer implements Renderable {
|
||||
this.mainGame = MainGame.getInstance();
|
||||
font = new BitmapFont();
|
||||
square = new Texture(Gdx.files.internal("square.png"));
|
||||
square2 = new Texture(Gdx.files.internal("square2.png"));
|
||||
makeTiles();
|
||||
}
|
||||
|
||||
@@ -111,17 +117,53 @@ public class MapRenderer implements Renderable {
|
||||
|
||||
if (cur.containsCharacter()) {
|
||||
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);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (surroundedTilesOfCurrentCharacter != null && !surroundedTilesOfCurrentCharacter.isEmpty()) {
|
||||
for (GameTile gameTile : surroundedTilesOfCurrentCharacter) {
|
||||
batch.draw(square2, gameTile.x, gameTile.y);
|
||||
}
|
||||
}
|
||||
|
||||
batch.end();
|
||||
x = 0;
|
||||
y = 0;
|
||||
}
|
||||
|
||||
private 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)
|
||||
res.add(gameTiles[cy][cx]);
|
||||
}
|
||||
surroundedTilesOfCurrentCharacter = res;
|
||||
return res;
|
||||
}
|
||||
|
||||
public int getPos(GameTile tile, String choice) {
|
||||
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)) {
|
||||
if (choice.toLowerCase().equals("row"))
|
||||
return row;
|
||||
else if (choice.toLowerCase().equals("col"))
|
||||
return col;
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(double deltaTime) {
|
||||
|
||||
@@ -137,4 +179,8 @@ public class MapRenderer implements Renderable {
|
||||
public GameTile[][] getGameTiles() {
|
||||
return gameTiles;
|
||||
}
|
||||
|
||||
public List<GameTile> getSurroundedTilesOfCurrentCharacter() {
|
||||
return surroundedTilesOfCurrentCharacter;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user