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,22 +1,24 @@
class Dialogue extends h2d.Object { class Dialogue extends h2d.Object {
var game:Game;
var bg:h2d.ScaleGrid;
var tf:h2d.Text;
var timer:haxe.Timer;
var int:h2d.Interactive;
var game : Game; public var width(default, set):Int;
var bg : h2d.ScaleGrid; public var height(default, set):Int;
var tf : h2d.Text; public var text(default, set):String;
var timer : haxe.Timer;
var int : h2d.Interactive; var textPos:Int = 0;
public var width(default, set) : Int; var chan:hxd.snd.Channel;
public var height(default, set) : Int;
public var text(default, set) : String;
var textPos : Int = 0;
var chan : hxd.snd.Channel;
// public function new(width:Int, height:Int, text : String,sfx:hxd.res.Sound) { // public function new(width:Int, height:Int, text : String,sfx:hxd.res.Sound) {
public function new(width:Int, height:Int, text : String) { public function new(width:Int, height:Int, text:String) {
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,8 +28,13 @@ 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 = {
int = new h2d.Interactive(0,0,this); dx: 0,
dy: 1,
color: 0,
alpha: 0.3
};
int = new h2d.Interactive(0, 0, this);
int.onClick = function(_) click(); int.onClick = function(_) click();
this.width = width; this.width = width;
this.height = height; this.height = height;
@ -36,22 +43,28 @@ class Dialogue extends h2d.Object {
override function onRemove() { override function onRemove() {
super.onRemove(); super.onRemove();
if( chan != null ) if (chan != null)
chan.stop(); chan.stop();
timer.stop(); timer.stop();
} }
function updateText() { function updateText() {
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

@ -2,11 +2,11 @@ import Const;
@:publicFields @:publicFields
class Game extends hxd.App { class Game extends hxd.App {
public var scene : h2d.Scene; public var scene:h2d.Scene;
public var font : h2d.Font; public var font:h2d.Font;
public var world : World; public var world:World;
public var curDialog : h2d.Object; public var curDialog:h2d.Object;
override function init() { override function init() {
scene = s2d; scene = s2d;
s2d.setFixedSize(Const.W, Const.H + 12); s2d.setFixedSize(Const.W, Const.H + 12);
@ -14,18 +14,13 @@ 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;
function dialog( t : Array<String> ) { function dialog(t:Array<String>) {
if( t.length == 0 ) { if (t.length == 0) {
return; return;
} }
var d = new Dialogue(Const.W, 100, t[0]); var d = new Dialogue(Const.W, 100, t[0]);
@ -39,5 +34,4 @@ class Game extends hxd.App {
}; };
curDialog = d; curDialog = d;
} }
} }

View File

@ -1,5 +1,5 @@
class Init { class Init {
public static function setup() { public static function setup() {
domkit.Macros.registerComponentsPath("components.$Component"); domkit.Macros.registerComponentsPath("components.$Component");
} }
} }

View File

@ -1,14 +1,21 @@
class World { class World {
var game:Game;
var map:hxd.res.TiledMap.TiledMapData;
var game : Game; public var root:h2d.Object;
var map : hxd.res.TiledMap.TiledMapData;
public var root : h2d.Object;
var layers : Map < String, { name : String, data : Array<Int>, g : h2d.TileGroup, alpha : Float } > ;
var tiles : Array<h2d.Tile>;
public var width : Int;
public var height : Int;
public function new( r : hxd.res.TiledMap, tiles : hxd.res.Image ) { var layers:Map<String, {
name:String,
data:Array<Int>,
g:h2d.TileGroup,
alpha:Float
}>;
var tiles:Array<h2d.Tile>;
public var width:Int;
public var height:Int;
public function new(r:hxd.res.TiledMap, tiles:hxd.res.Image) {
game = Game.inst; game = Game.inst;
root = new h2d.Object(); root = new h2d.Object();
map = r.toMap(); map = r.toMap();
@ -17,15 +24,18 @@ class World {
height = map.height; height = map.height;
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( ld in map.layers ) { 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)
if( ld.name == "hotspots") continue; ];
for (ld in map.layers) {
if (ld.name == "hotspots")
continue;
var l = { var l = {
name : ld.name, name: ld.name,
data : ld.data, data: ld.data,
g : new h2d.TileGroup(t, root), g: new h2d.TileGroup(t, root),
alpha : ld.opacity, alpha: ld.opacity,
} }
// l.g.colorKey = 0x1D8700; // l.g.colorKey = 0x1D8700;
l.g.alpha = ld.opacity; l.g.alpha = ld.opacity;
@ -34,21 +44,22 @@ 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();
while( g.numChildren > 0 ) while (g.numChildren > 0)
g.getChildAt(0).remove(); g.getChildAt(0).remove();
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() {}
} }