Skip to content

Commit

Permalink
merging
Browse files Browse the repository at this point in the history
  • Loading branch information
Jiayi Zheng committed May 11, 2012
2 parents d1cafda + 52c1f82 commit 4ca0b21
Show file tree
Hide file tree
Showing 11 changed files with 131 additions and 3 deletions.
3 changes: 2 additions & 1 deletion DebugState.as
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ package {
["Level End", switcher(SwitchLevel)],
["Intro Movie", switcher(MovieState)],
["Unlock Levels", function():void{SaveGame.unlockLevels();}],
["Lock Levels", function():void{SaveGame.initializeData();}]
["Lock Levels", function():void{SaveGame.initializeData();}],
["Tweening test", switcher(TweenTestState)]
]
var btn:AxButton;
var pos:int = 100;
Expand Down
2 changes: 2 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
This code is © 2012 by Roger Braun and Jiayi Zheng.
All art assets are © 2012 by Henrik Haberman and Tim Schierbaum.

GTween (http://gskinner.com/libraries/gtween/) is licensed under a MIT License.

The code and art assets are not free to use. You can read, modify and compile them for your personal or educational use, but you can't redistribute any modified code, assets or resulting binaries.

We want other people to be able to learn from this code and see how we did it. Have fun!
11 changes: 11 additions & 0 deletions LevelState.as
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ package {
protected var _switchLevel:SwitchLevel;
protected var _particles:AxGroup;

protected var _shownDeathScreen:Boolean = false;

override public function create():void {
super.create();

Expand Down Expand Up @@ -233,6 +235,15 @@ package {

if(_snake.lives <= 0) {
levelOver();
} else if(_snake.alive) {
_shownDeathScreen = false;
} else {
if(_shownDeathScreen) {
_snake.resurrectNext = true;
} else {
_shownDeathScreen = true;
Ax.pushState(new SnakeDeath);
}
}

doCombos();
Expand Down
2 changes: 1 addition & 1 deletion MenuState.as
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ package {

private function switchToState(state:Class):Function {
return function ():void {
Ax.pushState(new state);
Ax.switchState(new state);
}
}

Expand Down
3 changes: 3 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
To compile:

mxmcl -library-path+=lib Main.as
11 changes: 10 additions & 1 deletion Snake.as
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package {
//private var _bling:FlxSound = new FlxSound;
private var _justAte:Boolean = false;
private var _alive:Boolean;
private var _resurrect:Boolean = false;

private var _startMps:Number;
private var _emoLevel:int;
Expand Down Expand Up @@ -77,6 +78,14 @@ package {
_alive = b;
}

public function get resurrectNext():Boolean {
return _resurrect;
}

public function set resurrectNext(b:Boolean):void {
_resurrect = b;
}

public function get tail():AxSprite {
return _tail;
}
Expand Down Expand Up @@ -369,7 +378,7 @@ package {
die();
}
move();
} else {
} else if(_resurrect) {
resurrect();
}
_timer -= _speed;
Expand Down
35 changes: 35 additions & 0 deletions SnakeDeath.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package {
import org.axgl.*;
import org.axgl.text.*;
import org.axgl.input.*;
import org.humoralpathologie.axgleffects.*;
public class SnakeDeath extends AxState {
// TODO: Use better image
[Embed(source='assets/images/introsnake.png')] protected var sadSnake:Class;
private var _timer:Number = 0;
private var _addedText:Boolean = false;

override public function create():void {
var fsprite:FloodFilledSprite = new FloodFilledSprite(0,0,sadSnake,8);
fsprite.x = (640 - fsprite.width) / 2;

add(fsprite);
}

override public function update():void {
super.update();
_timer += Ax.dt;
if(_addedText) {
if(Ax.keys.pressed(AxKey.SPACE)) {
Ax.popState();
}
} else if(_timer >= 2) {
var text:AxText = new AxText(0,350,null, "PRESS SPACE", 640 / 4, 'center');
text.scale.x = 4;
text.scale.y = 4;
add(text);
_addedText = true;
}
}
}
}
16 changes: 16 additions & 0 deletions TweenTestState.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package {
import org.axgl.*;
import com.gskinner.motion.*;
import com.gskinner.motion.easing.*;

public class TweenTestState extends AxState {
override public function create():void {
var testsprite:AxSprite = new AxSprite(20,20);
testsprite.create(20,20,0xff00ff00);
add(testsprite);
GTweener.to(testsprite,2,{x: 500, y:400},{ease:Exponential.easeInOut});
GTweener.to(testsprite.scale,2,{x: 4, y:3},{ease:Sine.easeInOut});
GTweener.to(testsprite,1,{alpha: 0.5});
}
}
}
Binary file added assets/images/introsnake.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added lib/GTween_V2_01.swc
Binary file not shown.
51 changes: 51 additions & 0 deletions org/humoralpathologie/axgleffects/FloodFilledSprite.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package org.humoralpathologie.axgleffects {
import org.axgl.*;
import flash.display.BitmapData;
import flash.display.Bitmap;
import flash.geom.Point;
import flash.geom.Rectangle;

public class FloodFilledSprite extends AxSprite {

private var _canvas:BitmapData;
private var _fullImage:BitmapData;
private var _currY:int;
private var _step:int = 1;

public function FloodFilledSprite(x:Number, y:Number, resource:*, step:int = 1) {
super(x,y);
_step = step;

if (resource is Class) {
_fullImage = (new resource() as Bitmap).bitmapData;
} else if (resource is BitmapData) {
_fullImage = resource;
} else {
throw new Error("Invalid resource:", resource);
}

_canvas = new BitmapData(_fullImage.width, _fullImage.height, true, 0x00000000);
_currY = 0;
load(_canvas);
}

override public function update():void {

for(var j:int = 0; j < _step; j++){
if(_currY + 1 < height) {
var r:Rectangle;
var p:Point = new Point(0,0);
r = new Rectangle(0,height - (_currY + 1),width,1);
for(var i:int = 0; i <= height - _currY; i++) {
p.y = i;
_canvas.copyPixels(_fullImage,r,p);
}
_currY++;
load(_canvas);
}
}

super.update();
}
}
}

0 comments on commit 4ca0b21

Please sign in to comment.