Basic FlashPunk game prototype using Flash IDE

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.

Get the most popular Phaser 3 book

Through 202 pages, 32 source code examples and an Android Studio project you will learn how to build cross platform HTML5 games and create a complete game along the way.

Get the book

215 GAME PROTOTYPES EXPLAINED WITH SOURCE CODE
// 1+2=3
// 100 rounds
// 10000000
// 2 Cars
// 2048
// A Blocky Christmas
// A Jumping Block
// A Life of Logic
// Angry Birds
// Angry Birds Space
// Artillery
// Astro-PANIC!
// Avoider
// Back to Square One
// Ball Game
// Ball vs Ball
// Ball: Revamped
// Balloon Invasion
// BallPusher
// Ballz
// Bar Balance
// Bejeweled
// Biggification
// Block it
// Blockage
// Bloons
// Boids
// Bombuzal
// Boom Dots
// Bouncing Ball
// Bouncing Ball 2
// Bouncy Light
// BoxHead
// Breakout
// Bricks
// Bubble Chaos
// Bubbles 2
// Card Game
// Castle Ramble
// Chronotron
// Circle Chain
// Circle Path
// Circle Race
// Circular endless runner
// Cirplosion
// CLOCKS - The Game
// Color Hit
// Color Jump
// ColorFill
// Columns
// Concentration
// Crossy Road
// Crush the Castle
// Cube Jump
// CubesOut
// Dash N Blast
// Dashy Panda
// Deflection
// Diamond Digger Saga
// Don't touch the spikes
// Dots
// Down The Mountain
// Drag and Match
// Draw Game
// Drop Wizard
// DROP'd
// Dudeski
// Dungeon Raid
// Educational Game
// Elasticity
// Endless Runner
// Erase Box
// Eskiv
// Farm Heroes Saga
// Filler
// Flappy Bird
// Fling
// Flipping Legend
// Floaty Light
// Fuse Ballz
// GearTaker
// Gem Sweeper
// Globe
// Goat Rider
// Gold Miner
// Grindstone
// GuessNext
// Helicopter
// Hero Emblems
// Hero Slide
// Hexagonal Tiles
// HookPod
// Hop Hop Hop Underwater
// Horizontal Endless Runner
// Hundreds
// Hungry Hero
// Hurry it's Christmas
// InkTd
// Iromeku
// Jet Set Willy
// Jigsaw Game
// Knife Hit
// Knightfall
// Legends of Runeterra
// Lep's World
// Line Rider
// Lumines
// Magick
// MagOrMin
// Mass Attack
// Math Game
// Maze
// Meeblings
// Memdot
// Metro Siberia Underground
// Mike Dangers
// Mikey Hooks
// Nano War
// Nodes
// o:anquan
// One Button Game
// One Tap RPG
// Ononmin
// Pacco
// Perfect Square!
// Perfectionism
// Phyballs
// Pixel Purge
// PixelField
// Planet Revenge
// Plants Vs Zombies
// Platform
// Platform game
// Plus+Plus
// Pocket Snap
// Poker
// Pool
// Pop the Lock
// Pop to Save
// Poux
// Pudi
// Pumpkin Story
// Puppet Bird
// Pyramids of Ra
// qomp
// Quick Switch
// Racing
// Radical
// Rebuild Chile
// Renju
// Rise Above
// Risky Road
// Roguelike
// Roly Poly
// Run Around
// Rush Hour
// SameGame
// SamePhysics
// Save the Totem
// Security
// Serious Scramblers
// Shrink it
// Sling
// Slingy
// Snowflakes
// Sokoban
// Space Checkers
// Space is Key
// Spellfall
// Spinny Gun
// Splitter
// Spring Ninja
// Sproing
// Stabilize!
// Stack
// Stairs
// Stick Hero
// String Avoider
// Stringy
// Sudoku
// Super Mario Bros
// Surfingers
// Survival Horror
// Talesworth Adventure
// Tetris
// The Impossible Line
// The Moops - Combos of Joy
// The Next Arrow
// Threes
// Tic Tac Toe
// Timberman
// Tiny Wings
// Tipsy Tower
// Toony
// Totem Destroyer
// Tower Defense
// Trick Shot
// Tunnelball
// Turn
// Turnellio
// TwinSpin
// vvvvvv
// Warp Shift
// Way of an Idea
// Whack a Creep
// Wheel of Fortune
// Where's my Water
// Wish Upon a Star
// Word Game
// Wordle
// Worms
// Yanga
// Yeah Bunny
// Zhed
// zNumbers