Skip to content
Browse files

merge portal

  • Loading branch information...
2 parents 03c007a + fc65740 commit e20e71cd9db7669d3cd454537f4f26b0345d5049 @thebluber committed Apr 19, 2012
Showing with 45 additions and 22 deletions.
  1. +5 −0 PlayState.as
  2. +4 −8 Portal.as
  3. +36 −14 Snake.as
View
5 PlayState.as
@@ -152,5 +152,10 @@ package {
} while(egg.overlaps(_snake));
_food.add(egg);
}
+
+ override public function destroy():void {
+ remove(_snake.tailCam);
+ super.destroy();
+ }
}
}
View
12 Portal.as
@@ -14,37 +14,33 @@ package {
} else {
loadGraphic(RedP, true, false, 32, 32);
};
- offset.x = 11;
- offset.y = 11;
width = 10;
height = 10;
+ offset.x = 11;
+ offset.y = 11;
addAnimation('twinkle', [0,1,2,3], 3);
}
public function teleport(snake:Snake, portal2:Portal):void{
- snake.head.reset(portal2.x, portal2.y);
-
+ snake.nextPos = new FlxPoint(portal2.x, portal2.y);
+
switch(snake.head.facing){
case FlxObject.DOWN:
snake.head.facing = FlxObject.UP;
- snake.head.play('up');
break;
case FlxObject.UP:
snake.head.facing = FlxObject.DOWN;
- snake.head.play('down');
break;
case FlxObject.RIGHT:
snake.head.facing = FlxObject.LEFT;
- snake.head.play('left');
break;
case FlxObject.LEFT:
snake.head.facing = FlxObject.RIGHT;
- snake.head.play('right');
break;
}
View
50 Snake.as
@@ -16,6 +16,7 @@ package {
private var _lives:int = 3;
private var _previousFacing:uint = FlxObject.RIGHT;
private var _tailCam:FlxCamera;
+ private var _nextPos:FlxPoint = null;
public function Snake(movesPerSecond:Number = 1) {
super();
@@ -48,6 +49,10 @@ package {
return _tailCam;
}
+ public function set nextPos(pos:FlxPoint):void {
+ _nextPos = pos;
+ }
+
public function checkCombos():Array {
var combos:Array = [[_body.members[0]]];
var currentType:int = 0;
@@ -234,8 +239,14 @@ package {
break;
}
- _head.x += xSpeed;
- _head.y += ySpeed;
+ if(_nextPos) {
+ _head.x = _nextPos.x;
+ _head.y = _nextPos.y;
+ _nextPos = null;
+ } else {
+ _head.x += xSpeed;
+ _head.y += ySpeed;
+ }
}
@@ -248,29 +259,40 @@ package {
if(FlxG.keys.UP && _previousFacing != FlxObject.DOWN){
_head.facing = FlxObject.UP;
- _head.offset.x = 4;
- _head.offset.y = 15;
- _head.play('up');
} else
if(FlxG.keys.DOWN && _previousFacing != FlxObject.UP){
_head.facing = FlxObject.DOWN;
- _head.offset.x = 4;
- _head.offset.y = 0;
- _head.play('down');
} else
if(FlxG.keys.RIGHT && _previousFacing != FlxObject.LEFT){
_head.facing = FlxObject.RIGHT;
- _head.offset.x = 0;
- _head.offset.y = 15;
- _head.play('right');
} else
if(FlxG.keys.LEFT && _previousFacing != FlxObject.RIGHT){
_head.facing = FlxObject.LEFT;
- _head.offset.x = 15;
- _head.offset.y = 15;
- _head.play('left');
}
+ switch(_head.facing) {
+ case FlxObject.UP:
+ _head.offset.x = 4;
+ _head.offset.y = 15;
+ _head.play('up');
+ break;
+ case FlxObject.DOWN:
+ _head.offset.x = 4;
+ _head.offset.y = 0;
+ _head.play('down');
+ break;
+ case FlxObject.RIGHT:
+ _head.offset.x = 0;
+ _head.offset.y = 15;
+ _head.play('right');
+ break;
+ case FlxObject.LEFT:
+ _head.offset.x = 15;
+ _head.offset.y = 15;
+ _head.play('left');
+ break;
+ }
+
_timer += FlxG.elapsed;
if(_timer >= _speed){
if(alive){

0 comments on commit e20e71c

Please sign in to comment.
Something went wrong with that request. Please try again.