diff --git a/src/Const.hx b/src/Const.hx index 4816efe..0632189 100644 --- a/src/Const.hx +++ b/src/Const.hx @@ -1,6 +1,4 @@ class Const { - public static inline var W = 960; public static inline var H = 640; - } diff --git a/src/Dialogue.hx b/src/Dialogue.hx index 1e00a52..4d43fef 100644 --- a/src/Dialogue.hx +++ b/src/Dialogue.hx @@ -1,22 +1,24 @@ 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; - var bg : h2d.ScaleGrid; - var tf : h2d.Text; - var timer : haxe.Timer; - var int : h2d.Interactive; - public var width(default, set) : Int; - public var height(default, set) : Int; - public var text(default, set) : String; - var textPos : Int = 0; - var chan : hxd.snd.Channel; + public var width(default, set):Int; + 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) { + public function new(width:Int, height:Int, text:String) { super(); // if( sfx != null ) // chan = sfx.play(true); - if( text == null ) text = "NULL"; + if (text == null) + text = "NULL"; game = Game.inst; game.scene.add(this, 1); bg = new h2d.ScaleGrid(Res.ui.toTile(), 5, 5, this); @@ -26,8 +28,13 @@ class Dialogue extends h2d.Object { tf.scaleY = 2; tf.y = 5; tf.x = 7; - tf.dropShadow = { dx : 0, dy : 1, color : 0, alpha : 0.3 }; - int = new h2d.Interactive(0,0,this); + tf.dropShadow = { + dx: 0, + dy: 1, + color: 0, + alpha: 0.3 + }; + int = new h2d.Interactive(0, 0, this); int.onClick = function(_) click(); this.width = width; this.height = height; @@ -36,22 +43,28 @@ class Dialogue extends h2d.Object { override function onRemove() { super.onRemove(); - if( chan != null ) + if (chan != null) chan.stop(); timer.stop(); } function updateText() { - if( textPos == text.length ) { + if (textPos == text.length) { timer.stop(); onReady(); - if( chan != null ) chan.stop(); + if (chan != null) + chan.stop(); return; } - if( chan != null ) { - switch( text.charCodeAt(textPos) ) { - case " ".code, "\n".code: chan.volume = 0; - default: if( chan.volume == 0 ) chan.volume = 1 else chan.volume *= 0.9; + if (chan != null) { + switch (text.charCodeAt(textPos)) { + case " ".code, "\n".code: + chan.volume = 0; + default: + if (chan.volume == 0) + chan.volume = 1 + else + chan.volume *= 0.9; } } textPos++; @@ -59,14 +72,18 @@ class Dialogue extends h2d.Object { } 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) { text = t; @@ -90,5 +107,4 @@ class Dialogue extends h2d.Object { int.height = h; return height = h; } - } diff --git a/src/Game.hx b/src/Game.hx index 0d81143..c530f91 100644 --- a/src/Game.hx +++ b/src/Game.hx @@ -2,11 +2,11 @@ import Const; @:publicFields class Game extends hxd.App { - public var scene : h2d.Scene; - public var font : h2d.Font; - public var world : World; - public var curDialog : h2d.Object; - + public var scene:h2d.Scene; + public var font:h2d.Font; + public var world:World; + public var curDialog:h2d.Object; + override function init() { scene = s2d; s2d.setFixedSize(Const.W, Const.H + 12); @@ -14,18 +14,13 @@ class Game extends hxd.App { s2d.add(world.root, 0); font = Res.minecraftia_regular_6.toFont(); - dialog([ - "(you slowly wake up)", - "...", - "where am I?", - "(the cold vastness of spaaaaace)" - ]); + dialog(["(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 ) { - if( t.length == 0 ) { + function dialog(t:Array) { + if (t.length == 0) { return; } var d = new Dialogue(Const.W, 100, t[0]); @@ -39,5 +34,4 @@ class Game extends hxd.App { }; curDialog = d; } - } diff --git a/src/Init.hx b/src/Init.hx index a2c6dee..02b37cf 100644 --- a/src/Init.hx +++ b/src/Init.hx @@ -1,5 +1,5 @@ class Init { - public static function setup() { - domkit.Macros.registerComponentsPath("components.$Component"); - } + public static function setup() { + domkit.Macros.registerComponentsPath("components.$Component"); + } } diff --git a/src/World.hx b/src/World.hx index 28ebe12..08c26ca 100644 --- a/src/World.hx +++ b/src/World.hx @@ -1,14 +1,21 @@ class World { + var game:Game; + var map:hxd.res.TiledMap.TiledMapData; - var game : Game; - var map : hxd.res.TiledMap.TiledMapData; - public var root : h2d.Object; - var layers : Map < String, { name : String, data : Array, g : h2d.TileGroup, alpha : Float } > ; - var tiles : Array; - public var width : Int; - public var height : Int; + public var root:h2d.Object; - public function new( r : hxd.res.TiledMap, tiles : hxd.res.Image ) { + var layers:Map, + g:h2d.TileGroup, + alpha:Float + }>; + var tiles:Array; + + public var width:Int; + public var height:Int; + + public function new(r:hxd.res.TiledMap, tiles:hxd.res.Image) { game = Game.inst; root = new h2d.Object(); map = r.toMap(); @@ -17,15 +24,18 @@ class World { height = map.height; var t = tiles.toTile(); layers = new Map(); - 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)]; - for( ld in map.layers ) { - if( ld.name == "hotspots") continue; + 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) + ]; + for (ld in map.layers) { + if (ld.name == "hotspots") + continue; var l = { - name : ld.name, - data : ld.data, - g : new h2d.TileGroup(t, root), - alpha : ld.opacity, + name: ld.name, + data: ld.data, + g: new h2d.TileGroup(t, root), + alpha: ld.opacity, } // l.g.colorKey = 0x1D8700; l.g.alpha = ld.opacity; @@ -34,21 +44,22 @@ class World { } } - function rebuildLayer( name : String ) { + function rebuildLayer(name:String) { var l = layers.get(name); - if( l == null ) return; + if (l == null) + return; var pos = 0; var g = l.g; g.clear(); - while( g.numChildren > 0 ) + while (g.numChildren > 0) g.getChildAt(0).remove(); - for( y in 0...height ) - for( x in 0...width ) { + for (y in 0...height) + for (x in 0...width) { var t = l.data[pos++] - 1; - if( t < 0 ) continue; + if (t < 0) + continue; g.add(x * 32, y * 32, tiles[t]); } } - } diff --git a/src/components/MenubuttonComponent.hx b/src/components/MenubuttonComponent.hx index 5224e80..977483c 100644 --- a/src/components/MenubuttonComponent.hx +++ b/src/components/MenubuttonComponent.hx @@ -37,4 +37,3 @@ class MenubuttonComponent extends h2d.Flow implements h2d.domkit.Object { public dynamic function onClick() {} } -