This commit is contained in:
3wc 2024-02-16 03:52:16 -03:00
parent fd6b9ee8dd
commit 8be7c18d4f
6 changed files with 348 additions and 329 deletions

View File

@ -1,23 +1,19 @@
import h2d.Layers;
import h2d.Console;
import h3d.Vector4;
import scene.TitleScene;
import scene.WorldMapScene;
import scene.GameScene;
import event.EventBus;
import event.ChangeSceneEvent;
import Const;
import dialogue.DialogueBox;
import dialogue.DialogueManager;
import dialogue.event.LineShown;
import dialogue.event.OptionsShown;
import dialogue.event.OptionSelected;
import dialogue.event.DialogueComplete;
import dialogue.event.NextLine;
import dialogue.command.OpenRoomCommand;
@:uiComp("game-container")
@ -41,11 +37,14 @@ class Game extends hxd.App {
public var dialogueManager:DialogueManager;
public var globalEventBus:EventBus;
public static var current:Game; // Current Game (singleton)
var layer:Layers;
public var root:GameContainer;
public var console:Console;
var style = null;
public static var loader = new tiled.Tiled();
@ -86,14 +85,8 @@ class Game extends hxd.App {
dialogueManager = new DialogueManager(globalEventBus);
var yarnText = [
hxd.Res.text.intro.entry.getText(),
hxd.Res.text.rooms.entry.getText(),
];
var yarnFileNames = [
hxd.Res.text.intro.entry.name,
hxd.Res.text.rooms.entry.name,
];
var yarnText = [hxd.Res.text.intro.entry.getText(), hxd.Res.text.rooms.entry.getText(),];
var yarnFileNames = [hxd.Res.text.intro.entry.name, hxd.Res.text.rooms.entry.name,];
dialogueManager.load(yarnText, yarnFileNames);
globalEventBus.subscribe(LineShown, dialogue);
@ -155,7 +148,7 @@ class Game extends hxd.App {
return g;
}
function addOption(o: String, enabled : Bool, callback: () -> Void) {
function addOption(o:String, enabled:Bool, callback:() -> Void) {
var spr = newPanel(Const.W, 60);
curDialogue.addChild(spr);
var tf = new h2d.Text(font, spr);

View File

@ -1,17 +1,16 @@
import h2d.col.Point;
import h2d.Object;
import h2d.SpriteBatch;
import tiled.types.TmxLayer;
import tiled.types.TmxMap;
using tiled.TiledTools;
class TilemapLayer extends h2d.TileGroup {
public var map:TmxMap;
public var layer:TmxLayer;
public function new (map:TmxMap, layer:TmxLayer, ?parent:Object) {
public function new(map:TmxMap, layer:TmxLayer, ?parent:Object) {
this.map = map;
this.layer = layer;
super(parent);
@ -41,12 +40,19 @@ class TilemapLayer extends h2d.TileGroup {
var t = tsets.getImage(gid);
var x = cx + ix * tw;
var y = cy + iy * th + th - t.height;
if (gid.flippedHorizontally) addTransform(x + t.width, y, -1, 1, 0, t);
else if (gid.flippedVertically) addTransform(x, y + t.height, 1, -1, 0, t);
else if (gid.flippedDiagonally) addTransform(x + t.width, y + t.height, -1, -1, 0, t);
else add(x, y, t);
if (gid.flippedHorizontally)
addTransform(x + t.width, y, -1, 1, 0, t);
else if (gid.flippedVertically)
addTransform(x, y + t.height, 1, -1, 0, t);
else if (gid.flippedDiagonally)
addTransform(x + t.width, y + t.height, -1, -1, 0, t);
else
add(x, y, t);
}
if (++ix == chunk.width) {
iy++;
ix = 0;
}
if (++ix == chunk.width) { iy++; ix = 0; }
}
case Isometric:
var isoW = tw >> 1;
@ -60,15 +66,25 @@ class TilemapLayer extends h2d.TileGroup {
var t = tsets.getImage(gid);
var x = cx + (ix - iy) * isoW;
var y = cy + (ix + iy) * isoH + th - t.height;
if (gid.flippedHorizontally) addTransform(x + t.width, y, -1, 1, 0, t);
else if (gid.flippedVertically) addTransform(x, y + t.height, 1, -1, 0, t);
else if (gid.flippedDiagonally) addTransform(x + t.width, y + t.height, -1, -1, 0, t);
else add(x, y, t);
if (gid.flippedHorizontally)
addTransform(x + t.width, y, -1, 1, 0, t);
else if (gid.flippedVertically)
addTransform(x, y + t.height, 1, -1, 0, t);
else if (gid.flippedDiagonally)
addTransform(x + t.width, y + t.height, -1, -1, 0, t);
else
add(x, y, t);
}
if (++ix == chunk.width) {
iy++;
ix = 0;
}
if (++ix == chunk.width) { iy++; ix = 0; }
}
case Staggered(staggerYAxis, staggerIndexOdd):
var staggerX = 0, staggerY = 0, stepX = tw >> 1, stepY = th >> 1;
var staggerX = 0,
staggerY = 0,
stepX = tw >> 1,
stepY = th >> 1;
var cx = chunk.x * stepX + layer.offsetX;
var cy = chunk.y * stepY + layer.offsetY;
if (staggerYAxis) {
@ -94,12 +110,19 @@ class TilemapLayer extends h2d.TileGroup {
var t = tsets.getImage(gid);
var x = cx + ix * stepX + staggerX * (ix % 1);
var y = cy + iy * stepY + th - t.height;
if (gid.flippedHorizontally) addTransform(x + t.width, y, -1, 1, 0, t);
else if (gid.flippedVertically) addTransform(x, y + t.height, 1, -1, 0, t);
else if (gid.flippedDiagonally) addTransform(x + t.width, y + t.height, -1, -1, 0, t);
else add(x, y, t);
if (gid.flippedHorizontally)
addTransform(x + t.width, y, -1, 1, 0, t);
else if (gid.flippedVertically)
addTransform(x, y + t.height, 1, -1, 0, t);
else if (gid.flippedDiagonally)
addTransform(x + t.width, y + t.height, -1, -1, 0, t);
else
add(x, y, t);
}
if (++ix == chunk.width) {
iy++;
ix = 0;
}
if (++ix == chunk.width) { iy++; ix = 0; }
}
case Hexagonal(sideLength, staggerYAxis, staggerIndexOdd):
// TODO: Fix
@ -134,19 +157,26 @@ class TilemapLayer extends h2d.TileGroup {
var t = tsets.getImage(gid);
var x = cx + ix * stepX;
var y = cy + iy * stepY + th - t.height;
if (gid.flippedHorizontally) addTransform(x + t.width, y, -1, 1, 0, t);
else if (gid.flippedVertically) addTransform(x, y + t.height, 1, -1, 0, t);
else if (gid.flippedDiagonally) addTransform(x + t.width, y + t.height, -1, -1, 0, t);
else add(x, y, t);
if (gid.flippedHorizontally)
addTransform(x + t.width, y, -1, 1, 0, t);
else if (gid.flippedVertically)
addTransform(x, y + t.height, 1, -1, 0, t);
else if (gid.flippedDiagonally)
addTransform(x + t.width, y + t.height, -1, -1, 0, t);
else
add(x, y, t);
}
if (++ix == chunk.width) {
iy++;
ix = 0;
}
if (++ix == chunk.width) { iy++; ix = 0; }
}
}
}
public function addTile(tx:Int, ty:Int, ox:Float, oy:Float, gid:TmxTileIndex) {
if (gid == 0) return;
if (gid == 0)
return;
var t = map.tilesets.getImage(gid);
if (t != null) {
var x, y;
@ -186,12 +216,14 @@ class TilemapLayer extends h2d.TileGroup {
y = ty * map.tileHeight + ((tx + 1) % 2) * (map.tileHeight >> 1);
}
}
if (gid.flippedHorizontally) addTransform(x + t.width, y, -1, 1, 0, t);
else if (gid.flippedVertically) addTransform(x, y + t.height, 1, -1, 0, t);
else if (gid.flippedDiagonally) addTransform(x + t.width, y + t.height, -1, -1, 0, t);
else add(x, y, t);
if (gid.flippedHorizontally)
addTransform(x + t.width, y, -1, 1, 0, t);
else if (gid.flippedVertically)
addTransform(x, y + t.height, 1, -1, 0, t);
else if (gid.flippedDiagonally)
addTransform(x + t.width, y + t.height, -1, -1, 0, t);
else
add(x, y, t);
}
}
}

