RPG tutorial coins
This commit is contained in:
@@ -15,7 +15,23 @@
|
||||
"gridCellsX": 40,
|
||||
"gridCellsY": 30,
|
||||
"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}
|
||||
]
|
||||
},
|
||||
{
|
||||
|
@@ -39,7 +39,7 @@
|
||||
{
|
||||
"exportID": "65218053",
|
||||
"name": "player",
|
||||
"limit": -1,
|
||||
"limit": 1,
|
||||
"size": {"x": 16, "y": 16},
|
||||
"origin": {"x": 0, "y": 0},
|
||||
"originAnchored": true,
|
||||
@@ -71,6 +71,42 @@
|
||||
"nodeGhost": true,
|
||||
"tags": [],
|
||||
"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": [
|
||||
|
BIN
projects/flixel/rpg-tutorial/assets/images/coin.png
Normal file
BIN
projects/flixel/rpg-tutorial/assets/images/coin.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 984 B |
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("source/Coin.kiss"))
|
||||
class Coin extends FlxSprite {}
|
20
projects/flixel/rpg-tutorial/source/Coin.kiss
Normal file
20
projects/flixel/rpg-tutorial/source/Coin.kiss
Normal 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))
|
@@ -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)))
|
@@ -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;
|
||||
|
Reference in New Issue
Block a user