added characters to game tile and map renderer
This commit is contained in:
@@ -2,12 +2,14 @@ package netwerkprog.game.client.game.map;
|
|||||||
|
|
||||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||||
import com.badlogic.gdx.math.Rectangle;
|
import com.badlogic.gdx.math.Rectangle;
|
||||||
|
import netwerkprog.game.util.game.Character;
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
public class GameTile extends Rectangle {
|
public class GameTile extends Rectangle {
|
||||||
private TextureRegion textureRegion;
|
private TextureRegion textureRegion;
|
||||||
private char symbol;
|
private char symbol;
|
||||||
|
private Character character;
|
||||||
|
|
||||||
public GameTile(TextureRegion textureRegion, int xPos, int yPos, char symbol) {
|
public GameTile(TextureRegion textureRegion, int xPos, int yPos, char symbol) {
|
||||||
this.textureRegion = textureRegion;
|
this.textureRegion = textureRegion;
|
||||||
@@ -18,6 +20,29 @@ public class GameTile extends Rectangle {
|
|||||||
super.height = textureRegion.getRegionHeight();
|
super.height = textureRegion.getRegionHeight();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Character getCharacter() {
|
||||||
|
return character;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean containsCharacter() {
|
||||||
|
return character == null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* sets the character on this tile
|
||||||
|
* @param character the character to visit this tile
|
||||||
|
* @return false if this tile already had a character on it.
|
||||||
|
*/
|
||||||
|
public boolean setCharacter(Character character) {
|
||||||
|
if (this.character != null) return false;
|
||||||
|
this.character = character;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeCharacter() {
|
||||||
|
this.character = null;
|
||||||
|
}
|
||||||
|
|
||||||
public TextureRegion getTextureRegion() {
|
public TextureRegion getTextureRegion() {
|
||||||
return textureRegion;
|
return textureRegion;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,9 +25,9 @@ public class MapRenderer implements Renderable {
|
|||||||
private GameTile[][] gameTiles;
|
private GameTile[][] gameTiles;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* makea a new mapRenderer object
|
* makea a new mapRenderer object
|
||||||
|
*
|
||||||
* @param map the map object
|
* @param map the map object
|
||||||
* @param tileWidth the width of the tile
|
* @param tileWidth the width of the tile
|
||||||
* @param batch the batch object so no new ones have to be made
|
* @param batch the batch object so no new ones have to be made
|
||||||
@@ -60,11 +60,11 @@ public class MapRenderer implements Renderable {
|
|||||||
x = 0;
|
x = 0;
|
||||||
for (int col = 0; col < map.getWidth(); col++) {
|
for (int col = 0; col < map.getWidth(); col++) {
|
||||||
if (map.get(row, col) == ' ') {
|
if (map.get(row, col) == ' ') {
|
||||||
gameTiles[row][col] = new GameTile(FLOOR_TILE,x,y, ' ');
|
gameTiles[row][col] = new GameTile(FLOOR_TILE, x, y, ' ');
|
||||||
} else if (map.get(row, col) == '#') {
|
} else if (map.get(row, col) == '#') {
|
||||||
gameTiles[row][col] = new GameTile(WALL_TILE,x,y, '#');
|
gameTiles[row][col] = new GameTile(WALL_TILE, x, y, '#');
|
||||||
} else if (map.get(row, col) == 'x') {
|
} else if (map.get(row, col) == 'x') {
|
||||||
gameTiles[row][col] = new GameTile(PATH_TILE,x,y, 'x');
|
gameTiles[row][col] = new GameTile(PATH_TILE, x, y, 'x');
|
||||||
}
|
}
|
||||||
x += 32;
|
x += 32;
|
||||||
}
|
}
|
||||||
@@ -96,6 +96,9 @@ 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()) {
|
||||||
|
batch.draw(cur.getCharacter().getTextureRegion(), x, y);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
package netwerkprog.game.util.game;
|
package netwerkprog.game.util.game;
|
||||||
|
|
||||||
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||||
|
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
|
||||||
@@ -8,12 +11,16 @@ public abstract class Character {
|
|||||||
protected Faction faction;
|
protected Faction faction;
|
||||||
protected HashSet<Ability> abilities;
|
protected HashSet<Ability> abilities;
|
||||||
protected boolean override;
|
protected boolean override;
|
||||||
|
protected TextureRegion textureRegion;
|
||||||
|
protected SpriteBatch batch;
|
||||||
|
|
||||||
public Character(String name, Faction faction, Ability... abilities) {
|
public Character(String name, Faction faction, TextureRegion textureRegion, Ability... abilities) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.faction = faction;
|
this.faction = faction;
|
||||||
this.abilities = new HashSet<>(Arrays.asList(abilities));
|
this.abilities = new HashSet<>(Arrays.asList(abilities));
|
||||||
this.override = false;
|
this.override = false;
|
||||||
|
this.textureRegion = textureRegion;
|
||||||
|
batch = new SpriteBatch();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addAbilities(Ability ability) {
|
public void addAbilities(Ability ability) {
|
||||||
@@ -27,4 +34,14 @@ public abstract class Character {
|
|||||||
public void changeControl() {
|
public void changeControl() {
|
||||||
this.override = !this.override;
|
this.override = !this.override;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public TextureRegion getTextureRegion() {
|
||||||
|
return textureRegion;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void render(float x, float y) {
|
||||||
|
batch.begin();
|
||||||
|
batch.draw(this.textureRegion, x, y);
|
||||||
|
batch.end();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user