current (working) code:
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard
public class Main extends Sprite
{
private var aDown:Boolean = false;
private var dDown:Boolean = false;
private var sDown:Boolean = false;
private var wDown:Boolean = false;
private var char : player;
private var gDown:Boolean = false;
private var jDown:Boolean = false;
private var hDown:Boolean = false;
private var yDown:Boolean = false;
private var par : shark;
private var bar : Back;
private var sar : Speed;
private var randomX:int = Math.floor(Math.random()*12)+1;
public function Main():void
{
bar = new Back();
bar.x = -300;
bar.y = 0;
addChild(bar);
sar = new Speed();
if(randomX == 1)
{
sar.x = -100;
sar.y = 400;
}
else if(randomX == 2)
{
sar.x = 275;
sar.y = 350;
}
else if(randomX == 3)
{
sar.x = 150;
sar.y = 200;
}
else if(randomX == 4)
{
sar.x = 700;
sar.y = 50
}
else if(randomX == 5)
{
sar.x = -50;
sar.y = 300;
}
else if(randomX == 6)
{
sar.x = 100;
sar.y = 400;
}
else if(randomX == 7)
{
sar.x = 750;
sar.y = 50;
}
else if(randomX == 8)
{
sar.x = 800;
sar.y = 400;
}
else if(randomX == 9)
{
sar.x = 350;
sar.y = 400;
}
else if(randomX == 10)
{
sar.x = 650;
sar.y = 450
}
else if(randomX == 11)
{
sar.x = 150;
sar.y = 500;
}
else if(randomX == 12)
{
sar.x = 700;
sar.y = 200;
}
addChild(sar);
char = new player();
char.x = 500;
char.y = 300;
addChild(char);
par = new shark();
par.x = 600;
par.y = 400;
addChild(par);
stage.addEventListener(Event.ENTER_FRAME, keys);
stage.addEventListener(KeyboardEvent.KEY_DOWN, keysdown);
stage.addEventListener(KeyboardEvent.KEY_UP, keysup);
}
public function keys(e:Event):void
{
if (aDown == true)
char.x -= 10;
if (dDown == true)
char.x += 10;
if (sDown == true)
char.y += 10;
if (wDown == true)
char.y -= 10;
if (gDown == true)
par.x -= 10;
if (jDown == true)
par.x += 10;
if (hDown == true)
par.y += 10;
if (yDown == true)
par.y -= 10;
}
public function keysdown(e:KeyboardEvent):void
{
switch (e.keyCode)
{
case Keyboard.A:
{
aDown = true;
break;
}
case Keyboard.D:
{
dDown = true;
break;
}
case Keyboard.S:
{
sDown = true;
break;
}
case Keyboard.W:
{
wDown = true;
break;
}
case Keyboard.G:
{
gDown = true;
break;
}
case Keyboard.J:
{
jDown = true;
break;
}
case Keyboard.H:
{
hDown = true;
break;
}
case Keyboard.Y:
{
yDown = true;
break;
}
}
}
public function keysup(e:KeyboardEvent):void
{
switch (e.keyCode)
{
case Keyboard.A:
{
aDown = false;
break;
}
case Keyboard.D:
{
dDown = false;
break;
}
case Keyboard.S:
{
sDown = false;
break;
}
case Keyboard.W:
{
wDown = false;
break;
}
case Keyboard.G:
{
gDown = false;
break;
}
case Keyboard.J:
{
jDown = false;
break;
}
case Keyboard.H:
{
hDown = false;
break;
}
case Keyboard.Y:
{
yDown = false;
break;
}
}
}
}
}
now I need three more things before my code is complete;
1) The speed boost to add speed that goes away in 5 seconds to Bob when he comes near, causing the speed boost to respawn and the score to go up one.
2) When the shark comes near, I want it to display "game over" and the recently earned score as well as the best score scored on the console.
3) I also need to use the blitting tool to make the image I created for the speed block have a strobe effect.