|
@@ -8,11 +8,20 @@ import me.hammerle.snuviengine.api.Engine;
|
|
import me.hammerle.snuviengine.api.FontRenderer;
|
|
import me.hammerle.snuviengine.api.FontRenderer;
|
|
import me.hammerle.snuviengine.api.KeyBinding;
|
|
import me.hammerle.snuviengine.api.KeyBinding;
|
|
import me.hammerle.snuviengine.api.Shader;
|
|
import me.hammerle.snuviengine.api.Shader;
|
|
|
|
+import me.hammerle.snuviscript.code.SnuviParser;
|
|
|
|
+import me.hammerle.supersnuvi.entity.Entity;
|
|
|
|
+import me.hammerle.supersnuvi.entity.EntityBuilder;
|
|
|
|
+import me.hammerle.supersnuvi.entity.components.ai.PlatformController;
|
|
|
|
+import me.hammerle.supersnuvi.gamelogic.FileLevel;
|
|
import me.hammerle.supersnuvi.gamelogic.Level;
|
|
import me.hammerle.supersnuvi.gamelogic.Level;
|
|
import me.hammerle.supersnuvi.gamelogic.StartScreenLevel;
|
|
import me.hammerle.supersnuvi.gamelogic.StartScreenLevel;
|
|
|
|
+import me.hammerle.supersnuvi.rendering.LevelRenderer;
|
|
import me.hammerle.supersnuvi.savegame.SimpleConfig;
|
|
import me.hammerle.supersnuvi.savegame.SimpleConfig;
|
|
|
|
+import me.hammerle.supersnuvi.snuviscript.SnuviLogger;
|
|
|
|
+import me.hammerle.supersnuvi.snuviscript.SnuviScheduler;
|
|
import me.hammerle.supersnuvi.tiles.*;
|
|
import me.hammerle.supersnuvi.tiles.*;
|
|
import me.hammerle.supersnuvi.util.SoundUtils;
|
|
import me.hammerle.supersnuvi.util.SoundUtils;
|
|
|
|
+import me.hammerle.supersnuvi.util.Utils;
|
|
|
|
|
|
public class Game extends Engine
|
|
public class Game extends Engine
|
|
{
|
|
{
|
|
@@ -35,7 +44,7 @@ public class Game extends Engine
|
|
public static final NullTile FALLBACK_TILE = new NullTile();
|
|
public static final NullTile FALLBACK_TILE = new NullTile();
|
|
|
|
|
|
// tiles
|
|
// tiles
|
|
- private final Tile[] registeredTiles = new Tile[70];
|
|
|
|
|
|
+ private final Tile[] registeredTiles = new Tile[75];
|
|
|
|
|
|
// levels
|
|
// levels
|
|
private Level currentLevel = null;
|
|
private Level currentLevel = null;
|
|
@@ -43,6 +52,11 @@ public class Game extends Engine
|
|
private int levelIndex = 0;
|
|
private int levelIndex = 0;
|
|
private final StartScreenLevel startScreenLevel = new StartScreenLevel();
|
|
private final StartScreenLevel startScreenLevel = new StartScreenLevel();
|
|
|
|
|
|
|
|
+ // scripting
|
|
|
|
+ private final SnuviLogger snuviLogger = new SnuviLogger();
|
|
|
|
+ private final SnuviScheduler snuviScheduler = new SnuviScheduler();
|
|
|
|
+ private final SnuviParser snuviParser = new SnuviParser(snuviLogger, snuviScheduler);
|
|
|
|
+
|
|
// config and savegames
|
|
// config and savegames
|
|
private final SimpleConfig config = new SimpleConfig("options.txt", true);
|
|
private final SimpleConfig config = new SimpleConfig("options.txt", true);
|
|
private final SimpleConfig[] saveSlots = new SimpleConfig[]
|
|
private final SimpleConfig[] saveSlots = new SimpleConfig[]
|
|
@@ -61,30 +75,43 @@ public class Game extends Engine
|
|
|
|
|
|
// sound
|
|
// sound
|
|
private boolean sound = config.getBoolean("sound", false);
|
|
private boolean sound = config.getBoolean("sound", false);
|
|
|
|
+
|
|
|
|
+ // renderer
|
|
|
|
+ private final LevelRenderer levelRenderer = new LevelRenderer();
|
|
|
|
+ // this dummy will be removed later
|
|
|
|
+ private final Shader dummy = new Shader();
|
|
|
|
|
|
public Game()
|
|
public Game()
|
|
{
|
|
{
|
|
instance = this;
|
|
instance = this;
|
|
registerTiles();
|
|
registerTiles();
|
|
|
|
+ addSnuviCommands();
|
|
|
|
|
|
File[] files = new File("./levels").listFiles();
|
|
File[] files = new File("./levels").listFiles();
|
|
Arrays.sort(files, (o1, o2) -> o1.compareTo(o2));
|
|
Arrays.sort(files, (o1, o2) -> o1.compareTo(o2));
|
|
- ArrayList<Level> levelList = new ArrayList<>();
|
|
|
|
|
|
+ ArrayList<FileLevel> levelList = new ArrayList<>();
|
|
for(File file : files)
|
|
for(File file : files)
|
|
{
|
|
{
|
|
- if(file.isFile())
|
|
|
|
|
|
+ if(file.isFile() && file.getName().endsWith(".map"))
|
|
{
|
|
{
|
|
- Level l = new Level(file);
|
|
|
|
- levelList.add(l);
|
|
|
|
|
|
+ try
|
|
|
|
+ {
|
|
|
|
+ FileLevel l = new FileLevel(file);
|
|
|
|
+ levelList.add(l);
|
|
|
|
+ }
|
|
|
|
+ catch(IllegalArgumentException ex)
|
|
|
|
+ {
|
|
|
|
+ //System.out.println(ex.getMessage());
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- levels = levelList.toArray(new Level[levelList.size()]);
|
|
|
|
|
|
+ levels = levelList.toArray(new FileLevel[levelList.size()]);
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public void init()
|
|
public void init()
|
|
{
|
|
{
|
|
- setMaxFps(120);
|
|
|
|
|
|
+ setMaxFps(60);
|
|
setNanosPerTick(MS_PER_TICK * 1_000_000);
|
|
setNanosPerTick(MS_PER_TICK * 1_000_000);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -100,10 +127,15 @@ public class Game extends Engine
|
|
SoundUtils.playSound(SoundUtils.Sound.SONG_1);
|
|
SoundUtils.playSound(SoundUtils.Sound.SONG_1);
|
|
SoundUtils.stopSound(SoundUtils.Sound.MENU_MUSIC);
|
|
SoundUtils.stopSound(SoundUtils.Sound.MENU_MUSIC);
|
|
|
|
|
|
- currentLevel.tick();
|
|
|
|
|
|
+ snuviScheduler.setActiveLevel(currentLevel);
|
|
|
|
+ //if(Keys.TEST.isReleased())
|
|
|
|
+ {
|
|
|
|
+ currentLevel.tick();
|
|
|
|
+ }
|
|
|
|
+ snuviScheduler.tick(currentLevel);
|
|
|
|
|
|
// doing that here to prevent concurent modification
|
|
// doing that here to prevent concurent modification
|
|
- if(currentLevel.shouldFinish())
|
|
|
|
|
|
+ if(currentLevel.isFinished())
|
|
{
|
|
{
|
|
String base = "level." + currentLevel.getFileName();
|
|
String base = "level." + currentLevel.getFileName();
|
|
SimpleConfig sp = saveSlots[slotScreenIndex];
|
|
SimpleConfig sp = saveSlots[slotScreenIndex];
|
|
@@ -128,17 +160,14 @@ public class Game extends Engine
|
|
// final save
|
|
// final save
|
|
sp.save();
|
|
sp.save();
|
|
|
|
|
|
- currentLevel.resetLevel();
|
|
|
|
|
|
+ currentLevel.reset();
|
|
currentLevel = null;
|
|
currentLevel = null;
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
if(currentLevel.shouldReset())
|
|
if(currentLevel.shouldReset())
|
|
{
|
|
{
|
|
- if(currentLevel.resetLevel())
|
|
|
|
- {
|
|
|
|
- currentLevel = null;
|
|
|
|
- }
|
|
|
|
|
|
+ currentLevel.reset();
|
|
}
|
|
}
|
|
|
|
|
|
if(Keys.ESCAPE.isReleased())
|
|
if(Keys.ESCAPE.isReleased())
|
|
@@ -230,13 +259,13 @@ public class Game extends Engine
|
|
}
|
|
}
|
|
optionsDirty = true;
|
|
optionsDirty = true;
|
|
break;
|
|
break;
|
|
- case 15: // save options
|
|
|
|
|
|
+ case 9: // save options
|
|
Keys.write(config);
|
|
Keys.write(config);
|
|
config.set("sound", sound);
|
|
config.set("sound", sound);
|
|
config.save();
|
|
config.save();
|
|
optionsDirty = false;
|
|
optionsDirty = false;
|
|
break;
|
|
break;
|
|
- case 16: // go back
|
|
|
|
|
|
+ case 10: // go back
|
|
screen = 0;
|
|
screen = 0;
|
|
break;
|
|
break;
|
|
default: // rebind keys
|
|
default: // rebind keys
|
|
@@ -280,8 +309,8 @@ public class Game extends Engine
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- private final static int COLOR_BROWN = 0xFF13458B;
|
|
|
|
- private final static int COLOR_OVERLAY = 0x77000000;
|
|
|
|
|
|
+ private final static int COLOR_OVERLAY = 0x77808080;
|
|
|
|
+ private final static int COLOR_OVERLAY2 = 0x77202020;
|
|
|
|
|
|
private String getKeyName(KeyBinding key)
|
|
private String getKeyName(KeyBinding key)
|
|
{
|
|
{
|
|
@@ -297,10 +326,12 @@ public class Game extends Engine
|
|
{
|
|
{
|
|
if(currentLevel != null)
|
|
if(currentLevel != null)
|
|
{
|
|
{
|
|
- currentLevel.renderTick(lag);
|
|
|
|
|
|
+ levelRenderer.renderTick(dummy, lag, currentLevel);
|
|
|
|
+ //currentLevel.renderTick(lag);
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
- startScreenLevel.renderTick(lag);
|
|
|
|
|
|
+ levelRenderer.renderTick(dummy, lag, startScreenLevel);
|
|
|
|
+
|
|
Shader.translateTo(0.0f, 0.0f);
|
|
Shader.translateTo(0.0f, 0.0f);
|
|
Shader.updateMatrix();
|
|
Shader.updateMatrix();
|
|
switch(screen)
|
|
switch(screen)
|
|
@@ -329,7 +360,7 @@ public class Game extends Engine
|
|
Shader.setBlendingEnabled(true);
|
|
Shader.setBlendingEnabled(true);
|
|
cr.drawRectangle(left, top, right, bottom, COLOR_OVERLAY);
|
|
cr.drawRectangle(left, top, right, bottom, COLOR_OVERLAY);
|
|
float base = top + (3 + startScreenIndex) * line;
|
|
float base = top + (3 + startScreenIndex) * line;
|
|
- cr.drawRectangle(left, base, right, base + line, COLOR_OVERLAY);
|
|
|
|
|
|
+ cr.drawRectangle(left, base, right, base + line, COLOR_OVERLAY2);
|
|
Shader.setBlendingEnabled(false);
|
|
Shader.setBlendingEnabled(false);
|
|
|
|
|
|
Shader.setTextureEnabled(true);
|
|
Shader.setTextureEnabled(true);
|
|
@@ -365,7 +396,7 @@ public class Game extends Engine
|
|
Shader.setBlendingEnabled(true);
|
|
Shader.setBlendingEnabled(true);
|
|
cr.drawRectangle(left, top, right, bottom, COLOR_OVERLAY);
|
|
cr.drawRectangle(left, top, right, bottom, COLOR_OVERLAY);
|
|
float base = top + (3 + slotScreenIndex) * line;
|
|
float base = top + (3 + slotScreenIndex) * line;
|
|
- cr.drawRectangle(left, base, right, base + line, COLOR_OVERLAY);
|
|
|
|
|
|
+ cr.drawRectangle(left, base, right, base + line, COLOR_OVERLAY2);
|
|
Shader.setBlendingEnabled(false);
|
|
Shader.setBlendingEnabled(false);
|
|
|
|
|
|
Shader.setTextureEnabled(true);
|
|
Shader.setTextureEnabled(true);
|
|
@@ -390,8 +421,8 @@ public class Game extends Engine
|
|
|
|
|
|
float left = width * 0.2f;
|
|
float left = width * 0.2f;
|
|
float right = width * 0.8f;
|
|
float right = width * 0.8f;
|
|
- float top = (height - line * 21.0f) * 0.5f;
|
|
|
|
- float bottom = top + line * 21.0f;
|
|
|
|
|
|
+ float top = (height - line * 15.0f) * 0.5f;
|
|
|
|
+ float bottom = top + line * 15.0f;
|
|
|
|
|
|
Shader.setTextureEnabled(false);
|
|
Shader.setTextureEnabled(false);
|
|
Shader.setColorEnabled(true);
|
|
Shader.setColorEnabled(true);
|
|
@@ -402,7 +433,7 @@ public class Game extends Engine
|
|
Shader.setBlendingEnabled(true);
|
|
Shader.setBlendingEnabled(true);
|
|
cr.drawRectangle(left, top, right, bottom, COLOR_OVERLAY);
|
|
cr.drawRectangle(left, top, right, bottom, COLOR_OVERLAY);
|
|
float base = top + (3 + optionScreenIndex) * line;
|
|
float base = top + (3 + optionScreenIndex) * line;
|
|
- cr.drawRectangle(left, base, right, base + line, COLOR_OVERLAY);
|
|
|
|
|
|
+ cr.drawRectangle(left, base, right, base + line, COLOR_OVERLAY2);
|
|
Shader.setBlendingEnabled(false);
|
|
Shader.setBlendingEnabled(false);
|
|
|
|
|
|
Shader.setTextureEnabled(true);
|
|
Shader.setTextureEnabled(true);
|
|
@@ -429,18 +460,6 @@ public class Game extends Engine
|
|
y = fr.drawString(secLeft, y, getKeyName(Keys.ESCAPE));
|
|
y = fr.drawString(secLeft, y, getKeyName(Keys.ESCAPE));
|
|
fr.drawString(left, y, "K: Enter");
|
|
fr.drawString(left, y, "K: Enter");
|
|
y = fr.drawString(secLeft, y, getKeyName(Keys.ENTER));
|
|
y = fr.drawString(secLeft, y, getKeyName(Keys.ENTER));
|
|
- fr.drawString(left, y, "K: Combat");
|
|
|
|
- y = fr.drawString(secLeft, y, getKeyName(Keys.COMBAT));
|
|
|
|
- fr.drawString(left, y, "K: Switch Face");
|
|
|
|
- y = fr.drawString(secLeft, y, getKeyName(Keys.COMBAT_SWITCH_FACE));
|
|
|
|
- fr.drawString(left, y, "K: Dash/Dodge");
|
|
|
|
- y = fr.drawString(secLeft, y, getKeyName(Keys.COMBAT_DASH));
|
|
|
|
- fr.drawString(left, y, "K: Dash/Dodge");
|
|
|
|
- y = fr.drawString(secLeft, y, getKeyName(Keys.COMBAT_DODGE));
|
|
|
|
- fr.drawString(left, y, "K: Block");
|
|
|
|
- y = fr.drawString(secLeft, y, getKeyName(Keys.COMBAT_BLOCK));
|
|
|
|
- fr.drawString(left, y, "K: Attack");
|
|
|
|
- y = fr.drawString(secLeft, y, getKeyName(Keys.COMBAT_ATTACK));
|
|
|
|
if(optionsDirty)
|
|
if(optionsDirty)
|
|
{
|
|
{
|
|
y = fr.drawString(left, y, true, "&cSave");
|
|
y = fr.drawString(left, y, true, "&cSave");
|
|
@@ -507,7 +526,7 @@ public class Game extends Engine
|
|
baseIndex = half;
|
|
baseIndex = half;
|
|
}
|
|
}
|
|
float base = top + (3 + baseIndex) * line;
|
|
float base = top + (3 + baseIndex) * line;
|
|
- cr.drawRectangle(left, base, right, base + line, COLOR_OVERLAY);
|
|
|
|
|
|
+ cr.drawRectangle(left, base, right, base + line, COLOR_OVERLAY2);
|
|
Shader.setBlendingEnabled(false);
|
|
Shader.setBlendingEnabled(false);
|
|
|
|
|
|
Shader.setTextureEnabled(true);
|
|
Shader.setTextureEnabled(true);
|
|
@@ -528,15 +547,15 @@ public class Game extends Engine
|
|
{
|
|
{
|
|
Level l = levels[i];
|
|
Level l = levels[i];
|
|
fr.drawString(left, y, l.getName());
|
|
fr.drawString(left, y, l.getName());
|
|
- fr.drawString(secLeft, y, l.formatBottles(sc.getInt("level." + l.getFileName() + ".bottles", 0)));
|
|
|
|
- y = fr.drawString(thirdLeft, y, l.formatTime(sc.getFloat("level." + l.getFileName() + ".time", 0)));
|
|
|
|
|
|
+ fr.drawString(secLeft, y, LevelRenderer.formatBottles(sc.getInt("level." + l.getFileName() + ".bottles", 0), l.getMaxBottles()));
|
|
|
|
+ y = fr.drawString(thirdLeft, y, LevelRenderer.formatTime(sc.getFloat("level." + l.getFileName() + ".time", 0)));
|
|
}
|
|
}
|
|
if(lastIndex == levels.length)
|
|
if(lastIndex == levels.length)
|
|
{
|
|
{
|
|
Level l = levels[lastIndex - 1];
|
|
Level l = levels[lastIndex - 1];
|
|
fr.drawString(left, y, l.getName());
|
|
fr.drawString(left, y, l.getName());
|
|
- fr.drawString(secLeft, y, l.formatBottles(sc.getInt("level." + l.getFileName() + ".bottles", 0)));
|
|
|
|
- fr.drawString(thirdLeft, y, l.formatTime(sc.getFloat("level." + l.getFileName() + ".time", 0)));
|
|
|
|
|
|
+ fr.drawString(secLeft, y, LevelRenderer.formatBottles(sc.getInt("level." + l.getFileName() + ".bottles", 0), l.getMaxBottles()));
|
|
|
|
+ fr.drawString(thirdLeft, y, LevelRenderer.formatTime(sc.getFloat("level." + l.getFileName() + ".time", 0)));
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
@@ -600,12 +619,12 @@ public class Game extends Engine
|
|
registeredTiles[34] = new DecoShroomTile(0.0625f, 0.21875f, 0.125f, 0.25f);
|
|
registeredTiles[34] = new DecoShroomTile(0.0625f, 0.21875f, 0.125f, 0.25f);
|
|
registeredTiles[35] = new DecoShroomTile(0.0625f, 0.1875f, 0.125f, 0.21875f);
|
|
registeredTiles[35] = new DecoShroomTile(0.0625f, 0.1875f, 0.125f, 0.21875f);
|
|
// ramp
|
|
// ramp
|
|
- registeredTiles[36] = new Ramp(0.375f, 0.0f, 0.4375f, 0.0625f, 0.0f, Tile.SIZE, Tile.SIZE, 0.0f);
|
|
|
|
- registeredTiles[37] = new Ramp(0.4375f, 0.0f, 0.5f, 0.0625f, 0.0f, Tile.SIZE, Tile.SIZE, Tile.SIZE * 0.5f);
|
|
|
|
- registeredTiles[38] = new Ramp(0.5f, 0.0f, 0.5625f, 0.0625f, 0.0f, Tile.SIZE * 0.5f, Tile.SIZE, 0.0f);
|
|
|
|
- registeredTiles[39] = new Ramp(0.375f, 0.0625f, 0.4375f, 0.125f, Tile.SIZE, Tile.SIZE, 0.0f, 0.0f);
|
|
|
|
- registeredTiles[40] = new Ramp(0.4375f, 0.0625f, 0.5f, 0.125f, Tile.SIZE, Tile.SIZE, 0.0f, Tile.SIZE * 0.5f);
|
|
|
|
- registeredTiles[41] = new Ramp(0.5f, 0.0625f, 0.5625f, 0.125f, Tile.SIZE, Tile.SIZE * 0.5f, 0.0f, 0.0f);
|
|
|
|
|
|
+ registeredTiles[36] = new RampTile(0.375f, 0.0f, 0.4375f, 0.0625f, 0.0f, Tile.SIZE, Tile.SIZE, 0.0f);
|
|
|
|
+ registeredTiles[37] = new RampTile(0.4375f, 0.0f, 0.5f, 0.0625f, 0.0f, Tile.SIZE, Tile.SIZE, Tile.SIZE * 0.5f);
|
|
|
|
+ registeredTiles[38] = new RampTile(0.5f, 0.0f, 0.5625f, 0.0625f, 0.0f, Tile.SIZE * 0.5f, Tile.SIZE, 0.0f);
|
|
|
|
+ registeredTiles[39] = new RampTile(0.375f, 0.0625f, 0.4375f, 0.125f, Tile.SIZE, Tile.SIZE, 0.0f, 0.0f);
|
|
|
|
+ registeredTiles[40] = new RampTile(0.4375f, 0.0625f, 0.5f, 0.125f, Tile.SIZE, Tile.SIZE, 0.0f, Tile.SIZE * 0.5f);
|
|
|
|
+ registeredTiles[41] = new RampTile(0.5f, 0.0625f, 0.5625f, 0.125f, Tile.SIZE, Tile.SIZE * 0.5f, 0.0f, 0.0f);
|
|
|
|
|
|
// london stuff
|
|
// london stuff
|
|
// street
|
|
// street
|
|
@@ -622,6 +641,17 @@ public class Game extends Engine
|
|
registeredTiles[45 + 5 * y + x] = new BaseTile(0.0625f * x, 0.25f + 0.0625f * y, 0.0625f * (x + 1), 0.25f + 0.0625f * (y + 1));
|
|
registeredTiles[45 + 5 * y + x] = new BaseTile(0.0625f * x, 0.25f + 0.0625f * y, 0.0625f * (x + 1), 0.25f + 0.0625f * (y + 1));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ // !-Tile
|
|
|
|
+ registeredTiles[70] = new HeadHitTile(0.5625f, 0.0f, 0.625f, 0.0625f);
|
|
|
|
+ // ?-Tile
|
|
|
|
+ registeredTiles[71] = new HeadHitOnceTile(0.625f, 0.0f, 0.6875f, 0.0625f, 0.6875f, 0.0f, 0.75f, 0.0625f);
|
|
|
|
+ // button
|
|
|
|
+ registeredTiles[72] = new InteractTile(0.75f, 0.0f, 0.8125f, 0.0625f);
|
|
|
|
+ // wooden pressure plate
|
|
|
|
+ registeredTiles[73] = new PressureTile(0.568359375f, 0.072265625f, 0.619140625f, 0.078125f);
|
|
|
|
+ // stone pressure plate
|
|
|
|
+ registeredTiles[74] = new PressureTile(0.568359375f, 0.087890625f, 0.619140625f, 0.09375f);
|
|
}
|
|
}
|
|
|
|
|
|
public Tile getTile(int id)
|
|
public Tile getTile(int id)
|
|
@@ -633,7 +663,7 @@ public class Game extends Engine
|
|
return registeredTiles[id];
|
|
return registeredTiles[id];
|
|
}
|
|
}
|
|
|
|
|
|
- public void resetTiles(Level l)
|
|
|
|
|
|
+ public void resetTiles(FileLevel l)
|
|
{
|
|
{
|
|
for(Tile t : registeredTiles)
|
|
for(Tile t : registeredTiles)
|
|
{
|
|
{
|
|
@@ -688,4 +718,154 @@ public class Game extends Engine
|
|
{
|
|
{
|
|
SoundUtils.closeSounds();
|
|
SoundUtils.closeSounds();
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ public SnuviParser getParser()
|
|
|
|
+ {
|
|
|
|
+ return snuviParser;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public Level getCurrentLevel()
|
|
|
|
+ {
|
|
|
|
+ return currentLevel;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void setCurrentLevel(Level l)
|
|
|
|
+ {
|
|
|
|
+ snuviScheduler.setActiveLevel(l);
|
|
|
|
+ currentLevel = l;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void addSnuviCommands()
|
|
|
|
+ {
|
|
|
|
+ snuviParser.registerFunction("level.getname", (sc, in) -> currentLevel.getName());
|
|
|
|
+ snuviParser.registerFunction("level.getwidth", (sc, in) -> (double) currentLevel.getData().getWidth());
|
|
|
|
+ snuviParser.registerFunction("level.getheight", (sc, in) -> (double) currentLevel.getData().getHeight());
|
|
|
|
+ snuviParser.registerFunction("level.getlayers", (sc, in) -> (double) currentLevel.getData().getLayers());
|
|
|
|
+ snuviParser.registerFunction("level.getbackgroundindex", (sc, in) -> (double) currentLevel.getData().getBackgroundIndex());
|
|
|
|
+ snuviParser.registerFunction("level.gettile", (sc, in) -> currentLevel.getData().getTile(in[0].getInt(sc), in[1].getInt(sc), in[2].getInt(sc)));
|
|
|
|
+ snuviParser.registerFunction("level.settile", (sc, in) ->
|
|
|
|
+ {
|
|
|
|
+ int layer = in[0].getInt(sc);
|
|
|
|
+ int x = in[1].getInt(sc);
|
|
|
|
+ int y = in[2].getInt(sc);
|
|
|
|
+ int tile = in[3].getInt(sc);
|
|
|
|
+ currentLevel.getData().setTile(layer, x, y, tile);
|
|
|
|
+ currentLevel.getTileUpdater().add(layer, x, y);
|
|
|
|
+ Game.get().getTile(tile).reset(x, y, currentLevel);
|
|
|
|
+ return Void.TYPE;
|
|
|
|
+ });
|
|
|
|
+ snuviParser.registerFunction("level.addmessage", (sc, in) ->
|
|
|
|
+ {
|
|
|
|
+ currentLevel.addMessage(in[0].getString(sc));
|
|
|
|
+ return Void.TYPE;
|
|
|
|
+ });
|
|
|
|
+ snuviParser.registerFunction("level.finish", (sc, in) ->
|
|
|
|
+ {
|
|
|
|
+ currentLevel.finishLevel();
|
|
|
|
+ return Void.TYPE;
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ snuviParser.registerFunction("tile.totilecoord", (sc, in) -> (double) Utils.toBlock(in[0].getFloat(sc)));
|
|
|
|
+ snuviParser.registerFunction("tile.tolevelcoord", (sc, in) -> (double) Utils.toCoord(in[0].getInt(sc)));
|
|
|
|
+ snuviParser.registerFunction("tile.scale", (sc, in) -> in[0].getDouble(sc) * Tile.SIZE_SCALE);
|
|
|
|
+
|
|
|
|
+ snuviParser.registerFunction("entity.gethero", (sc, in) -> currentLevel.getHero());
|
|
|
|
+ snuviParser.registerFunction("entity.getx", (sc, in) -> (double) ((Entity) in[0].get(sc)).getX());
|
|
|
|
+ snuviParser.registerFunction("entity.gety", (sc, in) -> (double) ((Entity) in[0].get(sc)).getY());
|
|
|
|
+ snuviParser.registerFunction("entity.teleport", (sc, in) ->
|
|
|
|
+ {
|
|
|
|
+ Entity ent = (Entity) in[0].get(sc);
|
|
|
|
+ float x = in[1].getFloat(sc);
|
|
|
|
+ float y = in[2].getFloat(sc);
|
|
|
|
+ ent.setPosition(x, y);
|
|
|
|
+ ent.setPosition(x, y);
|
|
|
|
+ return Void.TYPE;
|
|
|
|
+ });
|
|
|
|
+ snuviParser.registerFunction("entity.getmotionx", (sc, in) -> (double) ((Entity) in[0].get(sc)).getOwnForceX());
|
|
|
|
+ snuviParser.registerFunction("entity.getmotiony", (sc, in) -> (double) ((Entity) in[0].get(sc)).getOwnForceY());
|
|
|
|
+ snuviParser.registerFunction("entity.setmotionx", (sc, in) ->
|
|
|
|
+ {
|
|
|
|
+ ((Entity) in[0].get(sc)).applyForce(in[1].getFloat(sc), 0.0f);
|
|
|
|
+ return Void.TYPE;
|
|
|
|
+ });
|
|
|
|
+ snuviParser.registerFunction("entity.setmotiony", (sc, in) ->
|
|
|
|
+ {
|
|
|
|
+ ((Entity) in[0].get(sc)).applyForce(0.0f, in[1].getFloat(sc));
|
|
|
|
+ return Void.TYPE;
|
|
|
|
+ });
|
|
|
|
+ snuviParser.registerFunction("entity.ishero", (sc, in) -> currentLevel.getHero() == in[0].get(sc));
|
|
|
|
+ snuviParser.registerFunction("entity.gethealth", (sc, in) -> ((Entity) in[0].get(sc)).getHealth().getHealthPercent());
|
|
|
|
+ snuviParser.registerFunction("entity.addhealth", (sc, in) ->
|
|
|
|
+ {
|
|
|
|
+ ((Entity) in[0].get(sc)).getHealth().addHealthPercent(in[1].getFloat(sc));
|
|
|
|
+ return Void.TYPE;
|
|
|
|
+ });
|
|
|
|
+ snuviParser.registerFunction("entity.getenergy", (sc, in) -> ((Entity) in[0].get(sc)).getEnergy().getEnergyPercent());
|
|
|
|
+ snuviParser.registerFunction("entity.addenergy", (sc, in) ->
|
|
|
|
+ {
|
|
|
|
+ ((Entity) in[0].get(sc)).getEnergy().addEnergyPercent(in[1].getFloat(sc));
|
|
|
|
+ return Void.TYPE;
|
|
|
|
+ });
|
|
|
|
+ snuviParser.registerFunction("entity.spawn", (sc, in) ->
|
|
|
|
+ {
|
|
|
|
+ Entity ent = EntityBuilder.fromId(in[0].getInt(sc), currentLevel, in[1].getFloat(sc), in[2].getFloat(sc));
|
|
|
|
+ if(ent != null)
|
|
|
|
+ {
|
|
|
|
+ currentLevel.spawnEntity(ent);
|
|
|
|
+ }
|
|
|
|
+ return ent;
|
|
|
|
+ });
|
|
|
|
+ snuviParser.registerFunction("entity.remove", (sc, in) ->
|
|
|
|
+ {
|
|
|
|
+ Entity ent = (Entity) in[0].get(sc);
|
|
|
|
+ // move entity out of world so it is removed
|
|
|
|
+ ent.setPosition(0.0f, Float.MAX_VALUE * 0.5f);
|
|
|
|
+ return Void.TYPE;
|
|
|
|
+ });
|
|
|
|
+ snuviParser.registerFunction("entity.gettype", (sc, in) -> ((Entity) in[0].get(sc)).getType());
|
|
|
|
+
|
|
|
|
+ snuviParser.registerFunction("platform.spawn", (sc, in) ->
|
|
|
|
+ {
|
|
|
|
+ Entity ent = EntityBuilder.buildPlatform(currentLevel, in[0].getInt(sc), in[1].getFloat(sc), in[2].getInt(sc));
|
|
|
|
+ currentLevel.spawnEntity(ent);
|
|
|
|
+ return ent;
|
|
|
|
+ });
|
|
|
|
+ snuviParser.registerFunction("platform.addmove", (sc, in) ->
|
|
|
|
+ {
|
|
|
|
+ PlatformController controller = (PlatformController) ((Entity) in[0].get(sc)).getController();
|
|
|
|
+ controller.addMoveData(in[1].getFloat(sc), in[2].getFloat(sc), in[3].getFloat(sc) * Tile.SIZE_SCALE, in[4].getFloat(sc) * Tile.SIZE_SCALE, in[5].getInt(sc));
|
|
|
|
+ return Void.TYPE;
|
|
|
|
+ });
|
|
|
|
+ snuviParser.registerFunction("platform.clear", (sc, in) ->
|
|
|
|
+ {
|
|
|
|
+ ((PlatformController) ((Entity) in[0].get(sc)).getController()).clearMoveData();
|
|
|
|
+ return Void.TYPE;
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ snuviParser.registerFunction("light.setambient", (sc, in) ->
|
|
|
|
+ {
|
|
|
|
+ currentLevel.setAmbientLight(in[0].getFloat(sc), in[1].getFloat(sc), in[2].getFloat(sc));
|
|
|
|
+ return Void.TYPE;
|
|
|
|
+ });
|
|
|
|
+ snuviParser.registerFunction("light.setcolor", (sc, in) ->
|
|
|
|
+ {
|
|
|
|
+ currentLevel.getLight(in[0].getInt(sc)).setColor(in[1].getFloat(sc), in[2].getFloat(sc), in[3].getFloat(sc));
|
|
|
|
+ return Void.TYPE;
|
|
|
|
+ });
|
|
|
|
+ snuviParser.registerFunction("light.setposition", (sc, in) ->
|
|
|
|
+ {
|
|
|
|
+ currentLevel.getLight(in[0].getInt(sc)).setPosition(in[1].getFloat(sc), in[2].getFloat(sc));
|
|
|
|
+ return Void.TYPE;
|
|
|
|
+ });
|
|
|
|
+ snuviParser.registerFunction("light.setpositionsmooth", (sc, in) ->
|
|
|
|
+ {
|
|
|
|
+ currentLevel.getLight(in[0].getInt(sc)).setPositionSmooth(in[1].getFloat(sc), in[2].getFloat(sc));
|
|
|
|
+ return Void.TYPE;
|
|
|
|
+ });
|
|
|
|
+ snuviParser.registerFunction("light.setstrength", (sc, in) ->
|
|
|
|
+ {
|
|
|
|
+ currentLevel.getLight(in[0].getInt(sc)).setStrength(in[1].getFloat(sc));
|
|
|
|
+ return Void.TYPE;
|
|
|
|
+ });
|
|
|
|
+ }
|
|
}
|
|
}
|