Characters moving #9

Merged
SemvdH merged 7 commits from characters-moving into master 2020-06-06 14:30:24 +00:00
7 changed files with 75 additions and 32 deletions
Showing only changes of commit 8b4538da39 - Show all commits

BIN
core/assets/square.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 913 B

View File

@@ -7,6 +7,8 @@ import com.badlogic.gdx.audio.Music;
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.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
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.util.game.GameCharacter;
import netwerkprog.game.util.graphics.FrameRate;
import netwerkprog.game.util.graphics.TextRenderer;
public class MainGame extends ApplicationAdapter {
SpriteBatch batch;
@@ -29,6 +32,10 @@ public class MainGame extends ApplicationAdapter {
private GameInputProcessor gameInputProcessor;
private GameCharacter selectedCharacter;
private Team team;
private Team enemyTeam;
private TextRenderer textRenderer;
private BitmapFont font;
private Map map;
public MapRenderer mapRenderer;
@@ -55,6 +62,8 @@ public class MainGame extends ApplicationAdapter {
screenHeight = Gdx.graphics.getHeight();
frameRate = new FrameRate();
camera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
textRenderer = new TextRenderer();
font = new BitmapFont();
String[] strings = new String[]{
@@ -80,6 +89,7 @@ public class MainGame extends ApplicationAdapter {
camera.viewportWidth = screenWidth / 2;
camera.viewportHeight = screenHeight / 2;
camera.update();
initCharacters();
// this.tree.insert(new Hacker(,new BodySwap()));
@@ -93,7 +103,7 @@ 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("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"));
this.setSelectedCharacter(testCharacter);
mapRenderer.getGameTiles()[1][1].visit(testCharacter);
@@ -135,6 +145,13 @@ public class MainGame extends ApplicationAdapter {
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
mapRenderer.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;
frameRate.resize(width, height);
mapRenderer.resize(width, height);
textRenderer.resize(width,height);
}
@Override
@@ -163,6 +181,7 @@ public class MainGame extends ApplicationAdapter {
@Override
public void dispose() {
batch.dispose();
textRenderer.dispose();
}
public float getScreenWidth() {

View File

@@ -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() {
}
}

View File

@@ -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() {
}
}

View File

@@ -108,6 +108,10 @@ public class GameInputProcessor implements InputProcessor {
}
return true;
} else {
if (keycode == Input.Keys.ENTER) {
}
}
return false;
}
@@ -132,7 +136,8 @@ public class GameInputProcessor implements InputProcessor {
if (mainGame.hasCharacterSelected() && !gameTile.containsCharacter()) {
// System.out.println(mainGame.getSelectedCharacter());
removeCharacterFromTile(mainGame.getSelectedCharacter());
gameTile.visit(mainGame.getSelectedCharacter());
if (gameTile.getSymbol() != '#')
gameTile.visit(mainGame.getSelectedCharacter());
}
if (!mainGame.hasCharacterSelected() && gameTile.containsCharacter()) {
mainGame.setSelectedCharacter(gameTile.getCharacter());

View File

@@ -3,7 +3,9 @@ package netwerkprog.game.client.game.map;
import com.badlogic.gdx.Gdx;
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.SpriteBatch;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import netwerkprog.game.client.MainGame;
import netwerkprog.game.util.graphics.Renderable;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
@@ -17,8 +19,12 @@ public class MapRenderer implements Renderable {
private OrthographicCamera cam;
private static int x = 0;
private static int y = 0;
private BitmapFont font;
private ShapeRenderer shapeRenderer;
private MainGame mainGame;
private Texture square;
public static TextureRegion FLOOR_TILE;
@@ -43,6 +49,8 @@ public class MapRenderer implements Renderable {
cam = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
this.camera = camera;
this.mainGame = MainGame.getInstance();
font = new BitmapFont();
square = new Texture(Gdx.files.internal("square.png"));
makeTiles();
}
@@ -100,9 +108,11 @@ public class MapRenderer implements Renderable {
for (int col = 0; col < gameTiles[0].length; col++) {
GameTile cur = gameTileRow[col];
batch.draw(cur.getTextureRegion(), cur.x, cur.y);
if (cur.containsCharacter()) {
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);
}
}
}

View 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();
}
}