Enable player movements
This commit is contained in:
@@ -1,7 +1,36 @@
|
||||
package com.bartlomiejpluta.demo.map;
|
||||
|
||||
import com.bartlomiejpluta.base.api.map.handler.MapHandler;
|
||||
import com.bartlomiejpluta.base.api.map.model.GameMap;
|
||||
import com.bartlomiejpluta.base.api.map.layer.object.ObjectLayer;
|
||||
import com.bartlomiejpluta.base.api.context.Context;
|
||||
import com.bartlomiejpluta.base.api.move.Direction;
|
||||
import com.bartlomiejpluta.base.api.input.*;
|
||||
|
||||
import com.bartlomiejpluta.demo.runner.DemoRunner;
|
||||
import com.bartlomiejpluta.demo.entity.Player;
|
||||
|
||||
public abstract class BaseMapHandler implements MapHandler {
|
||||
protected Context context;
|
||||
protected Player player;
|
||||
protected ObjectLayer mainLayer;
|
||||
|
||||
@Override
|
||||
public void onCreate(Context context, GameMap map) {
|
||||
this.context = context;
|
||||
this.player = ((DemoRunner) context.getGameRunner()).getPlayer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void input(Input input) {
|
||||
if(input.isKeyPressed(Key.KEY_DOWN)) {
|
||||
mainLayer.pushMovement(player.prepareMovement(Direction.DOWN));
|
||||
} else if(input.isKeyPressed(Key.KEY_UP)) {
|
||||
mainLayer.pushMovement(player.prepareMovement(Direction.UP));
|
||||
} else if(input.isKeyPressed(Key.KEY_LEFT)) {
|
||||
mainLayer.pushMovement(player.prepareMovement(Direction.LEFT));
|
||||
} else if(input.isKeyPressed(Key.KEY_RIGHT)) {
|
||||
mainLayer.pushMovement(player.prepareMovement(Direction.RIGHT));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,28 +9,9 @@ public class ForrestTempleHandler extends BaseMapHandler {
|
||||
public static final String UID = "f845355e-b9ad-4884-a217-dd3a4c18a3fa";
|
||||
public static final int MAIN_LAYER = 4;
|
||||
|
||||
@Override
|
||||
public void onCreate(Context context, GameMap map) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onOpen(Context context, GameMap map) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void input(Input input) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Context context, GameMap map, float dt) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postRender(Screen screen) {
|
||||
|
||||
}
|
||||
@Override
|
||||
public void onCreate(Context context, GameMap map) {
|
||||
super.onCreate(context, map);
|
||||
this.mainLayer = map.getObjectLayer(MAIN_LAYER);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.bartlomiejpluta.demo.runner;
|
||||
|
||||
import lombok.*;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -15,6 +17,8 @@ public class DemoRunner implements GameRunner {
|
||||
private static final Logger log = LoggerFactory.getLogger(DemoRunner.class);
|
||||
private Screen screen;
|
||||
private Context context;
|
||||
|
||||
@Getter
|
||||
private Player player;
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user