Refactor some code and create new Forrest map
This commit is contained in:
@@ -14,7 +14,7 @@ import com.bartlomiejpluta.base.api.icon.Icon;
|
||||
|
||||
import com.bartlomiejpluta.base.lib.camera.*;
|
||||
|
||||
import com.bartlomiejpluta.base.util.world.CharacterSpawner;
|
||||
import com.bartlomiejpluta.base.util.world.*;
|
||||
|
||||
import com.bartlomiejpluta.demo.runner.DemoRunner;
|
||||
import com.bartlomiejpluta.demo.entity.*;
|
||||
@@ -34,7 +34,6 @@ public abstract class BaseMapHandler implements MapHandler {
|
||||
protected Player player;
|
||||
protected ObjectLayer mainLayer;
|
||||
protected CameraController cameraController;
|
||||
protected final List<CharacterSpawner> spawners = new LinkedList<>();
|
||||
|
||||
@Override
|
||||
public void onCreate(Context context, GameMap map) {
|
||||
@@ -75,13 +74,13 @@ public abstract class BaseMapHandler implements MapHandler {
|
||||
}
|
||||
} else {
|
||||
if(input.isKeyPressed(Key.KEY_DOWN)) {
|
||||
mainLayer.pushMovement(player.prepareMovement(Direction.DOWN));
|
||||
player.getLayer().pushMovement(player.prepareMovement(Direction.DOWN));
|
||||
} else if(input.isKeyPressed(Key.KEY_UP)) {
|
||||
mainLayer.pushMovement(player.prepareMovement(Direction.UP));
|
||||
player.getLayer().pushMovement(player.prepareMovement(Direction.UP));
|
||||
} else if(input.isKeyPressed(Key.KEY_LEFT)) {
|
||||
mainLayer.pushMovement(player.prepareMovement(Direction.LEFT));
|
||||
player.getLayer().pushMovement(player.prepareMovement(Direction.LEFT));
|
||||
} else if(input.isKeyPressed(Key.KEY_RIGHT)) {
|
||||
mainLayer.pushMovement(player.prepareMovement(Direction.RIGHT));
|
||||
player.getLayer().pushMovement(player.prepareMovement(Direction.RIGHT));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -89,40 +88,47 @@ public abstract class BaseMapHandler implements MapHandler {
|
||||
@Override
|
||||
public void update(Context context, GameMap map, float dt) {
|
||||
cameraController.update();
|
||||
for(var spawner : spawners) {
|
||||
spawner.update(dt);
|
||||
}
|
||||
}
|
||||
|
||||
public Enemy enemy(@NonNull String id) {
|
||||
return new Enemy(id);
|
||||
}
|
||||
|
||||
public Enemy enemy(int x, int y, @NonNull String id) {
|
||||
public Enemy enemy(ObjectLayer layer, int x, int y, @NonNull String id) {
|
||||
var enemy = new Enemy(id);
|
||||
enemy.setCoordinates(x, y);
|
||||
mainLayer.addEntity(enemy);
|
||||
layer.addEntity(enemy);
|
||||
return enemy;
|
||||
}
|
||||
|
||||
public MapObject object(int x, int y, @NonNull String id) {
|
||||
public MapObject object(ObjectLayer layer, int x, int y, @NonNull String id) {
|
||||
var object = new MapObject(id);
|
||||
object.setCoordinates(x, y);
|
||||
mainLayer.addEntity(object);
|
||||
layer.addEntity(object);
|
||||
return object;
|
||||
}
|
||||
|
||||
public CharacterSpawner spawner(int x, int y, ObjectLayer layer) {
|
||||
var spawner = new CharacterSpawner(x, y, context, map, layer).trackEntities(EnemyDiedEvent.TYPE);
|
||||
this.spawners.add(spawner);
|
||||
public CharacterSpawner spawner(ObjectLayer layer, int x, int y) {
|
||||
var spawner = new CharacterSpawner().trackEntities(EnemyDiedEvent.TYPE);
|
||||
spawner.setCoordinates(x, y);
|
||||
layer.addEntity(spawner);
|
||||
return spawner;
|
||||
}
|
||||
|
||||
public void icon(int x, int y, String iconSetUid, int row, int column) {
|
||||
public Icon icon(ObjectLayer layer, int x, int y, String iconSetUid, int row, int column) {
|
||||
var icon = context.createIcon(iconSetUid, row, column);
|
||||
icon.setScale(1f);
|
||||
icon.setZIndex(-1);
|
||||
icon.setCoordinates(x, y);
|
||||
mainLayer.addEntity(icon);
|
||||
layer.addEntity(icon);
|
||||
return icon;
|
||||
}
|
||||
|
||||
public Warp warp(ObjectLayer layer, int x, int y, String targetMap, String targetLayer, int targetX, int targetY) {
|
||||
var warp = new Warp(A.maps.get(targetMap).uid, A.maps.getLayer(targetMap, targetLayer), targetX, targetY);
|
||||
warp.setEntity(player);
|
||||
warp.setCoordinates(x, y);
|
||||
layer.addEntity(warp);
|
||||
return warp;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.bartlomiejpluta.demo.map;
|
||||
|
||||
import com.bartlomiejpluta.base.api.context.Context;
|
||||
import com.bartlomiejpluta.base.api.input.Input;
|
||||
import com.bartlomiejpluta.base.api.map.model.GameMap;
|
||||
import com.bartlomiejpluta.base.api.map.handler.MapHandler;
|
||||
import com.bartlomiejpluta.base.api.screen.Screen;
|
||||
|
||||
public class ForrestHandler extends BaseMapHandler {
|
||||
|
||||
}
|
||||
@@ -7,6 +7,8 @@ import com.bartlomiejpluta.base.api.screen.Screen;
|
||||
|
||||
public class ForrestTempleHandler extends BaseMapHandler {
|
||||
public static final String UID = "f845355e-b9ad-4884-a217-dd3a4c18a3fa";
|
||||
public static final A.maps.GameMapAsset_Layers_ForrestTemple LAYERS = A.maps.forrest_temple.layers;
|
||||
|
||||
public static final int MAIN_LAYER = 4;
|
||||
|
||||
@Override
|
||||
|
||||
@@ -50,8 +50,8 @@ public class DemoRunner implements GameRunner {
|
||||
|
||||
private void configureScreen() {
|
||||
var resolution = screen.getCurrentResolution();
|
||||
screen.setSize(800, 600);
|
||||
screen.setPosition((resolution.x() - 800)/2, (resolution.y() - 600)/2);
|
||||
screen.setSize(1800, 1000);
|
||||
screen.setPosition((resolution.x() - 1800)/2, (resolution.y() - 1000)/2);
|
||||
}
|
||||
|
||||
private void configureCamera() {
|
||||
@@ -79,7 +79,6 @@ public class DemoRunner implements GameRunner {
|
||||
this.player.setSpeed(4f);
|
||||
this.player.setAnimationSpeed(2f);
|
||||
this.player.setBlocking(true);
|
||||
this.player.setCoordinates(14, 11);
|
||||
this.player.setWeapon(new RangedWeapon("wooden_bow"));
|
||||
}
|
||||
|
||||
@@ -87,8 +86,9 @@ public class DemoRunner implements GameRunner {
|
||||
menu.closeAll();
|
||||
menu.enableGameMenu();
|
||||
resetPlayer();
|
||||
context.openMap(A.maps.forrest_temple.uid);
|
||||
context.getMap().getObjectLayer(ForrestTempleHandler.MAIN_LAYER).addEntity(this.player);
|
||||
context.openMap(A.maps.forrest.uid);
|
||||
context.getMap().getObjectLayer(A.maps.forrest.layers.main).addEntity(this.player);
|
||||
player.setCoordinates(5, 36);
|
||||
context.resume();
|
||||
hud.show();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user