Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- tArgs = {...}
- config = tArgs[1]
- function testfor(x1,y1,x2,y2,ex,ey)
- for i=x1,x2 do
- for o=y1,y2 do
- if i == ex and o == ey then
- return true
- end
- end
- end
- return false
- end
- if not fs.exists(config) then
- file = fs.open(config,"w")
- file.write("{\n")
- file.write("Difficulty = normal;\n")
- file.write("Startstep = 0;")
- file.write("Record = 0;")
- file.write("}")
- file.close()
- difi = "normal"
- end
- data = complile(config)
- data[3][2] = tonumber(data[3][2])
- difi = data[1][2]
- platnum = tonumber(data[2][2])
- function editsettings(edit)
- file = fs.open(config,"w")
- file.write("{\n")
- if not edit then
- data[1][2] = difi
- data[2][2] = platnum
- end
- for i=1,#data do
- file.write(data[i][1].." = "..data[i][2]..";\n")
- end
- file.write("}")
- file.close()
- end
- function coloredsteps(num)
- if num < 50 then return blue
- elseif num < 100 then return green
- elseif num < 150 then return yellow
- elseif num < 200 then return orange
- elseif num < 250 then return red
- elseif num < 300 then return lightGray
- elseif num < 350 then return gray
- elseif num < 400 then return black
- elseif num < 450 then return white
- elseif num >= 450 then return 2^math.random(1,15) end
- end
- function gameover()
- sel = 1
- while true do
- Clear()
- scp(20,8)
- write((sel == 1 and ">" or sel == 2 and " ").."Restart"..(sel == 1 and "<" or sel == 2 and " "))
- scp(21,10)
- write((sel == 2 and ">" or sel == 1 and " ").."CLOSE"..(sel == 2 and "<" or sel == 1 and " "))
- repeat event,key = os.pullEvent("key_up") until key == up or key == down or key == enter
- if key == up then sel = 1 end
- if key == down then sel = 2 end
- if key == enter then
- if sel == 1 then shell.run("Doodle/game",config) end
- break
- end
- end
- end
- function settings()
- while true do
- Clear(lightBlue)
- scp(2,6)
- write("!Every 50th Step new color!")
- scp(2,18)
- write("Record: "..data[3][2])
- scp(2,2)
- write("Difficulty: ")
- drawPixel(14,2,(difi == "normal" and yellow or difi == "easy" and green or difi == "hard" and red))
- sbc(lightBlue)
- write(" "..data[1][2])
- scp(2,4)
- write("Starting at step: "..platnum)
- drawPixel(20,4,coloredsteps(platnum))
- drawBox(45,16,50,18,green)
- scp(46,17)
- write("Back")
- event,key,x,y = os.pullEvent("mouse_click")
- if testfor(45,16,50,18,x,y) then os.startTimer(0.001) break end
- if testfor(2,2,12,2,x,y) then
- if difi == "normal" then
- difi = "hard"
- elseif difi == "hard" then
- difi = "easy"
- elseif difi == "easy" then
- difi = "normal"
- end
- editsettings()
- end
- if testfor(2,4,18,4,x,y) then
- if platnum + 50 <= data[3][2] and platnum < 450 then
- platnum = platnum + 50
- else
- platnum = 0
- end
- editsettings()
- end
- end
- end
- function smenu()
- os.startTimer(0.001)
- menu = true
- while menu do
- if event == "timer" then
- os.startTimer(3)
- Clear(lightBlue)
- for i=1,7 do
- n = math.random(1,48)
- drawLine(n,i*2,n+3,i*2,blue)
- end
- x = math.random(3,48)
- y = math.random(3,10)
- drawPixel(x,y,green)
- drawBox(24,16,33,18)
- scp(25,17)
- write("Settings")
- drawBox(16,16,22,18,green)
- scp(17,17)
- write("Start")
- end
- event,key,x,y = os.pullEvent()
- if testfor(16,16,22,18,x,y) and event == "mouse_click" then break end
- if testfor(24,16,33,18,x,y) and event == "mouse_click" then settings() end
- end
- end
- smenu()
- if difi == "normal" then difi = 8
- elseif difi == "hard" then difi = 6
- elseif difi == "easy" then difi = 10
- else error("Unable to read Difficulty",0) end
- addlog("Game Started")
- doodle = {20,10}
- mot = 10
- plat = {}
- function generatePlat()
- addlog("All Platforms generated")
- for i=1,10 do
- n = math.random(1,48)
- table.insert(plat,1,{n,n+3,i*2,platnum})
- end
- end
- function addPlat()
- platnum = platnum + 1
- addlog("Added a new Platform")
- n = math.random(1,48)
- table.insert(plat,1,{n,n+3,1,platnum})
- table.remove(plat,20)
- end
- timer = os.startTimer(0.03)
- os.startTimer(0.2)
- generatePlat()
- while true do
- if event == "timer" and key ~= timer then
- for i=1,#plat do
- for o=plat[i][1],plat[i][2] do
- if doodle[1] == o and doodle[2]+1 == plat[i][3] and mot < 1 then
- mot = difi
- end
- end
- end
- if mot > 0 then
- doodle[2] = doodle[2] - 1
- if doodle[2] < 4 then
- doodle[2] = doodle[2] + 1
- for i=1,#plat do
- plat[i][3] = plat[i][3] + 2
- end
- addPlat()
- end
- else
- doodle[2] = doodle[2] + 1
- end
- if doodle[2] > 19 then
- Clear(black)
- if platnum - data[2][2] > data[3][2] then
- data[3][2] = platnum - data[2][2]
- editsettings(true)
- printError("!NEW RECORD!")
- print("")
- printError("SCORE: "..data[3][2])
- os.sleep(3)
- gameover()
- os.shutdown()
- else
- printError("GAME OVER")
- os.sleep(1)
- gameover()
- os.reboot()
- end
- end
- mot = mot - 1
- addlog("DrawScreen")
- Clear(lightBlue)
- for i=1,#plat do
- drawLine(plat[i][1],plat[i][3],plat[i][2],plat[i][3],coloredsteps(plat[i][4]))
- scp(plat[i][1],plat[i][3])
- write("----")
- end
- drawPixel(doodle[1],doodle[2],green)
- sbc(lightBlue)
- scp(43 - string.len(tostring(platnum)),1)
- write("Score: "..platnum-data[2][2])
- os.startTimer(0.3)
- elseif key == timer then
- if move then
- drawPixel(doodle[1],doodle[2],lightBlue)
- if doodle[1] == 1 and move == -1 then doodle[1],move = 51,nil
- elseif doodle[1] == 51 and move == 1 then doodle[1],move = 1,nil
- else doodle[1],move = doodle[1] + move,nil end
- drawPixel(doodle[1],doodle[2],green)
- end
- timer = os.startTimer(0.1)
- end
- event,key = os.pullEvent()
- if event == "key" then
- if key == left then addlog("Pressed Left") move = -1 end
- if key == right then addlog("pressed Right") move = 1 end
- if key == keys.enter then addlog("pressed Enter") Clear(black) break end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement