Add support for enemy spawners
This commit is contained in:
BIN
data.mv.db
BIN
data.mv.db
Binary file not shown.
Binary file not shown.
@@ -13,17 +13,27 @@ import com.bartlomiejpluta.base.api.input.*;
|
|||||||
|
|
||||||
import com.bartlomiejpluta.base.lib.camera.*;
|
import com.bartlomiejpluta.base.lib.camera.*;
|
||||||
|
|
||||||
|
import com.bartlomiejpluta.base.util.world.EntitySpawner;
|
||||||
|
|
||||||
import com.bartlomiejpluta.demo.runner.DemoRunner;
|
import com.bartlomiejpluta.demo.runner.DemoRunner;
|
||||||
import com.bartlomiejpluta.demo.entity.*;
|
import com.bartlomiejpluta.demo.entity.*;
|
||||||
|
import com.bartlomiejpluta.demo.event.*;
|
||||||
|
|
||||||
|
import com.bartlomiejpluta.demo.util.*;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.function.*;
|
||||||
|
|
||||||
public abstract class BaseMapHandler implements MapHandler {
|
public abstract class BaseMapHandler implements MapHandler {
|
||||||
protected Screen screen;
|
protected Screen screen;
|
||||||
protected Context context;
|
protected Context context;
|
||||||
protected DemoRunner runner;
|
protected DemoRunner runner;
|
||||||
protected Camera camera;
|
protected Camera camera;
|
||||||
|
protected GameMap map;
|
||||||
protected Player player;
|
protected Player player;
|
||||||
protected ObjectLayer mainLayer;
|
protected ObjectLayer mainLayer;
|
||||||
protected CameraController cameraController;
|
protected CameraController cameraController;
|
||||||
|
protected final List<EntitySpawner> spawners = new LinkedList<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Context context, GameMap map) {
|
public void onCreate(Context context, GameMap map) {
|
||||||
@@ -31,6 +41,7 @@ public abstract class BaseMapHandler implements MapHandler {
|
|||||||
this.screen = context.getScreen();
|
this.screen = context.getScreen();
|
||||||
this.runner = (DemoRunner) context.getGameRunner();
|
this.runner = (DemoRunner) context.getGameRunner();
|
||||||
this.camera = context.getCamera();
|
this.camera = context.getCamera();
|
||||||
|
this.map = map;
|
||||||
this.player = runner.getPlayer();
|
this.player = runner.getPlayer();
|
||||||
this.cameraController = FollowingCameraController
|
this.cameraController = FollowingCameraController
|
||||||
.on(screen, camera, map)
|
.on(screen, camera, map)
|
||||||
@@ -77,6 +88,9 @@ public abstract class BaseMapHandler implements MapHandler {
|
|||||||
@Override
|
@Override
|
||||||
public void update(Context context, GameMap map, float dt) {
|
public void update(Context context, GameMap map, float dt) {
|
||||||
cameraController.update();
|
cameraController.update();
|
||||||
|
for(var spawner : spawners) {
|
||||||
|
spawner.update(dt);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Enemy enemy(int x, int y, @NonNull String id) {
|
public Enemy enemy(int x, int y, @NonNull String id) {
|
||||||
@@ -92,4 +106,10 @@ public abstract class BaseMapHandler implements MapHandler {
|
|||||||
mainLayer.addEntity(object);
|
mainLayer.addEntity(object);
|
||||||
return object;
|
return object;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public EntitySpawner spawner(int x, int y, ObjectLayer layer) {
|
||||||
|
var spawner = new EntitySpawner(x, y, map, layer).trackEntities(EnemyDiedEvent.TYPE);
|
||||||
|
this.spawners.add(spawner);
|
||||||
|
return spawner;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user