Home Simple Shooting Game Write the Actionscript - Initialise
Write the Actionscript - Initialise PDF Print E-mail
Written by Geoff Hill   
Saturday, 03 April 2010 14:01

Begin:

There is a lot more code in this game so the actionscript has been spread over a number of pages to aid explanation and make it a little more obvious what each function is doing.
Download actionscript pdf file (23k)

Game Logic

In this game the logic flow is:

  1. Initialise common variables
  2. Add a function to the introduction movieclip to reset/initialise the game.
  3. Initialise/reset the game each time it is played
    • Reset the scoreboard
    • Attach and position the blowpipe from the library
    • Attach and position targets from the library
    • Add a function to each target to make it move
    • Add a function to each target to reset it when popped
  4. Start game engine
    • hide the mouse
    • Add a function to the blowpipe to detect keypresses for movement and firing darts
  5. Additional functions required:
    • shoot and move each dart
    • pop the balloon when hit by a dart
    • game over when all darts used

The Code

Write or copy/paste the following actionscript into Frame 1 of the Actions layer.

Initialise the Game

 

/*
initialise common variables
*/
var num_targets:Number = 3;
var num_darts:Number = 25;
var score:Number = 0;
var miss:Number = 0;
var tx:Number = 600;
var lvl:Number = 100;
// function get click from intro movieclip
intro.onRelease = function() {
init();
};
/*
hide the intro movieclip
initialise game variables
attach the dartgun and set time to fire
load the targets
start the game
*/
init = function () {
intro._visible = false;
num_targets = 3;
num_darts = 25;
score = 0;
miss = 0;
lvl = 100;
scoreboard.darts.text = num_darts;
scoreboard.score.text = score;
scoreboard.miss.text = miss;
_root.attachMovie("blowpipe", "dartgun", 999);
dartgun._x = 267;
dartgun._y = 351;
dart_ttl = getTimer();
loadTargets();
startGame();
};

 

 

 

 

Last Updated on Saturday, 03 April 2010 14:05
 
Copyright © 2012 geoffhill.com.au. All Rights Reserved.
Joomla! is Free Software released under the GNU/GPL License.