Browse Source

Added effects

tags/6
Madiwka 3 years ago
parent
commit
4aeebcc41f
13 changed files with 147 additions and 24 deletions
  1. +1
    -4
      entities/planet/planet.lua
  2. +13
    -0
      entities/ship/ship.lua
  3. +12
    -3
      explosion.lua
  4. +10
    -0
      levels/level1.lua
  5. +9
    -0
      levels/level2.lua
  6. +8
    -0
      levels/level3.lua
  7. +8
    -0
      levels/level4.lua
  8. +9
    -1
      levels/level5.lua
  9. +4
    -0
      levels/levelgeneral.lua
  10. +28
    -3
      levels/practice.lua
  11. +3
    -0
      main.lua
  12. +26
    -7
      src/GUI.lua
  13. +16
    -6
      src/musicController.lua

+ 1
- 4
entities/planet/planet.lua View File

@@ -24,7 +24,7 @@ end
function planet:update(dt) function planet:update(dt)
if not reachedGoal then if not reachedGoal then
local distanceToShip = math.sqrt((firstShip.x - self.x)^2 + (firstShip.y - self.y)^2) local distanceToShip = math.sqrt((firstShip.x - self.x)^2 + (firstShip.y - self.y)^2)
--print("update")
local gravitationalAttraction = G*self.mass/(distanceToShip^2) local gravitationalAttraction = G*self.mass/(distanceToShip^2)
--print((firstShip.x - self.x) .. " " .. (firstShip.y - self.y)) --print((firstShip.x - self.x) .. " " .. (firstShip.y - self.y))
self.angle = math.atan( (firstShip.y - self.y)/ (firstShip.x - self.x)) self.angle = math.atan( (firstShip.y - self.y)/ (firstShip.x - self.x))
@@ -37,9 +37,6 @@ function planet:update(dt)
love.window.setTitle(self.attractionX) love.window.setTitle(self.attractionX)
firstShip.dx = firstShip.dx + self.attractionX firstShip.dx = firstShip.dx + self.attractionX
firstShip.dy = firstShip.dy + self.attractionY firstShip.dy = firstShip.dy + self.attractionY
if distanceToShip < 100 then
sounds["close"]:play()
end
if distanceToShip < self.w/4 then if distanceToShip < self.w/4 then
shipIsHit = true shipIsHit = true
sounds["close"]:stop() sounds["close"]:stop()


+ 13
- 0
entities/ship/ship.lua View File

