Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if not fs.exists("/res/bg") then
- shell.run("pastebin get zRp6Q7de res/bg")
- end
- bg = paintutils.loadImage("/res/bg")
- inBattle = false
- inItems = false
- enemy = {
- lvl = 1,
- hp = 0,
- atk = 6
- }
- player = {
- x = 5,
- y = 5,
- xp = 0,
- next = 50,
- level = 1,
- hp = 100,
- maxhp=100,
- atk = 6,
- inventory = {
- [1]="----------",
- [2]="----------",
- [3]="----------",
- [4]="----------",
- [5]="----------",
- [6]="----------",
- [7]="----------",
- [8]="----------",
- [9]="----------",
- [10]="----------"
- }
- }
- function drawHud()
- term.setBackgroundColor(32768)
- term.setTextColor(1)
- term.setCursorPos(1,1)
- term.write("Lvl: "..player.level)
- term.write(" XP: "..player.xp.."/"..player.next)
- term.write(" Atk: "..player.atk)
- term.setCursorPos(1,2)
- term.write("HP: "..player.hp.."/"..player.maxhp)
- end
- function levelUp()
- if player.xp >= player.next then
- player.xp = player.xp - player.next
- player.level = player.level + 1
- player.next = math.ceil(player.next * 1.3)
- player.maxhp = player.maxhp + math.random(25,30)
- player.atk = player.atk + math.random(1,3)
- player.hp = player.maxhp
- end
- end
- while player.hp > 0 do
- sleep(0)
- term.clear()
- paintutils.drawImage(bg,1,1)
- drawHud()
- if inBattle == false then
- paintutils.drawPixel(player.x,player.y,128)
- local e, key = os.pullEvent("key")
- if key == keys.w then
- if player.y > 3 then
- player.y = player.y - 1
- end
- elseif key == keys.s then
- if player.y < 19 then
- player.y = player.y + 1
- end
- elseif key == keys.a then
- if player.x > 1 then
- player.x = player.x - 1
- end
- elseif key == keys.d then
- if player.x < 51 then
- player.x = player.x + 1
- end
- end
- if math.random(1,25) == 1 then
- inBattle = true
- end
- else
- if player.level > 1 then
- enemy.lvl = player.level -1
- else enemy.lvl = 1 end
- enemy.atk = enemy.lvl * 1.5
- enemy.hp = enemy.lvl * math.random(10,20)
- while enemy.hp > 0 and player.hp > 0 do
- term.clear()
- paintutils.drawImage(bg,1,1)
- drawHud()
- term.write(" Enemy HP: "..enemy.hp.." Enemy Lvl: "..enemy.lvl)
- term.setCursorPos(1,3)
- term.setTextColor(32768)
- term.setBackgroundColor(256)
- if not inItems then
- print("[Attack]")
- print("[Item] ")
- print("[Flee] ")
- else
- term.setCursorPos(1,3)
- print("[Back] ")
- for i=1,10 do
- if player.inventory[i] ~= " " then
- term.setCursorPos(1,i+3)
- print(player.inventory[i])
- end
- end
- end
- local e, b, x, y = os.pullEvent("mouse_click")
- if not inItems then
- if y == 3 and x < 9 then
- enemy.hp = enemy.hp - math.random(0,player.atk)
- player.hp = player.hp - math.random(0,enemy.atk)
- elseif y == 4 and x < 9 then
- inItems = true
- elseif y == 5 and x < 9 then
- if math.random(1,2) == 1 then
- inBattle = false
- break
- else
- player.hp = player.hp - math.random(0,enemy.atk)
- end
- end
- else
- if y == 3 and x < 13 then
- inItems = false
- else
- for i=1,10 do
- if y == i+3 and x < 13 then
- elseif player.inventory[i] == "Potion I" then
- player.inventory[i] = "----------"
- player.hp = player.hp + math.floor((player.maxhp/4))
- if player.hp > player.maxhp then
- player.hp = player.maxhp
- end
- elseif player.inventory[i] == "Potion II" then
- player.inventory[i] = "----------"
- player.hp = player.hp + math.floor((player.maxhp/2))
- if player.hp > player.maxhp then
- player.hp = player.maxhp
- end
- elseif player.inventory[i] == "Potion III" then
- player.inventory[i] = "----------"
- player.hp = player.hp + math.floor((player.maxhp/4) * 3)
- if player.hp > player.maxhp then
- player.hp = player.maxhp
- end
- elseif player.inventory[i] == "Potion IV" then
- player.inventory[i] = "----------"
- player.hp = player.maxhp
- end
- end
- end
- end
- end
- end
- end
- inBattle = false
- if player.hp < 1 then
- term.setBackgroundColor(32768)
- term.setTextColor(1)
- term.clear()
- term.setCursorPos(1,1)
- print("GAME OVER")
- sleep(1.5)
- os.reboot()
- else
- if math.random(1,10) == 1 then
- for i=1,10 do
- if player.inventory[i] == "----------" then
- item = math.random(1,4)
- if item == 1 then
- player.inventory[i] = "Potion I"
- elseif item == 2 then
- player.inventory[i] = "Potion II"
- elseif item == 3 then
- player.inventory[i] = "Potion III"
- else
- player.inventory[i] = "Potion IV"
- end
- break
- end
- end
- end
- player.xp = player.xp + math.random(player.level * 2,player.level * 5)
- levelUp()
- end
- end
- end
Add Comment
Please, Sign In to add comment