Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function checkLines(file)
- if fs.exists(file) == true then
- sFile = fs.open(file, "r")
- sCount = 0
- for i = 1, math.huge do
- line = sFile:readLine()
- if line ~= nil then
- sCount = sCount+1
- else
- return sCount
- end
- end
- sFile:close()
- else
- return false
- end
- end
- --POWER/HEALTH
- function loadHealth(health, maxHealth)
- term.setCursorPos(1,1)
- if health <= 0 then
- initDeath()
- end
- io.write("H: {")
- for i = 1, health/maxHealth*30 do
- io.write("|")
- end
- term.setCursorPos(35,1)
- io.write("}")
- term.setCursorPos(37,1)
- if health == math.floor(health) then
- io.write(health..".")
- else
- io.write(health)
- end
- end
- function loadPower(power, maxPower)
- term.setCursorPos(1,2)
- if power < 0 then
- power = 0
- end
- io.write("P: {")
- for i = 1, power/maxPower*30 do
- io.write("|")
- end
- term.setCursorPos(35,2)
- io.write("}")
- term.setCursorPos(37,2)
- if power == math.floor(power) then
- io.write(power..".")
- else
- io.write(power)
- end
- end
- --POWER/HEALTH
- --EXPERIENCE
- function loadEXP()
- term.setCursorPos(1,18)
- io.write("{")
- for i = 1, experience/(level^2*50)*46 do
- io.write("|")
- end
- term.setCursorPos(49,18)
- io.write("}")
- term.setCursorPos(24,17)
- io.write(level)
- end
- --EXPERIENCE
- --SAVE/LOAD STUFF
- function Save()
- if fs.exists(".WiredGameSave") == true then
- fs.delete(".WiredGameSave")
- file = io.open(".WiredGameSave","w")
- else
- file = io.open(".WiredGameSave","w")
- end
- file:write(tostring(health).."\n")
- file:write(tostring(maxHealth).."\n")
- file:write(tostring(power).."\n")
- file:write(tostring(maxPower).."\n")
- file:write(tostring(charPos[1]).."\n")
- file:write(tostring(charPos[2]).."\n")
- file:write(char.."\n")
- file:write(tostring(healthRegen).."\n")
- file:write(tostring(powerRegen).."\n")
- file:write(tostring(level).."\n")
- file:write(tostring(armor).."\n")
- file:write(tostring(experience).."\n")
- --MORE STUFF TO SAVE(positions and all that)
- file:close()
- end
- function Load()
- file = fs.open(".WiredGameSave","r")
- health = tonumber(file:readLine())
- maxHealth = tonumber(file:readLine())
- power = tonumber(file:readLine())
- maxPower = tonumber(file:readLine())
- charPos[1] = tonumber(file:readLine())
- charPos[2] = tonumber(file:readLine())
- char = tostring(file:readLine())
- healthRegen = tonumber(file:readLine())
- powerRegen = tonumber(file:readLine())
- level = tonumber(file:readLine())
- armor = tonumber(file:readLine())
- experience = tonumber(file:readLine())
- --MORE STUFF TO LOAD(positions and all that)
- file:close()
- end
- --SAVE/LOAD STUFF
- --DEATH
- function initDeath()
- term.clear()
- term.setCursorPos(1,1)
- print("You died, please submit score.")
- EXPERIENCEZZZ = 0
- for i=1, level do
- EXPERIENCEZZZ = EXPERIENCEZZZ+i^2*50
- end
- print("Experience: "..EXPERIENCEZZZ)
- io.write("Name: ")
- inp = read()
- file = fs.open(".WiredGameScores","r")
- scores = {}
- linesZZZ = checkLines(".WiredGameScores")
- for i = 1, linesZZZ do
- table.insert(scores, tostring(file:readLine()))
- end
- file:close()
- file = io.open(".WiredGameScores","w")
- file:write(tostring(inp)..": "..EXPERIENCEZZZ.."\n")
- for i = 1, linesZZZ do
- file:write(tostring(scores[i]).."\n")
- end
- fs.delete(".WiredGameSave")
- os.reboot()
- end
- --DEATH
- --SPELLS
- function castSpell(spell, currentTick)
- if spell == "Fire" then
- fireSpell = {true, currentTick, charPos[1], charPos[2]}
- end
- if spell == "Fireball" then
- fireballSpell = {true, currentTick, charPos[1], charPos[2], char}
- end
- if spell == "Fire Walk" then
- firewalkSpell = {true, currentTick, charPos[1], charPos[2]}
- end
- if spell == "Super Fire" then
- superfireSpell = {true, currentTick, charPos[1], charPos[2]}
- end
- if spell == "Sprint" then
- sprint = true
- else
- sprint = false
- end
- end
- --SPELLS
- --INPUT
- function processInput()
- while true do
- a, b = os.pullEvent()
- if a == "key" then
- if stopProcesses == false then --Asks if game is paused
- if b == 17 then
- if 3 < charPos[2] then
- charPos[2] = charPos[2]-1
- char = "^"
- end
- if sprint == true then
- if 3 < charPos[2] then
- charPos[2] = charPos[2]-2
- char = "^"
- else
- charPos[2] = 3
- end
- end
- end
- if b == 30 then
- if charPos[1] > 1 then
- charPos[1] = charPos[1]-1
- char = "<"
- end
- if sprint == true then
- if charPos[1] > 1 then
- charPos[1] = charPos[1]-2
- char = "<"
- else
- charPos[1] = 1
- end
- end
- end
- if b == 32 then
- if charPos[1] < 49 then
- charPos[1] = charPos[1]+1
- char = ">"
- end
- if sprint == true then
- if charPos[1] < 49 then
- charPos[1] = charPos[1]+2
- char = ">"
- else
- charPos[1] = 49
- end
- end
- end
- if b == 31 then
- if charPos[2] < 17 then
- charPos[2] = charPos[2]+1
- char = "v"
- end
- if sprint == true then
- if charPos[2] < 17 then
- charPos[2] = charPos[2]+2
- char = "v"
- else
- charPos[2] = 17
- end
- end
- end
- if b == 57 then
- castSpell(currentSpell, tick)
- end
- end
- if b == 2 then
- if level>=1 then
- currentSpell = "Fire"
- end
- end
- if b == 3 then
- if level>=10 then
- currentSpell = "Fireball"
- end
- end
- if b == 4 then
- if level>=20 then
- currentSpell = "Fire Walk"
- end
- end
- if b == 5 then
- if level>=30 then
- currentSpell = "Super Fire"
- end
- end
- if b == 6 then
- if level>=40 then
- currentSpell = "Sprint"
- end
- end
- if b == 7 then
- if level>=50 then
- currentSpell = ""
- end
- end
- if b == 18 then
- if statsMenu == nil then
- statsMenu = true
- end
- if statsMenu == true then
- statsMenu = false
- stopProcesses = false
- else
- statsMenu = true
- stopProcesses = true
- end
- if statsMenu == true then
- if scoreMenu == true then
- scoreMenu = false
- statsMenu = true
- end
- end
- end
- if b == 25 then
- if scoreMenu == nil then
- scoreMenu = true
- end
- if scoreMenu == true then
- scoreMenu = false
- stopProcesses = false
- else
- scoreMenu = true
- stopProcesses = true
- end
- if statsMenu == true then
- if scoreMenu == true then
- scoreMenu = false
- statsMenu = true
- end
- end
- end
- end
- end
- end
- --INPUT
- --TICK
- function processTick()
- while true do
- --Tick System
- if tick/20 == math.floor(tick/20) then
- Save() --Saves every 1s automatically.
- end
- sleep(.05)
- term.clear()
- tick = tick+1
- if statsMenu == true then
- stopProcesses = true
- else
- stopProcesses = false
- end
- if scoreMenu == true then
- stopProcesses = true
- else
- stopProcesses = false
- end
- --Tick System
- --STATS
- maxHealth = level*2
- maxPower = math.floor(level*1.5)
- healthRegen = maxHealth/3000
- powerRegen = maxPower/1000
- --STATS
- --EXPBoxes
- if stopProcesses == false then
- ran = math.random(1000,1500)
- ran2 = math.random(3,17)
- ran3 = math.random(1,49)
- ran4 = math.random(1,50)
- ran5 = math.random(1,5)
- if tick/ran == math.floor(tick/ran) then
- table.insert(box, ran2)
- table.insert(box2, ran3)
- table.insert(box3, ran4)
- if ran5 == 5 then
- table.insert(box4, 1)
- elseif ran5 == 4 then
- table.insert(box4, 2)
- elseif ran5 == 3 then
- table.insert(box4, 3)
- end
- end
- for i = 1, #box do
- term.setCursorPos(box2[i], box[i])
- if box4[i] == 2 or box4[i] == 3 then
- io.write("O")
- else
- io.write("o")
- if box4[i] == 1 then
- box3[i] = 250
- end
- end
- end
- for i = 1, #box do
- if charPos[1] == box2[i] then
- if charPos[2] == box[i] then
- term.setCursorPos(charPos[1]-1,charPos[2]-2)
- io.write(tostring(box3[i]))
- sleep(.08)
- box[i] = -99
- box2[i] = -99
- experience = experience+box3[i]
- box3[i] = -99
- if box4[i] == 1 then
- armor = armor+box4[i]
- elseif box4[i] == 2 then
- if armor>1 then
- armor = armor-1
- else
- health = health-1
- end
- end
- end
- end
- end
- end
- --EXPBoxes
- --Power Regeneration
- if statsMenu == false then --Asks if game is paused.
- if health ~= maxHealth then
- health = health+healthRegen
- end
- if power ~= maxPower then
- power = power+powerRegen
- end
- if maxPower <= power then
- power = maxPower
- end
- if maxHealth <= health then
- health = maxHealth
- end
- term.setCursorPos(37, 1)
- io.write("0.00000000000")
- term.setCursorPos(37, 2)
- io.write("0.00000000000")
- loadHealth(health, maxHealth)
- loadPower(power, maxPower)
- end
- --Power Regeneration
- --Character
- if statsMenu == false then --Asks if game is paused.
- term.setCursorPos(charPos[1], charPos[2])
- io.write(char)
- if lastCharPos ~= charPos then
- term.setCursorPos(lastCharPos[1],lastCharPos[2])
- io.write(" ")
- term.setCursorPos(charPos[1], charPos[2])
- io.write(char)
- end
- lastCharPos[1] = charPos[1]
- lastCharPos[2] = charPos[2]
- end
- --Character
- --DING
- if statsMenu == false then
- loadEXP()
- if experience >= level^2*50 then
- level = level+1
- experience = experience-(level-1)^2*50
- end
- if level == 100 then
- experience = 0
- end
- end
- --DING!
- --Stats Screen
- if scoreMenu == false then
- if statsMenu == true then
- stopProcesses = true
- tick = tick-1
- term.clear()
- term.setCursorPos(1,1)
- print(" -GAME PAUSED-")
- term.setCursorPos(1,4)
- print("Health: "..health.."/"..maxHealth)
- print("Health Regen: "..healthRegen*20 .." per second \n")
- print("Power: "..power.."/"..maxPower)
- print("Power Regen: "..powerRegen*20 .." per second \n")
- print("Armor: "..armor.."/"..maxArmor.."\n")
- print("Level: "..level)
- print("Experience: "..experience.."/"..tostring(level^2*50).."\n")
- io.write("Selected Spell: ")
- if currentSpell == "" or currentSpell == nil then
- io.write("None")
- else
- io.write(currentSpell)
- end
- sleep(.05)
- else
- stopProcesses = false
- end
- end
- if statsMenu == true then
- if scoreMenu == true then
- scoreMenu = false
- statsMenu = true
- end
- end
- --Stats Screen
- --Score Screen
- if statsMenu == false then
- if scoreMenu == true then
- stopProcesses = true
- term.clear()
- tick = tick-1
- file = fs.open(".WiredGameScores","r")
- term.setCursorPos(21,1)
- io.write("-SCORES-\n")
- for i = 1,14 do
- term.setCursorPos(1,i+3)
- print(file:readLine())
- end
- sleep(.05)
- else
- stopProcesses = false
- file:close()
- end
- end
- --Score Screen
- --ARMOR
- if armor >= maxArmor then
- armor = maxArmor
- end
- if armor <= 0 then
- armor = 0
- end
- --ARMOR
- --Spells
- if statsMenu == false and scoreMenu == false then
- if fireSpell[1] == true then
- currentTick = fireSpell[2]
- if power>0 then
- if tick < currentTick+10 then
- charPos[1] = fireSpell[3]
- charPos[2] = fireSpell[4]
- term.setCursorPos(charPos[1]+1,charPos[2])
- io.write("#")
- term.setCursorPos(charPos[1]-1,charPos[2])
- io.write("#")
- term.setCursorPos(charPos[1],charPos[2]+1)
- io.write("#")
- term.setCursorPos(charPos[1],charPos[2]-1)
- io.write("#")
- power = power-.01
- end
- end
- end
- if fireballSpell[1] == true then
- currentTick = fireSpell[2]
- if power>0 then
- vchar = fireballSpell[5]
- if vchar == "^" then
- if fireballSpell[4]-offsetY < 3 then
- fireballSpell[1] = false
- offsetY = 1
- end
- term.setCursorPos(fireballSpell[3], fireballSpell[4]-offsetY)
- io.write("|")
- if tick/1 == math.floor(tick/1) then
- offsetY = offsetY+1
- power = power-(1/9)
- end
- end
- if vchar == "v" then
- if fireballSpell[4]+offsetY > 17 then
- fireballSpell[1] = false
- offsetY = 1
- end
- term.setCursorPos(fireballSpell[3], fireballSpell[4]+offsetY)
- io.write("|")
- if tick/1 == math.floor(tick/1) then
- offsetY = offsetY+1
- power = power-(1/9)
- end
- end
- if vchar == ">" then
- if fireballSpell[3]+offsetX > 48 then
- fireballSpell[1] = false
- offsetX = 1
- end
- term.setCursorPos(fireballSpell[3]+offsetX, fireballSpell[4])
- io.write("-")
- if tick/1 == math.floor(tick/1) then
- offsetX = offsetX+1
- power = power-(1/9)
- end
- end
- if vchar == "<" then
- if fireballSpell[3]-offsetX < 1 then
- fireballSpell[1] = false
- offsetX = 1
- end
- term.setCursorPos(fireballSpell[3]-offsetX, fireballSpell[4])
- io.write("-")
- if tick/1 == math.floor(tick/1) then
- offsetX = offsetX+1
- power = power-(1/9)
- end
- end
- end
- end
- if firewalkSpell[1] == true then
- currentTick = firewalkSpell[2]
- if power>0 then
- if tick < currentTick+10 then
- term.setCursorPos(charPos[1]+1,charPos[2])
- io.write("&")
- term.setCursorPos(charPos[1]-1,charPos[2])
- io.write("&")
- term.setCursorPos(charPos[1],charPos[2]+1)
- io.write("&")
- term.setCursorPos(charPos[1],charPos[2]-1)
- io.write("&")
- power = power-.015
- end
- end
- end
- if superfireSpell[1] == true then
- currentTick = superfireSpell[2]
- if power>0 then
- if tick < currentTick+10 then
- term.setCursorPos(charPos[1]-1,charPos[2]+1)
- io.write("&")
- term.setCursorPos(charPos[1],charPos[2]+1)
- io.write("&")
- term.setCursorPos(charPos[1]+1,charPos[2]+1)
- io.write("&")
- term.setCursorPos(charPos[1]-1,charPos[2])
- io.write("&")
- term.setCursorPos(charPos[1]-2,charPos[2])
- io.write("&")
- term.setCursorPos(charPos[1]+1,charPos[2])
- io.write("&")
- term.setCursorPos(charPos[1]+2,charPos[2])
- io.write("&")
- term.setCursorPos(charPos[1],charPos[2]+2)
- io.write("&")
- term.setCursorPos(charPos[1]-1,charPos[2]-1)
- io.write("&")
- term.setCursorPos(charPos[1]+1,charPos[2]-1)
- io.write("&")
- term.setCursorPos(charPos[1],charPos[2]-1)
- io.write("&")
- term.setCursorPos(charPos[1],charPos[2]-2)
- io.write("&")
- power = power-.25
- end
- end
- end
- end
- --Spells
- end
- end
- --TICK
- --MAIN
- function MAIN()
- charPos = {}
- if lastCharPos == nil then
- lastCharPos = {50, 50}
- end
- if fs.exists(".WiredGameScores") ~= true then
- file = io.open(".WiredGameScores","w")
- file:write(" ")
- file:close()
- end
- if fs.exists(".WiredGameSave") ~= true then
- file = io.open(".WiredGameSave","w")
- file:write(tostring(3).."\n") --health
- file:write(tostring(3).."\n") --maxHealth
- file:write(tostring(3).."\n") --power
- file:write(tostring(3).."\n") --MaxPower
- file:write(tostring(1).."\n") --character xPos
- file:write(tostring(3).."\n") --character yPos
- file:write(tostring(">").."\n") --character looks
- file:write(tostring(.00099999).."\n") --healthRegen
- file:write(tostring(.005).."\n") --powerRegen
- file:write(tostring(1).."\n") --level
- file:write(tostring(0).."\n") --armor
- file:write(tostring(0).."\n") --experience
- file:write(tostring(0).."\n") --game time
- --MORE STUFF TO SAVE(positions and all that)
- file:close()
- end
- Load()
- if tick == nil then
- tick = 0
- end
- term.clear()
- maxArmor = level*10
- fireSpell = {}
- superfireSpell = {}
- fireballSpell = {}
- firewalkSpell = {}
- currentSpell = "Fire"
- offsetX = 1
- offsetY = 1
- maxHealth = level*2
- maxPower = math.floor(level*1.5)
- healthRegen = maxHealth/3000
- powerRegen = maxPower/1000
- box = {}
- box2 = {}
- box3 = {}
- box4 = {}
- stopProcesses = false
- statsMenu = false
- scoreMenu = false
- parallel.waitForAny(processTick, processInput)
- end
- --MAIN
- MAIN()
Advertisement
Add Comment
Please, Sign In to add comment