Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Define Stuff.
- local playerName = "-chucky_100-"
- local xpGained = 0
- local xpLevel = 0
- local sword = "bs"
- local armorEq = "no"
- local health = 20
- local mana = 20
- local armor = 0
- local guySpeaking = "Tjakka5"
- local allVariables = {}
- allVariables.playerName = playerName
- allVariables.xpGained = xpGained
- allVariables.xpLevel = xpLevel
- allVariables.sword = sword
- allVariables.armorAq = armorEq
- allVariables.health = health
- allVariables.mana = mana
- allVariables.armor = armor
- tableOfVariables = textutils.serialize(allVariables)
- local loadedMap = {} --set loadedmap as empty table
- local loadedProps = {}
- local playerSpot
- local loadedMapName
- -- testMap1.
- local testMap1 = {"[]", "[]", "[]", "[]", " ", "[]", "[]", "[]", "[]",
- "[]", " ", " ", " ", " ", " ", " ", " ", "[]",
- "[]", " ", " ", " ", " ", " ", " ", " ", "[]",
- "[]", " ", "[]", " ", "o/", " ", "[]", " ", "[]",
- " ", " ", " ", " ", " ", " ", " ", " ", " ",
- "[]", " ", "[]", " ", " ", " ", "[]", " ", "[]",
- "[]", " ", " ", " ", " ", " ", " ", " ", "[]",
- "[]", " ", " ", " ", " ", " ", " ", " ", "[]",
- "[]", "[]", "[]", "[]", " ", "[]", "[]", "[]", "[]",}
- local testMap2 = {"[]", "[]", "[]", "[]", "[]", "[]", "[]", "[]", "[]",
- "[]", " ", " ", " ", " ", " ", " ", " ", "[]",
- "[]", " ", " ", " ", " ", " ", " ", " ", "[]",
- "[]", " ", " ", " ", " ", " ", " ", " ", "[]",
- "[]", " ", " ", " ", " ", " ", " ", " ", "[]",
- "[]", " ", " ", " ", " ", " ", " ", " ", "[]",
- "[]", " ", " ", " ", " ", " ", " ", " ", "[]",
- "[]", " ", " ", " ", " ", " ", " ", " ", "[]",
- "[]", "[]", "[]", "[]", " ", "[]", "[]", "[]", "[]"}
- local testMap3 = {"[]", "[]", "[]", "[]", "[]", "[]", "[]", "[]", "[]",
- "[]", " ", " ", " ", " ", " ", " ", " ", "[]",
- "[]", " ", " ", " ", " ", " ", " ", " ", "[]",
- "[]", " ", " ", " ", " ", " ", " ", " ", "[]",
- " ", " ", " ", " ", " ", " ", " ", " ", "[]",
- "[]", " ", " ", " ", " ", " ", " ", " ", "[]",
- "[]", " ", " ", " ", " ", " ", " ", " ", "[]",
- "[]", " ", " ", " ", " ", " ", " ", " ", "[]",
- "[]", "[]", "[]", "[]", "[]", "[]", "[]", "[]", "[]"}
- local testMap4 = {"[]", "[]", "[]", "[]", "[]", "[]", "[]", "[]", "[]",
- "[]", " ", " ", " ", " ", " ", " ", " ", "[]",
- "[]", " ", " ", " ", " ", " ", " ", " ", "[]",
- "[]", " ", " ", " ", " ", " ", " ", " ", "[]",
- "[]", " ", " ", " ", " ", " ", " ", " ", " ",
- "[]", " ", " ", " ", " ", " ", " ", " ", "[]",
- "[]", " ", " ", " ", " ", " ", " ", " ", "[]",
- "[]", " ", " ", " ", " ", " ", " ", " ", "[]",
- "[]", "[]", "[]", "[]", "[]", "[]", "[]", "[]", "[]"}
- local testMap5 = {"[]", "[]", "[]", "[]", " ", "[]", "[]", "[]", "[]",
- "[]", " ", " ", " ", " ", " ", " ", " ", "[]",
- "[]", " ", " ", " ", " ", " ", " ", " ", "[]",
- "[]", " ", " ", " ", " ", " ", " ", " ", "[]",
- "[]", " ", " ", " ", " ", " ", " ", " ", "[]",
- "[]", " ", " ", " ", " ", " ", " ", " ", "[]",
- "[]", " ", " ", " ", " ", " ", " ", " ", "[]",
- "[]", " ", " ", " ", " ", " ", " ", " ", "[]",
- "[]", "[]", "[]", "[]", "[]", "[]", "[]", "[]", "[]"}
- function checkEvent(spot)
- if loadedMapName == "testMap1" then
- if spot == 32 then
- xpGained = xpGained+1
- end
- end
- end
- function levelUp()
- if xpLevel == 0 then
- xpReq = 5
- else
- xpReq = xpLevel*10
- if xpLevel > 10 then
- xpReq = xpLevel*20
- end
- end
- if xpGained == xpReq then
- xpGained = xpGained-xpReq
- xpLevel = xpLevel+1
- elseif xpGained > xpReq then
- xpGained = xpGained-xpReq
- xpLevel = xpLevel+1
- end
- end
- function doNewNum(pos, time)
- if time == 1 then
- pos = pos-10
- return(pos)
- elseif time == 2 then
- pos = pos+1
- return(pos)
- elseif time == 3 then
- pos = pos+1
- return(pos)
- elseif time == 4 then
- pos = pos+7
- return(pos)
- elseif time == 5 then
- pos = pos+2
- return(pos)
- elseif time == 6 then
- pos = pos+7
- return(pos)
- elseif time == 7 then
- pos = pos+1
- return(pos)
- elseif time == 8 then
- pos = pos+1
- return(pos)
- end
- end
- function checkValidClick(button, x, y)
- pos = checkPlayerPos()
- y = y-1
- y = y*18
- cp = x+y
- cp = cp/2
- nextNum = 0.5
- for i = 1, 81 do
- if cp == nextNum then
- cp = cp+0.5
- break
- else
- nextNum = nextNum+1
- end
- end
- nextNum = 0.5
- for i = 1, 8 do
- pos = doNewNum(pos, i)
- if pos == cp then
- checkEvent(cp)
- break
- end
- end
- end
- function loadAll()
- if fs.exists("RPG_Game_SaveFile") then
- local file = fs.open("RPG_Game_SaveFile", "r")
- things = file[1]
- print("" ..things)
- end
- end
- function saveAll()
- if fs.exists("RPG_Game_SaveFile") then
- local file = fs.open("RPG_Game_SaveFile", "w")
- file.write(tableOfVariables)
- file.close()
- print("Saved!")
- end
- end
- function gameMenu()
- term.clear()
- term.setCursorPos(1, 1)
- print("+------------------------------------------------+")
- print("| MENU |")
- print("| |")
- print("| |")
- print("| Resume |")
- print("| Save |")
- print("| Load |")
- print("| Log |")
- print("| Exit |")
- print("| |")
- print("| |")
- print("+------------------------------------------------+")
- inOptionScreen = 1
- while inOptionScreen == 1 do
- event, button, x, y = os.pullEvent("mouse_click")
- if (x == 22) or (x == 23) or (x == 24) or (x == 25) or (x == 26) or (x == 27) then
- if y == 5 then
- i = 1000000000000000
- inOptionScreen = 0
- elseif y == 6 then
- saveAll()
- elseif y == 7 then
- loadAll()
- elseif y == 8 then
- print("Log")
- elseif y == 9 then
- os.shutdown()
- end
- end
- runOs()
- end
- end
- function printTalk()
- term.setCursorPos(20, 11)
- print(" " ..guySpeaking)
- term.setCursorPos(20, 12)
- print("+-----------------------------+")
- term.setCursorPos(20, 13)
- print("| Hey Guys! |")
- term.setCursorPos(20, 14)
- print("| This part is not quite done |")
- term.setCursorPos(20, 15)
- print("| but here you can see what |")
- term.setCursorPos(20, 16)
- print("| the people say to you. |")
- term.setCursorPos(20, 17)
- print("| Stay Tuned! |")
- term.setCursorPos(20, 18)
- print("+-----------------------------+")
- end
- function checkStats()
- if armorEq == "no" then
- armor = 0
- elseif armorEq == "le" then
- armor = 1
- end
- end
- function printInv()
- term.setCursorPos(20, 1)
- print("+-----------------------------+")
- term.setCursorPos(20, 2)
- print("| |")
- term.setCursorPos(20, 3)
- term.write("| Sword: ")
- if sword == "bs" then
- print("Basic Sword |")
- term.setCursorPos(20, 4)
- term.write("| This sword does basic damage|")
- elseif sword == "as" then
- print("Advanced Sword |")
- term.setCursorPos(20, 4)
- term.write("| Just a bit sharper... |")
- elseif sword == "bk" then
- print("Basic Knife |")
- term.setCursorPos(20, 4)
- term.write("| Grose, it has blood on it! |")
- elseif sword == "ls" then
- print("Long Sword |")
- term.setCursorPos(20, 4)
- term.write("| Distant killing! |")
- end
- term.setCursorPos(20, 5)
- print("| |")
- term.setCursorPos(20, 6)
- term.write("| Armor: ")
- if armorEq == "no" then
- print("No armor equiped |")
- term.setCursorPos(20, 7)
- term.write("| You're naked! |")
- elseif armorEq == "le" then
- print("Leather armor |")
- term.setCursorPos(20, 7)
- term.write("| Warm, cozy, weak. |")
- end
- term.setCursorPos(20, 8)
- print("| |")
- term.setCursorPos(20, 9)
- print("+-----------------------------+")
- end
- function printStats()
- term.setCursorPos(1, 11)
- print(" " ..playerName)
- print("+----------------+")
- print("| |")
- term.write("| Health: " ..health)
- if health > 9 then
- print(" |")
- else
- print(" |")
- end
- term.write("| Mana: " ..mana)
- if mana > 9 then
- print(" |")
- else
- print(" |")
- end
- print("| Armor: " ..armor.. " |")
- term.write("| xpLvl: " ..xpLevel)
- if xpLevel > 9 then
- print(" |")
- else
- print(" |")
- end
- print("+----------------+")
- end
- function loadMap(map)
- for i = 1, 81 do
- if map == testMap1 then
- loadedMapName = "testMap1"
- loadedMap[i] = testMap1[i]
- setProps(testMap1)
- elseif map == testMap2 then
- loadedMapName = "testMap2"
- loadedMap[i] = testMap2[i]
- setProps(testMap2)
- elseif map == testMap3 then
- loadedMapName = "testMap3"
- loadedMap[i] = testMap3[i]
- setProps(testMap3)
- elseif map == testMap4 then
- loadedMapName = "testMap4"
- loadedMap[i] = testMap4[i]
- setProps(testMap4)
- elseif map == testMap5 then
- loadedMapName = "testMap5"
- loadedMap[i] = testMap5[i]
- setProps(testMap5)
- end
- end
- end
- function setProps(map)
- for i = 1, 81 do
- if map == testMap1 then
- o = testMap1[i]
- elseif map == testMap2 then
- o = testMap2[i]
- elseif map == testMap3 then
- o = testMap3[i]
- elseif map == testMap4 then
- o = testMap4[i]
- elseif map == testMap5 then
- o = testMap5[i]
- end
- if o == "[]" then
- loadedProps[i] = "s"
- elseif o == " " then
- loadedProps[i] = "a"
- elseif o == "O/" then
- loadedProps[i] = "p"
- elseif o == "o/" then
- loadedProps[i] = "e"
- end
- end
- end
- function printMap()
- term.clear()
- term.setCursorPos(1, 1)
- for i = 1, 81 do
- term.write("" ..loadedMap[i])
- if (i == 9) or (i == 18) or (i == 27) or (i == 36) or (i == 45) or (i == 54) or (i == 63) or (i == 72) then
- print("")
- end
- end
- end
- function checkPlayerPos()
- for i = 1, 81 do
- o = loadedProps[i]
- if o == "p" then
- playerSpot = i
- return(playerSpot)
- end
- end
- end
- function checkValidSpot(direction)
- playerSpot = checkPlayerPos()
- if direction == "up" then
- if loadedProps[playerSpot-9] == "a" then
- return(true)
- else
- return(false)
- end
- elseif direction == "down" then
- if loadedProps[playerSpot+9] == "a" then
- return(true)
- else
- return(false)
- end
- elseif direction == "left"then
- if loadedProps[playerSpot-1] == "a" then
- return(true)
- else
- return(false)
- end
- elseif direction == "right" then
- if loadedProps[playerSpot+1] == "a" then
- return(true)
- else
- return(false)
- end
- end
- end
- function movePlayer(direction)
- valid = checkValidSpot(direction)
- playerPos = checkPlayerPos()
- if valid == true then
- loadedMap[playerPos] = " "
- loadedProps[playerPos] = "a"
- if direction == "up" then
- loadedMap[playerPos-9] = "O/"
- loadedProps[playerPos-9] = "p"
- elseif direction == "down" then
- loadedMap[playerPos+9] = "O/"
- loadedProps[playerPos+9] = "p"
- elseif direction == "left" then
- loadedMap[playerPos-1] = "O/"
- loadedProps[playerPos-1] = "p"
- elseif direction == "right" then
- loadedMap[playerPos+1] = "O/"
- loadedProps[playerPos+1] = "p"
- end
- end
- end
- function checkTp()
- playerPos = checkPlayerPos()
- if loadedMapName == "testMap1" then
- if playerPos == 5 then
- loadMap(testMap2)
- loadedMap[68] = "O/"
- loadedProps[68] = "p"
- end
- if playerPos == 45 then
- loadMap(testMap3)
- loadedMap[38] = "O/"
- loadedProps[38] = "p"
- end
- if playerPos == 37 then
- loadMap(testMap4)
- loadedMap[44] = "O/"
- loadedProps[44] = "p"
- end
- if playerPos == 77 then
- loadMap(testMap5)
- loadedMap[14] = "O/"
- loadedProps[14] = "p"
- end
- end
- if loadedMapName == "testMap2" then
- if playerPos == 77 then
- loadMap(testMap1)
- loadedMap[14] = "O/"
- loadedProps[14] = "p"
- end
- end
- if loadedMapName == "testMap3" then
- if playerPos == 37 then
- loadMap(testMap1)
- loadedMap[44] = "O/"
- loadedProps[44] = "p"
- end
- end
- if loadedMapName == "testMap4" then
- if playerPos == 45 then
- loadMap(testMap1)
- loadedMap[38] = "O/"
- loadedProps[38] = "p"
- end
- end
- if loadedMapName == "testMap5" then
- if playerPos == 5 then
- loadMap(testMap1)
- loadedMap[68] = "O/"
- loadedProps[68] = "p"
- end
- end
- end
- -- Update tick functions, Oh gawd, here is where the fun part starts.
- function waitOs()
- os.startTimer(0.05)
- event, button, x, y = os.pullEvent()
- if event == "mouse_click" then
- checkValidClick(button, x, y)
- os.pullEvent("timer")
- elseif event == "key" then
- pressedKey = button
- if (pressedKey == 200) or (pressedKey == 17) then
- movePlayer("up")
- elseif (pressedKey == 203) or (pressedKey == 30) then
- movePlayer("left")
- elseif (pressedKey == 208) or (pressedKey == 31) then
- movePlayer("down")
- elseif (pressedKey == 205) or (pressedKey == 32) then
- movePlayer("right")
- elseif pressedKey == 28 then
- gameMenu()
- end
- os.pullEvent("timer")
- end
- checkTp()
- printMap()
- checkStats()
- printStats()
- printInv()
- printTalk()
- levelUp()
- end
- -- Function for middlePrinting, as many suggested...
- w, h = term.getSize()
- function centerPrint(y, text)
- term.setCursorPos(w/2 - #text/2, y)
- write(text)
- end
- -- Startup Stuff
- loadMap(testMap1)
- loadedMap[68] = "O/"
- loadedProps[68] = "p"
- function runOs()
- for i = 1, 10000000000000000000000000000000000000000000000000000000 do --Dont play this long, please.
- waitOs()
- end
- end
- runOs()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement