Developing An Application Using Flash And AS 3: Part Four
Project Progress So far
Welcome to the fourth instalment, and probably penultimate episode, of this development project of a game using Flash and ActionScript 3 – to catch up read Developing An Application Using Flash and Action Script 3. I have been reviewing the design plan so far – the welcome screen is in but I initially described it as a welcome/attract screen so I have put a little animation on this screen to grab the attention – I decided upon some gently rotating stars – I had snowflakes in mind when I put it together but they ended up being black which fitted the current design scheme better. In the design plan I also indicated that clicking on the START button on the welcome screen would lead to a setup/get ready type of screen but I’m not sure that is really necessary now.
The game is now pretty much complete, except a few finishing touches, which will come in the final instalment, give it a go and let me know what you make of it.
Read more…
Project Outline Review
- Pairs use a grid of 10 pairs of cards (20 cards in total) arranged in a 5×4 grid.
- At the start of the round cards are randomly shuffled and the timer starts counting in seconds.
- Player clicks one card which flips over to reveal its face; the player then clicks another (different) card which flips over to reveal its face.
- If the two cards are the same the pairs are removed. If there are no more pairs the timer is stopped, the game is over and the final time is presented to the player.
- If the two cards are different they are returned to their face down position after a short time (a few seconds for the player to remember them).
- Add a front information screen prior to the game starting and hook this into a menu button on the game.
Wish List Status
- Animate the cards flipping over – pending
- Play an animation when two matching cards are found – done
- If the player clicks on another card whilst two cards are face up they are immediately returned to their face down position – done
- Add a pause facility which will stop the timer, return cards to their face down position and disable flipping cards until the game is un-paused – pending
- Count the number of times the player flips cards – done
- Add a score to count the number of successful flips – done
- If add a score add a combo for successive matches in a row – done
- Add a game over element if too many flips are made or if timer reaches a certain time – done
- Add a scoreboard feature to record the time and number of flips – pending
- Keep an ongoing record of the players best time and number of flips – perhaps using a cookie?
- Add a high score table – pending
- If add a high score, allow user to enter their name – pending
- Add a title screen – done
- Add a high score screen – pending
Development Questions
During development a number of questions have been posed which require further exploration – these questions, so far, are included in this section.
Would it be better to place an EventListener on the Engine Class or on each card instance?
In the end I decided to use both – there is an event listener on each card to detect a click, this then fires an appropriate event on its parent class to action the event.
How does instance management work?
Instance management is something I have been looking into recently. When creating a new instance they are numbered sequentially however I noticed a few gaps in my numbering sequence. We had instance1, instance 7, instance8, instance 15. For some movie clips there was a gap of 6 instances – why is this?
What object deconstruction and garbage collection is required?
I am still looking into this
Can the stage be clipped or cropped to deal with objects which fall outside of it?
This is a new question which can up when designing the star backdrop. The stars can wander just outside of the stage (up to their width) however this seems to automatically grow the size of the stage – it would be useful to clip the stars to the size of the fixed stage.
Development Update
I have been dealing with a number of issues, call them development bugs, that have been introduced as a result of adding animation effects. In its simplistic form without animation effects, turning cards can be handled quite easily and the game works well. However, when introducing transition effects small delays are introduced (for the animation to play out) which could lead to things like:
- Three cards possibly being turned
- Pairs not disappearing before the end of the game
- Player clicking on a card whilst it is in a transition state
These have been dealt with using an inPlay variable to the Card Class and redirecting Click events based on this value. For example, a card inPlay (value 1) raises a “hit” event on its parent when clicked, however when it is being returned to its face down position based on a small delay the inPlay is set to another value (value 2) which generates a “return immediately” event.
// Define the event handler for this card
private function clickHandler(event:MouseEvent):void
{
// card clicked - inform parent to take action
switch(inPlay)
{
case 1:
dispatchEvent(new Event("hit",true));
break;
case 2:
dispatchEvent(new Event("block",true));
break;
}
}As a result, animation of key game events is requiring a little restructuring of code. These events are the pair match fade, the single card flip and flip back. When turning over the second card - I also need a small delay before any action is taken to ensure enough time is given for the player to assess what has happened.Future Ideas
I have been looking at implementing sound, these are notes for including Sound clips from the library. For this I plan to create a SoundEffect Class to which I can simply push new sounds. Depending on time I may keep this for a future project – so I can focus on the core elements for this project.
// Declare Sound
var mySoundInit:init_sound;
var mySoundInitChannel:SoundChannel;
// Initialise Sound
mySoundInit = new init_sound();
mySoundInitChannel = new SoundChannel();
// Play Sound
mySoundInitChannel = mySoundInit.play();
Comments