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

@@ -15,7 +15,23 @@
"gridCellsX": 40, "gridCellsX": 40,
"gridCellsY": 30, "gridCellsY": 30,
"entities": [ "entities": [
{"name": "player", "id": 0, "_eid": "65218053", "x": 432, "y": 288, "originX": 0, "originY": 0} {"name": "player", "id": 0, "_eid": "65218053", "x": 432, "y": 288, "originX": 0, "originY": 0},
{"name": "coin", "id": 1, "_eid": "72607845", "x": 384, "y": 288, "originX": 0, "originY": 0},
{"name": "coin", "id": 2, "_eid": "72607845", "x": 336, "y": 288, "originX": 0, "originY": 0},
{"name": "coin", "id": 3, "_eid": "72607845", "x": 352, "y": 256, "originX": 0, "originY": 0},
{"name": "coin", "id": 4, "_eid": "72607845", "x": 400, "y": 240, "originX": 0, "originY": 0},
{"name": "coin", "id": 5, "_eid": "72607845", "x": 368, "y": 208, "originX": 0, "originY": 0},
{"name": "coin", "id": 6, "_eid": "72607845", "x": 304, "y": 208, "originX": 0, "originY": 0},
{"name": "coin", "id": 7, "_eid": "72607845", "x": 256, "y": 176, "originX": 0, "originY": 0},
{"name": "coin", "id": 8, "_eid": "72607845", "x": 272, "y": 224, "originX": 0, "originY": 0},
{"name": "coin", "id": 9, "_eid": "72607845", "x": 368, "y": 160, "originX": 0, "originY": 0},
{"name": "coin", "id": 10, "_eid": "72607845", "x": 336, "y": 112, "originX": 0, "originY": 0},
{"name": "coin", "id": 11, "_eid": "72607845", "x": 400, "y": 48, "originX": 0, "originY": 0},
{"name": "coin", "id": 12, "_eid": "72607845", "x": 320, "y": 48, "originX": 0, "originY": 0},
{"name": "coin", "id": 13, "_eid": "72607845", "x": 272, "y": 112, "originX": 0, "originY": 0},
{"name": "coin", "id": 14, "_eid": "72607845", "x": 208, "y": 96, "originX": 0, "originY": 0},
{"name": "coin", "id": 15, "_eid": "72607845", "x": 176, "y": 128, "originX": 0, "originY": 0},
{"name": "coin", "id": 16, "_eid": "72607845", "x": 352, "y": 80, "originX": 0, "originY": 0}
] ]
}, },
{ {

View File

@@ -39,7 +39,7 @@
{ {
"exportID": "65218053", "exportID": "65218053",
"name": "player", "name": "player",
"limit": -1, "limit": 1,
"size": {"x": 16, "y": 16}, "size": {"x": 16, "y": 16},
"origin": {"x": 0, "y": 0}, "origin": {"x": 0, "y": 0},
"originAnchored": true, "originAnchored": true,
@@ -71,6 +71,42 @@
"nodeGhost": true, "nodeGhost": true,
"tags": [], "tags": [],
"values": [] "values": []
},
{
"exportID": "72607845",
"name": "coin",
"limit": -1,
"size": {"x": 16, "y": 16},
"origin": {"x": 0, "y": 0},
"originAnchored": true,
"shape": {
"label": "Rectangle",
"points": [
{"x": -1, "y": -1},
{"x": 1, "y": -1},
{"x": -1, "y": 1},
{"x": 1, "y": -1},
{"x": -1, "y": 1},
{"x": 1, "y": 1}
]
},
"color": "#ffe900ff",
"tileX": false,
"tileY": false,
"tileSize": {"x": 16, "y": 16},
"resizeableX": false,
"resizeableY": false,
"rotatable": false,
"rotationDegrees": 360,
"canFlipX": false,
"canFlipY": false,
"canSetColor": false,
"hasNodes": false,
"nodeLimit": 0,
"nodeDisplay": 0,
"nodeGhost": true,
"tags": [],
"values": []
} }
], ],
"tilesets": [ "tilesets": [

Binary file not shown.

After

Width:  |  Height:  |  Size: 984 B

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 :Player player null)
(defprop &mut :FlxOgmo3Loader map null) (defprop &mut :FlxOgmo3Loader map null)
(defprop &mut :FlxTilemap walls null) (defprop &mut :FlxTilemap walls null)
(defprop &mut :FlxTypedGroup<Coin> coins null)
// TODO make a &void meta // TODO make a &void meta
(defmethod &override create [] (defmethod &override create []
@@ -10,17 +11,28 @@
(walls.setTileProperties 1 FlxObject.NONE) (walls.setTileProperties 1 FlxObject.NONE)
(walls.setTileProperties 2 FlxObject.ANY) (walls.setTileProperties 2 FlxObject.ANY)
(add walls) (add walls)
(set coins (new FlxTypedGroup<Coin>))
(add coins)
(map.loadEntities placeEntities "entities") (map.loadEntities placeEntities "entities")
(FlxG.camera.follow player TOPDOWN 1) (FlxG.camera.follow player TOPDOWN 1)
(super.create) (super.create)
(return)) (return))
(defmethod placeEntities [:EntityData entity] (defmethod placeEntities [:EntityData entity]
(when (= "player" entity.name) (case entity.name
(set player (new Player entity.x entity.y)) ("player"
(add 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] (defmethod &override update [:Float elapsed]
(super.update elapsed) (super.update elapsed)
(FlxG.collide player walls) (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.math.FlxPoint;
import flixel.FlxObject; import flixel.FlxObject;
import flixel.addons.editors.ogmo.FlxOgmo3Loader; import flixel.addons.editors.ogmo.FlxOgmo3Loader;
import flixel.group.FlxGroup;
import flixel.tweens.FlxTween;
import flixel.tweens.FlxEase;
import kiss.Prelude; import kiss.Prelude;