Wednesday, 30 November 2011

Flash for games

flash games have a reputation of being short and fun. The graphics in flash games tend to be quite simple, this is good because there is not to get distracted by when play the game. also the controls are basic to make the game play as easy as possible. most flash games use a three life system, when you loose three live it game over and then you need to start again. this is good for quick game play.

Wednesday, 23 November 2011

My Graphics




These are the graphics I have made in illustrator for my flash game and a basic layout of the game.

scrolling background across

//set up variables.
var blockArray:Array = new Array();
var bGspeed:Number = 6


var gameover:Boolean = true;
var BgLeft:Boolean = false;
var BgRight:Boolean = false;

// set up and run a game control function.
stage.addEventListener(Event.ENTER_FRAME, gameControl);

function gameControl(myevent:Event):void
{
            if (BgLeft == true)
            {
                       
                        if (bGround.x  <-((bGround.width/2)-bGspeed))
                        {
                                    bGround.x = 0;
                        }
                        else
                        {
                                    bGround.x -=  bGspeed;
                        }

            }
            if (BgRight == true)
            {
                        if (bGround.x >= 0)
                        {
                                    bGround.x = -( bGround.width/2)+bGspeed;
                        }
                        else
                        {
                                    bGround.x +=  bGspeed;
                        }

            }
           
}


// listen to keyboard being pressed.
stage.addEventListener(KeyboardEvent.KEY_DOWN, moveBg);
stage.addEventListener(KeyboardEvent.KEY_UP, stopBg);

// if not pressed set move bGround to false.
function stopBg(myevent:KeyboardEvent):void
{
            if (myevent.keyCode == Keyboard.RIGHT)
            {
                        BgRight = false;
            }
            if (myevent.keyCode == Keyboard.LEFT)
            {
                        BgLeft = false;
            }


}

// if pressed set move bGround to true.
function moveBg(myevent:KeyboardEvent):void
{
            if (myevent.keyCode == Keyboard.RIGHT)
            {
                        BgRight = true;
            }
            if (myevent.keyCode == Keyboard.LEFT)
            {
                        BgLeft = true;
            }

}

Thursday, 17 November 2011

Flash clock

import flash.utils.Timer;
import flash.events.TimerEvent;

var seconds:int=0
var min:int=0

var myTimer:Timer = new Timer(1000);
myTimer.addEventListener(TimerEvent.TIMER, runOnce);
myTimer.start();

function runOnce(event:TimerEvent):void {
seconds++

if (seconds<10){
clock.text="0"+String(min)+":"+"0"+String(seconds);
}
if (seconds>9){
clock.text="0"+String(min)+":"+String(seconds);
}
if (seconds>=60){
min++
seconds=0
}
}

Flash Timer

import flash.utils.Timer;
import flash.events.TimerEvent;

var time:int=300

var myTimer:Timer = new Timer(1000, 300);
myTimer.addEventListener(TimerEvent.Timer, runOnce);
myTimer.start();

function runOnce(event:TimerEvent):void {
              time--
              lee.text=String(time);
}







import flash.utils.Timer;
import flash.events.TimerEvent;

var time:int=0

var myTimer:Timer = new Timer(10, 3000);// 1 second
myTimer.addEventListener(TimerEvent.TIMER, runOnce);
myTimer.start();

function runOnce(event:TimerEvent):void {
time++
clock.text=String(time);
}

Wednesday, 19 October 2011

game aspects

This is a screen shot of the game i am using for reference. I have come over a couple of problems during the make of my flash game. For example when to cars move from lane to lane the angle of the car view changes, this will be to difficult to do with out a 3D model. So I think I am going to make to game from a top view to make to game easier to make. Also I am going to make it 2D birds eye view to give it a retro feel. For the game I am going to make a scoring system go up during the time that you play, so the longer you last the more point you gain.

Thursday, 13 October 2011

Array in flash

import flash.display.MovieClip;
import flash.events.Event;

var blockArray:Array=new Array();
// create array called block array


for (var i:int = 0; i <15; i++){
// will loop cube 15 times
var cube:MovieClip = new box();
//brings in box from library
cube.x=Math.random()*550
//places cube from library along width of stage
cube.y=Math.random()*400
//places cube from library along hieght of stage
addChild(cube);
// duplicates cube from library

blockArray[i]=cube
// numbers the cubes
}

stage.addEventListener(Event.ENTER_FRAME, checkhit);
//listen to stage on every frame
function checkhit(myevent:Event):void{
for (var i:int = 0; i < 15; i++){
if (blockArray[i].hitTestPoint(mouseX,mouseY,true)){
// if any of the cubes get hit by the mouse in any direction (x,y) and if mouse hit whole object or reg point
blockArray[i].alpha=.3;
}// if box get hit make box transparent
}
}

hit test

stage.addEventListener(Event.ENTER_FRAME, checkhit);
//listen to stage on every frame
function checkhit(myevent:Event):void{

cube1.x+=3
cube2.x-=3


if (cube1.hitTestPoint(cube2.x,cube2.y,true)){
// if any of the cubes get hit by the mouse in any direction (x,y) and if mouse hit whole object or reg point
cube2.alpha=.3;
}// if box get hit make box transparent

}

Thursday, 6 October 2011

code demo 2 library placement

import flash.events.Event;
import flash.events.KeyboardEvent;

var moveRight:Boolean = false
var moveLeft:Boolean = false
var moveUp:Boolean = false
var moveDown:Boolean = false

var ship:MovieClip = new Ship();

ship.x=275
ship.y=200


addChild(ship);






stage.addEventListener(Event.ENTER_FRAME,moveShip);

function moveShip(event:Event){

if (moveRight==true){
ship.x+=3;
}
if (moveLeft==true){
ship.x-=3;
}

if (moveUp==true){
ship.y-=3;
}

if (moveDown==true){
ship.y+=3;
}
}

// listen to keyboard being pressed
stage.addEventListener(KeyboardEvent.KEY_DOWN,pressKey);
stage.addEventListener(KeyboardEvent.KEY_UP,stopShip);
// if not pressed set move ship to false
function stopShip(myevent:KeyboardEvent):void{
moveLeft=false;
moveRight=false;
moveUp=false;
moveDown=false;
}
//if pressed move ship to true
function pressKey(myevent:KeyboardEvent):void{
if(myevent.keyCode==Keyboard.RIGHT){
moveRight=true;
}

if(myevent.keyCode==Keyboard.LEFT){
moveLeft=true;


}

    if(myevent.keyCode==Keyboard.UP){
moveUp=true;


}

    if(myevent.keyCode==Keyboard.DOWN){
moveDown=true;


}
}