Skip to content
This repository has been archived by the owner on Sep 29, 2024. It is now read-only.

Commit

Permalink
Merge pull request #244 from SE-TINF22B6/refactor_jf
Browse files Browse the repository at this point in the history
chore: refactor tilemap navmap parsing
  • Loading branch information
LPkkjHD authored May 27, 2024
2 parents 29d3b00 + e9510f0 commit 6987cdc
Show file tree
Hide file tree
Showing 145 changed files with 1,166 additions and 2,661 deletions.
4 changes: 1 addition & 3 deletions game/core/src/main/de/dhbw/tinf22b6/screen/GameScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.audio.Music;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.maps.tiled.TiledMap;
Expand Down Expand Up @@ -75,8 +74,7 @@ public void show() {
}

@Override
public void hide() {
}
public void hide() {}

@Override
public void pause() {
Expand Down
40 changes: 19 additions & 21 deletions game/core/src/main/de/dhbw/tinf22b6/util/MusicPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,28 @@
import com.badlogic.gdx.utils.Disposable;

public class MusicPlayer implements Disposable {
public static final MusicPlayer instance = new MusicPlayer();
private Music music;
public static final MusicPlayer instance = new MusicPlayer();
private Music music;

private MusicPlayer() {
}
private MusicPlayer() {}

public void setMusic(Music music) {
if (this.music != null) {
this.music.stop();
music.dispose();
public void setMusic(Music music) {
if (this.music != null) {
this.music.stop();
music.dispose();
}
this.music = music;
this.music.setLooping(true);
this.music.setVolume(Gdx.app.getPreferences("Controls").getFloat("music"));
this.music.play();
}
this.music = music;
this.music.setLooping(true);
this.music.setVolume(Gdx.app.getPreferences("Controls").getFloat("music"));
this.music.play();
}

public void stop() {
this.music.stop();
}
public void stop() {
this.music.stop();
}

@Override
public void dispose() {
if (music != null)
music.dispose();
}
@Override
public void dispose() {
if (music != null) music.dispose();
}
}
3 changes: 2 additions & 1 deletion game/core/src/main/de/dhbw/tinf22b6/world/WorldParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ public static void parseStaticObjects(TiledMap map) {
public static ArrayList<GameObject> parseGameObjects(TiledMap map) {
ArrayList<GameObject> list = new ArrayList<>();
// TODO refactor animated game objects using an enum
String[] objects = new String[] {"coins", "torch", "chests", "enemy", "teleporter", "start", "hp", "speed", "trophy"};
String[] objects =
new String[] {"coins", "torch", "chests", "enemy", "teleporter", "start", "hp", "speed", "trophy"};
for (String s : objects) {
TiledMapTileLayer layer = (TiledMapTileLayer) map.getLayers().get(s);
if (layer == null) continue;
Expand Down
196 changes: 111 additions & 85 deletions game/core/src/main/de/dhbw/tinf22b6/world/tiled/FlatTiledGraph.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,14 @@ public void init(int[][] map) {
for (int x = 0; x < sizeX; x++) {
for (int y = 0; y < sizeY; y++) {
FlatTiledNode n = getNode(x, y);
if (x > 0) addConnection(n, -1, 0);
if (y > 0) addConnection(n, 0, -1);
if (x < sizeX - 1) addConnection(n, 1, 0);
if (y < sizeY - 1) addConnection(n, 0, 1);
if (x > 0)
addConnection(n, -1, 0);
if (y > 0)
addConnection(n, 0, -1);
if (x < sizeX - 1)
addConnection(n, 1, 0);
if (y < sizeY - 1)
addConnection(n, 0, 1);
}
}
return;
Expand All @@ -77,112 +81,92 @@ public void init(int[][] map) {
// check if wall is above and below
if (getNode(x, y + 1).type == FlatTiledNode.TILE_WALL
&& getNode(x, y - 1).type == FlatTiledNode.TILE_WALL) {
// W
addConnection(n, -1, 0);
// E
addConnection(n, 1, 0);
addConnection(n, Direction.W, Direction.E);
continue;
}
// check if wall is left and right
if (getNode(x + 1, y).type == FlatTiledNode.TILE_WALL
&& getNode(x - 1, y).type == FlatTiledNode.TILE_WALL) {
// S
addConnection(n, 0, -1);
// N
addConnection(n, 0, 1);
addConnection(n, Direction.N, Direction.S);
continue;
}
// check if wall is above
if (getNode(x, y + 1).type == FlatTiledNode.TILE_WALL) {
// W
addConnection(n, -1, 0);
// S
addConnection(n, 0, -1);
// E
addConnection(n, 1, 0);
// N
addConnection(n, 0, 1);
// SE
addConnection(n, 1, -1);
// SW
addConnection(n, -1, -1);
addConnection(
n,
Direction.N,
Direction.E,
Direction.S,
Direction.W,
Direction.SE,
Direction.SW);
continue;
}
// check if wall is below
if (getNode(x, y - 1).type == FlatTiledNode.TILE_WALL) {
// W
addConnection(n, -1, 0);
// S
addConnection(n, 0, -1);
// E
addConnection(n, 1, 0);
// N
addConnection(n, 0, 1);
// NE
addConnection(n, 1, 1);
// NW
addConnection(n, -1, 1);
addConnection(
n,
Direction.N,
Direction.E,
Direction.S,
Direction.W,
Direction.NE,
Direction.NW);
continue;
}
// check if wall is left
if (getNode(x - 1, y).type == FlatTiledNode.TILE_WALL) {
// W
addConnection(n, -1, 0);
// S
addConnection(n, 0, -1);
// E
addConnection(n, 1, 0);
// N
addConnection(n, 0, 1);
// NE
addConnection(n, 1, 1);
// SE
addConnection(n, 1, -1);
addConnection(
n,
Direction.N,
Direction.E,
Direction.S,
Direction.W,
Direction.NE,
Direction.SE);
continue;
}
// check if wall is right
if (getNode(x + 1, y).type == FlatTiledNode.TILE_WALL) {
// W
addConnection(n, -1, 0);
// S
addConnection(n, 0, -1);
// E
addConnection(n, 1, 0);
// N
addConnection(n, 0, 1);
// NW
addConnection(n, -1, 1);
// SW
addConnection(n, -1, -1);
addConnection(
n,
Direction.N,
Direction.E,
Direction.S,
Direction.W,
Direction.NW,
Direction.SW);
continue;
}
// W
addConnection(n, -1, 0);
// S
addConnection(n, 0, -1);
// E
addConnection(n, 1, 0);
// N
addConnection(n, 0, 1);
// NW
addConnection(n, -1, 1);
// SW
addConnection(n, -1, -1);
// NE
addConnection(n, 1, 1);
// SE
addConnection(n, 1, -1);
addConnection(
n,
Direction.N,
Direction.E,
Direction.S,
Direction.W,
Direction.NE,
Direction.SE,
Direction.NW,
Direction.SW);
continue;
}
// Do not delete this part it is important for the edge
if (x > 0) addConnection(n, -1, 0);
if (y > 0) addConnection(n, 0, -1);
if (x > 0 && y > 0) addConnection(n, -1, -1);
if (x < sizeX - 1) addConnection(n, 1, 0);
if (y < sizeY - 1) addConnection(n, 0, 1);
if (x < sizeX - 1 && y < sizeY - 1) addConnection(n, 1, 1);
if (x < sizeX - 1 && y > 0) addConnection(n, 1, -1);
if (y < sizeY - 1 && x > 0) addConnection(n, -1, 1);
if (x > 0)
addConnection(n, Direction.W);
if (y > 0)
addConnection(n, Direction.S);
if (x > 0 && y > 0)
addConnection(n, Direction.SW);
if (x < sizeX - 1)
addConnection(n, Direction.E);
if (y < sizeY - 1)
addConnection(n, Direction.N);
if (x < sizeX - 1 && y < sizeY - 1)
addConnection(n, Direction.NE);
if (x < sizeX - 1 && y > 0)
addConnection(n, Direction.SE);
if (y < sizeY - 1 && x > 0)
addConnection(n, Direction.NW);
}
}
}
Expand Down Expand Up @@ -214,6 +198,48 @@ public Array<Connection<FlatTiledNode>> getConnections(FlatTiledNode fromNode) {

private void addConnection(FlatTiledNode n, int xOffset, int yOffset) {
FlatTiledNode target = getNode(n.x + xOffset, n.y + yOffset);
if (target.type != FlatTiledNode.TILE_WALL) n.getConnections().add(new FlatTiledConnection(this, n, target));
if (target.type != FlatTiledNode.TILE_WALL)
n.getConnections().add(new FlatTiledConnection(this, n, target));
}

private enum Direction {
N, E, S, W, NE, NW, SE, SW
}

private void addConnection(FlatTiledNode n, Direction... directions) // throws Exception
{
// if (directions.length > 8 || directions.length < 0) {
// throw new Exception("Directions are fucked up");
// }
for (Direction direction : directions) {
switch (direction) {
case N:
addConnection(n, 0, 1);
break;
case E:
addConnection(n, 1, 0);
break;
case S:
addConnection(n, 0, -1);
break;
case W:
addConnection(n, -1, 0);
break;
case NE:
addConnection(n, 1, 1);
break;
case NW:
addConnection(n, -1, 1);
break;
case SE:
addConnection(n, 1, -1);
break;
case SW:
addConnection(n, -1, -1);
break;
default:
break;
}
}
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Loading

0 comments on commit 6987cdc

Please sign in to comment.