Advertisement
NaxeCode

Untitled

Sep 12th, 2017
3,079
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Haxe 3.31 KB | None | 0 0
  1. package game;
  2.  
  3. import flixel.FlxG;
  4. import flixel.FlxState;
  5. import flixel.FlxSprite;
  6. import flixel.text.FlxText;
  7.  
  8. class ShopState extends FlxState
  9. {
  10.     private var bellyButton:FlxText;
  11.     private var uravity:FlxText;
  12.     private var oneForAll:FlxText;
  13.     private var exit:FlxText;
  14.  
  15.     public static var bellyButtonAMNT:Int = 0;
  16.     public static var uravityAMNT:Int = 0;
  17.     public static var oneForAllAMNT:Int = 0;
  18.  
  19.     private var currentSelected:Int = 0;
  20.     private var interactiveElement:FlxText;
  21.  
  22.     override public function create():Void
  23.     {
  24.         super.create();
  25.  
  26.         initShopItems();
  27.         initInteractive();
  28.     }
  29.  
  30.     private function initShopItems():Void
  31.     {
  32.         bellyButton = new FlxText();
  33.         bellyButton.text = "Belly Button = x" + bellyButtonAMNT;
  34.         bellyButton.size = 30;
  35.         add(bellyButton);
  36.  
  37.         uravity = new FlxText(0, bellyButton.y);
  38.         uravity.text = "Uravity = x" + uravityAMNT;
  39.         uravity.size = 30;
  40.         uravity.y += 50;
  41.         add(uravity);
  42.  
  43.         oneForAll = new FlxText(0, uravity.y);
  44.         oneForAll.text = "One For All = x" + oneForAllAMNT;
  45.         oneForAll.size = 30;
  46.         oneForAll.y += 50;
  47.         add(oneForAll);
  48.  
  49.         exit = new FlxText(0, oneForAll.y);
  50.         exit.text = "Exit";
  51.         exit.size = 30;
  52.         exit.y += 50;
  53.         add(exit);
  54.     }
  55.  
  56.     private function initInteractive():Void
  57.     {
  58.         interactiveElement = new FlxText();
  59.         interactiveElement.text = "<-";
  60.         interactiveElement.size = 50;
  61.         add(interactiveElement);
  62.     }
  63.  
  64.     override public function update(elapsed:Float):Void
  65.     {
  66.         handleInput();
  67.         handleInteractive();
  68.         super.update(elapsed);
  69.        
  70.         updateText();
  71.     }
  72.  
  73.     private function handleInput():Void
  74.     {
  75.         /*
  76.         if (FlxG.keys.justPressed.ENTER)
  77.             FlxG.switchState(new PlayState());
  78.         */
  79.     }
  80.  
  81.     private function handleInteractive():Void
  82.     {
  83.         switch (currentSelected)
  84.         {
  85.             case 0: interactiveElement.setPosition(bellyButton.x + bellyButton.width, bellyButton.y);
  86.             case 1: interactiveElement.setPosition(uravity.x + uravity.width, uravity.y);
  87.             case 2: interactiveElement.setPosition(oneForAll.x + oneForAll.width, oneForAll.y);
  88.             case 3: interactiveElement.setPosition(exit.x + exit.width, exit.y);
  89.         }
  90.  
  91.         if (FlxG.keys.justPressed.UP || FlxG.keys.justPressed.W)
  92.             currentSelected--;
  93.         if (FlxG.keys.justPressed.DOWN || FlxG.keys.justPressed.S)
  94.             currentSelected++;
  95.        
  96.         if (FlxG.keys.justPressed.ENTER)
  97.         {
  98.             switch (currentSelected)
  99.             {
  100.                 case 0: bellyButtonAMNT++;
  101.                 case 1: uravityAMNT++;
  102.                 case 2: oneForAllAMNT++;
  103.                 case 3: FlxG.switchState(new PlayState());
  104.             }
  105.         }
  106.  
  107.         if (currentSelected < 0)
  108.             currentSelected = 3;
  109.         if (currentSelected > 3)
  110.             currentSelected = 0;
  111.     }
  112.  
  113.     private function updateText():Void
  114.     {
  115.         bellyButton.text = "Belly Button = x" + bellyButtonAMNT;
  116.         uravity.text = "Uravity = x" + uravityAMNT;
  117.         oneForAll.text = "One For All = x" + oneForAllAMNT;
  118.     }
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement