//***********************Scene Object - Initialize When Scene Starts Event****************// if($this. scene. state () == "PLAY" ) { // place both the road images road1.x(0); roadl.y(0); road2.x(0); road2.y(-1200); } //**********************road Object - Update Every Frame Event***************************// // move the road down $this.moveY(); // check to see if the road is off the screen if ($this.y() > 1200) { // move it back to the top of the screen $this.y(-1200); } //**********************cycleRed Object - Update Every Frame Event***********************// // move the cycle left if (isKeyPressed(Keys.a)) { $this.moveX(-100); } // move the cycle right if (isKeyPressed(Keys.d)) { $this.moveX(l00); } // if the cycle touches the boost // move the cycle up if ($this.isTouching(boost)) { $this.moveY (-50); } // if the cycle touches the mud // move the cycle down if ($this.isTouching(mud)) { $this.moveY(50); } //************************cycleBlue Object - Update Every Frame Event*********************// // move the cycle left if (isKeyPressed(Keys.leftArrow)) { $this.moveX(-100); } // move the cycle right if (isKeyPressed (Keys.rightArrow)) { $this.moveX(l00); } // if the cycle touches the boost // move the cycle up if ($this.isTouching (boost)) { $this.moveY(-50); } // if the cycle touches the mud // move the cycle down if ($this.isTouching (mud)) { $this.moveY(50); } //**************************mud and boost Objects - Update Every Frame Event***************// // move it down $this.moveY(); // if the it moves off the bottom of the screen if ($this.y() >= 600) { // pick a random x within the screen $this.x(random(l00, 700)); // pick a random y above the screen $this.y(random(-200 , -600)); } //**************************message Object - Update Every Frame Event***********************// // store they values var redY = cycleRed.y(); var blueY = cycleBlue.y(); // determine a winner or who is in the lead if (redY <= 50) { message.text("Red wins!"); } else if (blueY <= 50) { message.text("Blue wins!"); } else if (redY < blueY) { message.text("Red is in the lead!"); } else if (blueY < redY) { message.text("Blue is in the lead!"); } else { message.text("Tied!"); }