RPG tutorial menu & blue box movement
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
(defmethod new []
|
||||
(super)
|
||||
(addChild (new FlxGame 0 0 PlayState))
|
||||
(addChild (new FlxGame 0 0 MenuState))
|
||||
(return))
|
8
projects/flixel/rpg-tutorial/source/MenuState.hx
Normal file
8
projects/flixel/rpg-tutorial/source/MenuState.hx
Normal file
@@ -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 {}
|
10
projects/flixel/rpg-tutorial/source/MenuState.kiss
Normal file
10
projects/flixel/rpg-tutorial/source/MenuState.kiss
Normal file
@@ -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)))
|
@@ -1,4 +1,8 @@
|
||||
(defprop &mut :Player player null)
|
||||
|
||||
(defmethod &override create []
|
||||
(set player (new Player 20 20))
|
||||
(add player)
|
||||
(super.create)
|
||||
(return))
|
||||
|
||||
|
11
projects/flixel/rpg-tutorial/source/Player.hx
Normal file
11
projects/flixel/rpg-tutorial/source/Player.hx
Normal file
@@ -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 {}
|
42
projects/flixel/rpg-tutorial/source/Player.kiss
Normal file
42
projects/flixel/rpg-tutorial/source/Player.kiss
Normal file
@@ -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))
|
Reference in New Issue
Block a user