A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Score help

  1. #1
    Junior Member
    Join Date
    Apr 2010
    Posts
    2

    Score help

    Hey I'm trying to incorporate a scoring code into the current game...Could someone help me...Thanks!
    Attached Files Attached Files

  2. #2
    An FKer
    Join Date
    Sep 2005
    Location
    Ontario
    Posts
    1,167
    On the main timeline where you duplicate your movieclip add a score variable at the top before the loop. Lets assume you name it score = 0;.

    Now on the cross hair actions, where you have the if statement to check that if the mouse is released and is hit testing the tiki's, increment the score by one:

    PHP Code:
    if(this.hitTest(_root["tiki"+i])&&_root["tiki"+i].dead==0)
            {
                
    _root.score++
                
    trace(_root.score)
                
    _root["tiki"+i].gotoAndPlay(2);
            } 
    I added a trace() so that you can see the score incrementing as you played. Of course, you would just replace that with maybe a dynamic text box that display the score for you: _root.myScore.text = _root.score;.

  3. #3
    Junior Member
    Join Date
    Apr 2010
    Posts
    2
    For some reason it deletes all of the tiki's that are displayed on the current screen when you click. Could you like make a video or something showing the step-by-step? If not, thanks!

  4. #4
    :
    Join Date
    Dec 2002
    Posts
    3,518
    Here's another option...

    Remove all the code from the movie clips. Including the timeline code on the tiki.

    Create a text field on the stage, set the property to dynamic and use the variable 'score'.

    Place this code on the first frame of the main timeline.
    Code:
    var MAIN = this;
    tiki._visible = false;
    
    function inits(num) {
    	MAIN.score = 0;
    	MAIN.num = num;
    	for (var i = 0; i<num; i++) {
    		var myTiki = tiki.duplicateMovieClip("tiki"+i, i+1000, tiki);
    		reset(myTiki);
    		myTiki.onEnterFrame = function() {
    			this._x -= this.speed;
    			if (this._x<0-this.minX || this._currentframe == 5) {
    				reset(this);
    			}
    		};
    	}
    	startDrag(Crosshair, true);
    	Mouse.hide();
    	Crosshair.swapDepths(9999);
    	Crosshair.onMouseDown = doShoot;
    }
    
    function reset(mc) {
    	mc.dead = false;
    	mc.minX = 0-mc._width/2;
    	mc.speed = random(4)+3;
    	mc._x = 600;
    	mc._y = random(400);
    }
    
    function doShoot() {
    	var playsounds = new Sound(this);
    	playsounds.attachSound("shot");
    	playsounds.start(0,1);
    	for (var i = 0; i<MAIN.num; i++) {
    		var myMC = MAIN["tiki"+i];
    		if (myMC.hitTest(this._x, this._y, true) && myMC.dead == false) {
    			myMC.dead = true;
    			MAIN.score += 10;
    			trace(MAIN.score);
    			myMC.gotoAndPlay(2);
    		}
    	}
    }
    
    inits(5);
    Last edited by dawsonk; 05-25-2010 at 09:59 AM.

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