local sGameRunning local sMoving local sStartTime local sDirection on preOpenCard set the layerMode of btn "road1" to "dynamic" set the layerMode of btn "road2" to "dynamic" set the layerMode of btn "car" to "dynamic" setupscreen end preOpenCard on setupscreen set the bottomLeft of btn "road1" to 0, the height of this stack set the bottomLeft of btn "road2" to the right of btn "road1", the height of this stack set the left of btn "car" to 10 set the bottom of btn "car" to the height of this stack - 30 end setupscreen on startLoop ## Checks to see if the loop is already running; if not start loop if sMoving is not true then ## Starts responding to the game loop and resets script locals put true into sMoving put the millisecs into sStartTime end if end startLoop on stopLoop ## Stop responding to the game loop put false into sMoving end stopLoop on mouseDown put the millisecs into sStartTime end mouseDown on mouseUp put the millisecs into sStartTime end mouseUp on updateScreen ## Check if the screen should be updated if sMoving is true then moveRoad carAccelerate else # (if sMoving is false) end if end updateScreen on moveRoad set the left of btn "road1" to the left of btn "road1" - 5 set the left of btn "road2" to the left of btn "road2" - 5 if the right of btn "road2" < 0 then set the bottomleft of btn "road2" to the bottomright of btn "road1" end if if the right of btn "road1" < 0 then set the bottomleft of btn "road1" to the bottomright of btn "road2" end if end moveRoad on carAccelerate put the millisecs - sStartTime into tTimeSinceChange put 9.81 * ((tTimeSinceChange / 1000)^2) into tMoveAmount ## roughly simulate gravity, assuming one pixel is equal to one metre ## Update the game state if the mouse is not down then ## If the mouse is not being pressed, the car should slow down set the icon of button "car" to 1020 # you may need to change this image id number if (the left of button "car" - tMoveAmount) > the left of this card then set the right of button "car" to the right of button "car" - tMoveAmount end if else ## otherwise the car should accelerate set the icon of button "car" to 1020 # you may need to change this image id number if (the right of button "car" + tMoveAmount) <= the right of this card then set the right of button "car" to the right of button "car" + tMoveAmount end if end if end carAccelerate