Tuesday, 18 December 2012

Flash Coding




//**************VARIABLES**************/
Var gamestate;String (this creates a string variable with no value)

//*********BEGINNING STUFF**************/
endScreen.visible = false; (this line makes a movie clip called endScreen invisible)

//**************INTRO 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);
}

//**************STATE_INIT_GAME**************/
function initGame ():void {
trace("add stuff to initGame")
         gameState = "STARTPLAYER";
}

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

(This code is the same as STATE INIT GAME code)

//**************STATE_PLAY_GAME**************/
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 ();
}

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 {
      
(IntroScreen is a movie clip event called introScreen with a mouseEvent click on the child play button which finds the function clickaway when itis clicked.)
function moveScreenOff (screen:MovieClip):void (make the movie clip move off screen)
Screen.x (Is the axis which it is on X,Y
= (screen.width)*-1; the whole value moves it off screen by the width of the screen
gameState = "INITGAME"; (is a variable and if gameState remembers "INGAME" it will do something.)
addEventListener (Event.ENTER_FRAME, gameLoop); (This created an enterframe listener, once activated it becomes a gameloop)

Function initGame ():void{ (It is the function)
Trace("add stuff to initGame") ( )
gameState = "STARTPLAYER"; ( )

function makeEnemies ():void{ (this calls the function make enemies)
makeEnemies ();
      testForEnd ();
}

function showResults ():void {
 trace ("Show Results"); 
 endScreen.play_btn.addEventListener (MouseEvent.CLICK, clickFinalAway);
 function clickFinalAway (event:MouseEvent):void {
 trace ("clickFinalAway");
 moveScreenOff (endScreen);
      }
(This creates a function called showResults,it also creates a function called click final away)

//**************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;
      }
}


We will now add collision detection and explosions. Nest this within the “for” loop in function moveEnemies

var tempLaser:MovieClip;
             //Loop through the Lasers array
             for (var j:int=Lasers.length-1; j>=0; j--)     {
                   tempLaser = Lasers[j];
                   if (tempEnemy.hitTestObject(tempLaser))  {
                         //Remove enemy from enemies array
                         removeEnemy(i);
                         //Remove laser from Lasers array
                         removeLaser(j);
                         //Add to the score
                   }
             }


When explosions are generated they need to be listed in an array. So declare this variable putting the following in the variables section:

      var explosions:Array;

Put the following in the initGame function:

explosions = new Array();

create a function to make explosions, grabbing an instance from the movieClip symbol in the library. 
function makeExplosion(ex:Number, ey:Number):void  {
      var tempExplosion:MovieClip;
      tempExplosion = new Explosion();
      tempExplosion.x = ex;
      tempExplosion.y = ey;
      addChild(tempExplosion);
      explosions.push(tempExplosion);
}

Now to see when to get rid of the explosion. Put the following inside the “movelazer” function JUST BEFORE THE LAST CLOSING CURLY BRACE (Whoo-hoo ---- another “for” loop, this time testing all the explosions
                                                                                                                                                                                       remembered in the explosions array. If they have finished their animation
                                                                                                                                                                                       then a new function “removeExplosion” is called


      //Remove any tempExplosion from the explosions array that has already played
      var tempExplosion:MovieClip;
      for (i=explosions.length-1; i>=0; i--) {
             tempExplosion = explosions[i];
             if (tempExplosion.currentFrame >= tempExplosion.totalFrames){
                   removeExplosion(i);
             }
      }

This creates the function, removes the explosion from the stage, and                                                                  
                                                                                                                                                                                 splices it out of the explosions array

  function removeExplosion(idx:int) {
      removeChild(explosions[idx]);
      explosions.splice(idx,1);
}


You need these new variables. Paste into variables section at the top:Create 3 DYNAMIC text boxes on the stage (mobile device – best text is Sans point size 24). Give instance names of:         score_txt             lives_txt          level_txt


var score:Number;
var lives:Number;


Now you need to add script to display information into the text boxes you just made. This will happen in the initGame function (and elsewhere – explained later)When you script in a number into a text box, you have to turn the number into a string, so
                                                                                                                                                      you type the word “String”  before the number which is in brackets


level_txt.text = ("LEVEL:   " + String(level));
score = 0;
score_txt.text = ("SCORE:   " + String(score));
lives = 2;
lives_txt.text = ("LIVES:   " + String(lives));


We have made an explosion happen if the enemy gets to the bottom of the stage OR if it hits the player. Now, if either of these things happens, then the player LOSES A LIFE. So add the following script  inside the function moveEnemies, inside the IF bit that tests getting getting to the bottom of the stage OR hitting the player:

//Subtract a life
lives--;
lives_txt.text = ("LIVES:   " + String(lives));


Now to add to the score WHEN THE PLAYER SUCCEEDS. Paste the following inside the function moveEnemies, inside the IF bit that tests if the enemy hits the laser:
score++;
score_txt.text = ("SCORE:   " + String(score));



Next we need to see if the player is successful and the level needs to increase or see if the player is bad and has lost all lives. So the processor needs to get to the testForEnd function. We had to comment out a line in this function. Paste the following into the testForEnd function, REPLACING THE SINGLE LINE THAT IS THERE ALREADY and commentedThe testForEnd function is called from the playGame function.
                                                                                                                                                      By changing the variable gameState to ENDGAME, the enterFrame script (gameLoop) will now call the
                                                                                                                                                      endgamefunction, not playGame. In this way the processer deals with all the stuff needed to action what
                                                                                                                                                      happens when the game is over.


score++;
score_txt.text = ("SCORE:   " + String(score));

      if (score > level * 10)   {
             level++;
             level_txt.text = ("LEVEL:   " + String(level));
      }
      //Check to see how many lives the user has
      if (lives == 0)    {
             gameState = "ENDGAME"
             trace(gameState);
      }






TEST YOUR GAME. YOU WILL SEE THAT STUFF STAYS ON THE STAGE THAT SHOULDN’T BE THERE.
The endgame function calls the removeGame function then when that has been processed, calls theshowResults function. Paste the following into the removeGame function:
      //Remove enemies, the lasers, the explosions (from stage and array) and the player
      for (var i:int = enemies.length-1; i >=0; i--)     {
             removeEnemy(i);
      enemies.splice(i);
      }
      for (var j:int = Lasers.length-1; j >=0; j--)        {
             removeLaser(j);
      Lasers.splice(j);
      }
      for (var k:int = explosions.length-1; k >=0; k--)  {
             removeExplosion(k);
             explosions.splice(k)
      }
      removeChild(player);
      laserTimer.stop();

                                                                                                                                                      
If you test the game now, all should be working – except on gameover of a REPEAT play, the end screen does not appear, that’s because it was moved left of stage in the function moveScreenOff
which we did ages ago, so it needs to be bought back to centre stage when it is made visible. Add the following to  the endGame function
endScreen.x= stage.stageWidth/

We now have a very basic working game. So time to make it playable on a mobile device.
The player will move using the accelerometer feature of the device, so create an Accelerometer type variable, pastinfg this at the top of the script:

var accel:Accelerometer;

Now creat the accelerometer paste this in the function startPlayer before “If the phone has accelerometer support...”

      accel = new Accelerometer();
Then, inside the if bit that the processor accesses IF the device has an accelrometer facility paste the next:
The above script creates a listener for the device movement, and on receiving this trigger calls a new function. So now create the function. Paste this anywhere in column 1

function accelMove(event:AccelerometerEvent):void{
      //accelerationX returns a number between 0,1. Properties: Y, Z.
      player.x -=  event.accelerationX * 80;
      if (player.x < 0) {
             player.x = 0;
      }
      else if (player.x > (stage.stageWidth - player.width) )   {
             player.x = stage.stageWidth - player.width;
      }
}

Basically the code in this function moves the player in the x axis relative to the movement
                                                                                                                                                      of the phone, but with the constraint that if the player gets to the left or the right of the
                                                                                                                                                      stage, it is held there and cannot go outside the stage area.





If the app user answers a phone call, or deactivates the app in any other way, it is good practice to pause everything, so here follows 2 listeners, listening for de-activation and activation. Paste these into column 1:
If these listeners are triggered they call functions (pauseGame()  OR resumeGame



//When the user gets a phone call, or launches another app...
stage.addEventListener(Event.DEACTIVATE, Deactivate);
function Deactivate(event:Event):void{
      pauseGame();
}
//When the user comes back to the game...
stage.addEventListener(Event.ACTIVATE, Activate);
function Activate(event:Event):void{
      resumeGame();
}





Write functions for the two listeners above and paste into column 1:
If the enterFrame listener is not there, the processor cannot call any function and the game will pause
                                                                                                                                                          If the timer is stopped the lsers will not be generated
                                                                                                                                                          If the accelerometer listener is not there, the processor cannot call the function to move the player.

function pauseGame():void{
      //Remove any listener events, timers etc.
      if (gameState == "PLAY_GAME")    {
             removeEventListener(Event.ENTER_FRAME, gameLoop);
             laserTimer.stop();
             accel.removeEventListener(AccelerometerEvent.UPDATE, accelMove);
      }
}

Wednesday, 3 October 2012

Ideas generation




Ideas Generation






Here is a mind map showing some brief ideas for my game.



Idea 1

My first idea is something similar to space invaders. You will be in control of a gun, and you will have to shoot rabbits falling from the sky with para shoots. The setting is kind of similar to the world war theme, so all the backgrounds will be kind of a war zone with planes flying around and explosions. 

I will have levels and on each level the amount of rabbits will increase. I don't think I will change the speed at which they fall because there using para shoots and you cant really change the speed of them. But I think increasing the amount of them will equally be as good and still make it more difficult. 

For buffs, I'm thinking of crates falling from the sky with para shoots as well. The contents of the crate could be random so you don't know what your going to get. The kind of things you could get would be things weapon fire rate. A different kind of gun, maybe with better damage, or damage radius. Maybe as its a war zone you can get a nuke which will kill everything on the screen. Also maybe an XP bonus box which doubles your XP with every kill.

Some of the enemies may have abilities too. Some might have weapons which fire back at you, some with rockets maybe. Ordinary ones wont have anything. At the end of every level there could some kind of boss you have to kill, maybe a helicopter or something. Or just a really big rabbit.

Idea 2

My second idea is kind of similar to the android game 'doodle jump'. You will be some kind of object, maybe a ball, I'm not sure yet. But you will have to jump up loads of objects as quickly as you can because this ride line thing fills up below you and if you fall or miss jump something and fall in it you die. 

buffs for the game would include things like being able to jump higher, able to fly a certain distance, or slow the time of the red thing that moves behind you. The buffs would be identified by a glowing object like a star. 






Here is what my enemy's will look like. I've stuck with just one for now, I would like to add another kind of enemy, maybe a harder one but I'm still not sure how I would do it, or how I would make them harder so Im sticking to just one for the moment.



Here is a screenshot of what I hope the game will look like. The sand bags closest to the bottom is where a gun will be which the user controls to shoot the enemy's as they fall. I think I'm going to try and use my flag as my life system. Basically every time an enemy lands the flag will slowly go down and when it reaches bottom the game is over. When the game is over I think ill make a red flag which gets raised by a tween to show the game is over.


Monday, 1 October 2012

IDE Report

Flash as an IDE


Flash uses a 'Time Line' and with this you are able play a flash file. The timeline uses key frames which are like pages in a flick book. You can use the timeline to play images, animations (tweens) and sound effects. combine the timeline with layers and and action script you can make a very basic game.

vector based graphics are used in Flash. You can get two kinds of graphics, Pixels and Vector. Vector graphics use mathematical calculations which means you can either scale you image bigger or smaller and it wont effect the quality of edges of your image. If you use pixels however if you scale it from its original size your will decrease the quality of it in some shape or form. Also the edges are not sharp in anyway, if you zoomed in you would actually be able to see the individual pixels. So making flash use vector based graphics is a really great way to improve your work flow and just make life easier for the user.

You also have options to create buttons within flash and then use script to give it commands such as to make it play something, take you to a different scene, or play a sound. Flash makes all your graphics and sounds easy to access by using its 'Library'. The Library stores all your graphics and sounds, you can even use script to take things from your library without having to place your sound/ image in a scene.

You can create simple animations in flash as well by using a 'Tween'. To do this, place an image on one key frame, then put it on another key frame further down the timeline but move it slightly. Then right click and create a classic tween and it will create a simple animation.

Flash can also be used for testing you applications created on a simulator. You are able to put it onto a portable device and test it out to see if things are working properly and get a rough layout of it.

Wednesday, 12 September 2012

Task 1

 Here is the title screen for the first Asteroids game. It is is a really basic title screen, no colour. Even the asteroids are just white outlines. The menu only has a start a start button, no instructions or anything. Even though the title screen is so boring, it is still a fun game to play and at the time of release it would've probably looked worse than this.
The game plays exactly how you think it would play really. Again it is still really basic, your ship is just a triangle and the asteroids are just white outlines that move around. You move around by using the arrow keys, you can only move forward and turn left and right, you cant move left and right. This makes the game much more difficult. In the top left is where the scoring system, you gain points the more asteroids you destroy. You only start the game with 3 lives, this is displayed on the top left also. After you have destroyed all the asteroids, you advance to a new level where it gets harder each time. There is also another thing that can kill you, the game aliens which randomly come and go and try to kill you. It uses really simple sound effects, when you shoot its just a simple beep noise, and when you die its like a fuzzy noise. This just shows that you don't need amazing visuals to make game good or addictive.
This version of the game is slightly better visually but still works exactly the same . All that's different with this version is they've added textures and colour to the asteroids and actually turned the space ship into a ship instead of a triangle. Other than a few basic textures nothing has changed.
Here is a screenshot of the game in motion. Again, you can see that visually the game is slightly better. But it looks as if they've used the same shapes for the asteroids but just laid a texture over it. Also they added new sounds for the ship shooting.
This version of Asteroids is the best I could find visually. The first thing i noticed was the menu. IT had a much better background than all the others, it also displayed the controls which no of the others did and also displayed the different abilities and unlocks you can achieve while playing.
In game was also a lot better than the others. It actually had a background of space which looks pretty cool. The asteroids and ship looked quite cartoony but it worked. The asteroids had a better sense in quality about them, even though they wasnt as detailed as the last game, they looked better because you could tell a texture wasnt just slapped over the thing. Also every time you hit an asteroid a little explosion happens which actually looked pretty good. As always the score is located in the top right and your life in the top left.

Ideas generation