Casual Game: Failed flash game

Well as I didn’t know how to code a game in flash, I thought I would follow a platform game tutorial to see what I could come up with. I followed a written tutorial. This can be found here. I only followed it so far though because I came to a fault I didn’t know how to correct, I searched online and in a few books to find what the problem was but I really didn’t know what I was looking for.

The code I came up with allows my character to jump and if you get close enough to a wall or floor, you will land on it, otherwise the player will fall through it; which is what the main problem is.

Below is the background I drew for the flash game, a character stance and the code I followed.

var leftPressed:Boolean = false;
var rightPressed:Boolean = false;
var upPressed:Boolean = false;
var downPressed:Boolean = false;

var leftBumping:Boolean = false;
var rightBumping:Boolean = false;
var upBumping:Boolean = false;
var downBumping:Boolean = false;
//this will check whether the player detecting the collisions

var leftBumpPoint:Point = new Point(-30, -55);
var rightBumpPoint:Point = new Point(30, -55);
var upBumpPoint:Point = new Point(0, -120);
var downBumpPoint:Point = new Point(0, 0);

var scrollX:Number = 0;
var scrollY:Number = 0;
var xSpeed:Number = 0;
var ySpeed:Number = 0;
//this will determine how fast the background moves when it is scrolling.

var gravityConstant:Number = 1.5;

var speedConstant:int = 5;

var friction:Number = 0.95;
//This is the number we will multiply to slow the player down

stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
stage.addEventListener(KeyboardEvent.KEY_UP, keyUpHandler);
// creates an event listener to detect if the button is being pressed and the other being released.

function keyDownHandler(e:KeyboardEvent):void{
if(e.keyCode == Keyboard.LEFT){
leftPressed = true;

} else if(e.keyCode == Keyboard.RIGHT){
rightPressed = true;

} else if(e.keyCode == Keyboard.UP){
upPressed = true;

} else if(e.keyCode == Keyboard.DOWN){
downPressed = true;

function keyUpHandler(e:KeyboardEvent):void{
if(e.keyCode == Keyboard.LEFT){
leftPressed = false;

} else if(e.keyCode == Keyboard.RIGHT){
rightPressed = false;

} else if(e.keyCode == Keyboard.UP){
upPressed = false;

} else if(e.keyCode == Keyboard.DOWN){
downPressed = false;
// This code will trace to the output panel whenever you press or release the up, down, left, or right arrow keys.

stage.addEventListener(Event.ENTER_FRAME, loop);
function loop(e:Event):void{

if(back.hitTestPoint(player.x + leftBumpPoint.x, player.y + leftBumpPoint.y, true)){
leftBumping = true;
} else {
leftBumping = false;

if(back.hitTestPoint(player.x + rightBumpPoint.x, player.y + rightBumpPoint.y, true)){
rightBumping = true;
} else {
rightBumping = false;

if(back.hitTestPoint(player.x + upBumpPoint.x, player.y + upBumpPoint.y, true)){
upBumping = true;
} else {
upBumping = false;

if(back.hitTestPoint(player.x + downBumpPoint.x, player.y + downBumpPoint.y, true)){
downBumping = true;
} else {
downBumping = false;
if(ySpeed > 0){
ySpeed *= -0.5;
} else { //if we are not touching the floor
ySpeed += gravityConstant; //accelerate downwards
// this detects when a button is pressed and makes sure the player stops when it comes to a wall.

xSpeed -= speedConstant;

} else if(rightPressed){
xSpeed += speedConstant;


ySpeed -= speedConstant;

} else if(downPressed){
ySpeed += speedConstant;


if(xSpeed < 0){
xSpeed *= -0.5;

if(xSpeed > 0){
xSpeed *= -0.5;

if(ySpeed < 0){
ySpeed *= -0.5;

if(ySpeed > 0){
ySpeed *= -0.5;
xSpeed *= friction;
ySpeed *= friction;

scrollX -= xSpeed;
scrollY -= ySpeed;

back.x = scrollX;
back.y = scrollY;

// this will detect if the player is hitting any walls and floors and stop him from
// going any further. It will also slow him down and make sure he stops moving when
// no buttons are pressed.






~ by reeceharry on January 7, 2013.

Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )

Connecting to %s

( Project Example)

The Final Major Project of Matt Lane

Reece Harrison

Year 3 Game Design HSAD Student

Hms Hunter

From the Ashes


A fine site

AS3 Game Tutorials

Complete Flash game tutorials in ActionScript 3

Kevin Holbrook's Blog

Student at Hull College - BA (Honours) Degree


I am currently studying games design at the Hull school of art and design and this is the work i have been doing.

Greavsie93 - Uni Work

Games Design Degree Work

%d bloggers like this: