Advertisement
Bjornir90

Project alpha

Aug 3rd, 2013
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.18 KB | None | 0 0
  1. --Models :
  2.  
  3. --[[ player
  4.  
  5.         i
  6.       i i i    blue or lightBlue
  7.       iiiii
  8.      
  9.      ennemy
  10.      
  11.      iiiii
  12.     i  i  i    red
  13.        i
  14.        
  15.      projectile
  16.      
  17.        i
  18.        i   purple or blue for player's and red for ennemy's
  19. --]]
  20.  
  21.  
  22.  
  23. --[[
  24. Made by Bjornir90
  25. using gameutils API by nitrogenfingers
  26. You are not allowed to modify this without my permission
  27. --]]
  28.  
  29. --initialisation
  30. local termX, termY = term.getSize()
  31. local midX = math.ceil(termX/2)
  32. local midY = math.ceil(termY/2)
  33. local path = shell.resolve(".").."/projectAlpha"
  34. os.loadAPI(path.."/gameutils")
  35. gameutils.initializeBuffer()
  36. local tick = 0.05
  37. local alive = {}
  38. local dead = {}
  39. local lives = 3
  40. local isDead = false
  41. local gun =
  42.   {
  43.   pNumber = 1,
  44.   pType = "bullet",
  45.   wType = "primary",
  46.   rarity = 0
  47.   }
  48. local laser =
  49.   {
  50.   pNumber = 2,
  51.   pType = "laser",
  52.   wType = "primary",
  53.   rarity = 50 --On 1000
  54.   }
  55. local gatling =  
  56.   {
  57.   pNumber = 3,
  58.   pType = "bullet",
  59.   wType = "primary",
  60.   rarity = 40 --On 1000
  61.   }
  62. local orbitalStrike =
  63.   {
  64.   pNumber = 0,
  65.   pType = "explosive",
  66.   wType = "special",
  67.   rarity = 1 --On 1000
  68.   }
  69. local mine =
  70.   {
  71.   pNumber = 1,
  72.   pType = "explosive",
  73.   wType = "secondary",
  74.   rarity = 20 --On 1000
  75.   }
  76. local sideGun =
  77.   {
  78.   pNumber = 2,
  79.   pType = "bullet",
  80.   wType = "secondary",
  81.   rarity = 15 --On 1000
  82.   }
  83.  
  84. local actualWeapon = gun
  85. local currentUpgrade = nil
  86. local tickCount = 0
  87.  
  88. --alphaId = ennemy, pEnnemy, laser, gatling, pPlayer
  89.  
  90.  
  91. local function render()
  92.  for i= 1, #alive do
  93.   gameutils.drawToBuffer(alive[i])
  94.  end
  95.  gameutils.drawToBuffer(player)
  96.  gameutils.drawBuffer()
  97. end
  98.  
  99. local function drawExplosion(x, y)
  100.  paintutils.drawPixel(x+1, y+1, colors.red)
  101.  paintutils.drawPixel(x-1, y-1, colors.red)
  102.  paintutils.drawPixel(x-1, y+1, colors.orange)
  103.  paintutils.drawPixel(x+1, y-1, colors.red)
  104.  paintutils.drawPixel(x+1, y, colors.yellow)
  105.  paintutils.drawPixel(x, y+2, colors.yellow)
  106.  sleep(0.005) -- Slow down the game to tell the player
  107. end
  108.  
  109. local function loadGame()
  110.  term.clear()
  111.  player = gameutils.loadSprite(path.."/.sprites/player.nfp", midX, termY)
  112.  player.alphaId = "player"
  113.  table.insert(alive, player)
  114.  spawnEnnemy()
  115.  render()
  116. end
  117.  
  118. local function collision()
  119.  for i = 1, #alive do
  120.   if gameutils.pCollidesWith(player, alive[i]) then
  121.    if alive[i].alphaId == "ennemy" or alive[i].alphaId == "pEnnemy" then
  122.     lifes = lifes-1
  123.    elseif alive[i].alphaId == "laser" then
  124.     currentWeapon = laser
  125.    elseif alive[i].alphaId == "gatling" then
  126.     currentWeapon = gatling
  127.    end
  128.   end
  129.   for u = 1, #alive do
  130.    if gameutils.pCollidesWith(alive[i], alive[u]) then
  131.     if alive[u] ~= alive[i] then
  132.      if alive[i].alphaId == "pPlayer" then
  133.       dead[#dead+1] = alive[u]
  134.       drawExplosion(alive[u][x], alive[u][y])
  135.       alive[u] = nil
  136.      elseif alive[u].alphaId == "pPlayer" then
  137.       dead[#dead+1] = alive[i]
  138.       drawExplosion(alive[i][x], alive[i][y])
  139.       alive[i] = nil
  140.      end
  141.     end
  142.    end
  143.   end
  144.   for i=1, #alive do
  145.   if alive[i] == nil then
  146.    alive[i] = alive[i+1]  --So there is no blank case
  147.   end
  148.   end
  149.  end
  150. end
  151.  
  152. local function spawnEnnemy()
  153.  local numberEnnemys = math.random(0, 10) --So if > three then don't spawn ennemy
  154.  if numberEnnemys >= 4 then
  155.   numberEnnemys = 0
  156.  end
  157.  for i=1, numberEnnemys do
  158.   local ennemy = gameutils.loadSprite(path.."/.sprites/ennemy.nfp", math.random(1, termX), 1)
  159.   ennemy.alphaId = "ennemy"
  160.   table.insert(alive, ennemy)
  161.  end
  162. end
  163.  
  164.  
  165.  
  166. local function main()
  167.  loadGame()
  168.  while isDead ~= true do
  169.   os.startTimer(tick)
  170.   local event, param1, param2 = os.pullEvent()
  171.   if event == "key" then
  172.    if param1 == 205 then
  173.     player:moveTo(player.x + 1, player.y)
  174.    elseif param1 == 203 then
  175.     player:moveTo(player.x-1, player.y)
  176.    elseif param1 == 200 then --code for backspace
  177.     break
  178.    end
  179.   end
  180.   if event == "timer" then
  181.   if currentWeapon.pNumber == 1 then --Make the vessel fire
  182.    local pProjectil = gameutil.loadSprite(path.."/.sprites/pPlayer.nfp", player.x+2, player.y-3)
  183.    pProjectil.alphaId = "pPlayer"
  184.    table.insert(alive, pProjectil )
  185.   elseif currentWeapon.pNumber == 3 then
  186.    local pProjectile = gameutils.loadSprite(path.."/.sprites/pPlayer.nfp", player.x, player.y-2) --left projectile
  187.    local pProjectileR = gameutils.loadSprite(path.."/.sprites/pPlayer.nfp", player.x+4, player.y-2)
  188.    local pProjectil = gameutil.loadSprite(path.."/.sprites/pPlayer.nfp", player.x+2, player.y-3) -- Center projectile
  189.    pProjectil.alphaId = "pPlayer"
  190.    pProjectile.alphaId = "pPlayer"
  191.    pProjectileR.alphaId = "pPlayer"
  192.    table.insert(alive, pProjectil)
  193.    table.insert(alive, pProjectile)
  194.    table.insert(alive, pProjectileR)
  195.   end
  196.   spawnEnnemy()
  197.   for i=1, #alive do  --Move ennemy
  198.    if alive[i][alphaId] == "ennemy" then
  199.    alive[i]:moveTo(alive[i][x], alive[i][y]+1)
  200.    elseif alive[i][alphaId] == "pEnnemy" then
  201.    alive[i]:moveTo(alive[i][x], alive[i][y]+2)
  202.    elseif alive[i][alphaId] == "pPlayer" then
  203.    alive[i]:moveTo(alive[i][x], alive[i][y]-2)
  204.    end
  205.    render()
  206.    collision()
  207.   end
  208.   if lives == 0 then
  209.    isDead = true
  210.   end
  211.   end
  212.  end
  213.  term.clear()
  214.  term.setCursorPos(midX-5, midY-1)
  215.  if isDead == true then
  216.   print("Sorry, you lost :(\n")
  217.   print("Another game ?")
  218.   print("y|n")
  219.   local input = read()
  220.   if upper(input) == "Y" then
  221.    main()
  222.   end
  223.  end
  224. end
  225.    
  226.    
  227. term.clear()
  228. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement