[rpg] Generate enemies and boss
This commit is contained in:
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("source/Enemy.kiss"))
|
||||||
|
class Enemy extends FlxSprite {}
|
||||||
52
projects/flixel/rpg-tutorial/source/Enemy.kiss
Normal file
52
projects/flixel/rpg-tutorial/source/Enemy.kiss
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
(defvar &inline :Float SPEED 140)
|
||||||
|
|
||||||
|
(defprop &mut :EnemyType type null)
|
||||||
|
|
||||||
|
(defmethod new [:Float x :Float y :EnemyType type]
|
||||||
|
(super x y)
|
||||||
|
(set this.type type)
|
||||||
|
(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)
|
||||||
|
(return))
|
||||||
|
|
||||||
|
(defmethod &override 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")))
|
||||||
|
|
||||||
|
(super.update elapsed))
|
||||||
|
(return))
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
(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)
|
(defprop &mut :FlxTypedGroup<Coin> coins null)
|
||||||
|
(defprop &mut :FlxTypedGroup<Enemy> enemies null)
|
||||||
|
|
||||||
// TODO make a &void meta
|
// TODO make a &void meta
|
||||||
(defmethod &override create []
|
(defmethod &override create []
|
||||||
@@ -13,6 +14,8 @@
|
|||||||
(add walls)
|
(add walls)
|
||||||
(set coins (new FlxTypedGroup<Coin>))
|
(set coins (new FlxTypedGroup<Coin>))
|
||||||
(add coins)
|
(add coins)
|
||||||
|
(set enemies (new FlxTypedGroup<Enemy>))
|
||||||
|
(add enemies)
|
||||||
(map.loadEntities placeEntities "entities")
|
(map.loadEntities placeEntities "entities")
|
||||||
(FlxG.camera.follow player TOPDOWN 1)
|
(FlxG.camera.follow player TOPDOWN 1)
|
||||||
(super.create)
|
(super.create)
|
||||||
@@ -24,7 +27,12 @@
|
|||||||
(set player (new Player entity.x entity.y))
|
(set player (new Player entity.x entity.y))
|
||||||
(add player))
|
(add player))
|
||||||
("coin"
|
("coin"
|
||||||
(coins.add (new Coin (+ entity.x 4) (+ entity.y 4)))))
|
(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))))
|
||||||
|
|
||||||
(return))
|
(return))
|
||||||
|
|
||||||
(defmethod &override update [:Float elapsed]
|
(defmethod &override update [:Float elapsed]
|
||||||
|
|||||||
Reference in New Issue
Block a user