local MAXPOINTS = 10 local index = 0 local altitudes = {} local launches = {} local lastTime = 0 local lastTimerValue = 0 local lastMaxAltitude = 0 local time local altitude local timer local bestTime = 0 local bestTime1 = 0 local bestTime2 = 0 local counter = 0 local target = 10 local timer2 local score = 0 local tasktime = 600 local mark = 1 local lasttimer2 = 0 local tensecmark = 1 local playcountdown = 0 local topscore = 0 local swtch = 0 local lasttime5 = 600 local fivesec local alt_id = getFieldInfo("altitude").id local sc_id = getFieldInfo("sc").id local a1_id = getFieldInfo("a1").id local altmax_id = getFieldInfo("altitude-max").id local function init() for i=0,MAXPOINTS-1 do altitudes[i] = 0 --tasktime = model.getTimer(1) end for i=0,5 do launches[i] = { duration=0, maxHeight=0 } end end local function background() time = getTime() altitude = getValue(alt_id) timer2 = model.getTimer(1) end local function run(event) background() print(event) if time > (lasttime5 + 500) and tensecmark < 1 then lasttime5 = time fivesec = target - timer.value if fivesec > 0 then if score < 11 then playNumber (fivesec, 0, 1) end end end if time > lastTime + 100 then lastTime = time altitudes[index % MAXPOINTS] = altitude index = index+1 lasttimer2 = timer2.value timer = model.getTimer(0) if target > 10 and ((timer.value + 10) >= target) and tensecmark < 1 then playcountdown = 1 --playFile("SOUNDS/en/system/timer10countdown.wav") tensecmark = 1 end end if getValue(sc_id) > 0 then --if (timer2.value > lasttimer2) then counter = 0 score = 0 target = 10 tensecmark = 0 --target = popupInput("Overwrites existing functions!", event,0, 0, 0) --target = popupInput("Switch", event, swtch, -SWSRC_LAST, SWSRC_LAST) --target = popupInput("Switch", event, 5, 1, 30) end timer = model.getTimer(0) if timer.value < lastTimerValue then launches[5] = launches[4] launches[4] = launches[3] launches[3] = launches[2] launches[2] = launches[1] launches[1] = launches[0] launches[0] = { duration=lastTimerValue, maxHeight=lastMaxAltitude } lastMaxAltitude = 0 counter = counter + 1 mark = 1 tensecmark = 0 end lastTimerValue = timer.value if altitude > lastMaxAltitude then lastMaxAltitude = altitude end if (score > bestTime2) and (score < bestTime1) then bestTime2 = score end if (score > bestTime1) and (score < bestTime) then bestTime2 = bestTime1 bestTime1 = score end if score > bestTime then bestTime2 = bestTime1 bestTime1 = bestTime bestTime = score end --GAME --end if score < 11 then if ((launches[0].duration >= target) and (mark > 0)) and timer2.value > 0 then --if timer.value >= target target = target + 5 score = score + 1 if score > 9 then --and score < 11 then score = timer2.value playFile("SOUNDS/en/horn.wav") playFile("SOUNDS/en/pouet.wav") playNumber(score, 0, 1) --score = 0 end mark = 0 playFile("SOUNDS/en/system/0112.wav") playNumber(target, 0, 1) end end -- game timer draw lcd.drawTimer(105, 15, target, MIDSIZE) lcd.drawTimer(105, 30, timer2.value, MIDSIZE) --lcd.drawText(148, 23, "Best", SMLSIZE) --lcd.drawNumber (161, 30, topscore, MIDSIZE) lcd.drawTimer (105, 50, score, MIDSIZE) lcd.drawText(110, 43, "Score", SMLSIZE) if (playcountdown > 0) and score < 11 then playNumber((target + 5), 0, 1) playFile("SOUNDS/en/system/timer10countdown.wav") playcountdown = 0 end -- left column lcd.drawTimer(105, 0, timer.value, MIDSIZE) local maxAltitude = getValue(altmax_id) lcd.drawNumber(79, 0, 3.28*maxAltitude, MIDSIZE) for i=0,5 do if launches[i].duration > 0 then lcd.drawTimer(10, 11+i*9, launches[i].duration, 0) lcd.drawNumber(70, 11+i*9, 3.28*launches[i].maxHeight , 0) end end -- a1 rx voltage lcd.drawText(2, 0, "rx", 0) lcd.drawNumber(30, 0, (getValue(a1_id)) * 10, PREC1) lcd.drawText(31, 0, "v", 0) -- right column lcd.drawNumber(211, 0, 3.28*altitude, MIDSIZE) lcd.drawTimer(180, 21, bestTime, 0) lcd.drawTimer(180, 31, bestTime1, 0) lcd.drawTimer(180, 41, bestTime2, 0) lcd.drawText(175, 55, "Num", SMLSIZE) lcd.drawText(182, 13, "Best", SMLSIZE) lcd.drawNumber(210, 55, counter, 0) end return { init=init, background=background, run=run }