Alyssa

Quest SP

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