@@ -18,6 +18,7 @@ self.color = {1,1,1,1}
self.path = {} self.path = {}
self.dottimer = 0.5 self.dottimer = 0.5
self.fuel = 0 self.fuel = 0
self.destX = x
end end
function ship:newPathDot(dotx, doty, color) function ship:newPathDot(dotx, doty, color)
return { return {
@@ -58,6 +59,17 @@ function ship:update(dt)
self.speed = self.speed + 0.05 self.speed = self.speed + 0.05


end end
local tag = false
for i in ipairs(planets) do
local distanceToShip = math.sqrt((firstShip.x - planets[i].x)^2 + (firstShip.y - planets[i].y)^2)
if distanceToShip < 200 and not shipIsHit and gameStatus == "play" then
sounds["close"]:play()
tag = true
end
end
if not tag or shipIsHit then
sounds["close"]:stop()
end
--[[ --[[
if love.keyboard.isDown('left') then if love.keyboard.isDown('left') then
self.dx = self.dx - 0.5 self.dx = self.dx - 0.5
@@ -121,6 +133,7 @@ function ship:reset()
self.canvas = love.graphics.newCanvas(WINDOW_WIDTH, WINDOW_HEIGHT) self.canvas = love.graphics.newCanvas(WINDOW_WIDTH, WINDOW_HEIGHT)
self.vector = 1.56 self.vector = 1.56
self.speed = 1 self.speed = 1
self.destX = self.x
self.path = {} self.path = {}
self.dottimer = 0.5 self.dottimer = 0.5
end end

+ 12
- 3
explosion.lua View File

@@ -2,6 +2,7 @@ explosion = Class{}


function explosion:init(x, y, v, color) function explosion:init(x, y, v, color)
self.color = color self.color = color
self.type = 0
self.x = x self.x = x
self.y = y self.y = y
self.v = v self.v = v
@@ -12,7 +13,11 @@ end


function explosion:update(dt) function explosion:update(dt)
self.range = self.range + dt * 24 self.range = self.range + dt * 24
if self.range * self.v > WINDOW_WIDTH * 2 then
local maxRange = WINDOW_WIDTH*2
if self.type == 1 then
maxRange = WINDOW_WIDTH*6
end
if self.range * self.v > maxRange then
--print("killing myself with range" .. self.range) --print("killing myself with range" .. self.range)
self.killed = true self.killed = true
end end
@@ -20,8 +25,12 @@ end






function explosion:render()
function explosion:render(toggle)
--print("rendering myself" .. self.x .. " " .. self.y .. " " .. self.range .. " " .. self.v) --print("rendering myself" .. self.x .. " " .. self.y .. " " .. self.range .. " " .. self.v)
love.graphics.setColor(unpack(self.color)) love.graphics.setColor(unpack(self.color))
love.graphics.circle("fill", self.x, self.y, self.range * self.v, 100)
if toggle == "special" then
love.graphics.setColor(1,1,1,0.7/(self.range/6))
print(self.range)
end
love.graphics.circle("fill", self.x, self.y, self.range * self.v, 100)
end end

+ 10
- 0
levels/level1.lua View File

@@ -36,12 +36,22 @@ end
function level1.hint() function level1.hint()
GUIDraw("left") GUIDraw("left")
love.graphics.setFont(tinyfont) love.graphics.setFont(tinyfont)
love.graphics.setColor(1,1,1,1)
if (VCAM.x > WINDOW_WIDTH/2) then if (VCAM.x > WINDOW_WIDTH/2) then
if love.keyboard.isDown('a') then
love.graphics.setColor(1,0,0,1)
end
love.graphics.print("←[A]",10,50) love.graphics.print("←[A]",10,50)
love.graphics.setColor(1,1,1,1)
end end
if (VCAM.x < WINDOW_WIDTH*2) then if (VCAM.x < WINDOW_WIDTH*2) then
if love.keyboard.isDown('d') then
love.graphics.setColor(1,0,0,1)
end
love.graphics.print("[D]→",100,50) love.graphics.print("[D]→",100,50)
love.graphics.setColor(1,1,1,1)
end end
love.graphics.setColor(1,1,1,1)
end end
function level1.reset() function level1.reset()
firstShip:reset() firstShip:reset()


+ 9
- 0
levels/level2.lua View File

@@ -48,11 +48,20 @@ end
function level2.hint() function level2.hint()
GUIDraw("left") GUIDraw("left")
love.graphics.setFont(tinyfont) love.graphics.setFont(tinyfont)
if (VCAM.x > WINDOW_WIDTH/2) then if (VCAM.x > WINDOW_WIDTH/2) then
if love.keyboard.isDown('a') then
love.graphics.setColor(1,0,0,1)
end
love.graphics.print("←[A]",10,50) love.graphics.print("←[A]",10,50)
love.graphics.setColor(1,1,1,1)
end end
if (VCAM.x < WINDOW_WIDTH*2) then if (VCAM.x < WINDOW_WIDTH*2) then
if love.keyboard.isDown('a') then
love.graphics.setColor(1,0,0,1)
end
love.graphics.print("[D]→",100,50) love.graphics.print("[D]→",100,50)
love.graphics.setColor(1,1,1,1)
end end
end end
function level2.GUIControl() function level2.GUIControl()


+ 8
- 0
levels/level3.lua View File

@@ -39,10 +39,18 @@ function level3.hint()
GUIDraw("left") GUIDraw("left")
love.graphics.setFont(tinyfont) love.graphics.setFont(tinyfont)
if (VCAM.x > WINDOW_WIDTH/2) then if (VCAM.x > WINDOW_WIDTH/2) then
if love.keyboard.isDown('a') then
love.graphics.setColor(1,0,0,1)
end
love.graphics.print("←[A]",10,50) love.graphics.print("←[A]",10,50)
love.graphics.setColor(1,1,1,1)
end end
if (VCAM.x < WINDOW_WIDTH*2) then if (VCAM.x < WINDOW_WIDTH*2) then
if love.keyboard.isDown('a') then
love.graphics.setColor(1,0,0,1)
end
love.graphics.print("[D]→",100,50) love.graphics.print("[D]→",100,50)
love.graphics.setColor(1,1,1,1)
end end
end end
function level3.reset() function level3.reset()


+ 8
- 0
levels/level4.lua View File

@@ -60,10 +60,18 @@ function level4.hint()
GUIDraw("left") GUIDraw("left")
love.graphics.setFont(tinyfont) love.graphics.setFont(tinyfont)
if (VCAM.x > -WINDOW_WIDTH/2) then if (VCAM.x > -WINDOW_WIDTH/2) then
if love.keyboard.isDown('a') then
love.graphics.setColor(1,0,0,1)
end
love.graphics.print("←[A]",10,50) love.graphics.print("←[A]",10,50)
love.graphics.setColor(1,1,1,1)
end end
if (VCAM.x < WINDOW_WIDTH) then if (VCAM.x < WINDOW_WIDTH) then
if love.keyboard.isDown('a') then
love.graphics.setColor(1,0,0,1)
end
love.graphics.print("[D]→",100,50) love.graphics.print("[D]→",100,50)
love.graphics.setColor(1,1,1,1)
end end
end end
function level4.goBack() function level4.goBack()


+ 9
- 1
levels/level5.lua View File

@@ -61,10 +61,18 @@ function level5.hint()
GUIDraw("up") GUIDraw("up")
love.graphics.setFont(tinyfont) love.graphics.setFont(tinyfont)
if (VCAM.y > -WINDOW_WIDTH) then if (VCAM.y > -WINDOW_WIDTH) then
if love.keyboard.isDown('w') then
love.graphics.setColor(1,0,0,1)
end
love.graphics.print("↑[W]",50,10) love.graphics.print("↑[W]",50,10)
love.graphics.setColor(1,1,1,1)
end end
if (VCAM.y < WINDOW_WIDTH*2) then if (VCAM.y < WINDOW_WIDTH*2) then
love.graphics.print("↓[D]",50,100)
if love.keyboard.isDown('s') then
love.graphics.setColor(1,0,0,1)
end
love.graphics.print("↓[S]",50,100)
love.graphics.setColor(1,1,1,1)
end end
end end
function level5.goBack() function level5.goBack()


+ 4
- 0
levels/levelgeneral.lua View File

@@ -22,6 +22,7 @@ function levelgeneral.update(dt)
end end
--print("saveData.levelsBeaten is " .. saveData.levelsBeaten) --print("saveData.levelsBeaten is " .. saveData.levelsBeaten)
if animationComplete then if animationComplete then
reachedGoal = false
love.filesystem.write("save", serialize(saveData)) love.filesystem.write("save", serialize(saveData))
levelgeneral.goBack() levelgeneral.goBack()
end end
@@ -35,8 +36,10 @@ function levelgeneral.update(dt)
explosion:update(dt) explosion:update(dt)
if explosion.killed then if explosion.killed then
table.remove(explosions, i) table.remove(explosions, i)
if shipIsHit then
gameStatus = "setup" gameStatus = "setup"
levelgeneral.reset() levelgeneral.reset()
end
end end
end end
if gameStatus == "play" then if gameStatus == "play" then
@@ -82,6 +85,7 @@ function levelgeneral.draw()
love.graphics.clear(0,0,0,1) love.graphics.clear(0,0,0,1)
love.graphics.setColor(30/255, 30/255, 30/255, 1) love.graphics.setColor(30/255, 30/255, 30/255, 1)
if frame < WINDOW_WIDTH then if frame < WINDOW_WIDTH then
stopMusic()
sounds["finish"]:play() sounds["finish"]:play()
love.graphics.circle("fill", firstShip.x, firstShip.y, WINDOW_WIDTH - frame) love.graphics.circle("fill", firstShip.x, firstShip.y, WINDOW_WIDTH - frame)
end end


+ 28
- 3
levels/practice.lua View File

@@ -40,8 +40,10 @@ function practice.update(dt)
explosion:update(dt) explosion:update(dt)
if explosion.killed then if explosion.killed then
table.remove(explosions, i) table.remove(explosions, i)
if shipIsHit then
gameStatus = "setup" gameStatus = "setup"
practice.reset() practice.reset()
end
end end
end end
if gameStatus == "play" then if gameStatus == "play" then
@@ -49,6 +51,7 @@ function practice.update(dt)
--print(camera.x .. firstShip.x) --print(camera.x .. firstShip.x)
if shipIsHit then if shipIsHit then
if #explosions == 0 then if #explosions == 0 then
table.insert(explosions, explosion(firstShip.x, firstShip.y, 100, {1,1,1,1})) table.insert(explosions, explosion(firstShip.x, firstShip.y, 100, {1,1,1,1}))
end end
@@ -85,9 +88,13 @@ function practice.draw()
if gameStatus == "setup" then if gameStatus == "setup" then
GUIDraw("anywhere") GUIDraw("anywhere")
love.graphics.setFont(tinyfont)
local textW = tinyfont:getWidth("Top score: " .. math.floor(saveData.score/100))
love.graphics.print("Top score: " .. math.floor(saveData.score/100), WINDOW_WIDTH/2-textW/2, 10)
practice.hint() practice.hint()
elseif gameStatus == "play" then elseif gameStatus == "play" then
local textW = tinyfont:getWidth("Score: " .. math.floor(currentScore/100)) local textW = tinyfont:getWidth("Score: " .. math.floor(currentScore/100))
love.graphics.setFont(tinyfont)
love.graphics.print("Score: " .. math.floor(currentScore/100), WINDOW_WIDTH/2-textW/2, 10) love.graphics.print("Score: " .. math.floor(currentScore/100), WINDOW_WIDTH/2-textW/2, 10)
guimenu:butt(playbutts, WINDOW_WIDTH, WINDOW_HEIGHT, 1100, WINDOW_HEIGHT-50, 40, WINDOW_WIDTH/3) guimenu:butt(playbutts, WINDOW_WIDTH, WINDOW_HEIGHT, 1100, WINDOW_HEIGHT-50, 40, WINDOW_WIDTH/3)
love.keyboard.mouseisReleased = false love.keyboard.mouseisReleased = false
@@ -110,7 +117,9 @@ function practice.reset()
end end
shipsleft = 1 shipsleft = 1
if currentScore > saveData.score then if currentScore > saveData.score then
saveData.score = currentScore saveData.score = currentScore
love.filesystem.write("save", serialize(saveData))
end end
currentScore = 0 currentScore = 0
shipIsHit = false shipIsHit = false
@@ -133,10 +142,26 @@ function practice.GUIControl()
end end
function practice.hint() function practice.hint()
love.graphics.setFont(tinyfont) love.graphics.setFont(tinyfont)
love.graphics.print("↑[W]",50,10)
love.graphics.print("↓[S]",50,100)
if love.keyboard.isDown('w') then
love.graphics.setColor(1,0,0,1)
end
love.graphics.print("↑[W]",80,10)
love.graphics.setColor(1,1,1,1)
if love.keyboard.isDown('s') then
love.graphics.setColor(1,0,0,1)
end
love.graphics.print("↓[S]",80,100)
love.graphics.setColor(1,1,1,1)
if love.keyboard.isDown('a') then
love.graphics.setColor(1,0,0,1)
end
love.graphics.print("←[A]",10,50) love.graphics.print("←[A]",10,50)
love.graphics.print("→[D]",100,50)
love.graphics.setColor(1,1,1,1)
if love.keyboard.isDown('d') then
love.graphics.setColor(1,0,0,1)
end
love.graphics.print("→[D]",150,50)
love.graphics.setColor(1,1,1,1)




+ 3
- 0
main.lua View File

@@ -31,6 +31,9 @@ function love.load()
else else
--print("No save file found!") --print("No save file found!")
end end
if saveData.score == nil then
saveData.score = 0
end
tick.framerate = 60 tick.framerate = 60
camera = Camera() camera = Camera()
BG = love.graphics.newImage("entities/background.jpg") BG = love.graphics.newImage("entities/background.jpg")


+ 26
- 7
src/GUI.lua View File

@@ -1,7 +1,5 @@
selectedItem = "none" selectedItem = "none"
local planetImage = love.graphics.newImage("entities/planet/planet" .. math.random(1, 18) .. ".png") local planetImage = love.graphics.newImage("entities/planet/planet" .. math.random(1, 18) .. ".png")


function GUIDraw(mode) function GUIDraw(mode)
--MAIN --MAIN
love.graphics.setColor(1,1,1,1) love.graphics.setColor(1,1,1,1)
@@ -23,10 +21,12 @@ function GUIDraw(mode)
--SHIP --SHIP
--PLANET --PLANET
GUIButton(planetsleft, planetImage, menuX + 60, menuY+WINDOW_HEIGHT*0.4, function() selectedItem = "planet" end, 0.5, 0.5, {1,1,1,1}, 1.57) GUIButton(planetsleft, planetImage, menuX + 60, menuY+WINDOW_HEIGHT*0.4, function() selectedItem = "planet" end, 0.5, 0.5, {1,1,1,1}, 1.57)
for i, explosion in ipairs(explosions) do
explosion:render("special")
--print("exploding")
end
--PLANET --PLANET



--PLACING --PLACING
local mx, my = love.mouse.getPosition() local mx, my = love.mouse.getPosition()
@@ -35,6 +35,8 @@ function GUIDraw(mode)
local mx = mx * DIFFERENCE_X local mx = mx * DIFFERENCE_X
local my = my * DIFFERENCE_Y local my = my * DIFFERENCE_Y
local vmx, vmy = camera:toWorldCoords(mx, my) local vmx, vmy = camera:toWorldCoords(mx, my)
firstShip.x = firstShip.x + (math.abs(firstShip.destX-firstShip.x)/5)
if mode == "anywhere" then if mode == "anywhere" then
love.graphics.setColor(1,1,1,0.5) love.graphics.setColor(1,1,1,0.5)
if selectedItem == "ship" and mx < menuX then if selectedItem == "ship" and mx < menuX then
@@ -43,8 +45,14 @@ function GUIDraw(mode)
love.graphics.draw(shipImage,mx,my, 1.5708, 1, 1, shipW/2, shipH/2) love.graphics.draw(shipImage,mx,my, 1.5708, 1, 1, shipW/2, shipH/2)
if love.keyboard.mouseisReleased then if love.keyboard.mouseisReleased then
love.keyboard.mouseisReleased = false love.keyboard.mouseisReleased = false
firstShip.x = vmx
if #explosions == 0 then
table.insert(explosions, explosion(0, my, 100, {1,1,1,1}))
explosions[1].type = 1
end

firstShip.destX = vmx
firstShip.y = vmy firstShip.y = vmy
sounds["appear"]:play() sounds["appear"]:play()
shipsleft = shipsleft - 1 shipsleft = shipsleft - 1
end end
@@ -67,7 +75,12 @@ function GUIDraw(mode)
end end
if love.keyboard.mouseisReleased then if love.keyboard.mouseisReleased then
love.keyboard.mouseisReleased = false love.keyboard.mouseisReleased = false
firstShip.x = 250
if #explosions == 0 then
table.insert(explosions, explosion(0, my, 100, {1,1,1,1}))
explosions[1].type = 1
end
sounds["appear"]:play()
firstShip.destX = 250
firstShip.y = vmy firstShip.y = vmy
shipsleft = shipsleft - 1 shipsleft = shipsleft - 1
end end
@@ -90,7 +103,12 @@ function GUIDraw(mode)
end end
if love.keyboard.mouseisReleased then if love.keyboard.mouseisReleased then
love.keyboard.mouseisReleased = false love.keyboard.mouseisReleased = false
firstShip.x = vmx
if #explosions == 0 then
table.insert(explosions, explosion(0, 100, 100, {1,1,1,1}))
explosions[1].type = 1
end
sounds["appear"]:play()
firstShip.destX = vmx
firstShip.y = 100 firstShip.y = 100
shipsleft = shipsleft - 1 shipsleft = shipsleft - 1
end end
@@ -187,6 +205,7 @@ function GUIDraw(mode)
if pressed and hot then if pressed and hot then
love.keyboard.mouseisReleased = false love.keyboard.mouseisReleased = false
firstShip.x = -9000 firstShip.x = -9000
firstShip.destX = -9000
shipsleft = shipsleft + 1 shipsleft = shipsleft + 1
end end




+ 16
- 6
src/musicController.lua View File

@@ -1,19 +1,25 @@
sounds = { sounds = {
["menu"] = love.audio.newSource("entities/music/menu.ogg", "static"),
["boom"] = love.audio.newSource("entities/planet/boom.wav", "static"), ["boom"] = love.audio.newSource("entities/planet/boom.wav", "static"),
["close"] = love.audio.newSource("entities/planet/close.wav", "static"), ["close"] = love.audio.newSource("entities/planet/close.wav", "static"),
["play"] = love.audio.newSource("entities/music/play.wav", "static"),
["appear"] = love.audio.newSource("entities/ship/Appear.wav", "static"), ["appear"] = love.audio.newSource("entities/ship/Appear.wav", "static"),
["finish"] = love.audio.newSource("entities/ship/Finish.wav", "static") ["finish"] = love.audio.newSource("entities/ship/Finish.wav", "static")
} }
music = {
["menu"] = love.audio.newSource("entities/music/menu.ogg", "static"),
["play"] = love.audio.newSource("entities/music/play.wav", "static")
}
mute = false mute = false
function musicController(orders, toggling) function musicController(orders, toggling)
if (orders == 'norm' and not mute) then
if (orders == 'norm' and not mute and not reachedGoal) then
if (gameState == 'menu' or gameState == "selectlv") then if (gameState == 'menu' or gameState == "selectlv") then
sounds['menu']:play()
music['menu']:play()
music["play"]:play()
music["play"]:setVolume(0)
music["menu"]:setVolume(1)
elseif gameStatus == 'play' then elseif gameStatus == 'play' then
stopSounds()
sounds["play"]:play()
music["play"]:play()
music["play"]:setVolume(0.4)
music["menu"]:setVolume(1)
end end
elseif orders == "mute" then elseif orders == "mute" then
if toggling == 1 then if toggling == 1 then
@@ -32,4 +38,8 @@ function stopSounds()
sound[i]:stop() sound[i]:stop()
print("stopping sounds") print("stopping sounds")
end end
end
function stopMusic()
music["play"]:setVolume(0)
music["menu"]:setVolume(0)
end end

Loading…
Cancel
Save