Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function pastebin(sName, sFile, bOverride) --Gets pastebin file
- tPaste = http.get("http://www.pastebin.com/raw/"..sName)
- if bOverride or not fs.exists(sFile) then
- local tInternal = fs.open(sFile,"w")
- for line in tPaste.readLine do
- tInternal.writeLine(line)
- end
- tInternal.close()
- else
- print("File already exists!")
- end
- end
- function length(t)
- count = 0
- if t ~= nil then
- for _ in pairs(t) do count = count + 1 end
- return count
- else
- print "Got nil table!"
- return 1
- end
- end
- if not daemon then
- if not fs.exists("daemon") then
- pastebin("0zvqEG6N","daemon")
- end
- os.loadAPI("daemon")
- end
- pcall(pastebin("RhggaU2g","Asset1", true))
- img_ingame = paintutils.loadImage("Asset1")
- img_upgrades = paintutils.loadImage("Asset2")
- height = 19
- rounds = {}
- curround = -1
- inround = false
- timeinround = 0
- nextenemy = 0
- enemyspawned = 0
- nextshotupgrade = 1
- rounds[0] = {1,1,1}
- rounds[1] = {1,2,1,2,1}
- rounds[2] = {3,1,1,2}
- rounds[3] = {1,1,2,2,3,3,2,2,1,1}
- rounds[4] = {3,2,1,2,3,3,3,2,1}
- rounds[5] = {1,2,3,4,5,1,2,3,4,5}
- rounds[6] = {6,6,6}
- local world = setmetatable({},{
- __index = {
- add = function(self, type, hp, y)
- object = {}
- object.alive = true
- if type == "enemy" then
- object.type = "enemy"
- object.hp = hp or math.random(math.floor(1+score/8+0.5),math.floor(score/4+0.5))
- object.x = 48
- object.y = math.random(2,17)
- elseif type == "bullet" then
- object.type = "bullet"
- object.hp = hp or 1
- object.x = 5
- object.y = y
- end
- rawset(self,#self+1,object)
- end;
- }
- })
- function enemySpawner2()
- while true do
- if inround == true then
- if nextenemy < 0 and enemyspawned ~= length(rounds[curround]) then
- world:add("enemy", rounds[curround][enemyspawned])
- enemyspawned = enemyspawned + 1
- nextenemy = 20
- end
- else
- --print "test"
- end
- sleep(0.025)
- end
- end
- function chargeTimer()
- while true do
- sleep(0.05) --20
- if nextshot ~= 0 then
- nextshot = nextshot - 1
- end
- end
- end
- function tickWorld()
- while true do
- sleep(0.05)
- nextenemy = nextenemy - 1
- if inround then
- timeinround = timeinround + 1
- end
- enemieson = 0
- for _,object in ipairs(world) do
- if object.alive then
- if object.type == "enemy" then
- enemieson = enemieson + 1
- object.x = object.x - 1
- if object.x == 4 then
- lives = lives - 1
- end
- elseif object.type == "bullet" then
- object.x = object.x + 1
- end
- if object.type == "bullet" then
- for _,object2 in ipairs(world) do
- if object2.type == "enemy" and object2.alive then
- if object2.x == object.x and object2.y == object.y or object2.x == object.x+1 and object2.y == object.y then
- object2.hp = object2.hp - object.hp
- object.alive = false
- score = score + 1
- if object2.hp == 0 then
- object2.alive = false
- end
- end
- end
- end
- end
- end
- end
- if inround then
- if enemieson == 0 and enemyspawned == length(rounds[curround]) then
- inround = false
- enemieson = 0
- enemyspawned = 0
- end
- end
- end
- end
- function mouseRead()
- while true do
- _, _, evtx, evty = os.pullEvent("mouse_click")
- if inround then
- if nextshot == 0 then
- world:add("bullet",nil,evty)
- nextshot = nextshottime
- end
- else
- if evtx > 42 and evty == 1 then --Next Round
- inround = true
- curround = curround + 1
- timeinround = 0
- end
- if evtx > 15 and evtx < 20 and evty == 5 then
- if score > nextshotupgrade * 20 then
- nextshottime = nextshottime * 0.75
- score = score - nextshotupgrade * 20
- end
- end
- end
- end
- end
- function paintToScreen()
- while true do
- sleep(0.05)
- if inround then
- paintutils.drawImage(img_ingame,1,1)
- term.setCursorPos(42,1)
- term.write(nextenemy)
- term.setCursorPos(30,1)
- term.write(enemyspawned)
- term.setCursorPos(31,1)
- term.write("/")
- term.setCursorPos(32,1)
- term.write(length(rounds[curround]))
- for _,object in ipairs(world) do
- if object.alive then
- if object.type == "enemy" and object.hp > 0 then
- term.setCursorPos(object.x, object.y)
- term.write(object.hp)
- paintutils.drawPixel(object.x, object.y, object.hp)
- elseif object.type == "bullet" then
- paintutils.drawPixel(object.x, object.y, colours.black)
- end
- end
- end
- percent = nextshot/nextshottime
- bars = percent*height
- i = 1
- while i<bars do
- paintutils.drawPixel(1, i, colours.red)
- i = i + 1
- end
- else
- paintutils.drawImage(img_upgrades,1,1)
- term.setCursorPos(42,1)
- term.setBackgroundColour(colours.orange)
- term.write("Next Round")
- term.setCursorPos(22,2)
- term.setBackgroundColour(colours.red)
- term.write("Upgrades")
- end
- end
- end
- function debugger()
- print(inround)
- sleep(0.5)
- end
- daemon.add(enemySpawner2,"Handles enemy spawning")
- daemon.add(chargeTimer,"Handles shot recharge")
- daemon.add(tickWorld,"Ticks the world")
- daemon.add(mouseRead,"Reads the mouse input")
- --daemon.add(debugger,"Debugs")
- daemon.add(paintToScreen,"Paints to screen")
- nextshottime = 10
- nextshot = nextshottime
- lives_max = 3
- lives = 3
- score = 0
- bx = 0
- by = 0
- ba = false
- enemy_timer = 0
- while true do --Main loop
- --print("Running")
- sleep(0.5)
- end
Advertisement
Add Comment
Please, Sign In to add comment