Characters moving #9
BIN
core/assets/square.png
Normal file
BIN
core/assets/square.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 913 B |
@@ -7,6 +7,8 @@ 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.Sprite;
|
||||||
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;
|
||||||
@@ -18,6 +20,7 @@ import netwerkprog.game.client.game.map.MapRenderer;
|
|||||||
import netwerkprog.game.client.game.map.GameInputProcessor;
|
import netwerkprog.game.client.game.map.GameInputProcessor;
|
||||||
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;
|
||||||
|
|
||||||
public class MainGame extends ApplicationAdapter {
|
public class MainGame extends ApplicationAdapter {
|
||||||
SpriteBatch batch;
|
SpriteBatch batch;
|
||||||
@@ -29,6 +32,10 @@ public class MainGame extends ApplicationAdapter {
|
|||||||
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 Map map;
|
private Map map;
|
||||||
public MapRenderer mapRenderer;
|
public MapRenderer mapRenderer;
|
||||||
@@ -55,6 +62,8 @@ public class MainGame extends ApplicationAdapter {
|
|||||||
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();
|
||||||
|
|
||||||
|
|
||||||
String[] strings = new String[]{
|
String[] strings = new String[]{
|
||||||
@@ -80,6 +89,7 @@ public class MainGame extends ApplicationAdapter {
|
|||||||
camera.viewportWidth = screenWidth / 2;
|
camera.viewportWidth = screenWidth / 2;
|
||||||
camera.viewportHeight = screenHeight / 2;
|
camera.viewportHeight = screenHeight / 2;
|
||||||
camera.update();
|
camera.update();
|
||||||
|
|
||||||
initCharacters();
|
initCharacters();
|
||||||
// this.tree.insert(new Hacker(,new BodySwap()));
|
// this.tree.insert(new Hacker(,new BodySwap()));
|
||||||
|
|
||||||
@@ -93,7 +103,7 @@ public class MainGame extends ApplicationAdapter {
|
|||||||
private void initCharacters() {
|
private void initCharacters() {
|
||||||
Texture texture = new Texture(Gdx.files.internal("core/assets/characters.png"));
|
Texture texture = new Texture(Gdx.files.internal("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"));
|
this.testCharacter = new Hacker("harryyyyyyyyyy",characters[1][0], new BodySwap("test"));
|
||||||
GameCharacter character2 = new Hacker("test2",characters[2][0], new BodySwap("test"));
|
GameCharacter character2 = new Hacker("test2",characters[2][0], new BodySwap("test"));
|
||||||
this.setSelectedCharacter(testCharacter);
|
this.setSelectedCharacter(testCharacter);
|
||||||
mapRenderer.getGameTiles()[1][1].visit(testCharacter);
|
mapRenderer.getGameTiles()[1][1].visit(testCharacter);
|
||||||
@@ -135,6 +145,13 @@ public class MainGame extends ApplicationAdapter {
|
|||||||
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();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void renderText() {
|
||||||
|
String text = "Selected character: " + selectedCharacter.getName();
|
||||||
|
textRenderer.render(text,Gdx.graphics.getWidth() - text.length() * 6.5f,Gdx.graphics.getHeight() - 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -153,6 +170,7 @@ public class MainGame extends ApplicationAdapter {
|
|||||||
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
|
||||||
@@ -163,6 +181,7 @@ public class MainGame extends ApplicationAdapter {
|
|||||||
@Override
|
@Override
|
||||||
public void dispose() {
|
public void dispose() {
|
||||||
batch.dispose();
|
batch.dispose();
|
||||||
|
textRenderer.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getScreenWidth() {
|
public float getScreenWidth() {
|
||||||
|
|||||||
@@ -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() {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -108,6 +108,10 @@ public class GameInputProcessor implements InputProcessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
} else {
|
||||||
|
if (keycode == Input.Keys.ENTER) {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -132,7 +136,8 @@ public class GameInputProcessor implements InputProcessor {
|
|||||||
if (mainGame.hasCharacterSelected() && !gameTile.containsCharacter()) {
|
if (mainGame.hasCharacterSelected() && !gameTile.containsCharacter()) {
|
||||||
// System.out.println(mainGame.getSelectedCharacter());
|
// System.out.println(mainGame.getSelectedCharacter());
|
||||||
removeCharacterFromTile(mainGame.getSelectedCharacter());
|
removeCharacterFromTile(mainGame.getSelectedCharacter());
|
||||||
gameTile.visit(mainGame.getSelectedCharacter());
|
if (gameTile.getSymbol() != '#')
|
||||||
|
gameTile.visit(mainGame.getSelectedCharacter());
|
||||||
}
|
}
|
||||||
if (!mainGame.hasCharacterSelected() && gameTile.containsCharacter()) {
|
if (!mainGame.hasCharacterSelected() && gameTile.containsCharacter()) {
|
||||||
mainGame.setSelectedCharacter(gameTile.getCharacter());
|
mainGame.setSelectedCharacter(gameTile.getCharacter());
|
||||||
|
|||||||
@@ -3,7 +3,9 @@ package netwerkprog.game.client.game.map;
|
|||||||
import com.badlogic.gdx.Gdx;
|
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.BitmapFont;
|
||||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||||
|
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
|
||||||
import netwerkprog.game.client.MainGame;
|
import netwerkprog.game.client.MainGame;
|
||||||
import netwerkprog.game.util.graphics.Renderable;
|
import netwerkprog.game.util.graphics.Renderable;
|
||||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||||
@@ -17,8 +19,12 @@ public class MapRenderer implements Renderable {
|
|||||||
private OrthographicCamera cam;
|
private OrthographicCamera cam;
|
||||||
private static int x = 0;
|
private static int x = 0;
|
||||||
private static int y = 0;
|
private static int y = 0;
|
||||||
|
private BitmapFont font;
|
||||||
|
|
||||||
|
private ShapeRenderer shapeRenderer;
|
||||||
|
|
||||||
private MainGame mainGame;
|
private MainGame mainGame;
|
||||||
|
private Texture square;
|
||||||
|
|
||||||
|
|
||||||
public static TextureRegion FLOOR_TILE;
|
public static TextureRegion FLOOR_TILE;
|
||||||
@@ -43,6 +49,8 @@ public class MapRenderer implements Renderable {
|
|||||||
cam = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
|
cam = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
|
||||||
this.camera = camera;
|
this.camera = camera;
|
||||||
this.mainGame = MainGame.getInstance();
|
this.mainGame = MainGame.getInstance();
|
||||||
|
font = new BitmapFont();
|
||||||
|
square = new Texture(Gdx.files.internal("square.png"));
|
||||||
makeTiles();
|
makeTiles();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,9 +108,11 @@ 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user