Talking about Actionscript 3, Flash and Game development.
FlashPunk is a free ActionScript 3 library designed for developing 2D Flash games.
On the official site Chevy Ray Johnston, the author, says this framework is designed for use with the free Flex framework, used for building Flash applications; by combining this with a code editor such as FlashDevelop or Flash Builder, you can import the FlashPunk library and develop games without the need of the official Flash IDE.
And if you look at the forums, you’ll see there are some threads asking for a way to use FlashPunk with the official ID. And they are right! You paid some thousands dollars for your Flash environment, and you expect you can use it with any kind of 3rd party framework.
The following example is the old classic “tap arrow keys to move a ball” you already seen with AS2, AS3, Box2D and HTML5.
It has been entirely created with the Flash IDE and features the official splash screen. Uh, and a Bob sprite ripped somewhere.
The script is quite simple as it’s a mix between the official basic tutorial and the ball game prototype.
This is the main class:
package {
import splash.Splash;
import net.flashpunk.Engine;
import net.flashpunk.FP;
public class punk extends Engine {
public function punk() {
super(640, 480, 60, false);
}
override public function init():void {
var s:Splash=new Splash ;
FP.world.add(s);
s.start(on_splash_completed);
}
public function on_splash_completed():void {
FP.world=new the_world;
}
}
}
this is the_world
class:
package {
import net.flashpunk.World;
public class the_world extends World {
public function the_world() {
add(new the_player);
}
}
}
and finally the_player
class:
package {
import net.flashpunk.Entity;
import net.flashpunk.graphics.Image;
import net.flashpunk.utils.Input;
import net.flashpunk.utils.Key;
public class the_player extends Entity {
private const power:Number=0.2;
private const friction:Number=0.99;
private var xspeed:Number=0;
private var yspeed:Number=0;
[Embed(source='assets/player.png')]
private const PLAYER:Class;
public function the_player() {
graphic=new Image(PLAYER);
x=320;
y=240;
}
override public function update():void {
if (Input.check(Key.LEFT)) {
xspeed-=power;
}
if (Input.check(Key.RIGHT)) {
xspeed+=power;
}
if (Input.check(Key.UP)) {
yspeed-=power;
}
if (Input.check(Key.DOWN)) {
yspeed+=power;
}
xspeed*=friction;
yspeed*=friction;
x+=xspeed;
y+=yspeed;
}
}
}
and this is the result:
You may need to reload the page to see the splash screen. Then you can move Bob with arrow keys.
Download the source code. I can add more feature to the prototype and make a more detailed tutorial if I receive a good feedback.
Never miss an update! Subscribe, and I will bother you by email only when a new game or full source code comes out.