Guest User

Untitled

a guest
Oct 6th, 2018
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //PlayState.hx
  2.  
  3. package com.asmoprime.plamoles;
  4.  
  5. import org.flixel.FlxText;
  6. import org.flixel.FlxState;
  7. import org.flixel.FlxSprite;
  8. import org.flixel.FlxG;
  9. import org.flixel.FlxTilemap;
  10. import org.flixel.FlxButton;
  11. import org.flixel.FlxAssets;
  12. import org.flixel.FlxObject;
  13. import org.flixel.FlxGroup;
  14. import org.flixel.FlxCamera;
  15. import org.flixel.FlxPoint;
  16.  
  17. import com.asmoprime.utils.ColorUtils;
  18. import com.asmoprime.utils.ColorConverter;
  19. import com.asmoprime.utils.Random;
  20.  
  21. import com.asmoprime.plamoles.objects.Player;
  22. import com.asmoprime.plamoles.objects.Mole;
  23. import com.asmoprime.plamoles.objects.Platform;
  24. /**
  25.  * ...
  26.  * @author asmageddon
  27.  */
  28.  
  29. class PlayState extends FlxState {
  30.     private var player : Player;
  31.     private var mole1 : Mole;
  32.     private var mole2 : Mole;
  33.     private var mole3 : Mole;
  34.     private var platform : Platform;
  35.    
  36.     override public function create():Void {
  37.         #if !neko
  38.             FlxG.bgColor = 0xFFFFFFFF;
  39.         #else
  40.             FlxG.camera.bgColor = { rgb: 0xFFFFFF, a: 0xFF };
  41.         #end
  42.    
  43.         player = new Player(200, 100);
  44.         mole1 = new Mole(90, 391);
  45.         mole2 = new Mole(200, 391);
  46.         mole3 = new Mole(310, 391);
  47.         platform = new Platform(200, 370);
  48.         add(player);
  49.         add(mole1);
  50.         add(mole2);
  51.         add(mole3);
  52.         add(platform);
  53.     }
  54.    
  55.     override public function update():Void {
  56.         super.update();
  57.        
  58.         FlxG.collide(player, platform);
  59.     }
  60. }
  61.  
  62. //Player.hx
  63.  
  64. package com.asmoprime.plamoles.objects;
  65.  
  66. import org.flixel.FlxG;
  67. import org.flixel.FlxObject;
  68. import org.flixel.FlxSprite;
  69.  
  70. /**
  71.  * ...
  72.  * @author asmageddon
  73.  */
  74. class Player extends FlxSprite {
  75.     private var jump_ready : Bool = false;
  76.    
  77.     private var jump_power : Float = 200;
  78.     private var movement_speed : Float = 120;
  79.    
  80.     public function new(X : Int, Y : Int) {
  81.         super(X, Y);
  82.        
  83.         loadGraphic("assets/images/player.png", false, false, 24, 24);
  84.        
  85.         width = 24;
  86.         height = 24;
  87.         offset.x = 12;
  88.         offset.y = 23;
  89.        
  90.         drag.x = movement_speed * 8;
  91.        
  92.         acceleration.y = 420;
  93.         this.elasticity = 0.1;
  94.        
  95.         maxVelocity.x = movement_speed * 1.1;
  96.         maxVelocity.y = jump_power * 1.5;
  97.        
  98.     }
  99.    
  100.     override public function update() {
  101. /*      if(justTouched(FlxObject.FLOOR)) {
  102.             jump_ready = true;
  103.             velocity.y = 0;
  104.         }
  105.         if(isTouching(FlxObject.ANY) && velocity.y > 0) {
  106.             velocity.y = 0;
  107.         }*/
  108.        
  109.         //MOVEMENT
  110.         acceleration.x = 0;
  111.         if(FlxG.keys.A) {
  112.             facing = FlxObject.LEFT;
  113.             acceleration.x -= drag.x;
  114.         }
  115.         else if(FlxG.keys.D) {
  116.             facing = FlxObject.RIGHT;
  117.             acceleration.x += drag.x;
  118.         }
  119.        
  120.         if(FlxG.keys.justPressed("W") && velocity.y == 0 && jump_ready ) {
  121.             velocity.y = -jump_power;
  122.             jump_ready = false;
  123.         }
  124.        
  125.         super.update();
  126.     }
  127. }
  128.  
  129. //Platform.hx
  130.  
  131. package com.asmoprime.plamoles.objects;
  132.  
  133. import org.flixel.FlxSprite;
  134.  
  135. /**
  136.  * ...
  137.  * @author asmageddon
  138.  */
  139. class Platform extends FlxSprite {
  140.     public function new(X : Int, Y : Int) {
  141.         super(X, Y);
  142.        
  143.         loadGraphic("assets/images/platform.png", false, false, 256, 32);
  144.        
  145.        
  146.         width = 128;
  147.         height = 32;
  148.         offset.x = 128;
  149.         offset.y = 0;
  150.        
  151.         this.immovable = true;
  152.    
  153.     }
  154.    
  155.     override public function update() {
  156.  
  157.         super.update();
  158.     }
  159. }
Add Comment
Please, Sign In to add comment