Refactor travis testing
This commit is contained in:
4
projects/flixel-rpg-tutorial/source/AssetPaths.hx
Normal file
4
projects/flixel-rpg-tutorial/source/AssetPaths.hx
Normal file
@@ -0,0 +1,4 @@
|
||||
package;
|
||||
|
||||
@:build(flixel.system.FlxAssets.buildFileReferences("assets", true))
|
||||
class AssetPaths {}
|
||||
4
projects/flixel-rpg-tutorial/source/Coin.hx
Normal file
4
projects/flixel-rpg-tutorial/source/Coin.hx
Normal file
@@ -0,0 +1,4 @@
|
||||
package;
|
||||
|
||||
@:build(kiss.Kiss.build())
|
||||
class Coin extends FlxSprite {}
|
||||
18
projects/flixel-rpg-tutorial/source/Coin.kiss
Normal file
18
projects/flixel-rpg-tutorial/source/Coin.kiss
Normal file
@@ -0,0 +1,18 @@
|
||||
(defmethod new [:Float x :Float y]
|
||||
(super x y)
|
||||
(loadGraphic AssetPaths.coin__png false 8 8))
|
||||
|
||||
(defmethod &override :Void kill []
|
||||
(set alive false)
|
||||
(FlxTween.tween
|
||||
this
|
||||
(object
|
||||
alpha 0
|
||||
y (- y 16))
|
||||
0.33
|
||||
(object
|
||||
ease FlxEase.circOut
|
||||
onComplete finishKill)))
|
||||
|
||||
(defmethod finishKill [_]
|
||||
(set exists false))
|
||||
13
projects/flixel-rpg-tutorial/source/Enemy.hx
Normal file
13
projects/flixel-rpg-tutorial/source/Enemy.hx
Normal file
@@ -0,0 +1,13 @@
|
||||
package;
|
||||
|
||||
import flixel.FlxObject;
|
||||
import flixel.FlxSprite;
|
||||
|
||||
enum EnemyType
|
||||
{
|
||||
REGULAR;
|
||||
BOSS;
|
||||
}
|
||||
|
||||
@:build(kiss.Kiss.build())
|
||||
class Enemy extends FlxSprite {}
|
||||
80
projects/flixel-rpg-tutorial/source/Enemy.kiss
Normal file
80
projects/flixel-rpg-tutorial/source/Enemy.kiss
Normal file
@@ -0,0 +1,80 @@
|
||||
(defvar &inline :Float SPEED 140)
|
||||
|
||||
(defnew [:Float x :Float y :EnemyType _type]
|
||||
[:EnemyType type _type
|
||||
:FSM brain (new FSM idle)
|
||||
&mut :Float idleTimer 0
|
||||
&mut :Float moveDirection -1
|
||||
&mut :Bool seesPlayer false
|
||||
&mut :FlxPoint playerPosition (FlxPoint.get)]
|
||||
(super x y)
|
||||
|
||||
(loadGraphic
|
||||
(case type
|
||||
(BOSS
|
||||
AssetPaths.boss__png)
|
||||
(otherwise AssetPaths.enemy__png))
|
||||
true
|
||||
16
|
||||
16)
|
||||
|
||||
(setFacingFlip FlxObject.LEFT false false)
|
||||
(setFacingFlip FlxObject.RIGHT true false)
|
||||
(animation.add "d" [0 1 0 2] 6 false)
|
||||
(animation.add "lr" [3 4 3 5] 6 false)
|
||||
(animation.add "u" [6 7 6 8] 6 false)
|
||||
(set drag.x (set drag.y 10))
|
||||
(set width 8)
|
||||
(set height 14)
|
||||
(set offset.x 4)
|
||||
(set offset.y 2))
|
||||
|
||||
(defmethod &override :Void update [:Float elapsed]
|
||||
(when (and
|
||||
(or !(= velocity.x 0) !(= velocity.y 0))
|
||||
(= touching FlxObject.NONE))
|
||||
(if (> (Math.abs velocity.x) (Math.abs velocity.y))
|
||||
(if (< velocity.x 0)
|
||||
(set facing FlxObject.LEFT)
|
||||
(set facing FlxObject.RIGHT))
|
||||
(if (< velocity.y 0)
|
||||
(set facing FlxObject.UP)
|
||||
(set facing FlxObject.DOWN)))
|
||||
|
||||
(case facing
|
||||
((or FlxObject.LEFT FlxObject.RIGHT)
|
||||
(animation.play "lr"))
|
||||
|
||||
(FlxObject.UP
|
||||
(animation.play "u"))
|
||||
|
||||
(FlxObject.DOWN
|
||||
(animation.play "d"))))
|
||||
|
||||
(brain.update elapsed)
|
||||
(super.update elapsed))
|
||||
|
||||
(defmethod :Void idle [:Float elapsed]
|
||||
(cond
|
||||
(seesPlayer
|
||||
// TODO (the FSM) here should not be necessary!
|
||||
(set .activeState (the FSM brain) chase))
|
||||
((<= idleTimer 0)
|
||||
(if (FlxG.random.bool 1)
|
||||
{
|
||||
(set moveDirection -1)
|
||||
(set velocity.x (set velocity.y 0))
|
||||
}
|
||||
{
|
||||
(set moveDirection (* 45 (FlxG.random.int 0 8)))
|
||||
(velocity.set (* SPEED 0.5) 0)
|
||||
(velocity.rotate (FlxPoint.weak) moveDirection)
|
||||
})
|
||||
(set idleTimer (FlxG.random.int 1 4)))
|
||||
(true
|
||||
(-= idleTimer elapsed))))
|
||||
|
||||
(defmethod :Void chase [:Float elapsed]
|
||||
(if !seesPlayer
|
||||
(set brain.activeState idle)
|
||||
(FlxVelocity.moveTowardsPoint this playerPosition (Std.int SPEED))))
|
||||
4
projects/flixel-rpg-tutorial/source/FSM.hx
Normal file
4
projects/flixel-rpg-tutorial/source/FSM.hx
Normal file
@@ -0,0 +1,4 @@
|
||||
package;
|
||||
|
||||
@:build(kiss.Kiss.build())
|
||||
class FSM {}
|
||||
7
projects/flixel-rpg-tutorial/source/FSM.kiss
Normal file
7
projects/flixel-rpg-tutorial/source/FSM.kiss
Normal file
@@ -0,0 +1,7 @@
|
||||
(defprop &mut :Float->Void activeState null)
|
||||
|
||||
(defmethod new [:Float->Void initialState]
|
||||
(set activeState initialState))
|
||||
|
||||
(defmethod :Void update [:Float elapsed]
|
||||
(activeState elapsed))
|
||||
4
projects/flixel-rpg-tutorial/source/Main.hx
Normal file
4
projects/flixel-rpg-tutorial/source/Main.hx
Normal file
@@ -0,0 +1,4 @@
|
||||
package;
|
||||
|
||||
@:build(kiss.Kiss.build())
|
||||
class Main extends Sprite {}
|
||||
3
projects/flixel-rpg-tutorial/source/Main.kiss
Normal file
3
projects/flixel-rpg-tutorial/source/Main.kiss
Normal file
@@ -0,0 +1,3 @@
|
||||
(defmethod new []
|
||||
(super)
|
||||
(addChild (new FlxGame 320 240 MenuState)))
|
||||
4
projects/flixel-rpg-tutorial/source/MenuState.hx
Normal file
4
projects/flixel-rpg-tutorial/source/MenuState.hx
Normal file
@@ -0,0 +1,4 @@
|
||||
package;
|
||||
|
||||
@:build(kiss.Kiss.build())
|
||||
class MenuState extends FlxState {}
|
||||
9
projects/flixel-rpg-tutorial/source/MenuState.kiss
Normal file
9
projects/flixel-rpg-tutorial/source/MenuState.kiss
Normal file
@@ -0,0 +1,9 @@
|
||||
(defprop &mut :FlxButton playButton null)
|
||||
|
||||
(defmethod &override :Void create []
|
||||
(set playButton (new FlxButton 0 0 "Play" clickPlay))
|
||||
(playButton.screenCenter)
|
||||
(add playButton))
|
||||
|
||||
(defun clickPlay []
|
||||
(FlxG.switchState (new PlayState)))
|
||||
4
projects/flixel-rpg-tutorial/source/PlayState.hx
Normal file
4
projects/flixel-rpg-tutorial/source/PlayState.hx
Normal file
@@ -0,0 +1,4 @@
|
||||
package;
|
||||
|
||||
@:build(kiss.Kiss.build())
|
||||
class PlayState extends FlxState {}
|
||||
51
projects/flixel-rpg-tutorial/source/PlayState.kiss
Normal file
51
projects/flixel-rpg-tutorial/source/PlayState.kiss
Normal file
@@ -0,0 +1,51 @@
|
||||
(defprop &mut :Player player null)
|
||||
(defprop &mut :FlxOgmo3Loader map null)
|
||||
(defprop &mut :FlxTilemap walls null)
|
||||
(defprop &mut :FlxTypedGroup<Coin> coins null)
|
||||
(defprop &mut :FlxTypedGroup<Enemy> enemies null)
|
||||
|
||||
(defmethod &override :Void create []
|
||||
(set map (new FlxOgmo3Loader AssetPaths.turnBasedRPG__ogmo AssetPaths.room_001__json))
|
||||
(set walls (map.loadTilemap AssetPaths.tiles__png "walls"))
|
||||
(walls.follow)
|
||||
(walls.setTileProperties 1 FlxObject.NONE)
|
||||
(walls.setTileProperties 2 FlxObject.ANY)
|
||||
(add walls)
|
||||
(set coins (new FlxTypedGroup<Coin>))
|
||||
(add coins)
|
||||
(set enemies (new FlxTypedGroup<Enemy>))
|
||||
(add enemies)
|
||||
(map.loadEntities placeEntities "entities")
|
||||
(FlxG.camera.follow player TOPDOWN 1)
|
||||
(super.create))
|
||||
|
||||
(defmethod :Void placeEntities [:EntityData entity]
|
||||
(case entity.name
|
||||
("player"
|
||||
(set player (new Player entity.x entity.y))
|
||||
(add player))
|
||||
("coin"
|
||||
(coins.add (new Coin (+ entity.x 4) (+ entity.y 4))))
|
||||
("enemy"
|
||||
(enemies.add (new Enemy (+ entity.x 4) entity.y REGULAR)))
|
||||
("boss"
|
||||
(enemies.add (new Enemy (+ entity.x 4) entity.y BOSS)))))
|
||||
|
||||
(defmethod &override :Void update [:Float elapsed]
|
||||
(super.update elapsed)
|
||||
(FlxG.collide player walls)
|
||||
(FlxG.overlap player coins playerTouchCoin)
|
||||
(FlxG.collide enemies walls)
|
||||
(enemies.forEachAlive checkEnemyVision))
|
||||
|
||||
(defmethod :Void checkEnemyVision [:Enemy enemy]
|
||||
(if (walls.ray (enemy.getMidpoint) (player.getMidpoint))
|
||||
{
|
||||
(set enemy.seesPlayer true)
|
||||
(set enemy.playerPosition (player.getMidpoint))
|
||||
}
|
||||
(set enemy.seesPlayer false)))
|
||||
|
||||
(defmethod playerTouchCoin [:Player player :Coin coin]
|
||||
(when (and player.alive player.exists coin.alive coin.exists)
|
||||
(coin.kill)))
|
||||
4
projects/flixel-rpg-tutorial/source/Player.hx
Normal file
4
projects/flixel-rpg-tutorial/source/Player.hx
Normal file
@@ -0,0 +1,4 @@
|
||||
package;
|
||||
|
||||
@:build(kiss.Kiss.build())
|
||||
class Player extends FlxSprite {}
|
||||
67
projects/flixel-rpg-tutorial/source/Player.kiss
Normal file
67
projects/flixel-rpg-tutorial/source/Player.kiss
Normal file
@@ -0,0 +1,67 @@
|
||||
(defvar &inline :Float SPEED 200)
|
||||
|
||||
(defmethod new [:Float x :Float y]
|
||||
(super x y)
|
||||
(loadGraphic AssetPaths.player__png true 16 16)
|
||||
(setFacingFlip FlxObject.LEFT false false)
|
||||
(setFacingFlip FlxObject.RIGHT true false)
|
||||
(animation.add "lr" [3 4 3 5] 6 false)
|
||||
(animation.add "u" [6 7 6 8] 6 false)
|
||||
(animation.add "d" [0 1 0 2] 6 false)
|
||||
(set drag.x (set drag.y 1600))
|
||||
(setSize 8 8)
|
||||
(offset.set 4 4))
|
||||
|
||||
(defmethod :Void 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)))
|
||||
(if (or up down left right)
|
||||
(let [&mut :Float newAngle 0]
|
||||
(cond
|
||||
(up
|
||||
(set newAngle -90)
|
||||
(cond
|
||||
(left
|
||||
(set newAngle (- newAngle 45)))
|
||||
(right
|
||||
(set newAngle (+ newAngle 45))))
|
||||
(set facing FlxObject.UP))
|
||||
(down
|
||||
(set newAngle 90)
|
||||
(cond
|
||||
(left
|
||||
(set newAngle (+ newAngle 45)))
|
||||
(right
|
||||
(set newAngle (- newAngle 45))))
|
||||
(set facing FlxObject.DOWN))
|
||||
(left
|
||||
(set newAngle 180)
|
||||
(set facing FlxObject.LEFT))
|
||||
(right
|
||||
(set newAngle 0)
|
||||
(set facing FlxObject.RIGHT)))
|
||||
(velocity.set SPEED 0)
|
||||
(velocity.rotate (FlxPoint.weak 0 0) newAngle))
|
||||
(when animation.curAnim
|
||||
(set animation.curAnim.curFrame 0)
|
||||
(animation.curAnim.pause)))
|
||||
// TODO != is not implemented. Not sure how it would work as a variadic, because other
|
||||
// Lisps don't have that either
|
||||
(when !(and (= 0 velocity.x) (= 0 velocity.y))
|
||||
(case facing
|
||||
((or FlxObject.LEFT FlxObject.RIGHT)
|
||||
(animation.play "lr"))
|
||||
(FlxObject.UP
|
||||
(animation.play "u"))
|
||||
(FlxObject.DOWN
|
||||
(animation.play "d"))
|
||||
(otherwise
|
||||
(return))))))
|
||||
|
||||
(defmethod &override update [:Float elapsed]
|
||||
(updateMovement)
|
||||
(super.update elapsed))
|
||||
17
projects/flixel-rpg-tutorial/source/import.hx
Normal file
17
projects/flixel-rpg-tutorial/source/import.hx
Normal file
@@ -0,0 +1,17 @@
|
||||
import flixel.FlxGame;
|
||||
import openfl.display.Sprite;
|
||||
import flixel.FlxState;
|
||||
import flixel.ui.FlxButton;
|
||||
import flixel.FlxG;
|
||||
import flixel.FlxSprite;
|
||||
import flixel.util.FlxColor;
|
||||
import flixel.input.keyboard.FlxKey;
|
||||
import flixel.math.FlxPoint;
|
||||
import flixel.math.FlxVelocity;
|
||||
import flixel.FlxObject;
|
||||
import flixel.addons.editors.ogmo.FlxOgmo3Loader;
|
||||
import flixel.tile.FlxTilemap;
|
||||
import flixel.group.FlxGroup;
|
||||
import flixel.tweens.FlxTween;
|
||||
import flixel.tweens.FlxEase;
|
||||
import kiss.Prelude;
|
||||
Reference in New Issue
Block a user