Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Models :
- --[[ player
- i
- i i i blue or lightBlue
- iiiii
- ennemy
- iiiii
- i i i red
- i
- projectile
- i
- i purple or blue for player's and red for ennemy's
- --]]
- --[[
- Made by Bjornir90
- using gameutils API by nitrogenfingers
- You are not allowed to modify this without my permission
- --]]
- --initialisation
- local termX, termY = term.getSize()
- local midX = math.ceil(termX/2)
- local midY = math.ceil(termY/2)
- local path = shell.resolve(".").."/projectAlpha"
- os.loadAPI(path.."/gameutils")
- gameutils.initializeBuffer()
- local tick = 0.05
- local alive = {}
- local dead = {}
- local lives = 3
- local isDead = false
- local gun =
- {
- pNumber = 1,
- pType = "bullet",
- wType = "primary",
- rarity = 0
- }
- local laser =
- {
- pNumber = 2,
- pType = "laser",
- wType = "primary",
- rarity = 50 --On 1000
- }
- local gatling =
- {
- pNumber = 3,
- pType = "bullet",
- wType = "primary",
- rarity = 40 --On 1000
- }
- local orbitalStrike =
- {
- pNumber = 0,
- pType = "explosive",
- wType = "special",
- rarity = 1 --On 1000
- }
- local mine =
- {
- pNumber = 1,
- pType = "explosive",
- wType = "secondary",
- rarity = 20 --On 1000
- }
- local sideGun =
- {
- pNumber = 2,
- pType = "bullet",
- wType = "secondary",
- rarity = 15 --On 1000
- }
- local actualWeapon = gun
- local currentUpgrade = nil
- local tickCount = 0
- --alphaId = ennemy, pEnnemy, laser, gatling, pPlayer
- local function render()
- for i= 1, #alive do
- gameutils.drawToBuffer(alive[i])
- end
- gameutils.drawToBuffer(player)
- gameutils.drawBuffer()
- end
- local function drawExplosion(x, y)
- paintutils.drawPixel(x+1, y+1, colors.red)
- paintutils.drawPixel(x-1, y-1, colors.red)
- paintutils.drawPixel(x-1, y+1, colors.orange)
- paintutils.drawPixel(x+1, y-1, colors.red)
- paintutils.drawPixel(x+1, y, colors.yellow)
- paintutils.drawPixel(x, y+2, colors.yellow)
- sleep(0.005) -- Slow down the game to tell the player
- end
- local function loadGame()
- term.clear()
- player = gameutils.loadSprite(path.."/.sprites/player.nfp", midX, termY)
- player.alphaId = "player"
- table.insert(alive, player)
- spawnEnnemy()
- render()
- end
- local function collision()
- for i = 1, #alive do
- if gameutils.pCollidesWith(player, alive[i]) then
- if alive[i].alphaId == "ennemy" or alive[i].alphaId == "pEnnemy" then
- lifes = lifes-1
- elseif alive[i].alphaId == "laser" then
- currentWeapon = laser
- elseif alive[i].alphaId == "gatling" then
- currentWeapon = gatling
- end
- end
- for u = 1, #alive do
- if gameutils.pCollidesWith(alive[i], alive[u]) then
- if alive[u] ~= alive[i] then
- if alive[i].alphaId == "pPlayer" then
- dead[#dead+1] = alive[u]
- drawExplosion(alive[u][x], alive[u][y])
- alive[u] = nil
- elseif alive[u].alphaId == "pPlayer" then
- dead[#dead+1] = alive[i]
- drawExplosion(alive[i][x], alive[i][y])
- alive[i] = nil
- end
- end
- end
- end
- for i=1, #alive do
- if alive[i] == nil then
- alive[i] = alive[i+1] --So there is no blank case
- end
- end
- end
- end
- local function spawnEnnemy()
- local numberEnnemys = math.random(0, 10) --So if > three then don't spawn ennemy
- if numberEnnemys >= 4 then
- numberEnnemys = 0
- end
- for i=1, numberEnnemys do
- local ennemy = gameutils.loadSprite(path.."/.sprites/ennemy.nfp", math.random(1, termX), 1)
- ennemy.alphaId = "ennemy"
- table.insert(alive, ennemy)
- end
- end
- local function main()
- loadGame()
- while isDead ~= true do
- os.startTimer(tick)
- local event, param1, param2 = os.pullEvent()
- if event == "key" then
- if param1 == 205 then
- player:moveTo(player.x + 1, player.y)
- elseif param1 == 203 then
- player:moveTo(player.x-1, player.y)
- elseif param1 == 200 then --code for backspace
- break
- end
- end
- if event == "timer" then
- if currentWeapon.pNumber == 1 then --Make the vessel fire
- local pProjectil = gameutil.loadSprite(path.."/.sprites/pPlayer.nfp", player.x+2, player.y-3)
- pProjectil.alphaId = "pPlayer"
- table.insert(alive, pProjectil )
- elseif currentWeapon.pNumber == 3 then
- local pProjectile = gameutils.loadSprite(path.."/.sprites/pPlayer.nfp", player.x, player.y-2) --left projectile
- local pProjectileR = gameutils.loadSprite(path.."/.sprites/pPlayer.nfp", player.x+4, player.y-2)
- local pProjectil = gameutil.loadSprite(path.."/.sprites/pPlayer.nfp", player.x+2, player.y-3) -- Center projectile
- pProjectil.alphaId = "pPlayer"
- pProjectile.alphaId = "pPlayer"
- pProjectileR.alphaId = "pPlayer"
- table.insert(alive, pProjectil)
- table.insert(alive, pProjectile)
- table.insert(alive, pProjectileR)
- end
- spawnEnnemy()
- for i=1, #alive do --Move ennemy
- if alive[i][alphaId] == "ennemy" then
- alive[i]:moveTo(alive[i][x], alive[i][y]+1)
- elseif alive[i][alphaId] == "pEnnemy" then
- alive[i]:moveTo(alive[i][x], alive[i][y]+2)
- elseif alive[i][alphaId] == "pPlayer" then
- alive[i]:moveTo(alive[i][x], alive[i][y]-2)
- end
- render()
- collision()
- end
- if lives == 0 then
- isDead = true
- end
- end
- end
- term.clear()
- term.setCursorPos(midX-5, midY-1)
- if isDead == true then
- print("Sorry, you lost :(\n")
- print("Another game ?")
- print("y|n")
- local input = read()
- if upper(input) == "Y" then
- main()
- end
- end
- end
- term.clear()
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement