The Drunkard Demo Flash code

import flash.events.KeyboardEvent;
import flash.events.Event;
var KeyThatIsPressed:uint;
var rightKeyIsDown:Boolean = false;
var leftKeyIsDown:Boolean = false;
var upKeyIsDown:Boolean = false;
var downKeyIsDown:Boolean = false;

var playerSpeed:Number = 7;
var gravity:Number = 1;
var yVelocity:Number = 0;
var canJump:Boolean = false;

stage.addEventListener(KeyboardEvent.KEY_DOWN,PressAKey);
stage.addEventListener(KeyboardEvent.KEY_UP,ReleaseAKey);

function PressAKey(event:KeyboardEvent):void
{
if (event.keyCode == Keyboard.RIGHT)
{
rightKeyIsDown = true;
}
if (event.keyCode == Keyboard.LEFT)
{
leftKeyIsDown = true;
}
if (event.keyCode == Keyboard.UP)
{
upKeyIsDown = true;
}
if (event.keyCode == Keyboard.DOWN)
{
downKeyIsDown = true;
}
}

function ReleaseAKey(event:KeyboardEvent):void
{
if (event.keyCode == Keyboard.RIGHT)
{
rightKeyIsDown = false;
}
if (event.keyCode == Keyboard.LEFT)
{
leftKeyIsDown = false;
}
if (event.keyCode == Keyboard.UP)
{
upKeyIsDown = false;
}
if (event.keyCode == Keyboard.DOWN)
{
downKeyIsDown = false;
}
}
floor_mc.addEventListener(Event.ENTER_FRAME,moveThefloor_mc);

function moveThefloor_mc(event:Event):void
{
if (rightKeyIsDown)
{
trees_mc.x -= playerSpeed && +6;
fore_mc.x -= playerSpeed && +7.5;
back_mc.x -= playerSpeed && +3;
bump_mc.x -= playerSpeed;
house_mc.x -= playerSpeed;
floor_mc.x -= playerSpeed;
bill_mc.scaleX = 1;
bill_mc.gotoAndStop(2);
}
if (leftKeyIsDown)
{
trees_mc.x += playerSpeed && +6;
fore_mc.x += playerSpeed && +7.5;
back_mc.x += playerSpeed && +3;
bump_mc.x += playerSpeed;
house_mc.x += playerSpeed;
floor_mc.x += playerSpeed;
bill_mc.scaleX = -1;
bill_mc.gotoAndStop(2);
}
if (upKeyIsDown && canJump)
{
yVelocity = -15;
canJump = false;
}
if (! rightKeyIsDown && ! leftKeyIsDown)
{
bill_mc.gotoAndStop(1);
}
yVelocity += gravity;

if (! floor_mc.hitTestPoint(bill_mc.x,bill_mc.y,true))
{
bill_mc.y += yVelocity;
}
if (yVelocity > 20)
{
yVelocity = 20;
}
for (var i:int = 0; i<10; i++)
{
if (floor_mc.hitTestPoint(bill_mc.x,bill_mc.y,true))

{
bill_mc.y–;
yVelocity = 0;
canJump = true;
}
}
}

The Drunkard Screen Shot

A screenshot of what the above code produced.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s