RPG tutorial coins

This commit is contained in:
2021-01-09 14:39:03 -07:00
parent 0c3427cf84
commit 6dd2c8f6a7
7 changed files with 97 additions and 6 deletions

View File

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

View File

@@ -0,0 +1,20 @@
(defmethod new [:Float x :Float y]
(super x y)
(loadGraphic AssetPaths.coin__png false 8 8)
(return))
(defmethod &override kill []
(set alive false)
(FlxTween.tween
this
(object
alpha 0
y (- y 16))
0.33
(object
ease FlxEase.circOut
onComplete finishKill))
(return))
(defmethod finishKill [_]
(set exists false))

View File

@@ -1,6 +1,7 @@
(defprop &mut :Player player null)
(defprop &mut :FlxOgmo3Loader map null)
(defprop &mut :FlxTilemap walls null)
(defprop &mut :FlxTypedGroup<Coin> coins null)
// TODO make a &void meta
(defmethod &override create []
@@ -10,17 +11,28 @@
(walls.setTileProperties 1 FlxObject.NONE)
(walls.setTileProperties 2 FlxObject.ANY)
(add walls)
(set coins (new FlxTypedGroup<Coin>))
(add coins)
(map.loadEntities placeEntities "entities")
(FlxG.camera.follow player TOPDOWN 1)
(super.create)
(return))
(defmethod placeEntities [:EntityData entity]
(when (= "player" entity.name)
(set player (new Player entity.x entity.y))
(add player)))
(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)))))
(return))
(defmethod &override update [:Float elapsed]
(super.update elapsed)
(FlxG.collide player walls)
(return))
(FlxG.overlap player coins playerTouchCoin)
(return))
(defmethod playerTouchCoin [:Player player :Coin coin]
(when (and player.alive player.exists coin.alive coin.exists)
(coin.kill)))

View File

@@ -9,4 +9,7 @@ import flixel.input.keyboard.FlxKey;
import flixel.math.FlxPoint;
import flixel.FlxObject;
import flixel.addons.editors.ogmo.FlxOgmo3Loader;
import flixel.group.FlxGroup;
import flixel.tweens.FlxTween;
import flixel.tweens.FlxEase;
import kiss.Prelude;