Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: LOVE-Party/LD24_Jam
base: 64f17cc06e
...
head fork: LOVE-Party/LD24_Jam
compare: e11d0a0097
  • 3 commits
  • 3 files changed
  • 0 commit comments
  • 1 contributor
Showing with 47 additions and 36 deletions.
  1. +28 −1 entity.lua
  2. +11 −28 ship.lua
  3. +8 −7 space.lua
View
29 entity.lua
@@ -5,9 +5,10 @@
local _M = {_NAME = "entity", _TYPE = 'module'}
local _MT = {__index = _M}
-------------------------------------------------------------------------
-
local count = 0
+local SFX_Explosion = love.audio.newSource("sfx/Explosion.wav", "static")
+-------------------------------------------------------------------------
-- Handles some texture properties
local function set_texture(self, texture)
@@ -78,6 +79,32 @@ function _M:draw()
love.graphics.draw(self.texture, self.pos_x, self.pos_y)
end
+-- damages the entity according to the given number,
+-- and tests / triggers death if appropriate
+function _M:dohit(n)
+ n = n or 1
+
+ local shield = self.shield - n
+ shield = shield >= 0 and shield or 0
+ shield = shield <= self.shieldmax and shield or self.shieldmax
+ self.shield = shield
+ love.audio.play(SFX_Explosion) -- shouldn't this be using the soundmanager?
+
+ if shield == 0 and self.state ~= 'dead'then
+ self:die()
+ end
+
+ return shield
+end
+
+-- handles the death of the entity.
+function _M:die()
+ self.state = 'dead'
+ self.shooting = false
+ self.dir_x = 0
+ self.dir_y = 0
+end
+
-------------------------------------------------------------------------
if _VERSION == "Lua 5.1" then _G[_M._NAME] = _M end
View
39 ship.lua
@@ -46,12 +46,7 @@ function ship:draw()
entity.draw(self)
end
--- updates the entity according the to time passed (in seconds)
-function ship:update(dt, level)
- local dv = self.speed * dt
- self.pos_x = self.pos_x + (self.dir_x * dv)
- self.pos_y = self.pos_y + (self.dir_y * dv)
-
+function ship:think(dt)
if self.npc then
self.dir_timer = self.dir_timer + dt
-- turn change directions
@@ -61,9 +56,18 @@ function ship:update(dt, level)
self.dir_y = math.random(-1, 1)
end
end
+end
+
+-- updates the entity according the to time passed (in seconds)
+function ship:update(dt, level)
+ local dv = self.speed * dt
+ self.pos_x = self.pos_x + (self.dir_x * dv)
+ self.pos_y = self.pos_y + (self.dir_y * dv)
self:docollision(level, dt)
+ self:think(dt)
+
-- Shoot lazers
self.shot_timer = self.shot_timer + dt
if self.shooting and self.shot_timer >= self.shot_rate then
@@ -147,30 +151,9 @@ function ship:docollision(level, dt) -- this is new
end
end
--- damages the entity according to the given number,
--- and tests / triggers death if appropriate
-function ship:dohit(n)
- n = n or 1
-
- local shield = self.shield - n
- shield = shield >= 0 and shield or 0
- shield = shield <= self.shieldmax and shield or self.shieldmax
- self.shield = shield
- love.audio.play(SFX_Explosion) -- shouldn't this be using the soundmanager?
-
- if shield == 0 and self.state ~= 'dead'then
- self:die()
- end
-
- return shield
-end
-
-- handles the death of the entity.
function ship:die()
- self.state = 'dead'
- self.shooting = false
- self.dir_x = 0
- self.dir_y = 0
+ entity.die(self)
if not self.npc then
Gamestate.space.level.scrolling = false
View
15 space.lua
@@ -24,7 +24,7 @@ local GUI_BarBack = love.graphics.newImage("gfx/GUI_EmbossedBar.png")
local GUI_GradientBar = love.graphics.newImage("gfx/GUI_GradientBar.png")
-- SFX
-state.music = love.audio.newSource("sfx/BGM.ogg", 'stream')
+state.music = love.audio.newSource("sfx/BGM.ogg", 'stream') -- long audio files should be streamed
state.music:setLooping(true)
state.player = Ship.new {name = 'player';
@@ -49,7 +49,13 @@ state.level = {name='default'; height = 15; scroll_speed = 50; scrolling = true;
1,1,1,1,1,1,1,1,1,5,6,5,6,5,6,5,6,5,1,1,1,1,1,1,1,1,2,3,4,3,2,3,2,3,4,
5,5,5,5,5,4,3,2,1,0};
x = -640;
+ entities = {};
}
+-- allows easy addition of entities to a level
+state.level.addentity = function(self, ent)
+ assert(ent and ent._TYPE == 'entity', "Can only add entities")
+ self.entities[#self.entities+1] = ent
+end
state.level.width = #state.level.data;
@@ -84,11 +90,6 @@ function state:enter()
-- bind enemies/entities to level
-- (a preliminary to reorganising to have a separate level class)
self.level.entities = self.enemies
- -- allows easy addition of entities to a level
- self.level.addentity = function(self, ent)
- assert(ent and ent._TYPE == 'entity', "Can only add entities")
- self.entities[#self.entities+1] = ent
- end
-- Populate the world with a few random enemies, for testing.
local enemies = self.enemies
@@ -101,7 +102,7 @@ function state:enter()
end
for x = 1, #self.level.data do
- self.level.data[x] = math.random(6)
+ self.level.data[x] = math.random(6)
end
-- Audio

No commit comments for this range

Something went wrong with that request. Please try again.