Put player onto Forrest Temple map
This commit is contained in:
15
src/main/java/com/bartlomiejpluta/demo/entity/Character.java
Normal file
15
src/main/java/com/bartlomiejpluta/demo/entity/Character.java
Normal file
@@ -0,0 +1,15 @@
|
||||
package com.bartlomiejpluta.demo.entity;
|
||||
|
||||
import lombok.*;
|
||||
import com.bartlomiejpluta.base.api.context.Context;
|
||||
import com.bartlomiejpluta.base.api.entity.Entity;
|
||||
import com.bartlomiejpluta.base.lib.entity.EntityDelegate;
|
||||
|
||||
public class Character extends EntityDelegate {
|
||||
protected final Context context;
|
||||
|
||||
public Character(@NonNull Context context, @NonNull Entity entity) {
|
||||
super(entity);
|
||||
this.context = context;
|
||||
}
|
||||
}
|
||||
12
src/main/java/com/bartlomiejpluta/demo/entity/Player.java
Normal file
12
src/main/java/com/bartlomiejpluta/demo/entity/Player.java
Normal file
@@ -0,0 +1,12 @@
|
||||
package com.bartlomiejpluta.demo.entity;
|
||||
|
||||
import lombok.*;
|
||||
import com.bartlomiejpluta.base.api.context.Context;
|
||||
import com.bartlomiejpluta.base.api.entity.Entity;
|
||||
|
||||
public class Player extends Character {
|
||||
|
||||
public Player(@NonNull Context context, @NonNull Entity entity) {
|
||||
super(context, entity);
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ 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 int MAIN_LAYER = 4;
|
||||
|
||||
@Override
|
||||
public void onCreate(Context context, GameMap map) {
|
||||
|
||||
@@ -8,16 +8,52 @@ import com.bartlomiejpluta.base.api.input.Input;
|
||||
import com.bartlomiejpluta.base.api.screen.Screen;
|
||||
import com.bartlomiejpluta.base.api.runner.GameRunner;
|
||||
|
||||
import com.bartlomiejpluta.demo.map.ForrestTempleHandler;
|
||||
import com.bartlomiejpluta.demo.entity.Player;
|
||||
|
||||
public class DemoRunner implements GameRunner {
|
||||
private static final Logger log = LoggerFactory.getLogger(DemoRunner.class);
|
||||
private Screen screen;
|
||||
private Context context;
|
||||
private Player player;
|
||||
|
||||
@Override
|
||||
public void init(Context context) {
|
||||
// Resume engine, because it is initially paused
|
||||
context.resume();
|
||||
|
||||
log.info("The game runner is not implemented yet...");
|
||||
throw new RuntimeException("Not implemented yet");
|
||||
this.context = context;
|
||||
this.screen = context.getScreen();
|
||||
|
||||
configureScreen();
|
||||
initPlayer();
|
||||
resetPlayer();
|
||||
newGame();
|
||||
|
||||
screen.show();
|
||||
}
|
||||
|
||||
private void configureScreen() {
|
||||
var resolution = screen.getCurrentResolution();
|
||||
screen.setSize(800, 600);
|
||||
screen.setPosition((resolution.x() - 800)/2, (resolution.y() - 600)/2);
|
||||
}
|
||||
|
||||
private void initPlayer() {
|
||||
this.player = new Player(context, context.createEntity("815a5c5c-4979-42f5-a42a-ccbbff9a97e5"));
|
||||
}
|
||||
|
||||
private void resetPlayer() {
|
||||
this.player.changeEntitySet("815a5c5c-4979-42f5-a42a-ccbbff9a97e5");
|
||||
this.player.setScale(1.0f);
|
||||
this.player.setSpeed(0.07f);
|
||||
this.player.setAnimationSpeed(0.005f);
|
||||
this.player.setBlocking(true);
|
||||
this.player.setCoordinates(0, 11);
|
||||
}
|
||||
|
||||
private void newGame() {
|
||||
resetPlayer();
|
||||
context.openMap(ForrestTempleHandler.UID);
|
||||
context.getMap().getObjectLayer(ForrestTempleHandler.MAIN_LAYER).addEntity(this.player);
|
||||
context.resume();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -29,4 +65,6 @@ public class DemoRunner implements GameRunner {
|
||||
public void dispose() {
|
||||
// Do something after game loop is end
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user