Design A Day Icon

There is a new (and still incomplete) version of eRadiRace posted.

Launch the new broken thing!

I’ve come to the conclusion that talking about learning Flash is about as interesting as watching The Paint Drying Channel. So, I’ll spare you further exposure to that curse. What I will do is post these things up as they are finished in the game design section, along with the source code and pertinent lessons learned. The code may be ugly, but it’s well commented.

The preview: Flash 8’s Draw API is your friend.

Lameness Alert:

Pre-production is in full swing on the next round of games at Helixe, which means I’m Johnny-on-the-Spot for the next couple of months.

So yes, expect further slippage on the Design-A-Day. You deserve better, and I’ll understand if you want to start seeing other designers. It’s not you…it’s me.

I’ll endeavor to keep you amused and entertained, if not enlightened, in the meantime.

Code to the new version after the jump.

//  Base Contruction for Multiplayer Line Blocking Game

/* This makes heavy use of the Flash 8 Drawing API
   there is a good overview of it here:
    http://www.adobe.com/devnet/flash/articles/image_api_print.html
*/

//import classes we will be using
import flash.display.BitmapData;
import mx.managers.DepthManager
    //http://livedocs.macromedia.com/flash/mx2004/main_7_2/wwhelp/wwhimpl/ common/html/wwhelp.htm?context=Flash_MX_2004&file=00002014.html
import flash.geom.Rectangle
//________________________________________________ _______________________
   
   
// Initialize Stage and Load BG image from Libray   
var stageW:Number = 485;
var stageH:Number = 600;

var bg_mc:MovieClip = this.createEmptyMovieClip ("mc", 1);
var myBmp:BitmapData = new BitmapData (stageW, stageH, true, 0×00000000);

myBmp.draw (BitmapData.loadBitmap ("bg_pic"));
bg_mc.attachBitmap (myBmp, 0, "never", false);
    //trace(bg_mc.getDepth());

// Sets the Player Avatar Depth above that of the Background
Player_1_mc.setDepthTo(DepthManager.kTopmost);
    //trace(Player_1_mc.getDepth());

//____________________________________________________________________ ___

// Initialize Sounds

badGoalSound = new Sound();
badGoalSound.attachSound("badGoal");

//____________________________________________________________________ ____
//Initialize all variables
gameOver = 0;
topSpeed = 7;
lowSpeed = 2;

// for Player 1
p1_X_Dir = 0;
p1_Y_Dir = -1;
p1_Speed = 3;
p1_X = 243;
p1_Y =590;
p1_lose = 0;
p1_baseScale=1;

//____________________________________________________________________ ____

// Main Game Loop

this.onEnterFrame = function() {
   
    if (gameOver == 0) {
        p1_Old_X = p1_X;
        p1_Old_Y = p1_Y;
        //__________________________________________________________
        // Player_1 Keyboard Input
       
        if (Key.isDown(Key.RIGHT)) {
           
            if(p1_X_Dir != -1){
               
                p1_X_Dir = 1;
                p1_Y_Dir = 0;
               
                if(p1_Speed < topSpeed){
                    p1_Speed += .5;
                }
            }
            else {
                if(p1_Speed > lowSpeed){
                    p1_Speed -= .5;
                }
            }
        }
   
        if (Key.isDown(Key.LEFT)) {
            if(p1_X_Dir != 1){
                p1_X_Dir = -1;
                p1_Y_Dir = 0;
                if(p1_Speed < topSpeed){
                    p1_Speed += .5;
                }
            }
            else {
                if(p1_Speed > lowSpeed){
                    p1_Speed -= .5;
                }
            }
        }
       
        if (Key.isDown(Key.UP)) {
            if(p1_Y_Dir != 1) {
                p1_X_Dir = 0;
                p1_Y_Dir = -1;
                if(p1_Speed < topSpeed){
                    p1_Speed += .5
                }
            }
            else {
                if(p1_Speed > lowSpeed){
                    p1_Speed -= .5
                }
            }
        }   
       
        if (Key.isDown(Key.DOWN)) {
            if(p1_Y_Dir != -1) {
                p1_X_Dir = 0;
                p1_Y_Dir = 1;
                if(p1_Speed < topSpeed){
                    p1_Speed += .5;
                }
            }
            else {
                if(p1_Speed > lowSpeed){
                    p1_Speed -= .5;
                }
            }
        }
        //__________________________________________________________
        // Update Player_1 Location
        p1_X += (p1_Speed * p1_X_Dir);
        p1_Y += (p1_Speed * p1_Y_Dir);
       
       
       
        //__________________________________________________________   
        // Collision Detection
        pixelColor = myBmp.getPixel(p1_X, p1_Y);
        //trace("0x"+pixelColor.toString(16)); //outputs : 0×00000000
        //trace(pixelColor);
        if (pixelColor == 65535) {
            p1_lose = 1;
            gameOver = 1;
            gotoAndPlay(3);
        }
       
                //___Add front array of detectors based on direction
       
       
       
        //__________________________________________________________
        // Place and Scale Player 1
        _root.Player_1_mc._x = p1_X;
        _root.Player_1_mc._y = p1_Y;   
       
        _root.Player_1_mc._xscale = p1_baseScale + (p1_Speed * 23);
        _root.Player_1_mc._yscale = p1_baseScale + (p1_Speed * 23);
       
       
       
        //__________________________________________________________
        // Draw the Line for Player 1
        if (p1_Y_Dir == -1) {
            p1Width = 7;
            p1Height = p1_Old_Y - p1_Y + 1;
            topleft_X = p1_X - 3;
            topleft_Y = p1_Y;
            myRect = new Rectangle(topleft_X,topleft_Y,p1Width,p1Height);
                //The first two parameters are the x/y coordinates of the top left-hand corner of the rectangle.
                //The last two parameters specify the dimensions of the rectangle (width and height).
            myBmp.fillRect(myRect,0xFF00FFFF);
        }
       
            if (p1_Y_Dir == 1) {
            p1Width = 7;
            p1Height = p1_Y - p1_Old_Y + 1;
            topleft_X = p1_X - 3;
            topleft_Y = p1_Old_Y;
            myRect = new Rectangle(topleft_X,topleft_Y,p1Width,p1Height);
                //The first two parameters are the x/y coordinates of the top left-hand corner of the rectangle.
                //The last two parameters specify the dimensions of the rectangle (width and height).
            myBmp.fillRect(myRect,0xFF00FFFF);
        }
       
        if (p1_X_Dir == -1) {
            p1Height = 7;
            p1Width = p1_Old_X - p1_X + 1;
            topleft_X = p1_X;
            topleft_Y = p1_Y - 3;
            myRect = new Rectangle(topleft_X,topleft_Y,p1Width,p1Height);
            myBmp.fillRect(myRect,0xFF00FFFF);   
        }
       
        if (p1_X_Dir == 1) {
            p1Height = 7;
            p1Width = p1_X - p1_Old_X + 1;
            topleft_X = p1_Old_X;
            topleft_Y = p1_Y - 3;
            myRect = new Rectangle(topleft_X,topleft_Y,p1Width,p1Height);
            myBmp.fillRect(myRect,0xFF00FFFF)   
        }
       
    //____________________________________________________________________ ____
       
       
    } // Closes "if(gameOver == 0)"
} // Closes "OnEnterFrame"
stop();