Sunday, August 12, 2007
ok now is 7.14am and i still haven slp yet..
still doing my flash "Space Invaders Game"..
got stuck wif the "gravity" thing and dun feel lyk doing anymore..
but after the nite i got some results of my hardship!

-> start of the game..

-> when the spaceship was hit by cannon ball..
i know the interface looks childish but i cannot do anything to it >.<
now the flash left the following haven finish:
-smoke come out when fire cannon ball
-a little bug that i dunno how to solve
-gravity problem
-countdown timer and game start button
-pop out window for the slider
-report and storyboard
the following is the Action Script coding i had done until now..
===================================
var nLeft:Number = 0;
var nTop:Number = 0;
var nRight:Number = Stage.width;
var nBottom:Number = Stage.height;
var nCannonLeft:Number = 230;
var nCannonRight:Number = 400;
var nThrustX:Number = 15; // initial value of Cannon force range from 0 to 30
var bFired:Boolean = false; // boolean variable to track if ball is fired & still within stage
var bHitShip:Boolean = false;
var bExplode:Boolean = false;
var nScore:Number = 0;
// Cannon ball movie clip
var mcBall:MovieClip = attachMovie("idBall", "ball", this.getNextHighestDepth());
// set ball initial position to outside the stage
mcBall._x = -mcBall._width;
mcBall._y = -mcBall._height;
// create sound object
var sArtillery:Sound = new Sound();
sArtillery.attachSound("idArtillery");
var sFire:Sound = new Sound();
sFire.attachSound("idFire");
var sExplode:Sound = new Sound();
sExplode.attachSound("idExplosion");
//set default spaceship position
mcShip._x = Stage.width + mcShip._width;
mcShip._y = (Math.random() * 310) + 80;
mcShip.nVelocityX = -25;
// set cannon position
mcCannon._x = 300;
mcCannon._y = 300;
// set Cannon rotation to zero
mcCannon.mcBarrel._rotation = 0;
mcCannon.nVelocityX = 0;
tRotation.text = mcCannon.mcBarrel._rotation;
function onEnterFrame():Void {
// update text fields
tCannonX.text = Math.round(10* mcCannon._x)/10;
tCannonY.text = Math.round(10 * mcCannon._y)/10;
tRotation.text = Math.round(10* mcCannon.mcBarrel._rotation)/10;
tThrust.text = Math.round(mcSliderThrust.value);
tSpeed.text = Math.round(mcSliderSpeed.value);
tGravity.text = Math.round(mcSliderGravity.value);
tFired.text = bFired;
tHitShip.text = bHitShip;
tScore.text = nScore;
mcShip.nVelocityX = -mcSliderSpeed.value;
mcShip._x += mcShip.nVelocityX;
//Regenerate ship when it go out of stage
if( mcShip._x < -200 ){
mcShip._x = Stage.width + mcShip._width;
mcShip._y = (Math.random() * 310) + 80;
}
if(mcBall.hitTest(mcShip)){
bHitShip = true;
}
if(bHitShip && !bExplode){
bExplode = true;
nScore++;
mcShip.play();
sExplode.start();
}
if(Key.isDown(Key.RIGHT)){ // right key is pressed
if(mcCannon._x < nCannonRight){
mcCannon._x += 5 ;
}
}else if (Key.isDown(Key.LEFT)){ // left key is pressed
if(mcCannon._x > nCannonLeft){
mcCannon._x -= 5;
}
}
if(Key.isDown(Key.DOWN)){ // down arrow key is pressed
if(mcCannon.mcBarrel._rotation <0){
mcCannon.mcBarrel._rotation += 1;
}
}else if (Key.isDown(Key.UP)){ // up arrow key is pressed
if(mcCannon.mcBarrel._rotation > -50){
mcCannon.mcBarrel._rotation -= 1;
}
}
if(!bFired && Key.isDown(Key.SPACE)){
// ********* ball is fired
bFired = true;
sArtillery.start();
sFire.start();
// calculate rotation of cannon barrel
var nRadians:Number = -mcCannon.mcBarrel._rotation * Math.PI / 180;
//make cannon ball appear behind the cannon
mcCannon.getNextHighestDepth();
// move ball to tip of barrel
mcBall._x = mcCannon._x + mcCannon.mcBarrel._x + ( Math.cos(nRadians) * (mcCannon.mcBarrel._width/2) );
mcBall._y = mcCannon._y + mcCannon.mcBarrel._y - ( Math.tan(nRadians) * ( Math.cos(nRadians) * (mcCannon.mcBarrel._width/2) ) );
mcBall.nSpeed = mcSliderThrust.value;
mcBall.nVelocityX = mcBall.nSpeed * Math.cos(nRadians);
mcBall.nVelocityY = mcBall.nSpeed * Math.tan(nRadians);
}
if(bFired){ // ball has been fired - update ball position
fireBall(mcBall);
}
// check boundary conditions of ball
if(mcBall._x > nRight + mcBall._width/2 || mcBall._y < nTop - mcBall._height/2 ) { // ball is out of stage
bFired = false; // reset the Boolean variable
// regenerate the ball
mcBall._x = -10;
mcBall._y = -10;
}
}//end onEnterFrame
function fireBall(mcCannonBall:MovieClip){ // you should add gravity here
mcCannonBall._x += mcCannonBall.nVelocityX;
mcCannonBall._y -= mcCannonBall.nVelocityY;
}
===================================
this is the pop out code for the slider.. code provided by LiYan
===================================
btnSilder.onRelease = function():Void
{
setProperty("mcSWindow",_visible,true);
}
mcSWindow.btnClose.onRelease = function():Void{
setProperty("mcSWindow",_visible,false);
}
//first set the window to visible to false
===================================
7:14 AM