PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
timer on a game
A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: timer on a game

  1. #1
    Junior Member
    Join Date
    Feb 2010
    Posts
    27

    timer on a game

    Hello,

    I'm making a game with Flash AS3. So far it works...

    Timer works too but it only count down from 100 till 0 in a fast way.
    But what I want to do is make a
    code:
    if / else

    function on the timer that is linked to movieclips.

    Just need a hint in the right direction.
    I was working on the same project as Joepiooo so dawsonk thank you for the reply on Joepiooo I was just working on that

    The timer is on a keyframe "Actions" on the timeline in the fla file.
    This is the code:

    Actionscript Code:
    var timer:Timer = new Timer(100, 100);
    timer.addEventListener(TimerEvent.TIMER, countdown);
    timer.start();
    function countdown(event:TimerEvent) {
    myText.text = String(100 - timer.currentCount);
    }

    This is the Code of my AS file:

    Actionscript Code:
    package
    {
        import flash.display.MovieClip;
        import flash.events.MouseEvent;
        import flash.display.Sprite;
        import flash.utils.Timer;
        import flash.events.Event;
        import flash.text.*;
        import flash.events.TimerEvent;
        import Card;
        import Cheese;
        import Chips;
        import Ham;
        import Sandwich;
        import Strawberry;
        import Pancake;
       

        public class Foodgame extends MovieClip
        {
            private var _card:Card;
            private var _Cheese:Cheese;
            private var _Chips:Chips;
            private var _Ham:Ham;
            private var _Sandwich:Sandwich;
            private var _Strawberry:Strawberry;
            private var _Pancake:Pancake;
            private var _cardX:Number;
            private var _cardY:Number;
            private var _firstCard:*;
            private var _totalMatches:Number;
            private var _currentMatches:Number;
            private var _cards:Array = new Array();
           
            public function Foodgame()
            {
                _totalMatches = 6;
                _currentMatches = 0;
                createCards();
            }

            private function createCards():void
            {
                _cardX = 45;
                _cardY = 31;
               
                for(var i:Number = 0; i < 2; i++)
                {
                _card = new Card();
                addChild(_card);
                _Cheese = new Cheese();
                _card.setType(_Cheese);
                _card.x = _cardX;
                _card.y = _cardY;
                _cardX += _card.width + 50;
                _card.addEventListener(MouseEvent.CLICK, checkCards);
                }
               
                for(var j:Number = 0; j < 2; j++)
                {
                _card = new Card();
                addChild(_card);
                _Chips = new Chips();
                _card.setType(_Chips);
                _card.x = _cardX;
                _card.y = _cardY;
                _cardX += _card.width + 50;
                _card.addEventListener(MouseEvent.CLICK, checkCards);
                }
                _cardX = 45;
                _cardY += _card.height + 50;
                for(var k:Number = 0; k < 2; k++)
                {
                _card = new Card();
                addChild(_card);
                _Ham = new Ham();
                _card.setType(_Ham);
                _card.x = _cardX;
                _card.y = _cardY;
                _cardX += _card.width + 50;
                _card.addEventListener(MouseEvent.CLICK, checkCards);
                }
               
                for(var l:Number = 0; l < 2; l++)
                {
                _card = new Card();
                addChild(_card);
                _Sandwich = new Sandwich();
                _card.setType(_Sandwich);
                _card.x = _cardX;
                _card.y = _cardY;
                _cardX += _card.width + 50;
                _card.addEventListener(MouseEvent.CLICK, checkCards);
                }
               
                _cardX = 45;
                _cardY += _card.height + 50;
                for(var m:Number = 0; m < 2; m++)
                {
                    _card = new Card();
                    addChild(_card);
                    _Strawberry = new Strawberry();
                    _card.setType(_Strawberry);
                    _card.x = _cardX;
                    _card.y = _cardY;
                    _cardX += _card.width + 50;
                    _card.addEventListener(MouseEvent.CLICK, checkCards);
                }
               
                for(var n:Number = 0; n < 2; n++)
                {
                    _card = new Card();
                    addChild(_card);
                    _Pancake = new Pancake();
                    _card.setType(_Pancake);
                    _card.x = _cardX;
                    _card.y = _cardY;
                    _cardX += _card.width + 50;
                    _card.addEventListener(MouseEvent.CLICK, checkCards);
                }
            }
           
            private function checkCards(event:MouseEvent):void
            {
                event.currentTarget.removeEventListener(MouseEvent.CLICK, checkCards);
               
                if(_firstCard == undefined)
                {
                    _firstCard = event.currentTarget;
                }
                else if(String(_firstCard._type) == String(event.currentTarget._type))
                {
                   
                    _firstCard = undefined;
                    _currentMatches ++;
                    if(_currentMatches >= _totalMatches)
                    {
                       
                    }
                }
                else
                {
                   
                    _firstCard.gotoAndPlay("flipBack");
                    event.currentTarget.gotoAndPlay("flipBack");
                    _firstCard.addEventListener(MouseEvent.CLICK, checkCards);
                    event.currentTarget.addEventListener(MouseEvent.CLICK, checkCards);
                    _firstCard = undefined;
                }
            }
        }
    }

    What I want to do is when you match all card you go to keyframe 2 and the timer stops and thats you "score" (the time you have left is your score).

    When the time is over I want to go to frame 3 and a game over page.

    I know you have to write an If/Else function but I'm not sure how to add these to my movieclip card to function properly.

    Can somebody guide me to the right direction?
    Tnx

    Geert
    Last edited by cancerinform; 02-12-2010 at 10:52 AM.

  2. #2
    Junior Member
    Join Date
    Feb 2010
    Posts
    27
    Is there somebody who can help me with that?

    Geert

  3. #3
    newb of many sorts Ralgoth's Avatar
    Join Date
    Apr 2002
    Posts
    466
    you already have your if statement...

    if(_currentMatches >= _totalMatches)

    for the score, use myTimer.currentCount;

    for the game over, add a timerComplete listener to the timer;
    Search first, asked questions later.

  4. #4
    Junior Member
    Join Date
    Feb 2010
    Posts
    27
    Hello,

    Yeah I got the if statement working now... when all cards match you go to another keyframe...

    But my knowledge of AS3 is not that good, so can you please help me out with hints you gave me?

    I know what you mean but I dont know how to use it in my code and get it working

    Tnx

    Geert

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center