diff --git a/projects/flixel/rpg-tutorial/source/Main.kiss b/projects/flixel/rpg-tutorial/source/Main.kiss index 916514bc..4ab64ad0 100644 --- a/projects/flixel/rpg-tutorial/source/Main.kiss +++ b/projects/flixel/rpg-tutorial/source/Main.kiss @@ -1,4 +1,4 @@ (defmethod new [] (super) - (addChild (new FlxGame 0 0 PlayState)) + (addChild (new FlxGame 0 0 MenuState)) (return)) \ No newline at end of file diff --git a/projects/flixel/rpg-tutorial/source/MenuState.hx b/projects/flixel/rpg-tutorial/source/MenuState.hx new file mode 100644 index 00000000..24e9bae6 --- /dev/null +++ b/projects/flixel/rpg-tutorial/source/MenuState.hx @@ -0,0 +1,8 @@ +package; + +import flixel.FlxState; +import flixel.ui.FlxButton; +import flixel.FlxG; + +@:build(kiss.Kiss.build("source/MenuState.kiss")) +class MenuState extends FlxState {} diff --git a/projects/flixel/rpg-tutorial/source/MenuState.kiss b/projects/flixel/rpg-tutorial/source/MenuState.kiss new file mode 100644 index 00000000..cebfb2c4 --- /dev/null +++ b/projects/flixel/rpg-tutorial/source/MenuState.kiss @@ -0,0 +1,10 @@ +(defprop &mut :FlxButton playButton null) + +(defmethod &override create [] + (set playButton (new FlxButton 0 0 "Play" clickPlay)) + (playButton.screenCenter) + (add playButton) + (return)) + +(defun clickPlay [] + (FlxG.switchState (new PlayState))) \ No newline at end of file diff --git a/projects/flixel/rpg-tutorial/source/PlayState.kiss b/projects/flixel/rpg-tutorial/source/PlayState.kiss index ba027f5f..3baab729 100644 --- a/projects/flixel/rpg-tutorial/source/PlayState.kiss +++ b/projects/flixel/rpg-tutorial/source/PlayState.kiss @@ -1,4 +1,8 @@ +(defprop &mut :Player player null) + (defmethod &override create [] + (set player (new Player 20 20)) + (add player) (super.create) (return)) diff --git a/projects/flixel/rpg-tutorial/source/Player.hx b/projects/flixel/rpg-tutorial/source/Player.hx new file mode 100644 index 00000000..6883d330 --- /dev/null +++ b/projects/flixel/rpg-tutorial/source/Player.hx @@ -0,0 +1,11 @@ +package; + +import flixel.FlxG; +import flixel.FlxSprite; +import flixel.util.FlxColor; +import flixel.input.keyboard.FlxKey; +import flixel.math.FlxPoint; +import kiss.Prelude; + +@:build(kiss.Kiss.build("source/Player.kiss")) +class Player extends FlxSprite {} \ No newline at end of file diff --git a/projects/flixel/rpg-tutorial/source/Player.kiss b/projects/flixel/rpg-tutorial/source/Player.kiss new file mode 100644 index 00000000..5ed17f40 --- /dev/null +++ b/projects/flixel/rpg-tutorial/source/Player.kiss @@ -0,0 +1,42 @@ +(defvar &inline :Float SPEED 200) + +(defmethod new [:Float x :Float y] + (super x y) + (makeGraphic 16 16 FlxColor.BLUE) + (set drag.x (set drag.y 1600)) + (return)) + +(defmethod updateMovement [] + (let [[&mut up &mut down &mut left &mut right] + (map [[UP W] [DOWN S] [LEFT A] [RIGHT D]] FlxG.keys.anyPressed)] + (when (and up down) + (set up (set down false))) + (when (and left right) + (set left (set right false))) + (when (or up down left right) + (deflocal &mut :Float newAngle 0) + (cond + (up + (set newAngle -90) + (cond + (left + (set newAngle (- newAngle 45))) + (right + (set newAngle (+ newAngle 45))))) + (down + (set newAngle 90) + (cond + (left + (set newAngle (+ newAngle 45))) + (right + (set newAngle (- newAngle 45))))) + (left + (set newAngle 180)) + (right + (set newAngle 0))) + (velocity.set SPEED 0) + (velocity.rotate (FlxPoint.weak 0 0) newAngle)))) + +(defmethod &override update [:Float elapsed] + (updateMovement) + (super.update elapsed)) \ No newline at end of file