View File

@ -10,7 +10,6 @@ import hxyarn.dialogue.OptionSet;
import hxyarn.dialogue.markup.MarkupParseResult;
import hxyarn.compiler.Compiler;
import hxyarn.compiler.CompilationJob;
import event.EventBus;
import dialogue.command.ICommandHandler;
import dialogue.event.LineShown;
@ -72,11 +71,9 @@ class DialogueManager {
dialogue.resume();
}
public function logDebugMessage(message:String):Void {
}
public function logDebugMessage(message:String):Void {}
public function logErrorMessage(message:String):Void {
}
public function logErrorMessage(message:String):Void {}
public function nextLine(event:NextLine) {
if ((dialogue.isActive()) && (!waitingForOption))

View File

@ -1,9 +1,7 @@
package scene;
import scene.WorldMapScene;
import event.ChangeSceneEvent;
import components.MenubuttonComponent;
@:uiComp("heading")
@ -46,7 +44,6 @@ class TitleScene extends h2d.Flow implements GameScene implements h2d.domkit.Obj
#else
btnQuit.remove();
#end
}
public function getH2dObject() {

View File

@ -15,7 +15,7 @@ class WorldMapScene extends h2d.Flow implements GameScene implements h2d.domkit.
public var width:Int;
public var height:Int;
var rooms:Map<String,Room> = new Map<String,Room>();
var rooms:Map<String, Room> = new Map<String, Room>();
public function new(?parent) {
super(parent);
@ -28,7 +28,7 @@ class WorldMapScene extends h2d.Flow implements GameScene implements h2d.domkit.
Game.current.globalEventBus.subscribe(OpenRoomEvent, openRoom);
for (layer in (map.layers)) {
switch(layer.kind) {
switch (layer.kind) {
case TTileLayer:
var l = new TilemapLayer(map, layer, root);
case TObjectGroup: