This commit is contained in:
3wc 2024-02-12 18:30:13 -03:00
parent ea32d0356d
commit 96c430c3c1
6 changed files with 89 additions and 71 deletions

View File

@ -1,6 +1,4 @@
class Const { class Const {
public static inline var W = 960; public static inline var W = 960;
public static inline var H = 640; public static inline var H = 640;
} }

View File

@ -1,13 +1,14 @@
class Dialogue extends h2d.Object { class Dialogue extends h2d.Object {
var game:Game; var game:Game;
var bg:h2d.ScaleGrid; var bg:h2d.ScaleGrid;
var tf:h2d.Text; var tf:h2d.Text;
var timer:haxe.Timer; var timer:haxe.Timer;
var int:h2d.Interactive; var int:h2d.Interactive;
public var width(default, set):Int; public var width(default, set):Int;
public var height(default, set):Int; public var height(default, set):Int;
public var text(default, set):String; public var text(default, set):String;
var textPos:Int = 0; var textPos:Int = 0;
var chan:hxd.snd.Channel; var chan:hxd.snd.Channel;
@ -16,7 +17,8 @@ class Dialogue extends h2d.Object {
super(); super();
// if( sfx != null ) // if( sfx != null )
// chan = sfx.play(true); // chan = sfx.play(true);
if( text == null ) text = "NULL"; if (text == null)
text = "NULL";
game = Game.inst; game = Game.inst;
game.scene.add(this, 1); game.scene.add(this, 1);
bg = new h2d.ScaleGrid(Res.ui.toTile(), 5, 5, this); bg = new h2d.ScaleGrid(Res.ui.toTile(), 5, 5, this);
@ -26,7 +28,12 @@ class Dialogue extends h2d.Object {
tf.scaleY = 2; tf.scaleY = 2;
tf.y = 5; tf.y = 5;
tf.x = 7; tf.x = 7;
tf.dropShadow = { dx : 0, dy : 1, color : 0, alpha : 0.3 }; tf.dropShadow = {
dx: 0,
dy: 1,
color: 0,
alpha: 0.3
};
int = new h2d.Interactive(0, 0, this); int = new h2d.Interactive(0, 0, this);
int.onClick = function(_) click(); int.onClick = function(_) click();
this.width = width; this.width = width;
@ -45,13 +52,19 @@ class Dialogue extends h2d.Object {
if (textPos == text.length) { if (textPos == text.length) {
timer.stop(); timer.stop();
onReady(); onReady();
if( chan != null ) chan.stop(); if (chan != null)
chan.stop();
return; return;
} }
if (chan != null) { if (chan != null) {
switch (text.charCodeAt(textPos)) { switch (text.charCodeAt(textPos)) {
case " ".code, "\n".code: chan.volume = 0; case " ".code, "\n".code:
default: if( chan.volume == 0 ) chan.volume = 1 else chan.volume *= 0.9; chan.volume = 0;
default:
if (chan.volume == 0)
chan.volume = 1
else
chan.volume *= 0.9;
} }
} }
textPos++; textPos++;
@ -59,14 +72,18 @@ class Dialogue extends h2d.Object {
} }
public function click() { public function click() {
if( textPos == text.length ) onClick() else if( textPos < text.length ) { textPos = text.length; tf.text = text; updateText(); }; if (textPos == text.length)
onClick()
else if (textPos < text.length) {
textPos = text.length;
tf.text = text;
updateText();
};
} }
public dynamic function onClick() { public dynamic function onClick() {}
}
public dynamic function onReady() { public dynamic function onReady() {}
}
function set_text(t) { function set_text(t) {
text = t; text = t;
@ -90,5 +107,4 @@ class Dialogue extends h2d.Object {
int.height = h; int.height = h;
return height = h; return height = h;
} }
} }

View File

@ -14,12 +14,7 @@ class Game extends hxd.App {
s2d.add(world.root, 0); s2d.add(world.root, 0);
font = Res.minecraftia_regular_6.toFont(); font = Res.minecraftia_regular_6.toFont();
dialog([ dialog(["(you slowly wake up)", "...", "where am I?", "(the cold vastness of spaaaaace)"]);
"(you slowly wake up)",
"...",
"where am I?",
"(the cold vastness of spaaaaace)"
]);
} }
public static var inst:Game; public static var inst:Game;
@ -39,5 +34,4 @@ class Game extends hxd.App {
}; };
curDialog = d; curDialog = d;
} }
} }

View File

@ -1,10 +1,17 @@
class World { class World {
var game:Game; var game:Game;
var map:hxd.res.TiledMap.TiledMapData; var map:hxd.res.TiledMap.TiledMapData;
public var root:h2d.Object; public var root:h2d.Object;
var layers : Map < String, { name : String, data : Array<Int>, g : h2d.TileGroup, alpha : Float } > ;
var layers:Map<String, {
name:String,
data:Array<Int>,
g:h2d.TileGroup,
alpha:Float
}>;
var tiles:Array<h2d.Tile>; var tiles:Array<h2d.Tile>;
public var width:Int; public var width:Int;
public var height:Int; public var height:Int;
@ -18,9 +25,12 @@ class World {
var t = tiles.toTile(); var t = tiles.toTile();
layers = new Map(); layers = new Map();
var font:h2d.Font = hxd.res.DefaultFont.get(); var font:h2d.Font = hxd.res.DefaultFont.get();
this.tiles = [for( y in 0...Std.int(t.height) >> 5 ) for( x in 0...Std.int(t.width) >> 5 ) t.sub(x * 32, y * 32, 32, 32)]; this.tiles = [
for (y in 0...Std.int(t.height) >> 5) for (x in 0...Std.int(t.width) >> 5) t.sub(x * 32, y * 32, 32, 32)
];
for (ld in map.layers) { for (ld in map.layers) {
if( ld.name == "hotspots") continue; if (ld.name == "hotspots")
continue;
var l = { var l = {
name: ld.name, name: ld.name,
data: ld.data, data: ld.data,
@ -36,7 +46,8 @@ class World {
function rebuildLayer(name:String) { function rebuildLayer(name:String) {
var l = layers.get(name); var l = layers.get(name);
if( l == null ) return; if (l == null)
return;
var pos = 0; var pos = 0;
var g = l.g; var g = l.g;
g.clear(); g.clear();
@ -46,9 +57,9 @@ class World {
for (y in 0...height) for (y in 0...height)
for (x in 0...width) { for (x in 0...width) {
var t = l.data[pos++] - 1; var t = l.data[pos++] - 1;
if( t < 0 ) continue; if (t < 0)
continue;
g.add(x * 32, y * 32, tiles[t]); g.add(x * 32, y * 32, tiles[t]);
} }
} }
} }

View File

@ -37,4 +37,3 @@ class MenubuttonComponent extends h2d.Flow implements h2d.domkit.Object {
public dynamic function onClick() {} public dynamic function onClick() {}
} }