Tuesday, 18 December 2012

Flash Action script

  //**************VARIABLES**************/
Creates a string variable that is empty and has no value
var gameState:String;



//*********BEGINNING STUFF**************/
Means that that the movie clip endScreen is false (i.e. invisible)
endScreen.visible = false;

//**************INTRO SCREEN**************/
Making the child of the movieclip introScreen a button that is clickable
Looks for the function click away ( this is done with open+closed brackets)
It calls the function to move the movie clip out of the screen to reveal game screen
Also sizes the screen and drags it the x axis and takes the image out of the screen (screen x= (screen.wdith*-1;) (-1 is left and +1 is right)
Gamestate is a variable and in the variable you are putting in INITGAME which shows the value and state of the variable.
AddEventListner means its listening out for the even Enter_FRAME, game loop, meaning it will listen out for a new enterframe event and until then loop the screen.
introScreen.play_btn.addEventListener (MouseEvent.CLICK, clickAway);
function clickAway (event:MouseEvent):void {
      moveScreenOff (introScreen);
}
function moveScreenOff (screen:MovieClip):void {
      screen.x = (screen.width)*-1;
      gameState = "INITGAME";
      addEventListener (Event.ENTER_FRAME, gameLoop);
}

//**************GAME STATES**************/
function gameLoop (e:Event):void {
      switch (gameState) {
             case "INITGAME":
                   initGame();
                   break;
             case "STARTPLAYER":
                   startPlayer ();
                   break;
             case "PLAYGAME" :
                   playGame ();
                   break;
             case "ENDGAME" :
                   endGame ();
                   break;
      }
}


//**************STATE_INIT_GAME**************/
Trace when you run the movie will be printed out on an out movie in flash.
function initGame ():void {
trace("add stuff to initGame")
         gameState = "STARTPLAYER";
}






//**************STATE_START_PLAYER**************/
function startPlayer ():void {
       trace("add player stuff")
      gameState = "PLAYGAME";



//**************STATE_PLAY_GAME**************/
Makes play game a function along with calling on with the 2 smaller ones,
 And then makes the clipboard memory remember Endgame
function playGame ():void {
      makeEnemies ();
      testForEnd ();
}
function makeEnemies ():void {
     
}
function testForEnd ():void {
      gameState = "ENDGAME";
}


/**************STATE ENDGAME**************/
function endGame ():void {
      removeGame ();
      endScreen.visible = true;
      removeEventListener (Event.ENTER_FRAME, gameLoop);
      showResults ();
}

Creates a function called showResults
With the child button
Creating a click event (clickFinalAway)

Calls a function shows results
function showResults ():void {
      trace ("Show Results"); 
      endScreen.play_btn.addEventListener (MouseEvent.CLICK, clickFinalAway);
      function clickFinalAway (event:MouseEvent):void {
             trace ("clickFinalAway");
             moveScreenOff (endScreen);
      }
}





//**************REMOVE GAME**************/
function removeGame ():void {
     
}
>imputed all script
>added movie clips (endscreen + start screen)
>animated start screen
>fixed bugs
>made buttons play_btn
> This allowed the loop actionscript to work


Screen grabs of working Script.


 This first screen shot is of all the beginning things, that need to take place before the game starts. I have added a few things myself that need to be hidden so that you can see the beginning screen properly, without still being able to view my nuke button, the score, lives and level. So by using their instance name followed by: ".visible = false" this will hide them from the screen and can only be made visible again by saying so through script.
This next print screen is things that need to happen within the 'init game' loop - meaning things that should happen when the game initiates. 
As you can see I have made that several things: ".visible = true" which means when the game starts the lives, level and score will now be visible and work as they should.

This next large shot of script is all about how my enemies get larger as they come towards the screen, and that they start off darker and get lighter and other such things that all come from perspective. These are all mathematically scaled and what not and so need to be scaled on the x & y axis, and by a percentage. As you can read this is all implemented through the scripting. Along with the percentage of the saturation.
This part of the script is used to say what happens when the enemies get hit buy the players 'laser' or the player itself. - in this case it causes an 'explosion' and then the enemy, laser and explosion is removed from stage however mine has an alteration and that is that if the 3rd frame within my enemy movie clip hits the player that it doesn't explode when it hits the player but instead provides a new button the the player - this is my nuke button. However I have made it so that the nuke can still be shot for points, but this will not provide the button. 
This is a screen shot of my "make Enemies Function"
This loop will create new enemies, determining their start position, within the parameters I have set ( so they don't go too far off the left or right of the stage)
The script we were given I have made amendments too so that my enemies don't rotate down but instead the go down horizontally  This was done by blanking out several lines of script. 
I also added so that there would be more than one enemy - I have added 2 enemies and a power-up. These are all within the same movie clip and are called out randomly. However I have also altered the speed of which they move. The first enemy and power-up move quite slow however the second enemy moves faster this is from a small bit of script:
"tempEnemy.speed = 2;" and then you put an 'if' statement and then you can do the same for the second and make the number higher to make it go faster.

This last screen shot is of the small bit of script I used for my nuke button. I basically took the script for the end game function and this is to clear the enemies from the stage. Along with this it removes the nuke button away from the stage again, adds 5 points to the score and also displays a 'wave' visual to clear the stage. 

No comments:

Post a Comment