Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- createEnemyTimerMax = 0.6
- createEnemyTimer = createEnemyTimerMax
- pauseTimerMax = 0.1
- pauseTimer = pauseTimerMax
- saved = false
- isAlive = false
- isPaused = false
- score = 0
- scores = {}
- cheat1ac = false
- cheat2ac = false
- canShoot = true
- canShootTimerMax = 0.2
- canShootTimer = canShootTimerMax
- bulletImg = nil
- lrDir = 0
- udDir = 0
- bullets = {}
- enemies = {}
- themes = {
- love.audio.newSource("assets/sounds/repost.mp3","stream"),
- love.audio.newSource("assets/sounds/sbq.mp3","stream"),
- love.audio.newSource("assets/sounds/stars.mp3","stream"),
- love.audio.newSource("assets/sounds/swing.mp3","stream"),
- love.audio.newSource("assets/sounds/wii.mp3","stream")}
- theme = math.random(1,#themes)
- particle = {}
- function CheckCollision(x1,y1,w1,h1, x2,y2,w2,h2)
- return x1 < x2+w2 and
- x2 < x1+w1 and
- y1 < y2+h2 and
- y2 < y1+h1
- end
- function formatTable()
- table.sort(scores,function(a,b) return a>b end)
- return "scores = {"..table.concat(scores, ", ").."}"
- end
- function love.load(arg)
- if love.filesystem.exists("save.nibba") then
- local run = love.filesystem.load("save.nibba")
- run()
- end
- player = { x = 200, y = 200, speed = 450, img = nil}
- main_img = love.graphics.newImage('assets/sprites/Player_John.png')
- player.img = main_img
- player.x = (love.graphics.getWidth()/2)-(player.img:getWidth()/2)
- player.y = (love.graphics.getHeight()/2)-(player.img:getWidth()/2)
- bltrecover = love.graphics.newImage("assets/sprites/L.png")
- bulletImg = love.graphics.newImage("assets/sprites/L.png")
- jooshrecover = love.graphics.newImage("assets/sprites/Joosh.jpg")
- scndImg = love.graphics.newImage("assets/sprites/Player_JohnSmall.png")
- enemyImg = {
- love.graphics.newImage("assets/sprites/Danny.jpg"),
- love.graphics.newImage("assets/sprites/Jerrod.jpg"),
- love.graphics.newImage("assets/sprites/Joosh.jpg"),
- love.graphics.newImage("assets/sprites/Agent.jpg"),}
- hit = {
- love.audio.newSource("assets/sounds/funny.wav","static"),
- love.audio.newSource("assets/sounds/funny2.wav","static"),
- love.audio.newSource("assets/sounds/funny3.wav","static"),
- love.audio.newSource("assets/sounds/funny4.wav","static"),
- love.audio.newSource("assets/sounds/funny5.wav","static"),
- love.audio.newSource("assets/sounds/funny6.wav","static"),
- love.audio.newSource("assets/sounds/funny7.wav","static"),
- love.audio.newSource("assets/sounds/funny8.wav","static"),
- love.audio.newSource("assets/sounds/funny9.wav","static")}
- local img = bulletImg
- love.audio.setVolume(0.7)
- end
- function love.update(dt)
- if love.keyboard.isDown('escape') then
- if saved == false then
- table.insert(scores,score)
- saved = true
- end
- if love.filesystem.exists("save.nibba") then --sorry i've never worked with filesystems before. just starting out.
- love.filesystem.write("save.nibba",formatTable())
- else
- local file = love.filesystem.newFile("save.nibba")
- file:open("w")
- file:write(formatTable())
- file:close()
- end
- love.event.push('quit')
- end
- pauseTimer = pauseTimer - (1*dt)
- if love.keyboard.isDown("space") and isPaused == false and pauseTimer < 0 and isAlive then
- isPaused = true
- love.audio.pause(themes[theme])
- pauseTimer = pauseTimerMax
- elseif love.keyboard.isDown("space") and isPaused == true and pauseTimer < 0 and isAlive then
- isPaused = false
- love.audio.resume(themes[theme])
- pauseTimer = pauseTimerMax
- end
- if love.keyboard.isDown("j") and love.keyboard.isDown("o") and love.keyboard.isDown("h") and love.keyboard.isDown("n") and cheat1ac == false then
- bulletImg = scndImg
- player.speed = 550
- cheat1ac = true
- end
- if love.keyboard.isDown("d") and love.keyboard.isDown("a") and love.keyboard.isDown("n") and love.keyboard.isDown("k") and cheat2ac == false then
- cheat2ac = true
- player.img = enemyImg[3]
- enemyImg[3] = main_img
- end
- if isPaused == false then
- canShootTimer = canShootTimer - (1*dt)
- if canShootTimer < 0 then
- canShoot = true
- end
- if love.mouse.isDown(1) then
- if isAlive and canShoot then
- local x,y = love.mouse.getPosition()
- local startX = player.x + ((player.img:getWidth() / 2) - bulletImg:getWidth()/2)
- local startY = player.y + ((player.img:getHeight() / 2) - bulletImg:getHeight()/2)
- local mouseX = x - bulletImg:getWidth()/2
- local mouseY = y - bulletImg:getHeight()/2
- local angle = math.atan2((mouseY - startY), (mouseX - startX))
- local bulletDx = score > 60 and 900 * math.cos(angle) or 600 * math.cos(angle)
- local bulletDy = score > 60 and 900 * math.sin(angle) or 600 * math.sin(angle)
- local bulletDz = nil
- local bulletDw = nil
- if cheat1ac then
- bulletDz = score > 60 and 900 * math.cos(angle+1.57079633) or 600 * math.cos(angle+1.57079633 )
- bulletDw = score > 60 and 900 * math.sin(angle+1.57079633) or 600 * math.sin(angle+1.57079633 )
- end
- table.insert(bullets, {x = startX, y = startY, img = bulletImg, dx = bulletDx, dy = bulletDy})
- if cheat1ac == true then
- table.insert(bullets, {x = startX, y = startY, img = bulletImg, dx = 0-bulletDx, dy = 0-bulletDy})
- table.insert(bullets, {x = startX, y = startY, img = bulletImg, dx = bulletDz, dy = bulletDw})
- table.insert(bullets, {x = startX, y = startY, img = bulletImg, dx = 0-bulletDz, dy = 0-bulletDw})
- end
- canShoot = false
- canShootTimer = canShootTimerMax
- end
- end
- if love.keyboard.isDown('left','a') then
- if player.x > 0 then -- binds us to the map
- player.x = player.x - (player.speed*dt)
- end
- lrDir = -1
- elseif love.keyboard.isDown('right','d') then
- if player.x < (love.graphics.getWidth() - player.img:getWidth()) then
- player.x = player.x + (player.speed*dt)
- end
- lrDir = 1
- end
- if love.keyboard.isDown('up','w') then
- if player.y > 0 then
- player.y = player.y - (player.speed*dt)
- end
- udDir = -1
- elseif love.keyboard.isDown('down','s') then
- if player.y < (love.graphics.getHeight() - player.img:getHeight()) then
- player.y = player.y + (player.speed*dt)
- end
- udDir = 1
- end
- for i, bullet in ipairs(bullets) do
- if cheat2ac and #enemies > 0 then
- local closest = {dist = 100000,index = 1}
- for i,v in ipairs(enemies) do
- if ((v.x-bullet.x)^2+(v.y-bullet.y)^2)^0.5 < closest.dist then
- closest = {dist = ((v.x-bullet.x)^2+(v.y-bullet.y)^2)^0.5, index = i}
- end
- end
- local angle = math.atan2((enemies[closest.index].y - bullet.y), (enemies[closest.index].x - bullet.x))
- local bulletDx = score > 60 and 900 * math.cos(angle) or 600 * math.cos(angle)
- local bulletDy = score > 60 and 900 * math.sin(angle) or 600 * math.sin(angle)
- bullet.x = bullet.x + (bulletDx * dt)
- bullet.y = bullet.y + (bulletDy * dt)
- else
- bullet.x = bullet.x + (bullet.dx * dt)
- bullet.y = bullet.y + (bullet.dy * dt)
- end
- if bullet.y+ bullet.img:getHeight() < 0 or bullet.y > (love.graphics.getHeight() + bullet.img:getHeight()) or bullet.x+ bullet.img:getWidth() < 0 or bullet.x > (love.graphics.getWidth() + bullet.img:getWidth()) then -- remove bullets when they pass off the screen
- table.remove(bullets, i)
- end
- end
- for i, enemy in ipairs(enemies) do
- for j, bullet in ipairs(bullets) do
- if CheckCollision(enemy.x, enemy.y, enemy.img:getWidth(), enemy.img:getHeight(), bullet.x, bullet.y, bullet.img:getWidth(), bullet.img:getHeight()) then
- if score < 29 or cheat2ac then
- table.remove(bullets, j)
- end
- local tPartic = {
- p = love.graphics.newParticleSystem(bulletImg, 8),
- x= enemy.x,
- y = enemy.y}
- tPartic.p:setSizes(0.8,0.7,0.6,0.5,0.4)
- tPartic.p:setSizeVariation(0.2)
- tPartic.p:setParticleLifetime(1, 3) -- Particles live at least 2s and at most 5s.
- tPartic.p:setLinearAcceleration(-50, 100, 50, 600) -- Randomized movement towards the bottom of the screen.
- tPartic.p:setSpeed(100,400)
- tPartic.p:setColors(255, 255, 255, 255, 255, 255, 255, 0) -- Fade to black.
- tPartic.p:setAreaSpread("normal", 15, 15 )
- tPartic.p:emit(8)
- table.insert(particle,tPartic)
- table.remove(enemies, i)
- if #particle > 7 then
- table.remove(particle,1)
- end
- score = score + 1
- if math.random(1,4)==0 then
- love.audio.play(hit[math.random(1,#hit)])
- end
- end
- end
- end
- for i, enemy in ipairs(enemies) do
- if CheckCollision(enemy.x, enemy.y, enemy.img:getWidth(), enemy.img:getHeight(), player.x, player.y, player.img:getWidth(), player.img:getHeight()) and isAlive then
- table.remove(enemies, i)
- isAlive = false
- saved = true
- table.insert(scores, score)
- table.sort(scores,function(a,b) return a>b end)
- end
- local angle = math.atan2((player.y - enemy.y), (player.x - enemy.x))
- local bulletDx = score > 29 and 350 * math.cos(angle) or 250 * math.cos(angle)
- local bulletDy = score > 29 and 350 * math.sin(angle) or 250 * math.sin(angle)
- enemy.x = enemy.x + (bulletDx * dt)
- enemy.y = enemy.y + (bulletDy * dt)
- if isAlive == false then
- enemies = {}
- end
- end
- createEnemyTimer = createEnemyTimer - (1 * dt)
- if createEnemyTimer < 0 and isAlive then
- createEnemyTimer = createEnemyTimerMax
- -- Create an enemy
- yopt = {math.random(love.graphics.getHeight(),love.graphics.getHeight()+70),math.random(-70,0)}
- xRand = math.random(-70,love.graphics.getWidth()+70)
- yRand = (xRand < 0 or xRand > love.graphics.getWidth()) and math.random(0,love.graphics.getHeight()) or yopt[math.random(1,2)]
- newEnemy = { x = xRand, y = yRand, img = enemyImg[math.random(1,#enemyImg)] }
- table.insert(enemies, newEnemy)
- end
- if score == 60 then
- createEnemyTimerMax = 0.45
- elseif score == 90 then
- canShootTimerMax = 0.1
- createEnemyTimerMax = 0.3
- end
- for i,v in ipairs(particle) do
- v.p:update(dt)
- end
- if not isAlive and love.keyboard.isDown('r') then
- -- remove all our bullets and enemies from screen
- bullets = {}
- enemies = {}
- -- reset timers
- score = 0
- canShootTimerMax = 0.2
- canShootTimer = canShootTimerMax
- createEnemyTimer = 0.6
- createEnemyTimer = createEnemyTimerMax
- cheat1ac = false
- cheat2ac = false
- player.img = main_img
- bulletImg = bltrecover
- enemyImg[3] = jooshrecover
- -- move player back to default position
- player.x = (love.graphics.getWidth()/2)-(player.img:getWidth()/2)
- player.y = (love.graphics.getHeight()/2)-(player.img:getWidth()/2)
- -- reset our game state
- saved = false
- isAlive = true
- isPaused = false
- love.audio.rewind(themes[theme])
- love.audio.pause()
- love.audio.setVolume(0.7)
- theme = math.random(1,#themes)
- love.audio.play(themes[theme])
- end
- end
- end
- function love.draw(dt)
- love.graphics.setColor(86,12,81)
- love.graphics.rectangle("fill",0,0,love.graphics.getWidth(),love.graphics.getHeight())
- love.graphics.setColor(255,255,255)
- love.graphics.print("Score "..score, love.graphics:getWidth()/2-30, 5)
- if isAlive then
- love.graphics.draw(player.img, player.x, player.y)
- else
- love.graphics.print("Press 'R' to Start", love.graphics:getWidth()/2-50, love.graphics:getHeight()/2-100)
- love.graphics.print("Top Scores", love.graphics:getWidth()/2-30, love.graphics:getHeight()/2-85)
- for i=1,#scores > 10 and 10 or #scores do
- love.graphics.print(i.." : "..scores[i],love.graphics:getWidth()/2-20, love.graphics:getHeight()/2-70+15*i)
- end
- end
- for i, bullet in ipairs(bullets) do
- love.graphics.draw(bullet.img, bullet.x, bullet.y)
- end
- --love.graphics.draw(psystem, love.graphics.getWidth()/2, love.graphics.getHeight()/2)
- for i,v in ipairs(particle) do
- love.graphics.draw(v.p,v.x,v.y)
- end
- for i, enemy in ipairs(enemies) do
- love.graphics.draw(enemy.img, enemy.x, enemy.y)
- end
- if isPaused == true then
- love.graphics.print("Press Space to Unpause", love.graphics:getWidth()/2-75, love.graphics:getHeight()/2-10)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement