flash punk 101

I've been playing recently with Chevy Ray's FlashPunk library, which can be found here. It's a 2d game library built on the premise of bitmapped data for all the speed and performance benefits that comes with using bitmaps versus vector data. It has some neat little built in features which are perfect for platform style or arcade style 2d games, like collision detection, scrolling backgrounds, sprite mapping, and more. They have some nice forums up, but I thought I'd do a little quick intro to how you can get started playing with it and making games.

first you need your base engine class which is provided

[code lang="actionscript"]
package
{
import punk.core.*;
import punk.util.*;
import punk.*;
[SWF(width = "1000", height = "500")]
public class Main extends Engine
{
public function Main()
{
showSplash(0x000000, 0xFFFFFF, .1, false);
super(500, 250, 60, 2, Menu);
}
}
}
[/code]

this is all very basic, but the showSplash() method displays the flashpunk splash screen, this is optional. the super() method is describing your engine's dimensions: 500×250, frames per second: 60, scale: 2 (i like a little pixelation), and the initial World class that will be launching the game: Menu. I have it launching menu as a world so that I can display my menu or splash screen before continuing on to the game.

now you need a world

[code lang="actionscript"]

package
{
import punk.core.World;
import punk.core.Entity;
import punk.Acrobat;
import punk.Backdrop;
import Space;
import punk.Text;
import punk.util.Input;
import punk.util.Key;
import punk.Text;
import punk.Actor;
import flash.geom.Point;
public class Menu extends World
{
[Embed(source = 'data/splash.png')] private var splashScreen:Class;
public function Menu():void
{
}
override public function init():void
{
Input.define("fire", Key.SPACE);
var t:Text = new Text("PRESS [SPACE] TO START");
t.x = FP.screen.width/2;
t.y = FP.screen.height/2;
t.center();
t.color = 0xFFFFFF;
add(t);
var bg:Actor = new Actor()
bg.sprite = FP.getSprite(splashScreen, 500, 250);
add(bg);
}
override public function update():void
{
if (Input.check("fire"))
{
var space:Space = new Space()
FP.goto = space;
}
}
}
}
[/code]

so what we're doing here is making a custom splash screen, with 3 important things going on. note you don't do anything in the world constructor, only in the override for the init method. we add an input listener for the spacebar, add text telling the user to press the spacebar, and add a background image to make it look all pretty. then in the update method when the spacebar is hit we switch worlds to the class that extends our game world.

that's the basics, you would then create another class that extends world, in my example above it is called Space. Then you can add Entities, Actors and Acrobats, which are all elements of your game and animate them by performing tasks in the World's or their own update methods. and soon enough you'll have something resembling a game!