os.loadAPI("lgs/gameapi") function achieve(num) if num == 1 then gameapi.achieve("questsp","Monster attacker","kill 10 monsters", 5) elseif num == 2 then gameapi.achieve("questsp","Monster killer", "kill 50 monsters", 15) elseif num == 3 then gameapi.achieve("questsp","Monster Champion","kill 250 monsters", 25) elseif num == 4 then gameapi.achieve("questsp","Monster Destroyer", "kill 500 monsters", 35) elseif num == 5 then gameapi.achieve("questsp","Leveled up", "Get to Level 10", 5) elseif num == 6 then gameapi.achieve("questsp", "Alot stronger", "Get to level 25",15) elseif num == 7 then gameapi.achieve("questsp", "Dragon fighter", "Get to level 50", 25) elseif num == 8 then gameapi.achieve("questsp", "Ultimate fighter", "Get to level 100", 40) end end if term.isColor() then color = true else color = false end function lvlup() lvl = lvl +1 if lvl == 10 then achieve(5) end if lvl == 25 then achieve(6) end if lvl == 50 then achieve(7) end if lvl == 100 then achieve(8) end if class == "knight" then att = att +4 -- 4 defense = defense +4 -- 8 maxhp = maxhp +4 -- 12 hp = maxhp acc = acc +3 -- 15 elseif class == "archer" then acc = acc +5 -- 5 att = att +3 -- 8 defense = defense +3 -- 11 maxhp = maxhp +4 -- 15 hp = maxhp elseif class == "magician" then acc = acc +3 -- 3 att = att +6 -- 9 defense = defense +3 -- 12 maxhp = maxhp +3 -- 15 hp = maxhp end xp = 0 xpn = xpn *2 end function draw() g = 1 f = 1 grass = 1 if color == true then term.setBackgroundColor(colors.lime) end for grass = 1, 15 do term.setCursorPos(17,grass +2) write(" ") end if color == true then term.setBackgroundColor(colors.lightGray) end for g = 1,walls do sleep(0.05) term.setCursorPos(wallsx[g] + 16,wallsy[g] +2) if color == false then write("=") else write(" ") end end term.setCursorPos(x +16,y +2) if color == true then term.setBackgroundColor(colors.blue) end write("+") end function collidet(xt,yt) collidev = false for coll = 1, walls do if wallsx[coll] == xt then if wallsy[coll] == yt then collidev = true return true end end end for coll = 1, mc do if malive[coll] == true then if mx[coll] == xt then if my[coll] == yt then collidev = true return true end end end end if collidev == false then return false end end function mdie(monid) term.setCursorPos(mx[monid] +16, my[monid] +2) malive[monid] = false if color == true then term.setBackgroundColor(colors.lime) end write(" ") term.setBackgroundColor(colors.black) xp = xp +mxp[monid] mkilled = mkilled +1 if mkilled == 10 then achieve(1) elseif mkilled == 50 then achieve(2) elseif mkilled == 250 then achieve(3) elseif mkilled == 500 then achieve(4) end mx[monid] = 20 my[monid] = 10 mhp[monid] = 0 end function attackf(tax, tay, tadmg) -- To attack X, to attack y, to attack damage if x == tax and y == tay then adef = defense / 10 adtadmg = adtadmg - adef hp = hp -adtadmg -- After defense To attack damage if hp < 0 then hp = 0 end end for i = 1, mc do if mx[i] == tax and my[i] == tay then if malive[i] == true then mhp[i] = mhp[i] -tadmg if mhp[i] <= 0 then mdie(i) end end end end end function updatechar() if color == true then term.setBackgroundColor(colors.lime) end term.setCursorPos(oldx +16 ,oldy +2) write(" ") if color == true then term.setBackgroundColor(colors.blue) end term.setCursorPos(x + 16, y +2) write("+") end function move(dir) oldx = x oldy = y if dir == "up" then if collidet(x,y -1) == false then y = y -1 end elseif dir == "down" then if collidet(x,y +1) == false then y = y +1 end elseif dir == "right" then if collidet(x +1,y) == false then x = x +1 end elseif dir == "left" then if collidet(x -1,y) == false then x = x -1 end else print("Error: Invalid direction") end end function collidem(xm,ym) collidev = false for coll = 1, walls do if wallsx[coll] == xm then if wallsy[coll] == ym then collidev = true return true end end end for coll = 1, mc do if mx[coll] == xm then if my[coll] == ym then collidev = true return true end end end if xm == x then if ym == y then collidev = true return true end end if collidev == false then return false end end function movemon() for ms = 1, mc do if malive[ms] == true then -- if mx[ms] ~= x -1 or mx[ms] ~= x +1 and my[ms] ~= y +1 and my[ms] ~= y -1 then if mx[ms] > x then if collidem(mx[ms] -1 , my[ms]) == false then oldmx[ms] = mx[ms] oldmy[ms] = my[ms] mx[ms] = mx[ms] -1 end elseif mx[ms] < x then if collidem(mx[ms] +1,my[ms]) == false then oldmy[ms] = my[ms] oldmx[ms] = mx[ms] mx[ms] = mx[ms] +1 end elseif my[ms] > y then if collidem(mx[ms],my[ms] -1) == false then oldmy[ms] = my[ms] oldmx[ms] = mx[ms] my[ms] = my[ms] -1 end elseif my[ms] < y then if collidem(mx[ms],my[ms] +1) == false then oldmy[ms] = my[ms] oldmx[ms] = mx[ms] my[ms] = my[ms] +1 end -- end end end end end mxp = {} function monsterchar(type) if type == "skeleton" then return "#" elseif type == "dragon" then return "&" elseif type == "great_dragon" then return "@" elseif type == "orb" then return "*" elseif type == "enemy_soldier" then return "%" elseif type == "enemy_general" then return "$" else return "^" end end function updatemon() for i = 1, mc do if oldmx[i] and oldmy[i] then term.setCursorPos(oldmx[i] +16, oldmy[i] +2) if color == true then term.setBackgroundColor(colors.lime) end write(" ") end end for i = 1, mc do if malive[i] == true then term.setCursorPos(mx[i] +16, my[i] +2) if color == true then term.setBackgroundColor(colors.red) end local char = monsterchar(mt[i]) write(char) end end end function skill(skillname) if att ~= nil and acc ~= nil then att = att -1 acc = acc -1 att = att +1 acc = acc +1 if skillname == "focus" then tempattack = att*1.5 skillt = 3 elseif skillname == "charge" then tempattack = att*3 skillt = 1 elseif skillname == "aim" then tempacc = acc*1.5 skillt = 1 end end end function mca() --[[ for i = 1, mc do if malive[i] == true then if mx[i] == x -1 then attackf(x,y, matk[i]) elseif mx[i] == x +1 then attackf(x,y, matk[i]) elseif my[i] == y +1 then attackf(x,y, matk[i]) elseif my[i] == y - 1 then attackf(x,y, matk[i]) end end end --]] end function newmon(mcx,mcy,mctype) mc = mc +1 malive[mc] = true mx[mc] = mcx -- Monster creation x my[mc] = mcy -- Monster creation y mt[mc] = mctype -- Monster creation type if mctype == "skeleton" then mhp[mc] = 10 mxp[mc] = 10 matk[mc] = 2 elseif mctype == "dragon" then mhp[mc] = 25 mxp[mc] = 20 matk[mc] = 5 elseif mctype == "great_dragon" then mhp[mc] = 50 mxp[mc] = 65 matk[mc] = 8 elseif mctype == "orb" then mhp[mc] = 20 mxp[mc] = 20 matk[mc] = 2 elseif mctype == "enemy_soldier" then mhp[mc] = 20 mxp[mc] = 30 matk[mc] = 3 elseif mctype == "enemy_general" then mhp[mc] = 30 mxp[mc] = 40 matk[mc] = 4 else mhp[mc] = 35 mxp[mc] = 50 matk[mc] = 5 end end function showstats() term.setBackgroundColor(colors.black) term.setCursorPos(38,1) write("HP: "..hp.."/"..maxhp.."") term.setCursorPos(38,2) write("XP: "..xp.."/"..xpn.."") term.setCursorPos(1,4) write("Level: "..lvl.."") term.setCursorPos(1,5) write("Attack: "..att.." "..tempattack.."") term.setCursorPos(1,6) write("Defense: "..defense.." ") term.setCursorPos(1,16) if acc and tempacc then write("Accuracy: "..acc.." "..tempacc) end end mkilled = 0 malive = {} -- Records if the monster is alive oldmx = {} -- old monster position x oldmy = {} -- Old monster position y mx = {} -- Monster position x my = {} -- Monster position y mc = 0 -- Monster count mt = {} -- Monster type matk = {} -- mcr = {} color could come later mhp = {} -- Health of monster, max health is set when creating monster walls = 0 up = 17 up2 = 200 r = 32 r2 = 205 l = 30 l2 = 203 down =31 down2 =208 x = 5 y = 5 wallsx = {} wallsy = {} term.setCursorPos(1,1) term.clear() s = 1 confirm = false print("Welcome to Quest!") print("Please select a character with D or Right arrow key Or A and left arrow key") print("Press W or up arrow key to confirm") sleep(2) term.clear() term.setCursorPos(1,1) write("Knight, good attack and defense stats") while confirm == false do sleep(0.05) e, k = os.pullEvent("key") term.clear() term.setCursorPos(1,1) term.setTextColor(colors.white) if k == r or k == r2 then if s ~= 3 then s = s +1 else s = 1 end elseif k == l or k == l2 then if s ~= 1 then s = s -1 else s = 3 end elseif k == up or k == up2 then if s == 1 then class = "knight" confirm = true elseif s == 2 then class = "archer" term.setCursorPos(1,2) confirm = true else class = "magician" term.setCursorPos(1,2) confirm = true end end term.setCursorPos(1,1) if s == 1 then write("Knight, good attack and defense stats") elseif s == 2 then term.setTextColor(colors.white) write("Archer, Great accuracy") elseif s == 3 then term.setTextColor(colors.white) write("Magician, Low defense, Low health, Best attack") end end run = true term.clear() term.setCursorPos(1,1) print("Setting up walls!") print("This could take up to about 5 seconds") for i = 1, 15 do walls = walls +1 w = walls sleep(0.05) wallsx[w] = i wallsy[i] = 1 end for u = 1, 15 do walls = walls +1 sleep(0.05) w = walls wallsx[w] = 1 wallsy[w] = u end for o = 1, 15 do walls = walls +1 sleep(0.05) w = walls wallsx[w] = o wallsy[w] = 15 end for p = 1, 15 do walls = walls +1 sleep(0.05) w = walls wallsx[w] = 15 wallsy[w] = p end wallsx[61] = 10 wallsy[61] = 12 wallsx[62] = 11 wallsy[62] = 12 wallsx[63] = 12 wallsy[63] = 12 wallsx[64] = 11 wallsy[64] = 4 wallsx[65] = 13 wallsy[65] = 10 wallsx[66] = 19 wallsy[66] = 10 wallsx[67] = 20 wallsy[67] = 9 wallsx[68] = 21 wallsy[68] = 10 wallsx[69] = 20 wallsy[69] = 11 wallsx[70] = 3 wallsy[70] = 10 walls = 70 term.setCursorPos(1,1) term.clear() draw() numloop = 1 t1 = os.clock() t2 = os.clock() + 0.3 newmon(11, 5, "dragon") skillt = 0 lvl = 1 maxhp = 10 hp = 10 att = 5 defense = 5 tempattack = att tempacc = acc acc = 50 xp = 1 xpn = 50 -- Amount of xp needed total to get to next level maxlvl = 100 while run == true do if xp >= xpn then lvlup() end if hp ~= 0 then --Do stuff else term.clear() print("YOU DIED!") sleep(3) run = false end showstats() term.setCursorPos(1,1) term.setBackgroundColor(colors.black) print("loops: "..numloop.."") numloop = numloop +1 os.startTimer(0.20) sleep(0.1) e,key = os.pullEvent() if e == "key" then t2t = os.clock() if t2t - t1 > 0.15 or t2 - t1 > 0.15 then if skillt ~= 0 then skillt = skillt -1 else tempacc = acc tempattack = att end if e == "key" then t1 = os.clock() t2 = os.clock() if key == r or key == r2 then move("right") updatechar() elseif key == l or key == l2 then move("left") updatechar() elseif key == up or key == up2 then move("up") updatechar() elseif key == down or key == down2 then move("down") updatechar() elseif key == 2 then if class == "knight" then skill("focus") elseif class == "archer" then skill("aim") elseif class == "magician" then skill("charge") end elseif key == 42 then mtcr = math.random(1,5) if mtcr == 1 then newmon(12,6, "skeleton") elseif mtcr == 2 then newmon(14,4, "orb") elseif mtcr == 3 then newmon(5,10, "dragon") elseif mtcr == 4 then newmon(8,8, "enemy_soldier") else newmon(12,6, "great_dragon") end elseif key == 57 then doatt = math.random(acc, 100) if doatt >= 80 then attackf(x +1, y, tempattack) attackf(x -1, y, tempattack) attackf(x, y +1, tempattack) attackf(x, y -1, tempattack) end end end end elseif e == "timer" then movemon() updatemon() mca() end end