Permalink
Browse files

Spawn sprite addition

  • Loading branch information...
Colin Farrell
Colin Farrell committed Jan 29, 2012
1 parent efb8327 commit 5ad549b9515a2cc800ea636a612c4c43642e9983
Showing with 68 additions and 9 deletions.
  1. +16 −5 src/PlayState.as
  2. +34 −4 src/Player.as
  3. +18 −0 src/PlayerSpawn.as
View
@@ -80,6 +80,7 @@ package
private var player:Player;
private var exit:Exit;
+ private var exitTransition:Boolean;
protected var trees:FlxGroup;
public var canopies:FlxGroup;
protected var explosions:FlxGroup;
@@ -195,7 +196,7 @@ package
//endLevel=false;
ambientPlayback.loadEmbedded(ambientSound, true);
ambientPlayback.play();
-
+ FlxG.flash(0xFFFFFF,1);
}
@@ -223,20 +224,30 @@ package
if (levelId>levels.length-1)
{
- OnEndGame();
+ //fade for second before End screen
+ FlxG.fade(0xFFFFFFFF,1,OnEndGame);
}
else
{
- //FlxG.camera.fade(0xff000000,1,OnEndLevelFade);
- FlxG.switchState(new SummaryState(levelId, statsTracker));
+ //set flag to prevent exit collision being detected multiple times when fading
+ exitTransition = true;
+ //fade for second before summary screen
+ FlxG.fade(0xFFFFFFFF,1,switchToSummary);
}
}
+
+ public function switchToSummary():void
+ {
+
+ FlxG.switchState(new SummaryState(levelId, statsTracker));
+ }
public function OnEndLevelFade():void
{
FlxG.camera.fade(0xFFFFFFFF,1,OnStartFadeDone,true);
}
+
public function OnStartFadeDone():void
{
OnStartLevel();
@@ -529,7 +540,7 @@ package
FlxG.collide(player, pickups);
//If we have hit the exit
- if(player.overlaps(exit))
+ if(player.overlaps(exit) && !exitTransition)
{
//FlxG.switchState(new MenuState());
OnEndLevel();
View
@@ -21,6 +21,9 @@ package
protected var keyboardInputEnabled:Boolean;
public var treeToClimb:Tree;
public var canClimb:Boolean;
+ protected var spawnSprite:PlayerSpawn;
+ protected var spawning:Boolean;
+ protected var spawnTimer: Number;
private var jumpSpeed : Number;
private var runSpeed : Number;
@@ -50,6 +53,7 @@ package
spawnY = closestTilePos(Y) + 31;
loadGraphic(ImgSpaceman,true,true,32,64);
_restart = 0;
+ spawnTimer = 0;
canClimb = false;
keyboardInputEnabled = true;
@@ -114,16 +118,42 @@ package
public function respawn():void
{
-
+ // spawnTimer = new FlxTimer();
x = spawnX;
- y = spawnY;
+ y = spawnY ;
+
+ respawnAnimation();
+ spawnTimer += FlxG.elapsed;
+ if(spawnTimer > 1.8)
+ {
+ respawnCharacter();
+ }
+ }
+
+ public function respawnAnimation():void
+ {
+ //spawn animation
+ if (!spawning)
+ {
+ spawning = true;
+ spawnSprite = new PlayerSpawn(spawnX -48,spawnY-48);
+ FlxG.state.add(spawnSprite);
+ spawnSprite.play("spawn");
+ }
+ }
+
+ public function respawnCharacter():void
+ {
+ spawning = false;
alive = true;
+ solid = true;
exists = true;
visible = true;
- solid = true;
+ FlxG.play(spawnInSound);
velocity.y = -400;
_restart = 0;
- FlxG.play(spawnInSound);
+ spawnTimer = 0;
+ FlxG.state.remove(spawnSprite);
}
override public function destroy():void
View
@@ -0,0 +1,18 @@
+package
+{
+ import org.flixel.*;
+
+ public class PlayerSpawn extends FlxSprite
+ {
+
+ [Embed(source="../assets/char_SpawnIN.png")] protected var ImgSpawn:Class;
+
+
+ public function PlayerSpawn(X:Number=0, Y:Number=0)
+ {
+ super(X, Y);
+ loadGraphic(ImgSpawn,true,true,128, 128);
+ addAnimation("spawn", [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,30,31], 18);
+ }
+ }
+}

0 comments on commit 5ad549b

Please sign in to comment.