Advertisement
Guest User

Untitled

a guest
Mar 26th, 2015
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.33 KB | None | 0 0
  1. package;
  2.  
  3. import flixel.addons.editors.ogmo.FlxOgmoLoader;
  4. import flixel.addons.editors.tiled.TiledMap;
  5. import flixel.FlxCamera;
  6. import flixel.FlxG;
  7. import flixel.FlxObject;
  8. import flixel.FlxSprite;
  9. import flixel.FlxState;
  10. import flixel.group.FlxGroup;
  11. import flixel.text.FlxText;
  12. import flixel.tile.FlxTilemap;
  13. import flixel.ui.FlxButton;
  14. import flixel.util.FlxMath;
  15. import flixel.util.FlxPoint;
  16.  
  17. /**
  18. * A FlxState which can be used for the actual gameplay.
  19. */
  20. class PlayState extends FlxState
  21. {
  22. private var player:FlxSprite;
  23. private var floor:FlxSprite;
  24.  
  25. private var loader:FlxOgmoLoader;
  26.  
  27. private var coinGroup:FlxGroup;
  28. private var midgroundMap:FlxTilemap;
  29.  
  30. private var score:Int;
  31. private var scoreText:FlxText;
  32. /**
  33. * Function that is called up when to state is created to set it up.
  34. */
  35. override public function create():Void
  36. {
  37. super.create();
  38. FlxG.camera.bgColor = 0xFFBA4ED1;
  39.  
  40. score = 0;
  41. scoreText = new FlxText(0, 0, 100, "Score: " + score);
  42.  
  43.  
  44. loader = new FlxOgmoLoader("assets/data/Level1.oel");
  45. midgroundMap = loader.loadTilemap("assets/images/tiles.png", 16, 16, "ground");
  46.  
  47. //floorCreate();
  48. //add(scoreText);
  49. //coinCreate();
  50. //add(coinGroup);
  51. add(midgroundMap);
  52. playerCreate();
  53.  
  54. FlxG.camera.follow(player, 1);
  55. }
  56.  
  57. /**
  58. * Function that is called when this state is destroyed - you might want to
  59. * consider setting all objects this state uses to null to help garbage collection.
  60. */
  61. override public function destroy():Void
  62. {
  63. super.destroy();
  64. }
  65.  
  66. /**
  67. * Function that is called once every frame.
  68. */
  69. override public function update():Void
  70. {
  71.  
  72. FlxG.overlap(coinGroup, player, coinCollect);
  73. FlxG.collide(floor, player);
  74.  
  75. super.update();
  76. }
  77.  
  78. function coinCollect(thisCoin:FlxObject, thisPlayer:FlxObject)
  79. {
  80. thisCoin.destroy();
  81. score++;
  82. scoreText.text = "Score: " + score;
  83. }
  84.  
  85. public function floorCreate():Void
  86. {
  87. floor = new FlxSprite(0, 430);
  88. floor.makeGraphic(640, 50, 0xFF700F0A);
  89. floor.immovable = true;
  90.  
  91. add(floor);
  92. }
  93.  
  94. public function playerCreate():Void
  95. {
  96. player = new Player(50, 50);
  97.  
  98. add(player);
  99. }
  100.  
  101. public function coinCreate():Void
  102. {
  103.  
  104. coinGroup = new FlxGroup();
  105. for (i in 0...25)
  106. {
  107. coinGroup.add(new Coin(i * 45, 380));
  108. }
  109. }
  110.  
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement