Permalink
Browse files

it works

  • Loading branch information...
1 parent bde0f1c commit 03c54da37fe3b2faeb48fc134568885ac2b3ec3c @rogerbraun rogerbraun committed Apr 10, 2012
Showing with 32 additions and 34 deletions.
  1. +1 −1 .FW.pid.7b306ddc9b88493d708178fcf07cd53f
  2. BIN Main.swf
  3. +8 −12 PlayState.as
  4. +21 −21 Snake.as
  5. +2 −0 org/flixel/FlxObject.as
@@ -1 +1 @@
-10891
+21650
View
BIN Main.swf
Binary file not shown.
View
@@ -64,11 +64,15 @@ package {
override public function update():void {
super.update();
+ if(_snake.lives == 0) {
+ FlxG.score = _score;
+ FlxG.switchState(new GameOver);
+ }
+
+ updateHud();
+
FlxG.overlap(_snake.head, _food, eat);
FlxG.collide(_snake.head, _level, hitBoundary);
- if(_snake.alive){
- FlxG.collide(_snake.head, _snake.body, hitBoundary);
- }
}
private function eat(snakeHead:FlxSprite, food:FlxSprite):void {
@@ -80,19 +84,11 @@ package {
_snake.faster();
_snake.swallow();
_score++;
- updateHud();
}
private function hitBoundary(snakeHead:FlxObject, tile:FlxObject):void {
FlxG.log("Hitting at " + tile.x + ", " + tile.y);
- if(_snake.lives == 0) {
- FlxG.score = _score;
- FlxG.switchState(new GameOver);
- }
- else {
- _snake.die();
- updateHud();
- }
+ _snake.die();
}
private function randomPlace(food:FlxSprite):void{
View
@@ -124,30 +124,30 @@ package {
override public function update():void {
super.update();
+ if(FlxG.keys.UP){
+ _head.facing = FlxObject.UP;
+ } else
+ if(FlxG.keys.DOWN){
+ _head.facing = FlxObject.DOWN;
+ } else
+ if(FlxG.keys.RIGHT){
+ _head.facing = FlxObject.RIGHT;
+ } else
+ if(FlxG.keys.LEFT){
+ _head.facing = FlxObject.LEFT;
+ }
- if(alive) {
- if(FlxG.keys.UP){
- _head.facing = FlxObject.UP;
- } else
- if(FlxG.keys.DOWN){
- _head.facing = FlxObject.DOWN;
- } else
- if(FlxG.keys.RIGHT){
- _head.facing = FlxObject.RIGHT;
- } else
- if(FlxG.keys.LEFT){
- _head.facing = FlxObject.LEFT;
- }
-
- _timer += FlxG.elapsed;
-
- if(_timer >= _speed){
+ _timer += FlxG.elapsed;
+ if(_timer >= _speed){
+ if(alive){
+ if(_head.overlaps(_body)){
+ die();
+ }
move();
- _timer -= _speed;
+ } else {
+ resurrect();
}
- }
- if(!alive){
- resurrect();
+ _timer -= _speed;
}
}
}
View
@@ -687,6 +687,7 @@ package org.flixel
var results:Boolean = false;
var i:uint = 0;
var members:Array = (ObjectOrGroup as FlxGroup).members;
+ var length:uint = (ObjectOrGroup as FlxGroup).length;
while(i < length)
{
if(overlaps(members[i++],InScreenSpace,Camera))
@@ -738,6 +739,7 @@ package org.flixel
var basic:FlxBasic;
var i:uint = 0;
var members:Array = (ObjectOrGroup as FlxGroup).members;
+ var length:uint = (ObjectOrGroup as FlxGroup).length;
while(i < length)
{
if(overlapsAt(X,Y,members[i++],InScreenSpace,Camera))

0 comments on commit 03c54da

Please sign in to comment.