Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package
- {
- import costumes.JoeAverage;
- import org.flixel.FlxGroup;
- import org.flixel.FlxSprite;
- import org.flixel.FlxState;
- import org.flixel.FlxSave;
- import org.flixel.FlxTilemap;
- import org.flixel.FlxG;
- import org.flixel.FlxU;
- /**
- * ...
- * @author Kristian Macanga
- */
- public class PlayState extends FlxState
- {
- [Embed(source = "/data/joeaverage.png")] private var ImgJoeAvg:Class;
- [Embed(source = "data/bakWall.png")] private var ImgBWall:Class;
- [Embed(source = "data/bakBlue.png")] private var ImgBBlue:Class;
- [Embed(source = "data/bakBrown.png")] private var ImgBBrown:Class;
- [Embed(source = "data/bakDesert.png")] private var ImgBDesert:Class;
- [Embed(source = "data/tiles.png")] private var ImgTiles:Class;
- private var playerGroup:PlayerGroup;
- private var player:Player;
- override public function create():void
- {
- super.create();
- addLayers();
- setLevel(1);
- setBackground(1);
- addPlayer();
- }
- private function addLayers():void
- {
- Global.backLayer = new FlxGroup();
- Global.spriteLayer = new FlxGroup();
- Global.HUDLayer = new FlxGroup();
- this.add(Global.backLayer);
- this.add(Global.spriteLayer);
- this.add(Global.HUDLayer);
- }
- private function setBackground(chapter:int):void
- {
- var tileGraphic:Class;
- switch ( chapter )
- {
- case 1 :
- {
- tileGraphic = ImgBWall;
- break;
- }
- case 2 :
- {
- tileGraphic = ImgBBlue;
- break;
- }
- case 3 :
- {
- tileGraphic = ImgBBrown;
- break;
- }
- case 4 :
- {
- tileGraphic = ImgBDesert;
- break;
- }
- default :
- {
- tileGraphic = ImgBWall;
- }
- }
- if (Global.background != null)
- {
- Global.backLayer.remove(Global.background, true);
- }
- Global.background = new Background(tileGraphic);
- Global.backLayer.add(Global.background);
- }
- private function setLevel( level:int ):void
- {
- if (Global.tileMap != null )
- {
- Global.spriteLayer.remove(Global.tileMap, true);
- }
- Global.tileMap = new FlxTilemap();
- Global.tileMap.drawIndex = 1;
- Global.tileMap.loadMap(Global.levelTiles[level - 1], ImgTiles, 16);
- Global.tileMap.collideIndex = 1;
- Global.spriteLayer.add(Global.tileMap);
- Global.spriteLayer.add(player);
- }
- private function addPlayer():void
- {
- new PlayerGroup();
- }
- override public function update():void
- {
- super.update();
- FlxU.collide(PlayerGroup.player, Global.tileMap);
- }
- }
- }
- package
- {
- import costumes.JoeAverage;
- import costumes.Mazkirov;
- import org.flixel.FlxSprite;
- import org.flixel.FlxGroup;
- import org.flixel.FlxG;
- import pixelperfectoverlap.HitTest;
- import org.flixel.FlxSprite;
- /**
- * ...
- * @author Kristian Macanga
- */
- public class PlayerGroup extends FlxSprite
- {
- private const MOVE_SPEED:int = 100;
- private const JUMP_STRENGTH:int = 140;
- public static var player:Player;
- private var equippedWeapon:Weapon;
- private var backWeapon:Weapon;
- public function PlayerGroup()
- {
- super();
- alpha = 0;
- Global.spriteLayer.add(this);
- player = new Mazkirov();
- }
- private function movePlayer():void
- {
- if ( FlxG.keys.LEFT || FlxG.keys.A )
- {
- player.velocity.x = ( -1) * MOVE_SPEED;
- player.facing = FlxSprite.LEFT;
- }
- else if ( FlxG.keys.RIGHT || FlxG.keys.D )
- {
- player.velocity.x = MOVE_SPEED;
- player.facing = FlxSprite.RIGHT;
- }
- else
- {
- player.velocity.x = 0;
- }
- }
- private function playerJump():void
- {
- if ( ( FlxG.keys.UP || FlxG.keys.W ) && player.velocity.y == 0 )
- {
- player.velocity.y = - JUMP_STRENGTH;
- }
- }
- private function adjustJumpAnimation():void
- {
- if ( Math.abs(velocity.y) > 10)
- {
- }
- }
- private function switchWeapon():void
- {
- }
- /*private function changeWeapon(weapon:Weapon)
- {
- equippedWeapon.x = weapon.x;
- equippedWeapon.y = weapon.y;
- this.remove(equippedWeapon);
- equippedWeapon = weapon;
- add(equippedWeapon);
- }
- /*private function pickUpWeapon():void
- {
- if ( FlxG.keys.DOWN || FlxG.keys.S )
- {
- for each( var pickUp:Weapon in Global.pickUps)
- {
- if (HitTest.complexHitTestObject(player.mask,pickUp.mask,6))
- {
- changeWeapon(pickUp);
- }
- }
- }
- }*/
- override public function update():void
- {
- movePlayer();
- playerJump();
- //setEquipVelocity();
- super.update();
- adjustJumpAnimation();
- //pickUpWeapon();
- }
- }
- }
- package
- {
- import org.flixel.FlxSprite;
- import pixelperfectoverlap.FlxSpriteEx;
- import org.flixel.FlxG;
- /**
- * ...
- * @author Kristian Macanga
- */
- public class Player extends FlxSpriteEx
- {
- private const GRAVITY:int = 200;
- protected var flm:int = 0;
- protected var name:String = "";
- protected var msg:String = "";
- protected var boost:Boolean = false;
- protected var pack:Boolean = false;
- protected var rightFace:int = 1;
- protected var ammo:int = 0;
- protected var backAmmo:int = 0;
- protected var canShoot:Boolean = true;
- protected var pHealth:int = 50;
- protected var life:int = 3;
- protected var char:int = 0;
- protected var jumpPower:int = 100;
- protected var runSpeed:int = 100;
- protected var swimSpeed:int = 100;
- protected var special:String = "";
- public function Player(costume:Class)
- {
- super(200, 150);
- loadGraphic(costume, true, true);
- setOrigin(0, 0);
- addAnimation("normal", [0]);
- addAnimation("jumping", [1]);
- addAnimation("midAir", [2]);
- addAnimation("falling", [3]);
- addAnimation("running", [4, 5, 6, 7, 8], 15, true);
- play("normal", true);
- Global.spriteLayer.add(this);
- acceleration.y = GRAVITY;
- }
- private function setAnimation():void
- {
- if ( FlxG.keys.LEFT || FlxG.keys.A )
- {
- play("running", false);
- facing = LEFT;
- }
- else if ( FlxG.keys.RIGHT || FlxG.keys.D )
- {
- play("running", false);
- facing = RIGHT;
- }
- else
- {
- play("normal", true);
- }
- }
- private function cameraFollow():void
- {
- FlxG.follow(this, 0.1);
- FlxG.followBounds(x - FlxG.width / 8, y - FlxG.height / 8, x + FlxG.width / 8, y + FlxG.height / 8);
- }
- override public function update():void
- {
- super.update();
- cameraFollow();
- setAnimation();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement