Guest User

playstate

a guest
Jun 30th, 2021
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. package;
  2.  
  3. import flixel.FlxG;
  4. import flixel.FlxObject;
  5. import flixel.FlxState;
  6. import flixel.addons.editors.ogmo.FlxOgmo3Loader;
  7. import flixel.group.FlxGroup.FlxTypedGroup;
  8. import flixel.tile.FlxTilemap;
  9.  
  10. class PlayState extends FlxState
  11. {
  12. var player:Player;
  13. var map:FlxOgmo3Loader;
  14. var walls:FlxTilemap;
  15. public var coins:FlxTypedGroup<Coin>;
  16.  
  17.  
  18. override public function create()
  19. {
  20. map = new FlxOgmo3Loader(AssetPaths.turnbasedRPG__ogmo, AssetPaths.room_001__json);
  21. walls = map.loadTilemap(AssetPaths.tiles__png, "walls");
  22. walls.follow();
  23. walls.setTileProperties(1, FlxObject.NONE);
  24. walls.setTileProperties(2, FlxObject.ANY);
  25. add(walls);
  26. player = new Player(0);
  27. map.loadEntities(placeEntities, "entities");
  28. add(player);
  29. coins = new FlxTypedGroup<Coin>();
  30.  
  31. FlxG.camera.follow(player, TOPDOWN, 1);
  32. super.create();
  33. }
  34.  
  35. function placeEntities(entity:EntityData)
  36. {
  37. if (entity.name == "player")
  38. {
  39. player.setPosition(entity.x, entity.y);
  40. }
  41. else if (entity.name == "coin")
  42. {
  43.  
  44. coins.add(new Coin(entity.x, entity.y));
  45. }
  46. }
  47.  
  48. function playerTouchCoin(player:Player, coin:Coin)
  49. {
  50. if (player.alive && player.exists && coin.alive && coin.exists)
  51. {
  52. coin.kill();
  53. }
  54. }
  55.  
  56. override public function update(elapsed:Float)
  57. {
  58. super.update(elapsed);
  59. FlxG.collide(player, walls);
  60. FlxG.overlap(player, coins, playerTouchCoin);
  61. }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment