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eeeeeUUUeUeVUVU`U`U`UVVVUeffUUUUeUUUUUUeUUUUUUUUUUUUUUUUfUfUUffUUUUVVV`U`U`UVUVUUeUUeUUUUUUeUUUeUUUUUUUUUUUUUUUUUUUUUUUUUUUeUUUeUUUUUeUeVU`UU`UUVUUVUU`UUU`UUUVUUUVVV````UUUUUUUUUUUUUUUUUUUUUUUUUUUUVUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUVUUUVUUU`UUUVUU`VU`VUVUU`UUUVUUUVUUUUUUUUUUUUUUU``V`UVU`UUVUUfUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUVUUU`UUU`UUUVUU`UUVU`V`UUUUUUUUUUUUUUUUUUUUUUUUUUUUVUUUeef`fUfVUUUUUU``V`VU`VUUVUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU`fVU`f``````eeeefefeeeV````VeeeUUUUeUeffffUUUUffff```````VeUeUUUUUUeUUeUUUUUUUUUefUefUUUeVVVffVffVVVVe`V`UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUeUUeUUUUeUUUfUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUeUeUUUUeUUUUUUUUUeUUUe````ffffUUUUeeeeeeeeUUUUffffVVVVVVVVffffUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUeUeUUeUUUeUUUUUUUUUUUUfUfUUefUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUeeee`ff`nffffffffffffffhffffffhffhffffffhhff`ffffff`ffffffffffffffff`f`ffffof " ̯ """"""""""""""( ̌````fff`fffffffffffffffffffffffffffffofoooo D D L LD 03 ("""(""(""""",""""""""""""Œ(""""""""""",""","",""of " f hf""""""""""""""f(h ff`03033330""",""""3"3"03"3,03,"""B""""""B"""""""""""""""""""","L" " """"ofoooo `D ` `f f f` dDd`dffffffoffffffFdfdFDf03 hh("""(""("""""fffffffffffffff&bff""""""""""†("""" " """"","""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""03033330""",""""3"3"03"3,03,"B"""B"" """""""""""""""","L" " """""""""""""""""""f""bf""fD"bfd"bff""""""""""bffffffmfmff""""""""f"""f""f-""-f"""""""""""""""""""""""""""""""""bff"bff"cf2323232332333FffFfffFdff`dff`DDd0fff333c3333mmmfffffffffffffffffff&"""f""fj"fj"jf!f&fa"ff"UUUUUUUUUUUUUUUUUUUUUUUU"333"333""23""""""""""""""""""""3333333333333333"333""""""""""""ff3@f333333332333""""""""&"a&"f&""3"""3"""#"""""""""""UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUffffUUUUUUUUUUUUUUUUUUUUUUUU00000000000033: 33 93:3333333:3 #33333333:333:0 1R3333 :PUUU3UUU3f`fffffffffff`fff?0000000000000000000000093933"3#93"333##1#33"233#333333331R1R3"13#"33333333333UUU3UUU3UU5RU3"23333 ?0?0?0?00?00?0000000000000000000%QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ HIJKQQQQQQQQ-./###7Z[QQQQQQQQ()*=>?333jkQQQ HIJKQQ5656QQQ89:MNQQQQQz{QQQ*****************XYZ[QQ%&7EF%&EFQQQUVQQQQQCDQQQ()*******************hijkQQզ!"զQQQ-.efQQQ\]^CDQQQ89:******************xyz{QQQQ!"ťQQQ%&=>?QQlmnQQQ***********************QQQQ!"CDQQQMNQQQQ |}~QQQ***-./###########7*QQQQ!"CDQQQQQQQQQ***=>?33333333333*QQQQťCDQQQQQ(QQQ***MNO**QQCDQQ&涘զQQQQQ8զQQQ*****QQCD&QQQ\]^QQQ****QQCDQQ&QQQQťlmnQQQ***QQCDQQQuvQQQٽ|}~QQQ***zzQQQQQQQQQQQQQ zzzzQQQQQQQQ]^QQQ񸹺QQQzQQȭQQ1Q1QQQmnQQQQQQ()*+zQQؽAA|}~QQQQQQť89:ިQQ뉉QQQQQQQQQQQQQQQQQQQQQQQQQ##QQQQQQQQQQQQQQQQQQQQQQQމզQQ3Q3QQQQQQQQQQQQQQQQQQQQQQQވQQQQQQQޘQQQQQQQިQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ.3-- title: game title -- author: game developer -- desc: short description -- script: lua --x=60 game_state = "title" x=550 y=50 speed = 0 angle = 47.6 acc = 0 max_speed = 2 min_speed = -0.5 angle_speed = 0.5 cx = 120 cy = 70 slow_tiles = {5, 8, 9, 10, 21, 24, 40, 54, 62, 63, 73, 74, 75, 78, 79, 91, 92, 93, 102, 107, 108, 109, 133, 149, 150, 155, 158, 159, 165, 166, 171, 174, 175, 185, 186, 187, 216, 232, 236, 237, 248, 249, 250, 252, 253} block_tiles = {33, 49, 51, 68, 81} goal_tiles = {6, 7, 23, 39, 55} checkpoint_tiles = {192, 193, 208, 209, 225, 241} car_front = { x = 8, y = 128, w = 8} car_back = { x = 8, y = 136, w = 8} total_started = 0 lap_started = 0 lap_time = 0 best_lap = 0 total_time = 0 current_lap = 0 max_laps = 3 max_acc = 0.05 checkpoint = false countdown = 0 goal_lap = 1200 play_sound1 = false play_sound2 = false play_sound3 = false level = 0 text = { "Hey new guy! I'm the mechanic", "I'll upgrade your car if it's", "too slow for the race. You'll", "be testing it. Let's go!", --level2 "Weird. Your time wasn't good", "enough. Maybe I'll tweak the", "steering a bit. Try this one!", "", --level3 "Haha! Car seems fine now, you", "don't! Maybe you should try ", "the warmup track. It's not as", "challenging....", --level4 "HRRMRM. I don't know why you", "were hired, but maybe you'll", "get better with this engine", "upgrade...", --level5 "YOU KNOW WHAT? I made sure", "that your steering wheel", "works superbly since you", "don't seem to stay on track", --level6 "I upgraded the engine again,", "but it's not like we get to", "see it. Maybe you should try", "our \"kids\" track. ", --level7 "How is this possible?", "Are you drunk?", "", "*throws his hands up*", --level8 "I had a talk with our", "supervisor. You'll be fired", "but you might just as well", "try the car one more time" } m1 = {x = 20, y = 0} m2 = {x = 550, y = 20} m3 = {x = 895, y = 27} level_params = { {speed=2, acc=0.05, angle_speed=0.5, x = m3.x, y = m3.y, angle = 47.6, goal = 14000}, {speed=2.5, acc=0.05, angle_speed=0.75, x = m3.x, y = m3.y, angle = 47.6, goal = 11500}, {speed=3.5, acc=0.05, angle_speed=0.75, x = m1.x, y = m1.y, angle = 47.6, goal = 7500}, {speed=4, acc=0.05, angle_speed=0.75, x = m1.x, y = m1.y, angle = 47.6, goal = 7900}, {speed=5, acc=0.06, angle_speed=1.25, x = m1.x, y = m1.y, angle = 47.6, goal = 8000}, {speed=6.5, acc=0.07, angle_speed=1.25, x = m2.x, y = m2.y, angle = 47.6, goal = 8500}, {speed=7.5, acc=0.08, angle_speed=1.75, x = m2.x, y = m2.y, angle = 47.6, goal = 7000}, {speed=9, acc=0.08, angle_speed=2, x = m2.x, y = m2.y, angle = 47.6, goal = 7500} } function TIC() if (game_state == "title") then cls(0) spr(262, 30, 10, -1, 2, 0, 0, 10, 4) print("Faster than you want it", 50, 80) print("Press X to continue", 60, 130) if btn(5) then game_state = "info" end elseif (game_state == "info") then cls(0) print("In this game you race against", 40, 10) print("time. Reach a goal lap time", 40, 20) print("to advance the plot. It doesn't", 40, 30) print("mean you did well....", 40, 40) print("Up - accelerate", 70, 60) print("Down - brake", 70, 70) print("reverse from tires", 106, 80) print("Left & right - steer", 70, 90) print("Z - restart level", 70, 100) print("Press X to continue", 70, 120) if btnp(5) then game_state = "cutscene" end elseif (game_state == "cutscene") then cls(0) params = level_params[level+1] goal_lap = params.goal max_acc = params.acc max_speed = params.speed angle_speed = params.angle_speed draw_speech() if btnp(5) then --level = level+1 game_state = "countdown" x = params.x y = params.y angle = params.angle current_lap = 0 best_lap = 0 total_started = 0 play_sound1 = false play_sound2 = false play_sound3 = false end --if btnp(4) then -- level = level + 1 --end elseif (game_state == "countdown") then if (countdown == 0) then countdown = time() end cls(5) map(0, 0, 100, 40, -x, -y, -1, 2) draw_car() draw_gui() draw_lights() elseif (game_state == "game") then cls(5) map(0, 0, 240, 136, -x, -y, -1, 2) if(total_started == 0) then total_started = time() lap_started = time() end if (contains(mget(map_x, map_y), checkpoint_tiles)) then checkpoint = true end if (checkpoint and contains(mget(map_x, map_y), goal_tiles)) then if(lap_time < best_lap or best_lap == 0) then best_lap = lap_time end lap_started = time() checkpoint = false if ((current_lap+1) == max_lap) then game_state = "finish" end if (current_lap < max_lap) then current_lap = current_lap + 1 end end total_time = time()-total_started lap_time = time()-lap_started car_physics() --print("HELLO WORLD!",84,84) --print("x: "..(math.floor(x/8+cx/8)/2)..", y: "..(math.floor(y/8+cy/8)/2)..", m:"..mget((x/8+cx/8)/2, (y/8+cy/8)/2), 10, 10) --print("s: .."..math.floor(total_started).." total: "..math.floor(total_time/1000), 10, 10) draw_car()--(angle, x, y) draw_gui() elseif (game_state == "finish") then cls(5) map(0, 0, 240, 136, -x, -y, -1, 2) draw_car() draw_gui() draw_results() if (btnp(5)) then if (level == 7) then game_state = "gameover" elseif (best_lap <= goal_lap) then game_state = "cutscene" level = level + 1 else game_state = "countdown" params = level_params[level+1] max_speed = params.speed angle_speed = params.angle_speed x = params.x y = params.y angle = params.angle max_acc = params.acc current_lap = 0 best_lap = 0 total_started = 0 play_sound1 = false play_sound2 = false play_sound3 = false end end elseif (game_state == "gameover") then cls(0) print("THE END", 100, 50) end end function contains(val, arr) for i=0,#arr do if (arr[i] == val) then return true end end return false end function draw_car()--(angle, x, y) xa31 = (-4)*math.cos(angle/10) + (-1)*math.sin(angle/10) + cx ya31 = (-1)*math.cos(angle/10) - (-4)*math.sin(angle/10) + cy xa32 = (-4)*math.cos(angle/10) + 9*math.sin(angle/10) + cx ya32 = 9*math.cos(angle/10) - (-4)*math.sin(angle/10) + cy xa33 = 3*math.cos(angle/10) + 9*math.sin(angle/10) + cx ya33 = 9*math.cos(angle/10) - 3*math.sin(angle/10) + cy xa34 = 3*math.cos(angle/10) + (-1)*math.sin(angle/10) + cx ya34 = (-1)*math.cos(angle/10) - (3)*math.sin(angle/10) + cy tri(xa31, ya31, xa32, ya32, xa33, ya33, 6) tri(xa31, ya31, xa34, ya34, xa33, ya33, 6) xa21 = (-4)*math.cos(angle/10) + (4)*math.sin(angle/10) + cx ya21 = (4)*math.cos(angle/10) - (-4)*math.sin(angle/10) + cy xa22 = (-4)*math.cos(angle/10) + 12*math.sin(angle/10) + cx ya22 = 12*math.cos(angle/10) - (-4)*math.sin(angle/10) + cy xa23 = 3*math.cos(angle/10) + 12*math.sin(angle/10) + cx ya23 = 12*math.cos(angle/10) - 3*math.sin(angle/10) + cy xa24 = 3*math.cos(angle/10) + (4)*math.sin(angle/10) + cx ya24 = (4)*math.cos(angle/10) - (3)*math.sin(angle/10) + cy --textri(xa21, ya21, xa22, ya22, xa23, ya23, 8, 8, 8, 16, 15, 16, false, 0) --textri(xa21, ya21, xa24, ya24, xa23, ya23, 8, 8, 15, 8, 15, 16, false, 0) textri(xa21, ya21, xa22, ya22, xa23, ya23, car_back.x, car_back.y, car_back.x, car_back.y+car_back.w, car_back.x+car_back.w, car_back.y+car_back.w, false, 0) textri(xa21, ya21, xa24, ya24, xa23, ya23, car_back.x, car_back.y, car_back.x+car_back.w, car_back.y, car_back.x+car_back.w, car_back.y+car_back.w, false, 0) xa = (-4)*math.cos(angle/10) + (-4)*math.sin(angle/10) + cx ya = (-4)*math.cos(angle/10) - (-4)*math.sin(angle/10) + cy xa2 = (-4)*math.cos(angle/10) + 4*math.sin(angle/10) + cx ya2 = 4*math.cos(angle/10) - (-4)*math.sin(angle/10) + cy xa3 = 3*math.cos(angle/10) + 4*math.sin(angle/10) + cx ya3 = 4*math.cos(angle/10) - 3*math.sin(angle/10) + cy xa4 = 3*math.cos(angle/10) + (-4)*math.sin(angle/10) + cx ya4 = (-4)*math.cos(angle/10) + (-3)*math.sin(angle/10) + cy --textri(xa, ya, xa2, ya2, xa3, ya3, 8, 0, 8, 8, 15, 8, false, 0) --textri(xa, ya, xa4, ya4, xa3, ya3, 8, 0, 15, 0, 15, 8, false, 0) textri(xa, ya, xa2, ya2, xa3, ya3, car_front.x, car_front.y, car_front.x, car_front.y+car_front.w, car_front.x+car_front.w, car_front.y+car_front.w, false, 0) textri(xa, ya, xa4, ya4, xa3, ya3, car_front.x, car_front.y, car_front.x+car_front.w, car_front.y, car_front.x+car_front.w, car_front.y+car_front.w, false, 0) end function draw_gui() lap = 0 max_lap = 3 lapt = format_time(lap_time) totalt = format_time(total_time)--"01:02.31" bestt = format_time(best_lap) print("LAP ", 0, 104) print((current_lap+1).." / "..max_lap, 32, 104) print("LAP", 0, 112) print(lapt, 32, 112) print("BEST", 0, 120) print(bestt, 32, 120) print("TOTAL "..totalt, 0, 128) spr(476, 205, 110, 0, 1, 0, 0, 4, 3) local coef = 0 if(speed > 0) then coef = speed/max_speed elseif(speed < 0) then coef = speed/min_speed end clip(205, 110, 4*8*coef, 3*8) spr(428, 205, 110, 0, 1, 0, 0, 4, 3) clip() end function car_physics() local angle_c = angle_speed*(speed/max_speed) if btn(0) then acc=max_acc elseif btn(1) then acc=-0.03 else if (speed < 0) then acc = -0.05 elseif (speed > 0) then acc = -2*max_acc else acc = 0 end end if btn(2) then angle=angle+angle_c end if btn(3) then angle=angle-angle_c end if btnp(4) then game_state = "cutscene" end speed = speed + acc if (speed > max_speed) then speed = max_speed end if(speed < min_speed) then speed = min_speed end local drive_speed = speed; map_x = math.floor(x/8+cx/8)/2 map_y = math.floor(y/8+cy/8)/2 if (contains(mget(map_x, map_y), slow_tiles)) then drive_speed = speed*0.66 end if (contains(mget(map_x, map_y), block_tiles)) then if (speed > 0) then speed = 0 drive_speed = 0 end end x = x - drive_speed*math.sin(angle/10) y = y - drive_speed*math.cos(angle/10) --print("speed: "..drive_speed, 84, 90) --print("rotation: "..angle_c, 84, 96) end function draw_speech() if (level < 6) then spr(304, 160, 72, -1, 2, 0, 0, 6, 6) else spr(342, 160, 72, -1, 2, 0, 0, 6, 6) end for i=0,21 do spr(6, i*8+20, 8) spr(6, i*8+20, 64) end for i=0,6 do spr(6, 20, i*8+16) spr(6, 188, i*8+16) end line(20, 8, 20, 12, 0) line(21, 8, 21, 10, 0) line(22, 8, 22, 9, 0) line(23, 8, 24, 8, 0) line(195, 8, 195, 12, 0) line(194, 8, 194, 10, 0) line(193, 8, 193, 9, 0) line(192, 8, 191, 8, 0) line(20, 71, 20, 67, 0) line(21, 71, 21, 69, 0) line(22, 71, 22, 70, 0) line(23, 71, 24, 71, 0) line(195, 71, 195, 67, 0) line(194, 71, 194, 69, 0) line(193, 71, 193, 70, 0) line(192, 71, 191, 71, 0) print(text[level*4+1], 30, 18) print(text[level*4+2], 30, 30) print(text[level*4+3], 30, 42) print(text[level*4+4], 30, 54) print("Your goal:", 100, 80) print(format_time(goal_lap), 100, 90) print("L", 8, 10, 11) print("E", 8, 20, 11) print("V", 8, 30, 11) print("E", 8, 40, 11) print("l", 8, 50, 11) print(level+1, 8, 65, 11) spr(384, 60, 65, 2, 1, 0, 0, 4, 4) rect(61, 99, max_speed*5, 6, 6) spr(464, 60, 98, 0, 1, 0, 0, 7, 1) rect(61, 109, max_acc*100*5, 6, 6) spr(464, 60, 108, 0, 1, 0, 0, 7, 1) rect(61, 119, angle_speed*5*5, 6, 6) spr(464, 60, 118, 0, 1, 0, 0, 7, 1) print("STATS", 25, 90) print("speed", 23, 100) print("acc", 35, 110) print("steering", 6, 120) end function format_time(t) local neg = false if (t < 0) then neg = true t = -t end local ms = math.floor(t/10%100) local sec = math.floor(t/1000%60) local min = math.floor(t/(1000*60)) if (not neg) then if(sec < 10) then sec = "0"..sec end if(min < 10) then min = "0"..min end else if(sec < 10) then sec = "0"..sec end if(min < 10) then min = "-0"..(-min) end end return min..":"..sec.."."..ms end function draw_lights() spr(480, 100, 40, 9, 1, 0, 0, 4, 2) --print(time()-countdown) if (time() - countdown > 1000) then spr(484, 105, 44, 0) if (not play_sound1) then play_sound1 = true sfx(0, "D-4", 15, 2) end end if (time() - countdown > 2000) then spr(484, 114, 44, 0) if (not play_sound2) then play_sound2 = true sfx(0, "D-4", 15) end end if (time() - countdown > 3000) then spr(500, 123, 44, 0) if (not play_sound3) then play_sound3 = true sfx(0, "G-4", 20) end end if (time() - countdown > 3350) then game_state = "game" countdown = 0 end end function draw_results() rect(56, 16, 120, 72, 0) for i=0,14 do spr(6, i*8+56, 16) spr(6, i*8+56, 80) end for i=0,7 do spr(6, 56, i*8+16) spr(6, 168, i*8+16) end local result_text = " VICTORY!" local result_color = 11 local goal_text = format_time(best_lap-goal_lap) if(best_lap - goal_lap > 0) then goal_text = "+"..goal_text result_text = "TRY AGAIN!" result_color = 6 end print(result_text, 96, 33) print("BEST LAP:", 72, 49) print(format_time(best_lap), 125, 49) print("GOAL: ", 72, 65) print(goal_text, 121, 65, result_color) --print("g:"..goal_lap, 0, 10) --print("l:"..best_lap, 0, 20) end = 02TvͫgE#2Tv2Tv 0D$404mNJNL04e$FHuqaY}},m,Ҫm^