Advertisement
Guest User

Untitled

a guest
May 27th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package  
  2. {
  3.     import costumes.JoeAverage;
  4.     import org.flixel.FlxGroup;
  5.     import org.flixel.FlxSprite;
  6.     import org.flixel.FlxState;
  7.     import org.flixel.FlxSave;
  8.     import org.flixel.FlxTilemap;
  9.     import org.flixel.FlxG;
  10.     import org.flixel.FlxU;
  11.     /**
  12.      * ...
  13.      * @author Kristian Macanga
  14.      */
  15.     public class PlayState extends FlxState
  16.     {
  17.             [Embed(source = "/data/joeaverage.png")] private var ImgJoeAvg:Class;
  18.         [Embed(source = "data/bakWall.png")] private var ImgBWall:Class;
  19.         [Embed(source = "data/bakBlue.png")] private var ImgBBlue:Class;
  20.         [Embed(source = "data/bakBrown.png")] private var ImgBBrown:Class;
  21.         [Embed(source = "data/bakDesert.png")] private var ImgBDesert:Class;
  22.         [Embed(source = "data/tiles.png")] private var ImgTiles:Class;
  23.        
  24.         private var playerGroup:PlayerGroup;
  25.         private var player:Player;
  26.        
  27.         override public function create():void
  28.         {
  29.             super.create();
  30.             addLayers();
  31.             setLevel(1);
  32.             setBackground(1);
  33.             addPlayer();
  34.        
  35.         }
  36.        
  37.         private function addLayers():void
  38.         {
  39.             Global.backLayer = new FlxGroup();
  40.             Global.spriteLayer = new FlxGroup();
  41.             Global.HUDLayer = new FlxGroup();
  42.            
  43.             this.add(Global.backLayer);
  44.             this.add(Global.spriteLayer);
  45.             this.add(Global.HUDLayer);
  46.         }
  47.        
  48.         private function setBackground(chapter:int):void
  49.         {
  50.             var tileGraphic:Class;
  51.             switch ( chapter )
  52.             {
  53.                 case 1 :
  54.                 {
  55.                     tileGraphic = ImgBWall;
  56.                     break;
  57.                 }
  58.                 case 2 :
  59.                 {
  60.                     tileGraphic = ImgBBlue;
  61.                     break;
  62.                 }
  63.                 case 3 :
  64.                 {
  65.                     tileGraphic = ImgBBrown;
  66.                     break;
  67.                 }
  68.                 case 4 :
  69.                 {
  70.                     tileGraphic = ImgBDesert;
  71.                     break;
  72.                 }
  73.                 default :
  74.                 {
  75.                     tileGraphic = ImgBWall;
  76.                 }
  77.             }
  78.            
  79.             if (Global.background != null)
  80.             {
  81.                 Global.backLayer.remove(Global.background, true);
  82.             }
  83.             Global.background = new Background(tileGraphic);
  84.             Global.backLayer.add(Global.background);
  85.            
  86.         }
  87.        
  88.        
  89.         private function setLevel( level:int ):void
  90.         {
  91.             if (Global.tileMap != null )
  92.             {
  93.                 Global.spriteLayer.remove(Global.tileMap, true);
  94.             }
  95.             Global.tileMap = new FlxTilemap();
  96.             Global.tileMap.drawIndex = 1;
  97.             Global.tileMap.loadMap(Global.levelTiles[level - 1], ImgTiles, 16);
  98.             Global.tileMap.collideIndex = 1;
  99.             Global.spriteLayer.add(Global.tileMap);
  100.             Global.spriteLayer.add(player);
  101.         }
  102.        
  103.         private function addPlayer():void
  104.         {
  105.               new PlayerGroup();
  106.         }
  107.        
  108.         override public function update():void
  109.         {
  110.             super.update();
  111.             FlxU.collide(PlayerGroup.player, Global.tileMap);
  112.         }
  113.     }
  114.  
  115. }
  116.  
  117.  
  118.  
  119. package  
  120. {
  121.     import costumes.JoeAverage;
  122.     import costumes.Mazkirov;
  123.     import org.flixel.FlxSprite;
  124.     import org.flixel.FlxGroup;
  125.     import org.flixel.FlxG;
  126.     import pixelperfectoverlap.HitTest;
  127.     import org.flixel.FlxSprite;
  128.     /**
  129.      * ...
  130.      * @author Kristian Macanga
  131.      */
  132.     public class PlayerGroup extends FlxSprite
  133.     {
  134.         private const MOVE_SPEED:int = 100;
  135.         private const JUMP_STRENGTH:int = 140;
  136.        
  137.         public static var player:Player;
  138.         private var equippedWeapon:Weapon;
  139.         private var backWeapon:Weapon;
  140.        
  141.         public function PlayerGroup()
  142.         {
  143.             super();
  144.             alpha = 0;
  145.             Global.spriteLayer.add(this);
  146.            
  147.             player = new Mazkirov();
  148.         }
  149.        
  150.         private function movePlayer():void
  151.         {
  152.             if ( FlxG.keys.LEFT || FlxG.keys.A )
  153.             {
  154.                 player.velocity.x =  ( -1) * MOVE_SPEED;
  155.                 player.facing = FlxSprite.LEFT;
  156.             }
  157.             else if ( FlxG.keys.RIGHT || FlxG.keys.D )
  158.             {
  159.                 player.velocity.x = MOVE_SPEED;
  160.                 player.facing = FlxSprite.RIGHT;
  161.             }
  162.             else
  163.             {
  164.                 player.velocity.x = 0;
  165.             }
  166.  
  167.         }
  168.        
  169.         private function playerJump():void
  170.         {
  171.             if ( ( FlxG.keys.UP || FlxG.keys.W ) && player.velocity.y == 0 )
  172.             {
  173.                 player.velocity.y = - JUMP_STRENGTH;
  174.             }
  175.         }
  176.        
  177.         private function adjustJumpAnimation():void
  178.         {
  179.             if ( Math.abs(velocity.y) > 10)
  180.             {
  181.                
  182.             }
  183.         }
  184.        
  185.         private function switchWeapon():void
  186.         {
  187.            
  188.         }
  189.        
  190.         /*private function changeWeapon(weapon:Weapon)
  191.         {
  192.             equippedWeapon.x = weapon.x;
  193.             equippedWeapon.y = weapon.y;
  194.             this.remove(equippedWeapon);
  195.             equippedWeapon = weapon;
  196.             add(equippedWeapon);       
  197.         }
  198.        
  199.         /*private function pickUpWeapon():void
  200.         {
  201.             if ( FlxG.keys.DOWN || FlxG.keys.S )
  202.             {
  203.                 for each( var pickUp:Weapon in Global.pickUps)
  204.                 {
  205.                     if (HitTest.complexHitTestObject(player.mask,pickUp.mask,6))
  206.                     {
  207.                         changeWeapon(pickUp);
  208.                     }
  209.                 }
  210.             }
  211.         }*/
  212.        
  213.         override public function update():void
  214.         {
  215.             movePlayer();
  216.             playerJump();
  217.             //setEquipVelocity();
  218.             super.update();
  219.             adjustJumpAnimation();
  220.             //pickUpWeapon();
  221.         }
  222.        
  223.     }
  224.  
  225. }
  226.  
  227.  
  228. package  
  229. {
  230.     import org.flixel.FlxSprite;
  231.     import pixelperfectoverlap.FlxSpriteEx;
  232.     import org.flixel.FlxG;
  233.    
  234.    
  235.     /**
  236.      * ...
  237.      * @author Kristian Macanga
  238.      */
  239.     public class Player extends FlxSpriteEx
  240.     {
  241.        
  242.         private const GRAVITY:int = 200;
  243.    
  244.         protected var flm:int = 0;
  245.         protected var name:String = "";
  246.         protected var msg:String = "";
  247.        
  248.         protected var boost:Boolean = false;
  249.         protected var pack:Boolean = false;
  250.         protected var rightFace:int = 1;
  251.         protected var ammo:int = 0;
  252.         protected var backAmmo:int = 0;
  253.         protected var canShoot:Boolean = true;
  254.        
  255.         protected var pHealth:int = 50;
  256.         protected var life:int = 3;
  257.         protected var char:int = 0;
  258.        
  259.         protected var jumpPower:int = 100;
  260.         protected var runSpeed:int = 100;
  261.         protected var swimSpeed:int = 100;
  262.         protected var special:String = "";
  263.  
  264.  
  265.         public function Player(costume:Class)
  266.         {
  267.             super(200, 150);
  268.             loadGraphic(costume, true, true);
  269.             setOrigin(0, 0);
  270.             addAnimation("normal", [0]);
  271.             addAnimation("jumping", [1]);
  272.             addAnimation("midAir", [2]);
  273.             addAnimation("falling", [3]);
  274.             addAnimation("running", [4, 5, 6, 7, 8], 15, true);
  275.             play("normal", true);
  276.             Global.spriteLayer.add(this);
  277.            
  278.             acceleration.y = GRAVITY;
  279.         }
  280.        
  281.         private function setAnimation():void
  282.         {
  283.            
  284.             if ( FlxG.keys.LEFT || FlxG.keys.A )
  285.             {
  286.                 play("running", false);
  287.                 facing = LEFT;
  288.             }
  289.             else if ( FlxG.keys.RIGHT || FlxG.keys.D )
  290.             {
  291.                 play("running", false);
  292.                 facing = RIGHT;
  293.             }
  294.             else
  295.             {
  296.                 play("normal", true);
  297.             }
  298.            
  299.            
  300.         }
  301.        
  302.         private function cameraFollow():void
  303.         {
  304.             FlxG.follow(this, 0.1);
  305.             FlxG.followBounds(x - FlxG.width / 8, y - FlxG.height / 8, x + FlxG.width / 8, y + FlxG.height / 8);
  306.         }
  307.        
  308.         override public function update():void
  309.         {
  310.             super.update();
  311.             cameraFollow();
  312.             setAnimation();
  313.  
  314.         }
  315.        
  316.     }
  317.  
  318. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement