Alyssa

LGS quest

Aug 29th, 2013
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 12.90 KB | None | 0 0
  1. os.loadAPI("lgs/gameapi")
  2.  
  3. function achieve(num)
  4.  if num == 1 then
  5.   gameapi.achieve("questsp","Monster attacker","kill 10 monsters", 5)
  6.  elseif num == 2 then
  7.   gameapi.achieve("questsp","Monster killer", "kill 50 monsters", 15)
  8.  elseif num == 3 then
  9.   gameapi.achieve("questsp","Monster Champion","kill 250 monsters", 25)
  10.  elseif num == 4 then
  11.   gameapi.achieve("questsp","Monster Destroyer", "kill 500 monsters", 35)
  12.  elseif num == 5 then
  13.   gameapi.achieve("questsp","Leveled up", "Get to Level 10", 5)
  14.  elseif num == 6 then
  15.   gameapi.achieve("questsp", "Alot stronger", "Get to level 25",15)
  16.  elseif num == 7 then
  17.   gameapi.achieve("questsp", "Dragon fighter", "Get to level 50", 25)
  18.  elseif num == 8 then
  19.   gameapi.achieve("questsp", "Ultimate fighter", "Get to level 100", 40)
  20.  end
  21. end
  22.  
  23. if term.isColor() then
  24.  color = true
  25. else
  26.  color = false
  27. end
  28.  
  29. function lvlup()
  30.  lvl = lvl +1
  31.  if lvl == 10 then achieve(5) end
  32.  if lvl == 25 then achieve(6) end
  33.  if lvl == 50 then achieve(7) end
  34.  if lvl == 100 then achieve(8) end
  35.  if class == "knight" then
  36.   att = att +4 -- 4
  37.   defense = defense +4 -- 8
  38.   maxhp = maxhp +4 -- 12
  39.   hp = maxhp
  40.   acc = acc +3 -- 15
  41.  elseif class == "archer" then
  42.   acc = acc +5 -- 5
  43.   att = att +3 -- 8
  44.   defense = defense +3 -- 11
  45.   maxhp = maxhp +4 -- 15
  46.   hp = maxhp
  47.  elseif class == "magician" then
  48.   acc = acc +3 -- 3
  49.   att = att +6 -- 9
  50.   defense = defense +3 -- 12
  51.   maxhp = maxhp +3 -- 15
  52.   hp = maxhp
  53.  end
  54.  xp = 0
  55.  xpn = xpn *2
  56. end
  57.  
  58. function draw()
  59.  g = 1
  60.  f = 1
  61.  grass = 1
  62.  if color == true then
  63.  term.setBackgroundColor(colors.lime)
  64.  end
  65.  for grass = 1, 15 do
  66.   term.setCursorPos(17,grass +2)
  67.   write("               ")
  68.  end
  69.  if color == true then
  70.  term.setBackgroundColor(colors.lightGray)
  71.  end
  72.  for g = 1,walls do
  73.   sleep(0.05)
  74.   term.setCursorPos(wallsx[g] + 16,wallsy[g] +2)
  75.   if color == false then
  76.    write("=")
  77.   else
  78.    write(" ")
  79.   end
  80.  end
  81.  term.setCursorPos(x +16,y +2)
  82.  if color == true then
  83.  term.setBackgroundColor(colors.blue)
  84.  end
  85.  write("+")
  86. end
  87. function collidet(xt,yt)
  88.  collidev = false
  89.  for coll = 1, walls do
  90.   if wallsx[coll] == xt then
  91.    if wallsy[coll] == yt then
  92.     collidev = true
  93.     return true
  94.    end
  95.   end
  96.  end
  97.  for coll = 1, mc do
  98.   if malive[coll] == true then
  99.    if mx[coll] == xt then
  100.     if my[coll] == yt then
  101.      collidev = true
  102.      return true
  103.     end
  104.    end
  105.   end
  106.  end
  107.  if collidev == false then
  108.   return false
  109.  end
  110. end
  111.  
  112. function mdie(monid)
  113.  term.setCursorPos(mx[monid] +16, my[monid] +2)
  114.  malive[monid] = false
  115.  if color == true then
  116.  term.setBackgroundColor(colors.lime)
  117.  end
  118.  write(" ")
  119.  term.setBackgroundColor(colors.black)
  120.  xp = xp +mxp[monid]
  121.  mkilled = mkilled +1
  122.  if mkilled == 10 then
  123.   achieve(1)
  124.  elseif mkilled == 50 then
  125.   achieve(2)
  126.  elseif mkilled == 250 then
  127.   achieve(3)
  128.  elseif mkilled == 500 then
  129.   achieve(4)
  130.  end
  131.  mx[monid] = 20
  132.  my[monid] = 10
  133.  mhp[monid] = 0
  134. end
  135.  
  136. function attackf(tax, tay, tadmg) -- To attack X, to attack y, to attack damage
  137.  if x == tax and y == tay then
  138.   adef = defense / 10
  139.   adtadmg = adtadmg - adef
  140.   hp = hp -adtadmg -- After defense To attack damage
  141.   if hp < 0 then
  142.    hp = 0
  143.   end
  144.  end
  145.  for i = 1, mc do
  146.   if mx[i] == tax and my[i] == tay then
  147.     if malive[i] == true then
  148.     mhp[i] = mhp[i] -tadmg
  149.     if mhp[i] <= 0 then
  150.      mdie(i)
  151.     end
  152.    end
  153.   end
  154.  end
  155. end
  156.  
  157. function updatechar()
  158.  if color == true then
  159.  term.setBackgroundColor(colors.lime)
  160.  end
  161.  term.setCursorPos(oldx +16 ,oldy +2)
  162.  write(" ")
  163.  if color == true then
  164.  term.setBackgroundColor(colors.blue)
  165.  end
  166.  term.setCursorPos(x + 16, y +2)
  167.  write("+")
  168. end
  169.  
  170. function move(dir)
  171.  oldx = x
  172.  oldy = y
  173.  if dir == "up" then
  174.   if collidet(x,y -1) == false then
  175.    y = y -1
  176.   end
  177.  elseif dir == "down" then
  178.   if collidet(x,y +1) == false then
  179.    y = y +1
  180.   end
  181.  elseif dir == "right" then
  182.   if collidet(x +1,y) == false then
  183.    x = x +1
  184.   end
  185.  elseif dir == "left" then
  186.   if collidet(x -1,y) == false then
  187.    x = x -1
  188.   end
  189.  else
  190.   print("Error: Invalid direction")
  191.  end
  192. end
  193.  
  194. function collidem(xm,ym)
  195.   collidev = false
  196.  for coll = 1, walls do
  197.   if wallsx[coll] == xm then
  198.    if wallsy[coll] == ym then
  199.     collidev = true
  200.     return true
  201.    end
  202.   end
  203.  end
  204.  for coll = 1, mc do
  205.   if mx[coll] == xm then
  206.    if my[coll] == ym then
  207.     collidev = true
  208.     return true
  209.    end
  210.   end
  211.  end
  212.  if xm == x then
  213.   if ym == y then
  214.    collidev = true
  215.    return true
  216.   end
  217.  end
  218.  if collidev == false then
  219.   return false
  220.  end
  221. end
  222.  
  223. function movemon()
  224.  for ms = 1, mc do
  225.   if malive[ms] == true then
  226.    -- if mx[ms] ~= x -1 or mx[ms] ~= x +1 and my[ms] ~= y +1 and my[ms] ~= y -1 then
  227.     if mx[ms] > x  then
  228.      if collidem(mx[ms] -1 , my[ms]) == false then
  229.       oldmx[ms] = mx[ms]
  230.       oldmy[ms] = my[ms]
  231.       mx[ms] = mx[ms] -1
  232.      end
  233.     elseif mx[ms] < x  then
  234.      if collidem(mx[ms] +1,my[ms]) == false then
  235.       oldmy[ms] = my[ms]
  236.       oldmx[ms] = mx[ms]
  237.       mx[ms] = mx[ms] +1
  238.      end
  239.     elseif my[ms] > y  then
  240.      if collidem(mx[ms],my[ms] -1) == false then
  241.       oldmy[ms] = my[ms]
  242.       oldmx[ms] = mx[ms]
  243.       my[ms] = my[ms] -1
  244.      end
  245.     elseif my[ms] < y  then
  246.      if collidem(mx[ms],my[ms] +1) == false then
  247.       oldmy[ms] = my[ms]
  248.       oldmx[ms] = mx[ms]
  249.       my[ms] = my[ms] +1
  250.      end
  251.    -- end
  252.     end
  253.    end
  254.   end
  255.  end
  256. mxp = {}
  257.  
  258. function monsterchar(type)
  259.  if type == "skeleton" then
  260.   return "#"
  261.  elseif type == "dragon" then
  262.   return "&"
  263.  elseif type == "great_dragon" then
  264.   return "@"
  265.  elseif type == "orb" then
  266.   return "*"
  267.  elseif type == "enemy_soldier" then
  268.   return "%"
  269.  elseif type == "enemy_general" then
  270.   return "$"
  271.  else
  272.   return "^"
  273.  end
  274. end
  275.  
  276. function updatemon()
  277.  for i = 1, mc do
  278.   if oldmx[i] and oldmy[i] then
  279.    term.setCursorPos(oldmx[i] +16, oldmy[i] +2)
  280.    if color == true then
  281.    term.setBackgroundColor(colors.lime)
  282.    end
  283.    write(" ")
  284.   end
  285.  end
  286.  for i = 1, mc do
  287.   if malive[i] == true then
  288.    term.setCursorPos(mx[i] +16, my[i] +2)
  289.    if color == true then
  290.    term.setBackgroundColor(colors.red)
  291.    end
  292.    local char = monsterchar(mt[i])
  293.    write(char)
  294.   end
  295.  end
  296. end
  297.  
  298. function skill(skillname)
  299.  if att ~= nil and acc ~= nil then
  300.   att = att -1
  301.   acc = acc -1
  302.   att = att +1
  303.   acc = acc +1
  304.   if skillname == "focus" then
  305.     tempattack = att*1.5
  306.     skillt = 3
  307.   elseif skillname == "charge" then
  308.     tempattack = att*3
  309.     skillt = 1
  310.   elseif skillname == "aim" then
  311.     tempacc = acc*1.5
  312.     skillt = 1
  313.   end
  314.  end
  315. end
  316. function mca()
  317. --[[ for i = 1, mc do
  318.   if malive[i] == true then
  319.    if mx[i] == x -1 then
  320.     attackf(x,y, matk[i])
  321.    elseif mx[i] == x +1 then
  322.     attackf(x,y, matk[i])
  323.    elseif my[i] == y +1 then
  324.     attackf(x,y, matk[i])
  325.    elseif my[i] == y - 1 then
  326.     attackf(x,y, matk[i])
  327.    end
  328.   end
  329.  end
  330. --]]
  331. end
  332.  
  333. function newmon(mcx,mcy,mctype)
  334.  mc = mc +1
  335.  malive[mc] = true
  336.  mx[mc] = mcx -- Monster creation x
  337.  my[mc] = mcy -- Monster creation y
  338.  mt[mc] = mctype -- Monster creation type
  339.  if mctype == "skeleton" then
  340.   mhp[mc] = 10
  341.   mxp[mc] = 10
  342.   matk[mc] = 2
  343.  elseif mctype == "dragon" then
  344.   mhp[mc] = 25
  345.   mxp[mc] = 20
  346.   matk[mc] = 5
  347.  elseif mctype == "great_dragon" then
  348.   mhp[mc] = 50
  349.   mxp[mc] = 65
  350.   matk[mc] = 8
  351.  elseif mctype == "orb" then
  352.   mhp[mc] = 20
  353.   mxp[mc] = 20
  354.   matk[mc] = 2
  355.  elseif mctype == "enemy_soldier" then
  356.   mhp[mc] = 20
  357.   mxp[mc] = 30
  358.   matk[mc] = 3
  359.  elseif mctype == "enemy_general" then
  360.   mhp[mc] = 30
  361.   mxp[mc] = 40
  362.   matk[mc] = 4
  363.  else
  364.   mhp[mc] = 35
  365.   mxp[mc] = 50
  366.   matk[mc] = 5
  367.  end
  368. end
  369.  
  370. function showstats()
  371.  term.setBackgroundColor(colors.black)
  372.  term.setCursorPos(38,1)
  373.  write("HP: "..hp.."/"..maxhp.."")
  374.  term.setCursorPos(38,2)
  375.  write("XP: "..xp.."/"..xpn.."")
  376.  term.setCursorPos(1,4)
  377.  write("Level: "..lvl.."")
  378.  term.setCursorPos(1,5)
  379.  write("Attack: "..att.." "..tempattack.."")
  380.  term.setCursorPos(1,6)
  381.  write("Defense: "..defense.." ")
  382.  term.setCursorPos(1,16)
  383.  if acc and tempacc then
  384.   write("Accuracy: "..acc.." "..tempacc)
  385.  end
  386. end
  387. mkilled = 0
  388. malive = {} -- Records if the monster is alive
  389. oldmx = {} -- old monster position x
  390. oldmy = {} -- Old monster position y
  391. mx = {} -- Monster position x
  392. my = {} -- Monster position y
  393. mc = 0 -- Monster count
  394. mt = {} -- Monster type
  395. matk = {}
  396. -- mcr = {} color could come later
  397. mhp = {} -- Health of monster, max health is set when creating monster
  398. walls = 0
  399. up = 17
  400. up2 = 200
  401. r = 32
  402. r2 = 205
  403. l = 30
  404. l2 = 203
  405. down =31
  406. down2 =208
  407. x = 5
  408. y = 5
  409. wallsx = {}
  410. wallsy = {}
  411. term.setCursorPos(1,1)
  412. term.clear()
  413.  s = 1
  414.  confirm = false
  415.  print("Welcome to Quest!")
  416.  print("Please select a character with D or Right arrow key Or A and left arrow key")
  417.  print("Press W or up arrow key to confirm")
  418.  sleep(2)
  419.  term.clear()
  420.  term.setCursorPos(1,1)
  421.  write("Knight, good attack and defense stats")
  422.  while confirm == false do
  423.   sleep(0.05)
  424.   e, k = os.pullEvent("key")
  425.   term.clear()
  426.   term.setCursorPos(1,1)
  427.   term.setTextColor(colors.white)
  428.   if k == r or k == r2 then
  429.    if s ~= 3 then
  430.     s = s +1
  431.    else
  432.     s = 1
  433.    end
  434.   elseif k == l or k == l2 then
  435.    if s ~= 1 then
  436.     s = s -1
  437.    else
  438.     s = 3
  439.    end
  440.   elseif k == up or k == up2 then
  441.    if s == 1 then
  442.     class = "knight"
  443.     confirm = true
  444.    elseif s == 2 then
  445.     class = "archer"
  446.     term.setCursorPos(1,2)
  447.     confirm = true
  448.    else
  449.     class = "magician"
  450.     term.setCursorPos(1,2)
  451.     confirm = true
  452.    end
  453.   end
  454.   term.setCursorPos(1,1)
  455.   if s == 1 then
  456.    write("Knight, good attack and defense stats")
  457.   elseif s == 2 then
  458.    term.setTextColor(colors.white)
  459.    write("Archer, Great accuracy")
  460.   elseif s == 3 then
  461.    term.setTextColor(colors.white)
  462.    write("Magician, Low defense, Low health, Best attack")
  463.   end
  464.  end
  465.  run = true
  466.  term.clear()
  467.  term.setCursorPos(1,1)
  468.  print("Setting up walls!")
  469.  print("This could take up to about 5 seconds")
  470.  for i = 1, 15 do
  471.   walls = walls +1
  472.   w = walls
  473.   sleep(0.05)
  474.   wallsx[w] = i
  475.   wallsy[i] = 1
  476.  end
  477.  for u = 1, 15 do
  478.   walls = walls +1
  479.   sleep(0.05)
  480.   w = walls
  481.   wallsx[w] = 1
  482.   wallsy[w] = u
  483.  end
  484.  for o = 1, 15 do
  485.   walls = walls +1
  486.   sleep(0.05)
  487.   w = walls
  488.   wallsx[w] = o
  489.   wallsy[w] = 15
  490.  end
  491.  for p = 1, 15 do
  492.   walls = walls +1
  493.   sleep(0.05)
  494.   w = walls
  495.   wallsx[w] = 15
  496.   wallsy[w] = p
  497.  end
  498.  wallsx[61] = 10
  499.  wallsy[61] = 12
  500.  wallsx[62] = 11
  501.  wallsy[62] = 12
  502.  wallsx[63] = 12
  503.  wallsy[63] = 12
  504.  wallsx[64] = 11
  505.  wallsy[64] = 4
  506.  wallsx[65] = 13
  507.  wallsy[65] = 10
  508.  wallsx[66] = 19
  509.  wallsy[66] = 10
  510.  wallsx[67] = 20
  511.  wallsy[67] = 9
  512.  wallsx[68] = 21
  513.  wallsy[68] = 10
  514.  wallsx[69] = 20
  515.  wallsy[69] = 11
  516.  wallsx[70] = 3
  517.  wallsy[70] = 10
  518.  walls = 70
  519.  term.setCursorPos(1,1)
  520.  term.clear()
  521.  draw()
  522.  numloop = 1
  523.  t1 = os.clock()
  524.  t2 = os.clock() + 0.3
  525.  newmon(11, 5, "dragon")
  526.  skillt = 0
  527.  lvl = 1
  528.  maxhp = 10
  529.  hp = 10
  530.  att = 5
  531.  defense = 5
  532.  tempattack = att
  533.  tempacc = acc
  534.  acc = 50
  535.  xp = 1
  536.  xpn = 50 -- Amount of xp needed total to get to next level
  537.  maxlvl = 100
  538.  while run == true do
  539.   if xp >= xpn then
  540.    lvlup()
  541.   end
  542.   if hp ~= 0 then
  543.    --Do stuff
  544.   else
  545.    term.clear()
  546.    print("YOU DIED!")
  547.    sleep(3)
  548.    run = false
  549.   end
  550.   showstats()
  551.   term.setCursorPos(1,1)
  552.   term.setBackgroundColor(colors.black)
  553.   print("loops: "..numloop.."")
  554.   numloop = numloop +1
  555.   os.startTimer(0.20)
  556.   sleep(0.1)
  557.   e,key = os.pullEvent()
  558.   if e == "key" then
  559.    t2t = os.clock()
  560.    if t2t - t1 > 0.15 or t2 - t1 > 0.15 then
  561.     if skillt ~= 0 then
  562.      skillt = skillt -1
  563.     else
  564.      tempacc = acc
  565.      tempattack = att
  566.     end
  567.     if e == "key" then
  568.      t1 = os.clock()
  569.      t2 = os.clock()
  570.      if key == r or key == r2 then
  571.       move("right")
  572.       updatechar()
  573.      elseif key == l or key == l2 then
  574.       move("left")
  575.       updatechar()
  576.      elseif key == up or key == up2 then
  577.       move("up")
  578.       updatechar()
  579.      elseif key == down or key == down2 then
  580.       move("down")
  581.       updatechar()
  582.      elseif key == 2 then
  583.        if class == "knight" then
  584.         skill("focus")
  585.        elseif class == "archer" then
  586.         skill("aim")
  587.        elseif class == "magician" then
  588.         skill("charge")
  589.        end
  590.       elseif key == 42 then
  591.        mtcr = math.random(1,5)
  592.        if mtcr == 1 then
  593.         newmon(12,6, "skeleton")
  594.        elseif mtcr == 2 then
  595.         newmon(14,4, "orb")
  596.        elseif mtcr == 3 then
  597.         newmon(5,10, "dragon")
  598.        elseif mtcr == 4 then
  599.         newmon(8,8, "enemy_soldier")
  600.        else
  601.          newmon(12,6, "great_dragon")
  602.         end
  603.       elseif key == 57 then
  604.        doatt = math.random(acc, 100)
  605.        if doatt >= 80 then
  606.         attackf(x +1, y, tempattack)
  607.         attackf(x -1, y, tempattack)
  608.         attackf(x, y +1, tempattack)
  609.         attackf(x, y -1, tempattack)
  610.        end
  611.      end
  612.     end
  613.    end
  614.   elseif e == "timer" then
  615.     movemon()
  616.     updatemon()
  617.     mca()
  618.  end  
  619. end
Advertisement
Add Comment
Please, Sign In to add comment