Skip to content

Commit

Permalink
Rotating the sublevel that the SwapTrigger places in
Browse files Browse the repository at this point in the history
  • Loading branch information
Interrupt committed Jan 15, 2019
1 parent 69ebec3 commit 253a69b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.interrupt.dungeoneer.game.Game;
import com.interrupt.dungeoneer.game.Level;
import com.interrupt.dungeoneer.serializers.v2.LevelSerializer;
import com.interrupt.dungeoneer.tiles.Tile;

public class LevelSwap extends Trigger {

Expand All @@ -15,6 +16,8 @@ public class LevelSwap extends Trigger {

public LevelSwap() { }

int rotAccumulator = 0;

// triggers can be delayed, fire the actual trigger here
public void doTriggerEvent(String value) {
super.doTriggerEvent(value);
Expand All @@ -24,8 +27,24 @@ public void doTriggerEvent(String value) {
try {
FileHandle levelFile = Game.findInternalFileInMods(levelFilename);
Level level = LevelSerializer.loadLevel(levelFile);

if (level != null) {
Level currentLevel = Game.GetLevel();

// Rotate the sublevel to match
for(int i = 0; i < rotAccumulator; i++) {
level.rotate90();
}

// Offset the tiles vertically
for(int i = 0; i < level.tiles.length; i++) {
Tile t = level.tiles[i];
if(t != null) {
t.floorHeight += z;
t.ceilHeight += z;
}
}

currentLevel.paste(level, (int) x - level.width / 2, (int) y - level.height / 2);

currentLevel.initEntities(level.entities, Level.Source.LEVEL_START);
Expand All @@ -39,4 +58,9 @@ public void doTriggerEvent(String value) {
Gdx.app.log("LevelSwapTrigger", ex.getMessage());
}
}

@Override
public void rotate90() {
rotAccumulator++;
}
}
2 changes: 1 addition & 1 deletion Dungeoneer/src/com/interrupt/dungeoneer/game/Level.java
Original file line number Diff line number Diff line change
Expand Up @@ -1511,7 +1511,7 @@ public void init(Source source) {
Game.pathfinding.InitForLevel(this);
}

private void initEntities(Array<Entity> entityList, Source source) {
public void initEntities(Array<Entity> entityList, Source source) {
if(entityList == null)
return;

Expand Down

0 comments on commit 253a69b

Please sign in to comment.