diff --git a/asteroid.lua b/asteroid.lua new file mode 100644 index 0000000..9f221b6 --- /dev/null +++ b/asteroid.lua @@ -0,0 +1,84 @@ +asteroid = class:new() + +function asteroid:init(x, y, size) + self.x = x or math.random(80)+10 + self.y = y or -10 + self.r = math.random(math.pi*20)/10 + self.size = size or 1 + self.rspeed = (math.random()*2-1)*10 + self.speedx = math.random(5)+20 + self.speedy = math.random(5)+10 + self.i = math.random(2) + self.direction = math.random(2) + if self.direction == 2 then + self.direction = -1 + end + + if self.size == 1 then + self.hp = 12*realasteroiddelay + else + self.hp = 6*realasteroiddelay + end +end + +function asteroid:update(dt) + self.x = self.x + self.speedx*dt*self.direction + self.y = self.y + self.speedy*dt + + if self.x > 90 then + self.direction = -1 + elseif self.x < 10 then + self.direction = 1 + end + + if self.y > 40 then + self.speedy = 100 + self.direction = 0 + end + + self.r = self.r + self.rspeed*dt + + if self.y > 120 then + self.dead = true + end + + return self.dead +end + +function asteroid:hit() + self.hp = self.hp - 1 + if self.hp <= 0 then + if self.size == 1 then + table.insert(asteroids, asteroid:new(self.x, self.y, 2)) + table.insert(asteroids, asteroid:new(self.x, self.y, 2)) + pointsget(10) + else + pointsget(10) + end + lastexplosion = {self.x, self.y} + self.dead = true + table.insert(explosions, explosion:new(self.x-12, self.y-16)) + backgroundwhite = 1 + end +end + +function asteroid:checkcol(x, y) + if self.size == 1 then --big + if math.abs(self.x-x) < 9 and math.abs(self.y-y) < 9 then + return true + end + else + if math.abs(self.x-x) < 6 and math.abs(self.y-y) < 6 then + return true + end + end + return false +end + +function asteroid:draw() + if self.size == 1 then + draw(_G["asteroid-big" .. self.i .. "img"], self.x, self.y, self.r, 1, 1, 11, 9) + else + draw(_G["asteroid-small" .. self.i .. "img"], self.x, self.y, self.r, 1, 1, 11, 9) + end +end \ No newline at end of file diff --git a/audio/approach.ogg b/audio/approach.ogg new file mode 100644 index 0000000..f2639a7 Binary files /dev/null and b/audio/approach.ogg differ diff --git a/audio/bigexplosion.ogg b/audio/bigexplosion.ogg new file mode 100644 index 0000000..0a487e3 Binary files /dev/null and b/audio/bigexplosion.ogg differ diff --git a/audio/credits.ogg b/audio/credits.ogg new file mode 100644 index 0000000..12033ef Binary files /dev/null and b/audio/credits.ogg differ diff --git a/audio/ding.ogg b/audio/ding.ogg new file mode 100644 index 0000000..4c6b83a Binary files /dev/null and b/audio/ding.ogg differ diff --git a/audio/explosion.wav b/audio/explosion.wav new file mode 100644 index 0000000..067b99f Binary files /dev/null and b/audio/explosion.wav differ diff --git a/audio/gunfire.wav b/audio/gunfire.wav new file mode 100644 index 0000000..a905579 Binary files /dev/null and b/audio/gunfire.wav differ diff --git a/audio/laser.wav b/audio/laser.wav new file mode 100644 index 0000000..e2094bf Binary files /dev/null and b/audio/laser.wav differ diff --git a/audio/launch.ogg b/audio/launch.ogg new file mode 100644 index 0000000..bebea90 Binary files /dev/null and b/audio/launch.ogg differ diff --git a/audio/space.ogg b/audio/space.ogg new file mode 100644 index 0000000..7e41cab Binary files /dev/null and b/audio/space.ogg differ diff --git a/audio/space.wav b/audio/space.wav new file mode 100644 index 0000000..902deef Binary files /dev/null and b/audio/space.wav differ diff --git a/audio/splat.ogg b/audio/splat.ogg new file mode 100644 index 0000000..8bfbb4d Binary files /dev/null and b/audio/splat.ogg differ diff --git a/audio/sunglasses.ogg b/audio/sunglasses.ogg new file mode 100644 index 0000000..9cec021 Binary files /dev/null and b/audio/sunglasses.ogg differ diff --git a/audio/trosong.ogg b/audio/trosong.ogg new file mode 100644 index 0000000..eec0f34 Binary files /dev/null and b/audio/trosong.ogg differ diff --git a/bigexplosion.lua b/bigexplosion.lua new file mode 100644 index 0000000..6e6a53d --- /dev/null +++ b/bigexplosion.lua @@ -0,0 +1,30 @@ +bigexplosion = class:new() + +function bigexplosion:init(x, y) + self.x = x + self.y = y + self.quad = 1 + self.quadtimer = 0 +end + +function bigexplosion:update(dt) + self.quadtimer = self.quadtimer + dt*3 + while self.quadtimer > 1 do + self.quadtimer = self.quadtimer - 1 + self.quad = self.quad + 1 + if self.quad == 26 then + return true + end + end +end + +function bigexplosion:draw() + local r, g, b = love.graphics.getColor() + if starttimer > 0 then + love.graphics.setColor(255, 255, 255, 255*math.min(1, math.max(0, (1-starttimer/7)))) + end + if self.quad <= 25 then + love.graphics.drawq(bigexplosionimg, bigexplosionquad[self.quad], self.x*scale, self.y*scale, 0, scale, scale) + end + love.graphics.setColor(r, g, b) +end \ No newline at end of file diff --git a/bird.lua b/bird.lua new file mode 100644 index 0000000..69fa2b6 --- /dev/null +++ b/bird.lua @@ -0,0 +1,52 @@ +bird = class:new() + +function bird:init(x, y) + self.x = math.random(100) + self.y = 90 + self.quad = 1 + self.quadtimer = 0 + self.speedx = (math.random()*2-1)*50 + self.speedy = math.random(30)+10 + + self.dir = math.random(2) + if self.dir == 2 then + self.dir = -1 + end +end + +function bird:update(dt) + self.quadtimer = self.quadtimer + dt*5 + if self.quadtimer > 1 then + self.quadtimer = self.quadtimer - 1 + if self.quad == 1 then + self.quad = 2 + else + self.quad = 1 + end + end + + self.x = self.x + self.speedx*dt*self.dir + self.y = self.y - self.speedy*dt + + if self.x > 100 then + self.dir = -1 + elseif self.x < 0 then + self.dir = 1 + end + + if self.y < -10 or self.dead then + return true + end +end + +function bird:checkcol(x, y) + if math.abs(self.x-x) < 7 and math.abs(self.y-y) < 4 then + self.dead = true + return true + end + return false +end + +function bird:draw() + love.graphics.drawq(birdimg, birdquad[self.quad], self.x*scale, self.y*scale, 0, scale/2, scale/2, 14, 8) +end \ No newline at end of file diff --git a/bullet.lua b/bullet.lua new file mode 100644 index 0000000..f55c323 --- /dev/null +++ b/bullet.lua @@ -0,0 +1,41 @@ +bullet = class:new() + +function bullet:init(x, y, r) + self.x = x + self.y = y + self.r = r + gunfire:stop() + gunfire:play() +end + +function bullet:update(dt) + if not self.kill then + self.x = self.x + math.sin(self.r)*500*dt + self.y = self.y - math.cos(self.r)*300*dt + + for i, v in pairs(asteroids) do + if v:checkcol(self.x, self.y) and not v.dead then + v:hit() + self.kill = 0 + end + end + end + + if self.kill then + self.kill = self.kill + dt + end + + if self.kill and self.kill >= 0.2 then + return true + end +end + +function bullet:draw() + if self.kill then + love.graphics.setColor(255, 255, 255, (1-self.kill/0.2)*255) + draw(littleexplosionimg, self.x, self.y, self.r, 1, 1, 8, 4) + love.graphics.setColor(255, 255, 255, 255) + else + draw(bulletimg, self.x, self.y, self.r, 1, 1, 6, 4) + end +end \ No newline at end of file diff --git a/bush.lua b/bush.lua new file mode 100644 index 0000000..acfc729 --- /dev/null +++ b/bush.lua @@ -0,0 +1,25 @@ +bush = class:new() + +function bush:init() + self.x = math.random()*100 + self.y = math.random()*20+57 + self.i = math.random(2) + self.speed = 50 +end + +function bush:update(dt) + if not rockets or rockets[1].x > 50 then + self.x = self.x - self.speed*dt + end + + if self.x < - _G["bush" .. self.i .. "img"]:getWidth() then + self.x = 100 + self.y = math.random()*20+57 + self.i = math.random(2) + self.speed = 50 + end +end + +function bush:draw() + draw(_G["bush" .. self.i .. "img"], self.x, self.y) +end \ No newline at end of file diff --git a/class.lua b/class.lua new file mode 100644 index 0000000..c42e794 --- /dev/null +++ b/class.lua @@ -0,0 +1,44 @@ +--[[ +Copyright (c) 2009 Bart van Strien + +Permission is hereby granted, free of charge, to any person +obtaining a copy of this software and associated documentation +files (the "Software"), to deal in the Software without +restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. +]] + +__HAS_SECS_COMPATIBLE_CLASSES__ = true + +local class_mt = {} + +function class_mt:__index(key) + return self.__baseclass[key] +end + +class = setmetatable({ __baseclass = {} }, class_mt) + +function class:new(...) + local c = {} + c.__baseclass = self + setmetatable(c, getmetatable(self)) + if c.init then + c:init(...) + end + return c +end \ No newline at end of file diff --git a/cloud.lua b/cloud.lua new file mode 100644 index 0000000..9dd6c56 --- /dev/null +++ b/cloud.lua @@ -0,0 +1,30 @@ +cloud = class:new() + +function cloud:init(random, y) + if y then + self.starty = y + end + self.x = math.random()*100 + self.y = y or math.random()*20+3 + self.i = math.random(2) + self.speed = math.random()*20+50 +end + +function cloud:update(dt) + if not rockets or rockets[1].x > 50 then + self.x = self.x - self.speed*dt + else + self.x = self.x - self.speed*0.3*dt + end + + if self.x < - _G["cloud" .. self.i .. "img"]:getWidth() then + self.x = 100 + self.y = self.starty or math.random()*20+3 + self.i = math.random(2) + self.speed = math.random()*20+50 + end +end + +function cloud:draw() + draw(_G["cloud" .. self.i .. "img"], self.x, self.y) +end \ No newline at end of file diff --git a/cloud2.lua b/cloud2.lua new file mode 100644 index 0000000..4cc984a --- /dev/null +++ b/cloud2.lua @@ -0,0 +1,22 @@ +cloud2 = class:new() + +function cloud2:init(y) + self.x = math.random()*100 + self.y = 120+y + self.i = math.random(2) + self.speed = -500 +end + +function cloud2:update(dt) + self.y = self.y + self.speed*dt + + if self.y < -20 then + self.y = self.y+140 + self.x = math.random()*100 + self.i = math.random(2) + end +end + +function cloud2:draw() + draw(_G["cloud" .. self.i .. "img"], self.x, self.y, 0, 1, 1, 15) +end \ No newline at end of file diff --git a/conf.lua b/conf.lua new file mode 100644 index 0000000..0bdaf1a --- /dev/null +++ b/conf.lua @@ -0,0 +1,9 @@ +function love.conf(t) + t.title = "TROSH: The Movie: The Game" + t.author = "Maurice" + t.console = false + t.screen.vsync = true + t.screen.width = 800 + t.screen.height = 640 + t.screen.fsaa = 0 +end \ No newline at end of file diff --git a/enemy.lua b/enemy.lua new file mode 100644 index 0000000..abf285e --- /dev/null +++ b/enemy.lua @@ -0,0 +1,64 @@ +enemy = class:new() + +function enemy:init() + self.quad = 1 + self.x = 100 + self.y = math.random()*20+40 + self.quadtimer = 0 + self.movement = math.random(7)-4 + if self.movement > 0 then + self.movement = 1 + elseif self.movement < 0 then + self.movement = -1 + end + self.speed = math.random(30)+40 + self.dead = false +end + +function enemy:update(dt) + self.quadtimer = self.quadtimer + dt*30 + if self.quadtimer > 1 then + self.quadtimer = self.quadtimer - 1 + self.quad = self.quad + 1 + if self.quad == 17 then + self.quad = 1 + end + end + + if self.movement == 1 then + self.y = self.y - dt*30 + if self.y < 40 then + self.movement = -1 + end + elseif self.movement == -1 then + self.y = self.y + dt*30 + if self.y > 70 then + self.movement = 1 + end + end + + self.x = self.x - self.speed*dt + + if self.dead then + return true + end +end + +function enemy:explode() + self.dead = true + table.insert(explosions, explosion:new(self.x-5, self.y-10)) + pointsget(1) + skycolor = getrainbowcolor(math.random()) + love.graphics.setBackgroundColor(skycolor) +end + +function enemy:checkcol(x, y, newx) + if x < self.x+4 and newx > self.x+4 and math.abs(self.y+7-y) < 6 then + return true + end + return false +end + +function enemy:draw() + love.graphics.drawq(enemyimg, enemyquad[self.quad], self.x*scale, self.y*scale, 0, 0.1875*scale, 0.1875*scale) +end \ No newline at end of file diff --git a/explosion.lua b/explosion.lua new file mode 100644 index 0000000..419ebe5 --- /dev/null +++ b/explosion.lua @@ -0,0 +1,25 @@ +explosion = class:new() + +function explosion:init(x, y) + self.x = x + self.y = y + self.quad = 1 + self.quadtimer = 0 + explosionsound:stop() + explosionsound:play() +end + +function explosion:update(dt) + self.quadtimer = self.quadtimer + dt*60 + if self.quadtimer > 1 then + self.quadtimer = self.quadtimer - 1 + self.quad = self.quad + 1 + if self.quad == 26 then + return true + end + end +end + +function explosion:draw() + love.graphics.drawq(explosionimg, explosionquad[self.quad], self.x*scale, self.y*scale, 0, 0.375*scale, 0.375*scale) +end \ No newline at end of file diff --git a/graphics/alert.png b/graphics/alert.png new file mode 100644 index 0000000..3eb5a30 Binary files /dev/null and b/graphics/alert.png differ diff --git a/graphics/arrow.png b/graphics/arrow.png new file mode 100644 index 0000000..385b90c Binary files /dev/null and b/graphics/arrow.png differ diff --git a/graphics/asteroid-big1.png b/graphics/asteroid-big1.png new file mode 100644 index 0000000..6f34e46 Binary files /dev/null and b/graphics/asteroid-big1.png differ diff --git a/graphics/asteroid-big2.png b/graphics/asteroid-big2.png new file mode 100644 index 0000000..15aff42 Binary files /dev/null and b/graphics/asteroid-big2.png differ diff --git a/graphics/asteroid-small1.png b/graphics/asteroid-small1.png new file mode 100644 index 0000000..b501c25 Binary files /dev/null and b/graphics/asteroid-small1.png differ diff --git a/graphics/asteroid-small2.png b/graphics/asteroid-small2.png new file mode 100644 index 0000000..b44e283 Binary files /dev/null and b/graphics/asteroid-small2.png differ diff --git a/graphics/awesome.png b/graphics/awesome.png new file mode 100644 index 0000000..dcb6dd1 Binary files /dev/null and b/graphics/awesome.png differ diff --git a/graphics/bigexplosion.png b/graphics/bigexplosion.png new file mode 100644 index 0000000..be548dc Binary files /dev/null and b/graphics/bigexplosion.png differ diff --git a/graphics/bird.png b/graphics/bird.png new file mode 100644 index 0000000..de0bc47 Binary files /dev/null and b/graphics/bird.png differ diff --git a/graphics/bullet.png b/graphics/bullet.png new file mode 100644 index 0000000..e0f6ecd Binary files /dev/null and b/graphics/bullet.png differ diff --git a/graphics/bush1.png b/graphics/bush1.png new file mode 100644 index 0000000..65d63d0 Binary files /dev/null and b/graphics/bush1.png differ diff --git a/graphics/bush2.png b/graphics/bush2.png new file mode 100644 index 0000000..02a3113 Binary files /dev/null and b/graphics/bush2.png differ diff --git a/graphics/cloud1.png b/graphics/cloud1.png new file mode 100644 index 0000000..2afc5c8 Binary files /dev/null and b/graphics/cloud1.png differ diff --git a/graphics/cloud2.png b/graphics/cloud2.png new file mode 100644 index 0000000..60be793 Binary files /dev/null and b/graphics/cloud2.png differ diff --git a/graphics/enemy.png b/graphics/enemy.png new file mode 100644 index 0000000..b8f382a Binary files /dev/null and b/graphics/enemy.png differ diff --git a/graphics/explosion.png b/graphics/explosion.png new file mode 100644 index 0000000..142f302 Binary files /dev/null and b/graphics/explosion.png differ diff --git a/graphics/font.png b/graphics/font.png new file mode 100644 index 0000000..ba7883e Binary files /dev/null and b/graphics/font.png differ diff --git a/graphics/ground.png b/graphics/ground.png new file mode 100644 index 0000000..fce252f Binary files /dev/null and b/graphics/ground.png differ diff --git a/graphics/groundwin.png b/graphics/groundwin.png new file mode 100644 index 0000000..2920c66 Binary files /dev/null and b/graphics/groundwin.png differ diff --git a/graphics/icon.png b/graphics/icon.png new file mode 100644 index 0000000..7fe436b Binary files /dev/null and b/graphics/icon.png differ diff --git a/graphics/littleexplosion.png b/graphics/littleexplosion.png new file mode 100644 index 0000000..c534734 Binary files /dev/null and b/graphics/littleexplosion.png differ diff --git a/graphics/powerup.png b/graphics/powerup.png new file mode 100644 index 0000000..fba89c3 Binary files /dev/null and b/graphics/powerup.png differ diff --git a/graphics/randomshit.png b/graphics/randomshit.png new file mode 100644 index 0000000..ce71f8a Binary files /dev/null and b/graphics/randomshit.png differ diff --git a/graphics/rocket.png b/graphics/rocket.png new file mode 100644 index 0000000..3954c3d Binary files /dev/null and b/graphics/rocket.png differ diff --git a/graphics/rocketkaputt.png b/graphics/rocketkaputt.png new file mode 100644 index 0000000..0aae52b Binary files /dev/null and b/graphics/rocketkaputt.png differ diff --git a/graphics/splatter.png b/graphics/splatter.png new file mode 100644 index 0000000..7e8c323 Binary files /dev/null and b/graphics/splatter.png differ diff --git a/graphics/star.png b/graphics/star.png new file mode 100644 index 0000000..ec23dd8 Binary files /dev/null and b/graphics/star.png differ diff --git a/graphics/sunglasses.png b/graphics/sunglasses.png new file mode 100644 index 0000000..689a098 Binary files /dev/null and b/graphics/sunglasses.png differ diff --git a/graphics/title.png b/graphics/title.png new file mode 100644 index 0000000..f513f10 Binary files /dev/null and b/graphics/title.png differ diff --git a/graphics/trosh.png b/graphics/trosh.png new file mode 100644 index 0000000..d0700c9 Binary files /dev/null and b/graphics/trosh.png differ diff --git a/graphics/troshwin.png b/graphics/troshwin.png new file mode 100644 index 0000000..b9380f1 Binary files /dev/null and b/graphics/troshwin.png differ diff --git a/graphics/warning.png b/graphics/warning.png new file mode 100644 index 0000000..0dd951b Binary files /dev/null and b/graphics/warning.png differ diff --git a/graphics/wheatley.png b/graphics/wheatley.png new file mode 100644 index 0000000..38b8c4e Binary files /dev/null and b/graphics/wheatley.png differ diff --git a/laser.lua b/laser.lua new file mode 100644 index 0000000..c5580c4 --- /dev/null +++ b/laser.lua @@ -0,0 +1,29 @@ +laser = class:new() + +function laser:init(x, y) + self.i = 0 + self.x = x + self.y = y +end + +function laser:update(dt) + local oldi = self.i + self.i = self.i + dt*5 + + if self.i > 1 then + return true + end + + if enemies then + for i, v in pairs(enemies) do + if v:checkcol(self.x + oldi*100, self.y, self.x + self.i*100) then + v:explode() + end + end + end +end + +function laser:draw() + love.graphics.setColor(getrainbowcolor(math.random(), 400)) + love.graphics.rectangle("fill", self.x*scale, self.y*scale, 100*scale*self.i, scale*2) +end \ No newline at end of file diff --git a/main.lua b/main.lua new file mode 100644 index 0000000..70ca008 --- /dev/null +++ b/main.lua @@ -0,0 +1,316 @@ +function love.load() + love.graphics.setDefaultImageFilter("nearest", "nearest") + + require "class" + require "menu" + require "cloud" + require "cloud2" + require "bush" + require "scene1" + require "scene2" + require "scene3" + require "scene4" + require "scene5" + require "scene6" + require "laser" + require "enemy" + require "explosion" + require "bigexplosion" + require "splatter" + require "powerup" + require "rocket" + require "star" + require "asteroid" + require "bullet" + require "bird" + + love.graphics.setIcon( love.graphics.newImage("graphics/icon.png") ) + imagelist = {"title", "cloud1", "cloud2", "ground", "bush1", "bush2", "powerup", "rocket", "star", "asteroid-big1", "sunglasses", "awesome", "arrow", "groundwin", + "asteroid-big2", "asteroid-small1", "asteroid-small2", "bullet", "littleexplosion", "warning", "wheatley", "alert", "randomshit", "bird"} + + for i = 1, #imagelist do + _G[imagelist[i] .. "img"] = love.graphics.newImage("graphics/" .. imagelist[i] .. ".png") + end + + fontimage = love.graphics.newImage("graphics/font.png") + + fontglyphs = "0123456789abcdefghijklmnopqrstuvwxyz.:/,'C-_>* !{}?" + fontquads = {} + for i = 1, string.len(fontglyphs) do + fontquads[string.sub(fontglyphs, i, i)] = love.graphics.newQuad((i-1)*8, 0, 8, 8, 408, 8) + end + + playerimg = love.graphics.newImage("graphics/trosh.png") + playerquad = {love.graphics.newQuad(0, 0, 14, 25, 54, 25), love.graphics.newQuad(14, 0, 14, 25, 54, 25), love.graphics.newQuad(28, 0, 26, 12, 54, 25), love.graphics.newQuad(28, 12, 26, 12, 54, 25)} + + winplayerimg = love.graphics.newImage("graphics/troshwin.png") + winplayerquad = {} + for x = 1, 4 do + winplayerquad[x] = love.graphics.newQuad((x-1)*11, 0, 11, 26, 44, 26) + end + + enemyimg = love.graphics.newImage("graphics/enemy.png") + enemyquad = {} + for y = 1, 4 do + for x = 1, 4 do + enemyquad[(y-1)*4+x] = love.graphics.newQuad((x-1)*100, (y-1)*96, 100, 96, 400, 384) + end + end + + explosionimg = love.graphics.newImage("graphics/explosion.png") + explosionquad = {} + for y = 1, 5 do + for x = 1, 5 do + explosionquad[(y-1)*5+x] = love.graphics.newQuad((x-1)*66, (y-1)*81, 66, 81, 330, 405) + end + end + + bigexplosionimg = love.graphics.newImage("graphics/bigexplosion.png") + bigexplosionquad = {} + for y = 1, 5 do + for x = 1, 5 do + bigexplosionquad[(y-1)*5+x] = love.graphics.newQuad((x-1)*108, (y-1)*121, 108, 121, 540, 605) + end + end + + splatterimg = love.graphics.newImage("graphics/splatter.png") + splatterquad = {} + for x = 1, 6 do + splatterquad[x] = love.graphics.newQuad((x-1)*64, 0, 64, 64, 384, 64) + end + + birdquad = {love.graphics.newQuad(0, 0, 29, 16, 29, 32), love.graphics.newQuad(0, 16, 29, 16, 29, 32)} + + scale = 8 + local w, h = love.graphics.getMode() + if w ~= 100*scale or h ~= 80*scale then + love.graphics.setMode(100*scale, 80*scale, false, true, 0) + end + love.graphics.setIcon( love.graphics.newImage("graphics/icon.png") ) + + bgmusic = love.audio.newSource("audio/trosong.ogg") + bgmusic:setLooping(true) + lasersound = love.audio.newSource("audio/laser.wav") + bigexplosionsound = love.audio.newSource("audio/bigexplosion.ogg") + explosionsound = love.audio.newSource("audio/explosion.wav") + launchsound = love.audio.newSource("audio/launch.ogg") + gunfire = love.audio.newSource("audio/gunfire.wav") + space = love.audio.newSource("audio/space.ogg") + sunglassessound = love.audio.newSource("audio/sunglasses.ogg") + splat = love.audio.newSource("audio/splat.ogg") + ding = love.audio.newSource("audio/ding.ogg") + credits = love.audio.newSource("audio/credits.ogg") + approach = love.audio.newSource("audio/approach.ogg") + credits:setLooping(true) + + skipupdate = true + shakeamount = 0 + shake = 0 + fade = 0 + playerframe = 1 + scoreanim = 1 + rainbowi = 0.5 + sini = 0 + sini2 = math.pi/2 + scrollx = 0 + points = 0 + machinedelay = 0.05 + stars = {} + explosions = {} + backgroundstripes = 10 + sunrot = 0 + + lasers = {} + + realasteroiddelay = 1 + movement1speed = 100 + laserdelay = 0 + reallaserdelay = 0.4 + starttimer = 0 + changegamestate("menu") +end + +function love.update(dt) + if skipupdate then + skipupdate = false + return + end + + sunrot = sunrot + dt*50 + + starttimer = starttimer + dt + + if scoreanim < 1 then + scoreanim = scoreanim + (1-scoreanim)*8*dt + end + + if laserdelay > 0 then + laserdelay = math.max(0, laserdelay-dt) + end + + shake = math.random()*shakeamount*2-shakeamount + + if _G[gamestate .. "_update"] then + _G[gamestate .. "_update"](dt) + end + + --LASERS + local delete = {} + + for i, v in pairs(lasers) do + if v:update(dt) == true then + table.insert(delete, i) + end + end + + table.sort(delete, function(a,b) return a>b end) + + for i, v in pairs(delete) do + table.remove(lasers, v) --remove + end +end + +function pointsget(i) + points = points + i + scoreanim = 0 + rainbowi = math.random() + shakeamount = 10 +end + +function love.draw() + love.graphics.translate(50*scale, 40*scale) + love.graphics.rotate(shake/300) + love.graphics.translate(-50*scale, -40*scale) + + love.graphics.translate(shake*scale/4, shake*scale/4) + + if _G[gamestate .. "_draw"] then + _G[gamestate .. "_draw"]() + end + + + if gamestate ~= "menu" and gamestate ~= "scene6" and not landing then + local r, g, b = unpack(getrainbowcolor(rainbowi)) + + local ar = r + (255-r)*scoreanim + local ag = g + (255-g)*scoreanim + local ab = b + (255-b)*scoreanim + + love.graphics.setColor(ar, ag, ab) + + local s = scale*0.5+(1-scoreanim)*10 + love.graphics.rotate((1-scoreanim)*0.4) + properprint("score: " .. points, 2, 2, s) + love.graphics.rotate(-(1-scoreanim)*0.4) + end + + love.graphics.translate(-shake*scale/4, -shake*scale/4) + + + love.graphics.translate(50*scale, 40*scale) + love.graphics.rotate(-shake/300) + love.graphics.translate(-50*scale, -40*scale) + if fade > 0 then + love.graphics.setColor(255, 255, 255, 255*fade) + love.graphics.rectangle("fill", 0, 0, 100*scale, 80*scale) + love.graphics.setColor(255, 255, 255, 255) + end +end + +function love.keypressed(key, unicode) + if _G[gamestate .. "_keypressed"] then + _G[gamestate .. "_keypressed"](key, unicode) + end + + if key ~= "left" and key ~= "up" and key ~= "right" and key ~= "down" then + if _G[gamestate .. "_action"] then + _G[gamestate .. "_action"](key) + end + end +end + +function love.keyreleased(key, unicode) + if _G[gamestate .. "_keyreleased"] then + _G[gamestate .. "_keyreleased"](key, unicode) + end +end + +function changegamestate(i) + gamestate = i + if _G[gamestate .. "_load"] then + _G[gamestate .. "_load"]() + end +end + +function draw(drawable, x, y, r, sx, sy, ox, oy, kx, ky) + if not sx then + sx = 1 + end + if not sy then + sy = 1 + end + love.graphics.draw(drawable, x*scale, y*scale, r, sx*scale, sy*scale, ox, oy, kx, ky ) +end + +function round(num, idp) --Not by me + local mult = 10^(idp or 0) + return math.floor(num * mult + 0.5) / mult +end + +function properprint(s, x, y, sc) + local sc = sc or scale + local startx = x + local skip = 0 + for i = 1, string.len(tostring(s)) do + if skip > 0 then + skip = skip - 1 + else + local char = string.sub(s, i, i) + if fontquads[char] then + love.graphics.drawq(fontimage, fontquads[char], x*scale+((i-1)*8+1)*sc, y*scale, 0, sc, sc) + end + end + end +end + +function round(num, idp) --Not by me + local mult = 10^(idp or 0) + return math.floor(num * mult + 0.5) / mult +end + +function getrainbowcolor(i, whiteness) + local whiteness = whiteness or 255 + local r, g, b + if i < 1/6 then + r = 1 + g = i*6 + b = 0 + elseif i >= 1/6 and i < 2/6 then + r = (1/6-(i-1/6))*6 + g = 1 + b = 0 + elseif i >= 2/6 and i < 3/6 then + r = 0 + g = 1 + b = (i-2/6)*6 + elseif i >= 3/6 and i < 4/6 then + r = 0 + g = (1/6-(i-3/6))*6 + b = 1 + elseif i >= 4/6 and i < 5/6 then + r = (i-4/6)*6 + g = 0 + b = 1 + else + r = 1 + g = 0 + b = (1/6-(i-5/6))*6 + end + + local add = 0 + if whiteness > 255 then + add = whiteness-255 + end + + return {math.min(255, round(r*whiteness)+add), math.min(255, round(g*whiteness)+add), math.min(255, round(b*whiteness)+add), 255} +end \ No newline at end of file diff --git a/menu.lua b/menu.lua new file mode 100644 index 0000000..3ee1ab6 --- /dev/null +++ b/menu.lua @@ -0,0 +1,125 @@ +function menu_load() + love.graphics.setBackgroundColor(153, 217, 234) + clouds = {} + bushes = {} + love.audio.play(bgmusic) + for i = 1, 5 do + table.insert(clouds, cloud:new(true)) + end + for i = 1, 30 do + table.insert(bushes, bush:new(true)) + end + + textpos = {} + for i = 0, 7 do + textpos[i] = 10 + end + playerframetimer = 0 + playery = 50 + playerx = 10 + -- 1 2 3 4 5 6 7 + startactions = {2.3, 4.6, 7, 8.20, 9.20, 10.20, 11.20} + starti = 0 + +end + +function menu_update(dt) + for i, v in pairs(clouds) do + v:update(dt) + end + for i, v in pairs(bushes) do + v:update(dt) + end + + scrollx = scrollx + dt*50 + + rainbowi = math.mod(rainbowi + dt/2, 1) + sini = math.mod(sini + dt*10, math.pi*2) + sini2 = math.mod(sini2 + dt*5, math.pi*2) + + if starttimer > startactions[starti+1] then + starti = starti+1 + if starti == 7 then + changegamestate("scene1") + return + end + end + + if starti >= 4 then + shakeamount = shakeamount + dt*4 + end + if starti >= 5 then + shakeamount = shakeamount + dt*10 + end + if starti >= 6 then + shakeamount = shakeamount + dt*50 + end + + for i = -1, starti-1 do + if i >= 0 then + textpos[i] = textpos[i]+(textpos[i]^2*dt) + end + end + + playerframetimer = playerframetimer + dt*10 + while playerframetimer >= 2 do + playerframetimer = playerframetimer - 2 + end + playerframe = math.floor(playerframetimer)+1 + + playermovement1(dt) +end + +function menu_action() + shootlaser() +end + +function menu_draw() + love.graphics.setColor(255, 255, 255) + for i, v in pairs(clouds) do + v:draw() + end + + for i = 1, 2 do + draw(groundimg, -math.mod(scrollx, 120) + (i-1)*120, 59) + end + for i, v in pairs(bushes) do + v:draw() + end + + love.graphics.drawq(playerimg, playerquad[playerframe], playerx*scale, playery*scale, 0, scale, scale, 7, 12) + for i, v in pairs(lasers) do + v:draw() + end + + love.graphics.setColor(getrainbowcolor(rainbowi, 420)) + draw(titleimg, 50, 23, math.sin(sini)/10, (math.sin(sini2)+1)/5+0.7, (math.sin(sini2)+1)/5+0.7, 50, 13) + + love.graphics.setColor(255, 0, 0) + if starti >= 0 then + properprint("directed by maurice", 13, 40+textpos[0], scale/2) + end + if starti >= 1 then + properprint("use arrow keys", 25, 40+textpos[1], scale/2) + end + if starti >= 2 then + properprint("and any other button", 9, 40+textpos[2], scale/2) + end + if starti >= 3 then + properprint("get ready...", 20, 40+textpos[3], scale/2) + end + if starti >= 4 then + properprint("3", 40, 40+textpos[4], scale*2) + end + if starti >= 5 then + properprint("2", 36, 40+textpos[5], scale*3) + end + if starti >= 6 then + properprint("1", 32, 40+textpos[6], scale*4) + end + if starti >= 7 then + properprint("go!", 10, 40+textpos[7], scale*6) + end + + love.graphics.setColor(255, 255, 255) +end diff --git a/powerup.lua b/powerup.lua new file mode 100644 index 0000000..42d2b3b --- /dev/null +++ b/powerup.lua @@ -0,0 +1,47 @@ +powerup = class:new() + +function powerup:init() + self.x = 108 + self.y = math.random()*20+40 + self.speed = 30 + self.movement = 1 + self.blinktimer = 0 + self.blink = true +end + +function powerup:update(dt) + if self.movement == 1 then + self.y = self.y - dt*30 + if self.y < 40 then + self.movement = -1 + end + elseif self.movement == -1 then + self.y = self.y + dt*30 + if self.y > 70 then + self.movement = 1 + end + end + + self.blinktimer = self.blinktimer + dt + if self.blinktimer > 0.2 then + self.blinktimer = self.blinktimer - 0.5 + self.blink = not self.blink + end + + self.x = self.x - self.speed*dt +end + +function powerup:checkcol(x, y) + if math.abs(self.x+8-x) < 10 and math.abs(self.y+4-y) < 10 then + return true + end + return false +end + +function powerup:draw() + draw(powerupimg, self.x, self.y, 0, 1, 1, 8, 4) + love.graphics.setColor(255, 0, 0) + if self.x > 0 and self.blink then + properprint("collect the powerup!!!", 10, 45, scale*0.5) + end +end \ No newline at end of file diff --git a/rocket.lua b/rocket.lua new file mode 100644 index 0000000..474aefd --- /dev/null +++ b/rocket.lua @@ -0,0 +1,227 @@ +rocket = class:new() + +rocketspeed = 300 +maxrocketspeed = 100 + +function rocket:init() + self.x = 115 + self.y = 60 + self.r = 0 + self.speedx = 0 + self.ground = true + self.startingoffset = 0 + self.thrusttimer = 0 + thrusts = {} + machinegundelay = 0 + self.explosiondelay = 0 + self.explosiontimer = 0 +end + +function rocket:update(dt) + if self.ground then + if self.x > 50 then + self.x = self.x - dt*50 + if self.x < 50 then + self.x = 50 + end + end + else + self.startingoffset = (math.random()*2-1)*0.5 + end + + if self.starting then + self.startingtimer = self.startingtimer + dt + self.startingoffset = (math.random()*2-1)*2 + + if self.startingtimer > 2 then + self.y = self.y - dt*5 + self:thrusts(dt) + end + + if self.startingtimer > 7 then + self.y = self.y + dt*50 + + if self.y > 70 then + self.starting = false + self.y = 70 + changegamestate("scene3") + self.inflight = true + end + end + end + + if self.inflight then + if love.keyboard.isDown("right") and self.x < 100 then + self.speedx = self.speedx + dt*rocketspeed + elseif self.speedx > 0 then + self.speedx = math.max(0, self.speedx - dt*rocketspeed) + end + + if love.keyboard.isDown("left") and self.x > 0 then + self.speedx = self.speedx - dt*rocketspeed + elseif self.speedx < 0 then + self.speedx = math.min(0, self.speedx + dt*rocketspeed) + end + + self.speedx = math.min(maxrocketspeed, math.max(-maxrocketspeed, self.speedx)) + + self.x = self.x + self.speedx*dt + if self.x > 100 then + self.x = 100 + elseif self.x < 0 then + self.x = 0 + end + + self.r = self.speedx/200 + + if #pressedkeys > 0 then + machinegundelay = machinegundelay + dt + while machinegundelay > machinedelay do + self:fire() + machinegundelay = machinegundelay - machinedelay + end + end + + if wheatleytimer then + wheatleytimer = wheatleytimer + dt*2 + wheatleyr = wheatleyr + dt*10 + + if wheatleytimer >= 0.95 and wheatleytimer - dt*2 < 0.95 then + table.insert(explosions, explosion:new(self.x-20, self.y-20)) + rocketimg = love.graphics.newImage("graphics/rocketkaputt.png") + changegamestate("scene4") + self.hit = true + self.inflight = false + end + end + end + shakeamount = self.startingoffset*3 + + if self.hit then + wheatleytimer = wheatleytimer + dt*2 + wheatleyr = wheatleyr + dt*10 + if wheatleytimer < 4 then + if self.r > 0 then + self.r = self.r - dt + else + self.r = self.r + dt + end + else + if self.r < math.pi*0.9 then + self.r = self.r + dt + starmover = -self.r + self.y = self.y - dt*20 + if self.x > 10 then + self.x = self.x - dt*10 + elseif self.x < 10 then + self.x = self.x + dt*10 + end + end + end + + self.explosiontimer = self.explosiontimer + dt + while self.explosiontimer > self.explosiondelay do + self.explosiontimer = self.explosiontimer - self.explosiondelay + self.explosiondelay = math.random(100)/300+0.1 + table.insert(explosions, explosion:new(self.x-16+math.random(16)-8, self.y-20+math.random(16)-8)) + end + self.startingoffset = self.startingoffset*10 + end + + --THRUSTS + local delete = {} + + for i, v in pairs(thrusts) do + if v:update(dt) == true then + table.insert(delete, i) + end + end + + table.sort(delete, function(a,b) return a>b end) + + for i, v in pairs(delete) do + table.remove(thrusts, v) --remove + end +end + +function rocket:fire() + local outx = -math.sin(self.r) * -14 + self.x + local outy = math.cos(self.r) * -14 + self.y + + table.insert(bullets, bullet:new(outx, outy, self.r)) +end + +function rocket:thrusts(dt) --if you know what I mean + self.thrusttimer = self.thrusttimer + dt + local delay = 0.01 + while self.thrusttimer > delay do + self.thrusttimer = self.thrusttimer - delay + table.insert(thrusts, thrust:new(self.x-6, self.y+10)) + table.insert(thrusts, thrust:new(self.x, self.y+10)) + table.insert(thrusts, thrust:new(self.x+6, self.y+10)) + end +end + +function rocket:start() + self.starting = true + self.ground = false + self.startingtimer = 0 +end + +function rocket:checkcol(x, y) + if math.abs(self.x-x) < 16 and math.abs(self.y-y) < 16 then + return true + end + return false +end + +function rocket:draw() + local r, g, b = love.graphics.getColor() + for i, v in pairs(thrusts) do + v:draw() + end + love.graphics.setColor(r, g, b) + draw(rocketimg, self.x+self.startingoffset, self.y, self.r, 1, 1, 15, 16) + + if wheatleytimer then + if wheatleytimer <= 0.95 then + draw(wheatleyimg, self.x-20*(1-wheatleytimer/1), self.y-120*(1-wheatleytimer/1), wheatleyr, 1, 1, 8, 9) + else + draw(wheatleyimg, self.x-20*(1-0.95/1)-(wheatleytimer-0.95)*200, self.y-120*(1-wheatleytimer/1)+(wheatleytimer-0.95)*20, wheatleyr, 1, 1, 8, 9) + end + end +end + +function rocket:wheatleyattack() + wheatleytimer = 0 + wheatleyr = 0 + space:play() +end + +--THRUST + +thrust = class:new() + +function thrust:init(x, y) + self.x = x + self.y = y + self.starty = rockets[1].y + self.dir = (math.random()*2-1)*0.4+math.pi/2 + rockets[1].r + self.speed = 40 + self.life = 1 +end + +function thrust:update(dt) + self.x = self.x + math.cos(self.dir)*self.speed*dt + self.y = self.y + math.sin(self.dir)*self.speed*dt + + self.life = self.life - dt + if self.life <= 0 then + return true + end +end + +function thrust:draw() + love.graphics.setColor(255, 255, 255, 255*self.life) + love.graphics.rectangle("fill", self.x*scale, self.y*scale+(rockets[1].y-self.starty)*scale, scale, scale) +end \ No newline at end of file diff --git a/scene1.lua b/scene1.lua new file mode 100644 index 0000000..060406c --- /dev/null +++ b/scene1.lua @@ -0,0 +1,189 @@ +function scene1_load() + shakeamount = 0 + shake = 0 + fade = 1 + enemies = {} + powerups = {} + enemytimer = 0 + nextenemy = 0 + nextstage = false +end + +function scene1_update(dt) + if shakeamount > 0 then + shakeamount = math.max(0, shakeamount-dt*10) + end + + enemytimer = enemytimer + dt + while enemytimer > nextenemy and not nextstage do + enemytimer = enemytimer - nextenemy + if massenemies then + nextenemy = math.random(10)/1000+.002 + else + nextenemy = math.random(10)/10+.1 + end + table.insert(enemies, enemy:new()) + end + rainbowi = math.mod(rainbowi + dt/2, 1) + + + for i, v in pairs(clouds) do + v:update(dt) + end + for i, v in pairs(bushes) do + v:update(dt) + end + for i, v in pairs(powerups) do + v:update(dt) + end + + if starttimer > 32 and starttimer - dt < 32 then + table.insert(powerups, powerup:new()) + end + + if starttimer > 45 and starttimer - dt < 45 then + nextstage = true + end + + if starttimer > 47 and starttimer - dt < 47 then + rockets = {rocket:new()} + end + + if powerups[1] and powerups[1]:checkcol(playerx, playery) then + reallaserdelay = 0.05 + massenemies = true + powerups[1] = nil + end + + --ENEMIES + local delete = {} + + for i, v in pairs(enemies) do + if v:update(dt) == true then + table.insert(delete, i) + end + end + + table.sort(delete, function(a,b) return a>b end) + + for i, v in pairs(delete) do + table.remove(enemies, v) --remove + end + + --EXPLOSION + local delete = {} + + for i, v in pairs(explosions) do + if v:update(dt) == true then + table.insert(delete, i) + end + end + + table.sort(delete, function(a,b) return a>b end) + + for i, v in pairs(delete) do + table.remove(explosions, v) --remove + end + + if fade > 0 then + fade = math.max(0, fade-dt) + end + + playerframetimer = playerframetimer + dt*10 + while playerframetimer >= 2 do + playerframetimer = playerframetimer - 2 + end + playerframe = math.floor(playerframetimer)+1 + + if not rockets or rockets[1].x > 50 then + scrollx = scrollx + dt*50 + end + + if rockets and rockets[1]:checkcol(playerx, playery) and rockets[1].x <= 50 then + changegamestate("scene2") + end + + playermovement1(dt) + + if rockets then + rockets[1]:update(dt) + end +end + +function playermovement1(dt) + if love.keyboard.isDown("left") then + playerx = math.max(0, playerx-dt*movement1speed) + elseif love.keyboard.isDown("right") then + playerx = math.min(100, playerx+dt*movement1speed) + end + + if love.keyboard.isDown("up") then + playery = math.max(50, playery-dt*movement1speed) + elseif love.keyboard.isDown("down") then + playery = math.min(80, playery+dt*movement1speed) + end +end + +function scene1_action() + shootlaser() +end + +function shootlaser() + if laserdelay == 0 then + table.insert(lasers, laser:new(playerx, playery-8)) + lasersound:stop() + lasersound:play() + laserdelay = reallaserdelay + end +end + +function scene1_draw() + local r, g, b = love.graphics.getColor() + love.graphics.setColor(math.random(255), math.random(255), math.random(255), 255*(1-scoreanim)) + for i = 1, backgroundstripes, 2 do + local alpha = math.rad((i/backgroundstripes + math.mod(sunrot/100, 1)) * 360) + local point1 = {50*scale+100*scale*math.cos(alpha), 64*scale+100*scale*math.sin(alpha)} + + local alpha = math.rad(((i+1)/backgroundstripes + math.mod(sunrot/100, 1)) * 360) + local point2 = {50*scale+100*scale*math.cos(alpha), 64*scale+100*scale*math.sin(alpha)} + + love.graphics.polygon("fill", 50*scale, 64*scale, point1[1], point1[2], point2[1], point2[2]) + end + love.graphics.setColor(r, g, b, 255) + + for i, v in pairs(clouds) do + v:draw() + end + + for i = 1, 2 do + draw(groundimg, -math.mod(scrollx, 100) + (i-1)*100, 59) + end + for i, v in pairs(bushes) do + v:draw() + end + for i, v in pairs(enemies) do + v:draw() + end + for i, v in pairs(explosions) do + v:draw() + end + + if rockets then + rockets[1]:draw() + end + + love.graphics.drawq(playerimg, playerquad[playerframe], playerx*scale, playery*scale, 0, scale, scale, 7, 12) + for i, v in pairs(lasers) do + v:draw() + end + love.graphics.setColor(255, 255, 255) + for i, v in pairs(powerups) do + v:draw() + end + + if starttimer > 46 then + love.graphics.setColor(255, 0, 0) + properprint("get in the rocket!!!", 10, 45, scale*0.5) + end + love.graphics.setColor(255, 255, 255) +end \ No newline at end of file diff --git a/scene2.lua b/scene2.lua new file mode 100644 index 0000000..a761072 --- /dev/null +++ b/scene2.lua @@ -0,0 +1,75 @@ +function scene2_load() + starttimer = 0 + shakeamount = 0 + rockets[1].x = 50 + rockets[1]:start() + launchsound:stop() + launchsound:play() + + for y = 1, 30 do + for i = 1, 5 do + table.insert(clouds, cloud:new(true, -y*30)) + end + end + + backgroundcolor = {love.graphics.getBackgroundColor()} +end + +function scene2_update(dt) + for i, v in pairs(clouds) do + v:update(dt) + end + rockets[1]:update(dt) + + if starttimer > 7 then + love.graphics.setBackgroundColor(0, 0, 0) + elseif starttimer > 6 then + local r, g, b = unpack(backgroundcolor) + r = r*(1-(starttimer-6)/1) + g = g*(1-(starttimer-6)/1) + b = b*(1-(starttimer-6)/1) + + love.graphics.setBackgroundColor(r, g, b) + end + + if starttimer > 7 then + if starttimer - dt <= 7 then + for i = 1, 10 do + table.insert(stars, star:new()) + end + end + + staralpha = math.min(1, (starttimer-7)/9) + end +end + +function scene2_draw() + + local launchoffset = 0 + if starttimer > 3 then + launchoffset = 10^(starttimer-3)+(starttimer-3)*20 + end + + love.graphics.translate(0, launchoffset) + + for i, v in pairs(clouds) do + v:draw() + end + + for i = 1, 2 do + draw(groundimg, -math.mod(scrollx, 100) + (i-1)*100, 59) + end + for i, v in pairs(bushes) do + v:draw() + end + love.graphics.translate(0, -launchoffset) + + + for i,v in pairs(stars) do + v:draw() + end + + love.graphics.setColor(255, 255, 255, 255) + + rockets[1]:draw() +end \ No newline at end of file diff --git a/scene3.lua b/scene3.lua new file mode 100644 index 0000000..53f6e1e --- /dev/null +++ b/scene3.lua @@ -0,0 +1,153 @@ +function scene3_load() + backgroundwhite = 0 + staralpha = 1 + asteroids = {} + bullets = {} + asteroidtimer = 0 + rockets = {rocket:new()} + love.audio.play(bgmusic) + rockets[1].x = 50 + rockets[1].y = 70 + rockets[1].ground = false + rockets[1].inflight = true + + table.insert(asteroids, asteroid:new()) + + if #stars == 0 then + for i = 1, 10 do + table.insert(stars, star:new()) + end + end + + lastexplosion = {50, 40} + + pressedkeys = {} + starttimer = 0 + warningtimer = 0 +end + +function scene3_update(dt) + realasteroiddelay = math.max(0.05, 8/starttimer) + backgroundwhite = math.max(0, backgroundwhite - dt) + love.graphics.setBackgroundColor(math.random(127)*backgroundwhite, math.random(127)*backgroundwhite, math.random(127)*backgroundwhite) + + if starttimer < 35 then + asteroidtimer = asteroidtimer + dt + + while asteroidtimer > realasteroiddelay do + asteroidtimer = asteroidtimer - realasteroiddelay + table.insert(asteroids, asteroid:new()) + end + end + + for i, v in pairs(stars) do + v:update(dt) + end + + --ASTEROIDS + local delete = {} + + for i, v in pairs(asteroids) do + if v:update(dt) == true then + table.insert(delete, i) + end + end + + table.sort(delete, function(a,b) return a>b end) + + for i, v in pairs(delete) do + table.remove(asteroids, v) --remove + end + + --BULLETS + local delete = {} + + for i, v in pairs(bullets) do + if v:update(dt) == true then + table.insert(delete, i) + end + end + + table.sort(delete, function(a,b) return a>b end) + + for i, v in pairs(delete) do + table.remove(bullets, v) --remove + end + + + + --EXPLOSION + local delete = {} + + for i, v in pairs(explosions) do + if v:update(dt) == true then + table.insert(delete, i) + end + end + + table.sort(delete, function(a,b) return a>b end) + + for i, v in pairs(delete) do + table.remove(explosions, v) --remove + end + + rockets[1]:update(dt) + + if (starttimer > 38 and starttimer < 40) or warningtimer > 0.1 then + warningtimer = math.mod(warningtimer + dt*7, math.pi*2) + end + + if starttimer >= 40 and starttimer - dt < 40 then + rockets[1]:wheatleyattack() + end +end + +function scene3_draw() + local r, g, b = love.graphics.getColor() + love.graphics.setColor(math.random(255), math.random(255), math.random(255), 255*(1-scoreanim)) + for i = 1, backgroundstripes, 2 do + local alpha = math.rad((i/backgroundstripes + math.mod(sunrot/100, 1)) * 360) + local point1 = {lastexplosion[1]*scale+200*scale*math.cos(alpha), lastexplosion[2]*scale+200*scale*math.sin(alpha)} + + local alpha = math.rad(((i+1)/backgroundstripes + math.mod(sunrot/100, 1)) * 360) + local point2 = {lastexplosion[1]*scale+200*scale*math.cos(alpha), lastexplosion[2]*scale+200*scale*math.sin(alpha)} + + love.graphics.polygon("fill", lastexplosion[1]*scale, lastexplosion[2]*scale, point1[1], point1[2], point2[1], point2[2]) + end + love.graphics.setColor(r, g, b, 255) + + for i,v in pairs(stars) do + v:draw() + end + for i,v in pairs(asteroids) do + v:draw() + end + + rockets[1]:draw() + for i,v in pairs(bullets) do + v:draw() + end + for i, v in pairs(explosions) do + v:draw() + end + + if (starttimer > 38 and starttimer < 40) or warningtimer > 0.1 then + love.graphics.setColor(255, 0, 0, math.abs(math.sin(warningtimer))*255) + draw(warningimg, -3+math.random(5)-3, 20+math.random(5)-3) + end +end + +function scene3_keypressed(key) + if key ~= "left" and key ~= "up" and key ~= "right" and key ~= "down" then + table.insert(pressedkeys, key) + end +end + +function scene3_keyreleased(key) + for i = 1, #pressedkeys do + if pressedkeys[i] == key then + table.remove(pressedkeys, i) + break + end + end +end \ No newline at end of file diff --git a/scene4.lua b/scene4.lua new file mode 100644 index 0000000..7fd71e7 --- /dev/null +++ b/scene4.lua @@ -0,0 +1,174 @@ +function scene4_load() + backgroundwhite = 0 + staralpha = 1 + asteroids = {} + bullets = {} + love.audio.play(bgmusic) + + starttimer = 0 + alerttimer = 0 + flyingquad = 3 + + pspeedx = 0 + pspeedy = 0 + + playerx = nil + + flyanimationtimer = 0 +end + +function scene4_update(dt) + if secondtimer then + secondtimer = secondtimer + dt + end + for i, v in pairs(stars) do + v:update(dt) + end + + --EXPLOSION + local delete = {} + + for i, v in pairs(explosions) do + if v:update(dt) == true then + table.insert(delete, i) + end + end + + table.sort(delete, function(a,b) return a>b end) + + for i, v in pairs(delete) do + table.remove(explosions, v) --remove + end + + if rockets[1] then + rockets[1]:update(dt) + end + + if (starttimer > 0 and starttimer < 3) or alerttimer > 0.1 then + alerttimer = math.mod(alerttimer + dt*7, math.pi*2) + end + + if jumped then + if rockets[1] then + rockets[1].x = rockets[1].x - dt*3 + end + + if rockets[1] and secondtimer > 2 and secondtimer - dt <= 2 then + for i = 1, 20 do + if explosions then + table.insert(explosions, explosion:new(rockets[1].x-16+math.random(16)-8, rockets[1].y-20+math.random(16)-8)) + end + end + starmover = math.pi + rockets[1] = nil + end + + playerx = playerx + pspeedx*dt + playery = playery + pspeedy*dt + + if pspeedx > 0 then + pspeedx = pspeedx - dt*5 + end + + if playery >= 20 then + playery = 20 + pspeedy = 0 + end + + if playerx >= 50 then + pspeedx = 0 + playerx = 50 + end + + if secondtimer > 2 then + local i = math.max(0, (1-(secondtimer-2)/2)) + staralpha = math.max(0, (1-(secondtimer-2)/2))*i + love.graphics.setBackgroundColor(153*(1-i), 217*(1-i), 234*(1-i)) + + if shakeamount < 5 then + shakeamount = math.min(5, shakeamount+dt*3) + elseif shakeamount > 5 then + shakeamount = math.max(5, shakeamount-dt*3) + end + end + + if secondtimer > 4 then + changegamestate("scene5") + end + end + + if starttimer >= 4.3 and starttimer - dt < 4.3 then + playerx = rockets[1].x+4 + playery = rockets[1].y + end + + if jumped then + flyanimationtimer = flyanimationtimer + dt + while flyanimationtimer > 0.1 do + flyanimationtimer = flyanimationtimer - 0.1 + if flyingquad == 3 then + flyingquad = 4 + else + flyingquad = 3 + end + end + end +end + +function scene4_draw() + local r, g, b = love.graphics.getColor() + love.graphics.setColor(math.random(255), math.random(255), math.random(255), 255*(1-scoreanim)) + for i = 1, backgroundstripes, 2 do + local alpha = math.rad((i/backgroundstripes + math.mod(sunrot/100, 1)) * 360) + local point1 = {lastexplosion[1]*scale+200*scale*math.cos(alpha), lastexplosion[2]*scale+200*scale*math.sin(alpha)} + + local alpha = math.rad(((i+1)/backgroundstripes + math.mod(sunrot/100, 1)) * 360) + local point2 = {lastexplosion[1]*scale+200*scale*math.cos(alpha), lastexplosion[2]*scale+200*scale*math.sin(alpha)} + + love.graphics.polygon("fill", lastexplosion[1]*scale, lastexplosion[2]*scale, point1[1], point1[2], point2[1], point2[2]) + end + love.graphics.setColor(r, g, b, 255) + + for i,v in pairs(stars) do + v:draw() + end + + + if playerx then + local off = 0 + if rockets[1] then + off = rockets[1].startingoffset + end + love.graphics.drawq(playerimg, playerquad[flyingquad], (playerx+off)*scale, playery*scale, 0, scale, scale, 13, 6) + end + + if rockets[1] then + rockets[1]:draw() + end + for i, v in pairs(explosions) do + v:draw() + end + + if (starttimer > 0 and starttimer < 3) or alerttimer > 0.1 then + local i = math.abs(math.sin(alerttimer)) + love.graphics.setColor(255, 0, 0, i*100) + love.graphics.rectangle("fill", 0, 0, 100*scale, 80*scale) + love.graphics.setColor(255, 0, 0, i*255) + draw(alertimg, 50+math.random(5)-3, 40+math.random(5)-3, (math.random()*2-1)*0.1, i*0.5+0.6, i*0.5+0.6, 54, 15) + draw(randomshitimg, 50+math.random(20)-10, 40+math.random(20)-10, 0, 1, 1, 50, 42) + end + + if starttimer > 4 and not jumped then + love.graphics.setColor(255, 0, 0, math.random(255)) + properprint("jump!!", 0, 40, scale*3) + end +end + +function scene4_action() + if starttimer > 4.3 and not jumped then + jumped = true + secondtimer = 0 + pspeedx = 20 + pspeedy = 2 + end +end \ No newline at end of file diff --git a/scene5.lua b/scene5.lua new file mode 100644 index 0000000..404eb41 --- /dev/null +++ b/scene5.lua @@ -0,0 +1,229 @@ +function scene5_load() + love.graphics.setBackgroundColor(153, 217, 234) + love.audio.play(bgmusic) + + clouds2 = {} + for i = 1, 3 do + for y = 1, 8 do + table.insert(clouds2, cloud2:new(math.random()*140)) + end + end + + lastexplosion = {50, 40} + + starttimer = 0 + flyingquad = 3 + + playerx = 50 + playery = 20 + pspeedx = 0 + pspeedy = 0 + + birds = {} + splatters = {} + birdtimer = 0 + + flyanimationtimer = 0 + + shakeamount = 5 + awesometimer = 0 + + screenx = 0 + + landingtime = 2 + groundy = 90 + + landing = false +end + +function scene5_update(dt) + if starttimer < 20 then + birdtimer = birdtimer + dt + local birddelay = 0.5 + while birdtimer > birddelay do + birdtimer = birdtimer - birddelay + table.insert(birds, bird:new()) + end + end + + if starttimer >= 25 and starttimer - dt < 25 then + landing = true + timeleft = landingtime + landingx = math.random(60)+20 + end + + if starttimer >= 25.4 and starttimer - dt < 25.4 then + approach:play() + end + + if landing then + timeleft = timeleft - dt + if timeleft <= 0 then + timeleft = 0 + groundy = groundy - 400*dt + if groundy <= playery-10 then + changegamestate("scene6") + end + end + end + + for i,v in pairs(clouds2) do + v:update(dt) + end + + flyanimationtimer = flyanimationtimer + dt + while flyanimationtimer > 0.1 do + flyanimationtimer = flyanimationtimer - 0.1 + if flyingquad == 3 then + flyingquad = 4 + else + flyingquad = 3 + end + end + + if awesometimer > 0 then + awesometimer = awesometimer - dt + end + + if landing or starttimer < 24 then + playermovement2(dt) + else + if playerx > 50 then + playerx = playerx - 50*dt + elseif playerx < 50 then + playerx = playerx + 50*dt + end + + if playery > 40 then + playery = playery - 50*dt + elseif playery < 40 then + playery = playery + 50*dt + end + end + + + --BIRDS + local delete = {} + + for i, v in pairs(birds) do + if v:update(dt) == true then + table.insert(delete, i) + end + end + + table.sort(delete, function(a,b) return a>b end) + + for i, v in pairs(delete) do + table.remove(birds, v) --remove + end + + + --SPLATTERS + local delete = {} + + for i, v in pairs(splatters) do + if v:update(dt) == true then + table.insert(delete, i) + end + end + + table.sort(delete, function(a,b) return a>b end) + + for i, v in pairs(delete) do + table.remove(splatters, v) --remove + end + + for i, v in pairs(birds) do + if v:checkcol(playerx, playery) then + splat:stop() + splat:play() + pointsget(20) + table.insert(splatters, splatter:new(v.x, v.y)) + skycolor = getrainbowcolor(math.random(), 400) + love.graphics.setBackgroundColor(skycolor) + lastexplosion = {v.x, v.y} + end + end +end + +function playermovement2(dt) + if love.keyboard.isDown("left") then + playerx = math.max(0, playerx-dt*movement1speed) + elseif love.keyboard.isDown("right") then + playerx = math.min(100, playerx+dt*movement1speed) + end + + if not landing then + if love.keyboard.isDown("up") then + playery = math.max(0, playery-dt*movement1speed) + elseif love.keyboard.isDown("down") then + playery = math.min(80, playery+dt*movement1speed) + end + end +end + +function scene5_draw() + local r, g, b = love.graphics.getColor() + love.graphics.setColor(math.random(255), math.random(255), math.random(255), 100*math.min(1, (starttimer/2))) + for i = 1, backgroundstripes, 2 do + local pos = {playerx, playery} + local alpha = math.rad((i/backgroundstripes + math.mod(sunrot/100, 1)) * 360) + local point1 = {pos[1]*scale+200*scale*math.cos(alpha), pos[2]*scale+200*scale*math.sin(alpha)} + + local alpha = math.rad(((i+1)/backgroundstripes + math.mod(sunrot/100, 1)) * 360) + local point2 = {pos[1]*scale+200*scale*math.cos(alpha), pos[2]*scale+200*scale*math.sin(alpha)} + + love.graphics.polygon("fill", pos[1]*scale, pos[2]*scale, point1[1], point1[2], point2[1], point2[2]) + end + love.graphics.setColor(r, g, b, 255) + + for i,v in pairs(clouds2) do + v:draw() + end + for i,v in pairs(birds) do + v:draw() + end + for i,v in pairs(splatters) do + v:draw() + end + + if groundy < 90 then + draw(groundwinimg, -200+landingx+2, groundy) + end + + love.graphics.drawq(playerimg, playerquad[flyingquad], (playerx)*scale, playery*scale, 0, scale, scale, 13, 6) + + + if sunglasses then + draw(sunglassesimg, playerx+4, playery) + end + + if awesometimer > 0 then + draw(awesomeimg, (awesometimer*2-1)*100, 0) + love.graphics.setColor(0, 0, 0) + properprint("1000 points!", (awesometimer*2-1)*100+3, 73, scale) + love.graphics.setColor(255, 255, 255) + end + + if starttimer > 24 then + if math.mod(starttimer*5, 2) >= 1 then + love.graphics.setColor(255, 0, 0) + properprint("land in the target!", 0, 20, scale/1.5) + love.graphics.setColor(255, 255, 255) + end + end + + if landing then + draw(arrowimg, math.max(8, landingx-(timeleft/landingtime)*80), 67, 0, 1, 1, 8) + draw(arrowimg, math.min(91, landingx+(timeleft/landingtime)*80), 67, 0, -1, 1, 9) + end +end + +function scene5_action() + if not sunglasses then + sunglasses = true + awesometimer = 1 + pointsget(1000) + sunglassessound:play() + end +end \ No newline at end of file diff --git a/scene6.lua b/scene6.lua new file mode 100644 index 0000000..27f1766 --- /dev/null +++ b/scene6.lua @@ -0,0 +1,174 @@ +function scene6_load() + love.graphics.setBackgroundColor(153, 217, 234) + love.audio.stop(bgmusic) + + clouds2 = {} + clouds = {} + bushes = {} + bigexplosions = {} + + playerquad = 1 + + if sunglasses then + playerquad = 3 + end + + playeranimationtimer = 0 + starttimer = 0 + + birds = {} + splatters = {} + + shakeamount = 10 + + fade = 0 + + playerx = playerx or 50 + landingx = landingx or 50 + + landdiff = playerx-landingx + + scoremul = round((1-math.abs(landdiff)/80)^8*4, 1) + 1 + + stars = {} + + texts = {} + texts[1] = "your awesome score:" + texts[2] = points + texts[3] = "" + texts[4] = "radical landing mul:" + texts[5] = scoremul + texts[6] = "" + texts[7] = "cray total:" + texts[8] = math.ceil(points*scoremul) + + prevt = 0 + + to = 0 + totimes = {8.55, 8.8, 9.4, 9.5, 9.7, 11.0, 12.3, 12.9, 13.2} +end + +function scene6_update(dt) + playeranimationtimer = playeranimationtimer + dt + while playeranimationtimer > 0.1 do + playeranimationtimer = playeranimationtimer - 0.1 + playerquad = playerquad + 1 + if playerquad == 3 then + playerquad = 1 + elseif playerquad == 5 then + playerquad = 3 + end + end + + for i, v in pairs(bigexplosions) do + v:update(dt) + end + + if starttimer >= 0.7 and starttimer - dt < 0.7 then + bigexplosionsound:play() + end + + if starttimer < 0.2 then + + elseif starttimer < 0.5 then + fade = 1 + + if #explosions == 0 then + table.insert(bigexplosions, bigexplosion:new(-4, -30)) + table.insert(bigexplosions, bigexplosion:new(-40, -30)) + table.insert(bigexplosions, bigexplosion:new(36, -30)) + table.insert(bigexplosions, bigexplosion:new(-4, -50)) + end + elseif starttimer < 4 then + if fade > 0.5 then + fade = fade - dt/2 + end + else + if fade > 0 then + fade = fade - dt/2 + end + end + + + if starttimer > 8.3 and starttimer - dt < 8.3 then + credits:play() + end + + if shakeamount > 0 then + shakeamount = shakeamount - dt*3 + end + + for i = 1, 9 do + if starttimer > totimes[i] then + to = i + end + end + + if starttimer >= 15.7 and starttimer -dt < 15.7 then + staralpha = 1 + + stars = {} + love.graphics.setBackgroundColor(0, 0, 0) + for i = 1, 10 do + table.insert(stars, star:new()) + end + end + for i,v in pairs(stars) do + v:update(dt) + end +end + +function scene6_draw() + local r, g, b = love.graphics.getColor() + for i = 1, backgroundstripes, 1 do + if math.mod(i, 2) == 1 then + love.graphics.setColor(255, 255, 0, math.min(1, math.max(0, 1-(starttimer-7)/2))*255) + else + love.graphics.setColor(255, 0, 0, math.min(1, math.max(0, 1-(starttimer-7)/2))*255) + end + local pos = {31, 53} + local alpha = math.rad((i/backgroundstripes + math.mod(sunrot/100, 1)) * 360) + local point1 = {pos[1]*scale+200*scale*math.cos(alpha), pos[2]*scale+200*scale*math.sin(alpha)} + + local alpha = math.rad(((i+1)/backgroundstripes + math.mod(sunrot/100, 1)) * 360) + local point2 = {pos[1]*scale+200*scale*math.cos(alpha), pos[2]*scale+200*scale*math.sin(alpha)} + + love.graphics.polygon("fill", pos[1]*scale, pos[2]*scale, point1[1], point1[2], point2[1], point2[2]) + end + love.graphics.setColor(r, g, b, 255) + for i,v in pairs(stars) do + v:draw() + v:draw() + v:draw() + v:draw() + end + + love.graphics.translate(20*scale, 50*scale) + love.graphics.rotate(math.pi/7) + love.graphics.translate(-20*scale, -50*scale) + + for i, v in pairs(bigexplosions) do + v:draw() + end + + draw(groundwinimg, -168-landdiff, 56) + love.graphics.drawq(winplayerimg, winplayerquad[playerquad], 30*scale, 55*scale, 0, scale, scale, 5, 13) + + love.graphics.translate(20*scale, 50*scale) + love.graphics.rotate(-math.pi/7) + love.graphics.translate(-20*scale, -50*scale) + + for i = 1, math.min(9, to) do + local s = scale/2 + if i >= 8 then + s = s * 2 + love.graphics.setColor(getrainbowcolor(math.random())) + end + if i == 9 then + draw(titleimg, 65, 65, 0, 0.7, 0.7, 50, 14) + else + properprint(texts[i], 50-tostring(texts[i]):len()*s/2, 5*i, s) + end + love.graphics.setColor(255, 255, 255) + end +end \ No newline at end of file diff --git a/splatter.lua b/splatter.lua new file mode 100644 index 0000000..2c974dd --- /dev/null +++ b/splatter.lua @@ -0,0 +1,23 @@ +splatter = class:new() + +function splatter:init(x, y) + self.x = x + self.y = y + self.quad = 1 + self.quadtimer = 0 +end + +function splatter:update(dt) + self.quadtimer = self.quadtimer + dt*30 + if self.quadtimer > 1 then + self.quadtimer = self.quadtimer - 1 + self.quad = self.quad + 1 + if self.quad == 7 then + return true + end + end +end + +function splatter:draw() + love.graphics.drawq(splatterimg, splatterquad[self.quad], self.x*scale, self.y*scale, 0, scale/2, scale/2, 40, 40) +end \ No newline at end of file diff --git a/star.lua b/star.lua new file mode 100644 index 0000000..66e53fc --- /dev/null +++ b/star.lua @@ -0,0 +1,37 @@ +star = class:new() + +function star:init() + self.x = math.random(100) + self.y = math.random(80)-90 + self.speed = math.random(10)+1000 +end + +function star:update(dt) + if not starmover then + self.y = self.y + self.speed*dt + else + self.y = self.y + math.cos(starmover)*self.speed*dt + self.x = self.x + math.sin(starmover)*self.speed*dt + end + + if self.y > 110 or self.y < -10 or self.x > 110 or self.x < -10 then + self.speed = math.random(10)+1000 + self.x = math.random(100) + if self.y > 110 then + self.y = self.y-120 + elseif self.y < -10 then + self.y = self.y+120 + elseif self.x > 110 then + self.x = self.x-120 + else + self.x = self.x+120 + end + end +end + +function star:draw() + local r, g, b = love.graphics.getColor() + love.graphics.setColor(255, 255, 255, 255*staralpha) + draw(starimg, self.x, self.y, 0, 1, 1, 4.5) + love.graphics.setColor(r, g, b) +end \ No newline at end of file -- libgit2 0.21.2