Skip to content

Commit

Permalink
added screen shake and shockwave to boss
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonLarsen committed Feb 27, 2013
1 parent 3392e00 commit bfb1bc4
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 6 deletions.
35 changes: 34 additions & 1 deletion boss.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ function Boss.create(x,y)
self.dir = 1
self.health = self.MAX_HEALTH
self.addedFire = false
self.shockwaveActive = false
self.shockwaveFrame = 0
self.shockwaveX = 0

self.anims = {}
self.anims[BS_JUMP] = newAnimation(img.boss_jump, 58, 64, 0.14, 5,
Expand Down Expand Up @@ -62,10 +65,16 @@ function Boss:update(dt)
self.y = MAPH-16
self.yspeed = 0
if self.addedFire == false then
-- Add fire
map:addFire(math.floor((self.x-8)/16), math.floor((self.y-5)/16))
map:addFire(math.floor((self.x+8)/16), math.floor((self.y-5)/16))
ingame.shake = 0.4
self.addedFire = true
-- Set shake
ingame.shake = 0.4
-- Add shockwave
self.shockwaveX = math.floor(self.x)
self.shockwaveFrame = 0
self.shockwaveActive = true
end
else
self.x = self.x + self.xspeed*dt
Expand All @@ -74,15 +83,34 @@ function Boss:update(dt)

self.x = cap(self.x, 194, 464)

-- Update shockwave if active
if self.shockwaveActive == true then
self.shockwaveFrame = self.shockwaveFrame + dt*24
if self.shockwaveFrame >= 10 then
self.shockwaveFrame = 0
self.shockwaveActive = false
end
end

-- Check if out of health
if self.health <= 0 then
self.alive = false
self.y = 1000
end
end

function Boss:draw()
self.flx = math.floor(self.x)
self.fly = math.floor(self.y)

-- Draw shockwave
if self.shockwaveActive == true then
local frame = math.floor(self.shockwaveFrame)
lg.drawq(img.shockwave, quad.shockwave[frame], self.shockwaveX, 240, 0, 1,1, 82, 32)
lg.drawq(img.shockwave, quad.shockwave[frame], self.shockwaveX, 240, 0,-1,1, 82, 32)
end

-- Draw boss
if self.hit == false then
if self.state == BS_IDLE then
self.anims[BS_JUMP]:draw(self.flx, self.fly, 0, self.dir, 1, 27, 64, 1)
Expand Down Expand Up @@ -118,6 +146,11 @@ function Boss:getBBox()
return {x = self.x-11, y = self.y-33, w = 22, h = 26}
end

function Boss:getShockwaveBBox()
local swwidth = self.shockwaveFrame*6.08
return {x = self.x-swwidth, y = 235, w = 2*swwidth, h = 5}
end

function Boss:setState(state)
self.state = state
self.anim = self.anims[state]
Expand Down
Binary file added data/shockwave.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion ingame.lua
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function ingame.nextLevel()
end

function ingame.update(dt)
if love.keyboard.isDown("l") then
if love.keyboard.isDown("e") then
dt = dt/4
end

Expand Down
7 changes: 4 additions & 3 deletions map.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ function Map.create(section, level)

-- Load base file
local file
if (level == 1 and section == 8) or
(level == 2 and section == 14) or
(level == 3 and section == 20) then
if (level == 1 and section == 8)
or (level == 2 and section == 14)
or (level == 3 and section == 20) then
self.type = MT_BOSS
else
self.type = MT_NORMAL
end
self.type = MT_BOSS

if self.type == MT_NORMAL then
file = love.filesystem.load("maps/base.lua")()
Expand Down
11 changes: 11 additions & 0 deletions player.lua
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,17 @@ function Player:collideFire(dt)
end
end

-- Check collision with boss
if map.type == MT_BOSS then
if self:collideBox(map.boss:getBBox()) == true then
self.heat = 1
elseif map.boss.shockwaveActive == true then
if self:collideBox(map.boss:getShockwaveBBox()) == true then
self.heat = 1.0
end
end
end

local cx = math.floor(self.x/16)
local cy = math.floor((self.y-11)/16)

Expand Down
7 changes: 6 additions & 1 deletion resources.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ local IMAGE_FILES = {
"enemy_angryjumper_hit", "enemy_angryjumper_jump",
"enemy_volcano_run", "enemy_volcano_shoot", "enemy_volcano_hit",
"enemy_angryvolcano_run", "enemy_angryvolcano_shoot", "enemy_angryvolcano_hit", "enemy_fireball",
"boss_jump", "boss_land", "boss_jump_hit", "boss_land_hit",
"boss_jump", "boss_land", "boss_jump_hit", "boss_land_hit", "shockwave",

"human_1_run", "human_2_run", "human_3_run", "human_4_run",
"human_1_carry_left", "human_2_carry_left", "human_3_carry_left", "human_4_carry_left",
Expand Down Expand Up @@ -212,6 +212,11 @@ function loadResources()
quad.boss_bar = lg.newQuad(0,48, 1,5, getSize(img.boss_health))
quad.boss_bar_end = lg.newQuad(1,48, 1,5, getSize(img.boss_health))

quad.shockwave = {}
for i=0,9 do
quad.shockwave[i] = lg.newQuad(0, i*32, 73, 32, getSize(img.shockwave))
end

-- Set audio tag volumes
love.audio.tags.sfx.setVolume(config.sfx_volume)
end
Expand Down

0 comments on commit bfb1bc4

Please sign in to comment.