topical media & game development

talk show tell print

script-game-event-game.ax

script-game-event-game.ax (swf ) [ flash ]


  
...
author: Default
version: 0.1

  
  
  package {
          import flash.display.MovieClip;
          import flash.text.TextField;
          import flash.events.Event;
          import flash.events.MouseEvent;
          public class script-game-event-game extends MovieClip{
                  private var balls:Array;
                  private var score:int;
                  private var misses:int;
                  public function script-game-event-game() {
                          balls = new Array();                        
                          addEventListener(Event.ENTER_FRAME, run);        
                          score = 0;
                          //ScoreText.text = "0";
                          misses = 0;
                          //MissesText.text = "0";
                  }                
                  
                  public function run(e:Event):void {
                          var tempVar:Number = Math.floor(Math.random() * 100);                        
                          if (tempVar > 90) {
                                  trace("create ball");                
                                  var rx:int = Math.floor(Math.random() * 550);
                                  var ry:int = 0;
                                  var tempBall:script_game_event_game_ball = new script_game_event_game_ball(rx,ry);
                                  tempBall.addEventListener(script_game_event_game_ball.CLICKED, ballClicked);
                                  tempBall.addEventListener(script_game_event_game_ball.MISSED, ballMissed);
                                  balls.push(tempBall);
                                  addChild(tempBall);                                
                          }                        
                          
                          for (var i:int = 0; i < balls.length; i++) {                                
                                  balls[i].run();
                          }
                          
                  }
                  
                  public function ballClicked(e:script_game_event_game_score) {
                          trace("Clicked:"+ script_game_event_game_ball(e.target));
                          for (var i:int = balls.length-1; i >= 0; i--) {                                
                                  if (balls[i] == e.target) {
                                          removeChild(balls[i]);        
                                          balls.splice(i,1);
                                          score+=e.score;
                                          //ScoreText.text = score.toString(); ;
                                  }
                                  
                          }
                          
                  }
                  
                  public function ballMissed(e:Event) {
                          trace("Clicked:"+ script_game_event_game_ball(e.target));
                          for (var i:int = balls.length-1; i >= 0; i--) {                                
                                  if (balls[i] == e.target) {
                                          removeChild(balls[i]);        
                                          balls.splice(i,1);
                                          misses++;
                                          //MissesText.text = misses.toString(); ;
                                  }
                                  
                          }
                          
                  }
                  
                  
          }
  }
  


(C) Æliens 20/2/2008

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.