Skip to content
Browse files

first attempt at first level. Mikey can go up stairs, woo!

  • Loading branch information...
1 parent 8a0499e commit 6ae79d76454e2c0ec7ff553763396f13c1e34e6b @tamagokun committed Apr 7, 2012
View
27 app/Level.as
@@ -0,0 +1,27 @@
+package
+{
+ import org.flixel.*;
+
+ public class Level
+ {
+ public var bricks:FlxGroup;
+ public var ladders:FlxGroup;
+
+ public function Level():void {
+ bricks = new FlxGroup();
+ ladders = new FlxGroup();
+ }
+
+ public function create():void
+ {
+
+ }
+
+ public function place_item(X:int,Y:int,Graphic:Class,Group:FlxGroup):FlxSprite
+ {
+ var item:FlxSprite = new FlxSprite(X,Y,Graphic);
+ Group.add(item);
+ return item;
+ }
+ }
+}
View
39 app/PlayState.as
@@ -2,27 +2,33 @@ package
{
import org.flixel.*;
import elements.*;
+ import levels.*;
public class PlayState extends FlxState
{
- public var level:FlxTilemap;
//public var exit:FlxSprite;
+ public var level:*;
public var barrels:FlxGroup;
- public var mikey:FlxSprite;
+ public var mikey:Mikey;
public var score:FlxText;
public var time:FlxText;
- [Embed(source="../assets/brick.gif")] private var ImgBrick:Class;
-
override public function create():void
{
//level init stuff
+ level = new Level1() as Level1;
+ add(level.bricks);
+ add(level.ladders);
+ if(level.stairs) add(level.stairs);
+ level.create();
- level = new FlxTilemap();
- //level.loadMap();
- add(level);
-
+ //create mikey!
+ mikey = new Mikey();
+ add(mikey);
+ barrels = new FlxGroup();
+ add(barrels);
+ //create_barrel(0,0);
}
public function create_barrel(X:uint,Y:uint):void
@@ -35,19 +41,28 @@ package
{
super.update();
- FlxG.overlap(barrels, mikey, touch_barrel);
+ //FlxG.overlap(barrels, mikey, touch_barrel);
//FlxG.overlap(exit, mikey, win);
- FlxG.collide(level,mikey);
+ FlxG.collide(level.bricks, mikey);
+ FlxG.collide(level.bricks, barrels);
+ if(level.stairs) FlxG.overlap(level.stairs, mikey, handle_stairs);
- if(mikey.y > FlxG.height)
+ /*if(mikey.y > FlxG.height)
{
FlxG.score = 1; //sets status.text to "Aww, you died!"
FlxG.resetState();
- }
+ }*/
}
+ public function handle_stairs(Brick:FlxSprite, Mikey:FlxSprite):void
+ {
+ if(Mikey.isTouching(FlxObject.FLOOR))
+ if(Mikey.y + Mikey.height > Brick.y) Mikey.y = Brick.y - Mikey.height;
+ FlxObject.separateY(Brick,Mikey);
+ }
+
public function touch_barrel(Barrel:FlxSprite,Mikey:FlxSprite):void
{
//Barrel.kill();
View
12 app/elements/Mikey.as
@@ -1,12 +1,22 @@
package elements
{
+ import org.flixel.*;
+
public class Mikey extends FlxSprite
{
[Embed(source="../../assets/mikey.gif")] private var ImgMikey:Class;
public function Mikey():void
{
super(0,0,ImgMikey);
+
+ x = 50;
+
+ var run_speed:uint = 80;
+ drag.x = run_speed * 8;
+ acceleration.y = 420;
+ maxVelocity.x = run_speed;
+ maxVelocity.y = 200;
}
override public function update():void
@@ -20,8 +30,6 @@ package elements
velocity.y = -maxVelocity.y/2;
super.update();
-
-
}
}
}
View
79 app/levels/Level1.as
@@ -0,0 +1,79 @@
+package levels
+{
+ import org.flixel.*;
+
+ public class Level1 extends Level
+ {
+ public var stairs:FlxGroup;
+
+ [Embed(source="../../assets/brick.png")] private var ImgBrick:Class;
+ [Embed(source="../../assets/ladder.png")] private var ImgLadder:Class;
+
+ public function Level1():void
+ {
+ super();
+ stairs = new FlxGroup();
+ }
+
+ override public function create():void
+ {
+ //bottom
+ create_row(8,224,15);
+ create_stairs(128,223,5);
+
+ create_stairs(216,188,9,false,true);
+
+ create_stairs(32,158,9,true,true);
+
+ create_stairs(216,128,9,false,true);
+
+ create_stairs(32,98,9,true,true);
+
+ create_stairs(216,68,4,false);
+
+ place_ladder(10,10,2);
+
+ //top
+ create_row(16,64,14);
+ create_row(104,40,6);
+ }
+
+ public function create_row(X:uint,Y:uint,count:uint):void
+ {
+ var i:uint = 0;
+ for(i; i < count; i++) place_brick(X+i*8,Y);
+ }
+
+ public function create_stairs(X:int,Y:int,count:int,right:Boolean=true,shorten_last:Boolean=false):void
+ {
+ var i:uint = 0;
+ var j:uint = 0;
+ var x_offset:int = 0;
+ var y_offset:int = 0;
+ for(i; i < count; i++)
+ {
+ var length:int = shorten_last && i+1==count? 2 : 3;
+ for(j = 0; j < length; j++)
+ {
+ var brick:FlxSprite = place_item(X+x_offset,Y+y_offset,ImgBrick,stairs);
+ brick.immovable = true;
+ x_offset += right? brick.width : -brick.width;
+ }
+ y_offset -= 1;
+ }
+ }
+
+ public function place_brick(X:int,Y:int):void
+ {
+ var brick:FlxSprite = place_item(X,Y,ImgBrick,bricks);
+ brick.immovable = true;
+ }
+
+ public function place_ladder(X:int,Y:int,height:int):void
+ {
+ var ladder:FlxSprite = place_item(X,Y,ImgLadder,ladders);
+ var i:uint = 0;
+ for(i; i < height; i++) ladder.stamp(ladder,0,i*8);
+ }
+ }
+}
View
BIN assets/brick.gif
Deleted file not rendered
View
BIN assets/brick.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN assets/ladder.gif
Deleted file not rendered
View
BIN assets/ladder.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
61 vendor/Console.as
@@ -0,0 +1,61 @@
+package
+{
+ import flash.display.Sprite;
+ import flash.events.ErrorEvent;
+ //import flash.events.UncaughtErrorEvent;
+ import flash.external.ExternalInterface;
+
+ public class Console extends Sprite
+ {
+ public function Console():void
+ {
+ super();
+ init();
+ }
+
+ public static function log(... arguments):void
+ {
+ Console.trace(arguments);
+ }
+
+ public static function warn(... arguments):void
+ {
+ Console.trace(arguments, "warn");
+ }
+
+ public static function error(... arguments):void
+ {
+ Console.trace(arguments, "error");
+ }
+
+ private static function trace(args:Object,type:String = "log"):void
+ {
+ for(var i:String in args)
+ {
+ if( !args[i] is String)
+ args[i] = args[i].toString();
+ ExternalInterface.call("console."+type,args[i]);
+ if( type == "log") trace(args[i]);
+ }
+ }
+
+ private function init():void
+ {
+ //if(loaderInfo.hasOwnProperty("uncaughtErrorEvents"))
+ //loaderInfo.uncaughtErrorEvents.addEventListener(UncaughtErrorEvent.UNCAUGHT_ERROR, uncaughtErrorHandler, false, 0, true);
+ }
+
+ /*private function uncaughtErrorHandler(e:UncaughtErrorEvent):void
+ {
+ if( e.error is Error)
+ {
+ var stack:String = Error(e.error).getStackTrace();
+ Console.error(Error(e.error).message + ((stack!=null)? "\n"+stack : ""));
+ }
+ else if( e.error is ErrorEvent)
+ Console.error(ErrorEvent(e.error).text);
+ else
+ Console.error(e.error.toString());
+ }*/
+ }
+}

0 comments on commit 6ae79d7

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