Refactor travis testing

This commit is contained in:
2021-06-07 12:36:22 -06:00
parent 32698b2d5b
commit 610a977b7c
77 changed files with 76 additions and 116 deletions

View File

@@ -0,0 +1,4 @@
package;
@:build(flixel.system.FlxAssets.buildFileReferences("assets", true))
class AssetPaths {}

View File

@@ -0,0 +1,4 @@
package;
@:build(kiss.Kiss.build())
class Coin extends FlxSprite {}

View 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))

View File

@@ -0,0 +1,13 @@
package;
import flixel.FlxObject;
import flixel.FlxSprite;
enum EnemyType
{
REGULAR;
BOSS;
}
@:build(kiss.Kiss.build())
class Enemy extends FlxSprite {}

View 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))))

View File

@@ -0,0 +1,4 @@
package;
@:build(kiss.Kiss.build())
class FSM {}

View 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))

View File

@@ -0,0 +1,4 @@
package;
@:build(kiss.Kiss.build())
class Main extends Sprite {}

View File

@@ -0,0 +1,3 @@
(defmethod new []
(super)
(addChild (new FlxGame 320 240 MenuState)))

View File

@@ -0,0 +1,4 @@
package;
@:build(kiss.Kiss.build())
class MenuState extends FlxState {}

View 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)))

View File

@@ -0,0 +1,4 @@
package;
@:build(kiss.Kiss.build())
class PlayState extends FlxState {}

View 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)))

View File

@@ -0,0 +1,4 @@
package;
@:build(kiss.Kiss.build())
class Player extends FlxSprite {}

View 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))

View 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;