Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <pre><code>public function startGame() { speed = C.PLAYER_SPEED; gravity = C.GRAVITY; score = C.PLAYER_START_SCORE; randomChance = C.APPLE_SPAWN_CHANCE; tol = C.HIT_TOLERANCE; apples = []; itemsToSpawn = []; mcGameStage.addEventListener(Event.ENTER_FRAME,update); nextSpawn:Number = 0; } private function update(evt:Event) { //Spawn new apples if (Math.random() &lt; randomChance) { //spawn x coordinates var newPirmas = new Pirmas(); newPirmas.x = Math.random() * C.APPLE_SPAWN_END_X + C.APPLE_SPAWN_START_X; var newAntras = new Antras(); newAntras.x = Math.random() * C.APPLE_SPAWN_END_X + C.APPLE_SPAWN_START_X; var newTrecias = new Trecias(); newTrecias.x = Math.random() * C.APPLE_SPAWN_END_X + C.APPLE_SPAWN_START_X; var newApple = new Apple(); newApple.x = Math.random() * C.APPLE_SPAWN_END_X + C.APPLE_SPAWN_START_X; //spawn y coordinates newPirmas.y = C.APPLE_START_Y; newAntras.y = C.APPLE_START_Y; newTrecias.y = C.APPLE_START_Y; newApple.y = C.APPLE_START_Y; newPirmas.addEventListener(MouseEvent.CLICK, onClick); newAntras.addEventListener(MouseEvent.CLICK, onClick); newTrecias.addEventListener(MouseEvent.CLICK, onClick); newApple.addEventListener(MouseEvent.CLICK, onClick); //add items to itemsToAdd itemsToAdd.push(newPirmas, newAntras, newTrecias, newApple); } //Move Apples for (var i = apples.length-1; i &gt;= 0; i--) { apples[i].y += gravity; if (apples[i].y &gt; C.APPLE_END_Y) { mcGameStage.removeChild(apples[i]); apples.splice(i,1); m_iLives--; if (!m_iLives) { trace("Game Over"); // newApple.removeEventListener(MouseEvent.CLICK, onClick); break; } } } txtScore.text = String(score); if( itemsToSpawn.length &gt; 0 &amp;&amp; getTimeout() &gt; nextSpawn ) { var item:DisplayObject = itemsToAdd.shift(); apples.push(item); mcGameStage.addChild(item); nextSpawn = getTimeout() + Math.random() * 4000; } } function onClick(event:MouseEvent):void { var apples = event.currentTarget; apples.visible = false; apples = tol; score += C.SCORE_PER_APPLE; if(score % 100 == 0) { gravity += 10; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload