Add support for map objects

This commit is contained in:
2022-08-18 18:59:31 +02:00
parent bf04597af6
commit 0bfe53cd8e
7 changed files with 94 additions and 1 deletions

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

View File

@@ -7,7 +7,8 @@ $cb4c89a7-a421-49ea-8c58-571e9b215d37(cb4c89a7-a421-49ea-8c58-571e9b215d37.png
$9da2c95b-45b7-49e5-957b-c1c8803cdf28(9da2c95b-45b7-49e5-957b-c1c8803cdf28.pngCorpse (2Z
$4fff029b-6c24-4c83-9dfb-51f5512a687e(4fff029b-6c24-4c83-9dfb-51f5512a687e.pngGaro (2\
$71414ffb-0e1c-4778-9a1a-0f9f53388fd0(71414ffb-0e1c-4778-9a1a-0f9f53388fd0.pngBlanca (2\
$a5c6c6eb-e6cf-4b9e-8c35-11e4c8587ce7(a5c6c6eb-e6cf-4b9e-8c35-11e4c8587ce7.pngTurtle (:`
$a5c6c6eb-e6cf-4b9e-8c35-11e4c8587ce7(a5c6c6eb-e6cf-4b9e-8c35-11e4c8587ce7.pngTurtle (2\
$15415d5a-2f53-4ee0-8f8f-8e81d702ccdb(15415d5a-2f53-4ee0-8f8f-8e81d702ccdb.pngChests (:`
$2261c04f-b02e-4486-b388-8a0fa41622e9(2261c04f-b02e-4486-b388-8a0fa41622e9.ttfRoboto RegularB\
$ab9d40b4-eb28-45d7-bff2-9432a05eb41a(ab9d40b4-eb28-45d7-bff2-9432a05eb41a.xml
Start MenuB[

View File

@@ -0,0 +1,77 @@
package com.bartlomiejpluta.demo.entity;
import lombok.*;
import com.bartlomiejpluta.base.api.entity.Entity;
import com.bartlomiejpluta.base.api.context.Context;
import com.bartlomiejpluta.base.api.move.*;
import com.bartlomiejpluta.base.lib.entity.EntityDelegate;
import com.bartlomiejpluta.base.util.path.*;
import com.bartlomiejpluta.base.generated.db.model.MapObjectModel;
import com.bartlomiejpluta.demo.entity.Character;
public class MapObject extends EntityDelegate {
private final PathExecutor<MapObject> pathExecutor = new PathExecutor<>(this);
private final Context context;
private final MapObjectModel template;
private final Short frame;
private final String interactSound;
private boolean interacting = false;
public MapObject(@NonNull Context context, @NonNull MapObjectModel template) {
super(context.createEntity(template.getEntset()));
this.context = context;
this.template = template;
this.frame = template.getFrame();
this.interactSound = template.getInteractSound();
setBlocking(true);
disableAnimation();
if(frame != null) {
setAnimationFrame(frame);
}
pathExecutor.setPath(
frame != null
? new EntityPath<MapObject>()
.run(this::startInteraction)
.turn(Direction.LEFT, frame)
.wait(0.05f)
.turn(Direction.RIGHT, frame)
.wait(0.05f)
.turn(Direction.UP, frame)
.wait(0.5f)
.turn(Direction.RIGHT, frame)
.wait(0.05f)
.turn(Direction.LEFT, frame)
.wait(0.05f)
.turn(Direction.DOWN, frame)
.wait(0.5f)
.run(this::finishInteraction)
: new EntityPath<MapObject>()
);
}
public void interact(Character character) {
interacting = true;
}
private void startInteraction() {
if(interactSound != null) {
context.playSound(interactSound);
}
}
private void finishInteraction() {
interacting = false;
}
@Override
public void update(float dt) {
if(interacting) {
pathExecutor.execute(getLayer(), dt);
}
}
}

View File

@@ -47,6 +47,10 @@ public abstract class BaseMapHandler implements MapHandler {
player.attack();
}
if(input.isKeyPressed(Key.KEY_ENTER)) {
player.interact();
}
if(input.isKeyPressed(Key.KEY_LEFT_CONTROL)) {
if(input.isKeyPressed(Key.KEY_DOWN)) {
player.setFaceDirection(Direction.DOWN);
@@ -81,4 +85,11 @@ public abstract class BaseMapHandler implements MapHandler {
mainLayer.addEntity(enemy);
return enemy;
}
public MapObject object(int x, int y, @NonNull String id) {
var object = new MapObject(context, runner.getMapObjectDAO().find(id));
object.setCoordinates(x, y);
mainLayer.addEntity(object);
return object;
}
}

View File

@@ -37,6 +37,9 @@ public class DemoRunner implements GameRunner {
@Getter
private EnemyDAO enemyDAO;
@Getter
private MapObjectDAO mapObjectDAO;
@Getter
private Player player;
@@ -73,6 +76,7 @@ public class DemoRunner implements GameRunner {
meleeWeaponDAO = new MeleeWeaponDAO(context);
enemyDAO = new EnemyDAO(context);
rangedWeaponDAO = new RangedWeaponDAO(context);
mapObjectDAO = new MapObjectDAO(context);
}
private void initMenu() {