Stuck on a couple of thing
Posted: Mon Dec 09, 2013 3:23 am
Hey I stuck on a couple of things in my project.
first thing enemy spawning I was looking at this post viewtopic.php?f=4&t=11701 and tried to use
and
Then I create a function to generate a new enemy. This create a table into the self.table( self = enemy / the name of the global table ) for the enemy.
Now you have to update the spawn and the enemy itself( here is just the spawner ).
yeah, and now there is only one thing left to do. Draw all enemys.
the ipairs goes through the full self.table ( enemy.table = stores the single enemys ). v is the value of a single enemy, i is the index ( the position of the enemy in the self.table )
But I don't know if I'm doing it wrong or the code is out dated
then I'm having issues getting bullets to work and I have looked at http://www.youtube.com/watch?v=S2oO2wbsXQs, https://love2d.org/wiki/Tutorial:Fire_Toward_Mouse , http://love2d.org/forums/viewtopic.php?f=3&t=41104 , viewtopic.php?f=4&t=45989 and http://www.headchant.com/2010/12/31/lov ... 2-pew-pew/
but for some reason I can't get it to work ??
and then for reason I can't get my audio to work out the way I want it to I have one audio file for the menu and other for in game which i set up as
Link to download the file
https://www.dropbox.com/s/9jt6t69hecr7q ... tzzzz.love
first thing enemy spawning I was looking at this post viewtopic.php?f=4&t=11701 and tried to use
Code: Select all
zombie = {}
function spawnZombies()
for i=1,10 do --Replace 10 with number of enemies you want
zombies[#zombies+1]={
x = math.random(0,728),
y = math.random(0,428),
}
end
end
function zombie:init()
self.timer = 0
self.spawnTime = 3
end
function zombie:update( dt )
self.timer = self.timer + dt
if self.timer > self.spawnTime then
spawnZombies() -- his code
self.timer = 0
end
-- update anything else enemy related here
end
Code: Select all
enemy = {}
function enemy:init()
self.table = {} -- stores the single enemys later
self.timer = 0 -- use with spawntimer
self.spawnTime = 3 -- time when the next enemy should spawn
end
Code: Select all
function enemy:new( x, y, xvel ) -- to use self you have to type a " : " to say that you want to use the self.
local temp = {
x = x,
y = y,
w = 32,
h = 64,
xvel = xvel,
}
table.insert( self.table, temp )
end
Code: Select all
function enemy:update( dt )
self.timer = self.timer + dt
if self.timer > self.spawnTime then
enemy:new( math.random( -200, width + 200 ) , height - 64 , 150 ) -- math.random for a different position everytime you spawn an enemy
self.timer = 0
end
-- update anything else enemy related here
end
the ipairs goes through the full self.table ( enemy.table = stores the single enemys ). v is the value of a single enemy, i is the index ( the position of the enemy in the self.table )
Code: Select all
function enemy:draw()
for i, v in ipairs( self.table ) do
lg.setColor( 0, 0, 255 )
lg.rectangle( "line", v.x, v.y, v.w, v.h )
end
end
then I'm having issues getting bullets to work and I have looked at http://www.youtube.com/watch?v=S2oO2wbsXQs, https://love2d.org/wiki/Tutorial:Fire_Toward_Mouse , http://love2d.org/forums/viewtopic.php?f=3&t=41104 , viewtopic.php?f=4&t=45989 and http://www.headchant.com/2010/12/31/lov ... 2-pew-pew/
but for some reason I can't get it to work ??
and then for reason I can't get my audio to work out the way I want it to I have one audio file for the menu and other for in game which i set up as
Code: Select all
function audioLoad()
if gameState == "menu" then
music = love.audio.newSource("sounds/menuMusic.mp3", "stream")
love.audio.setVolume(4.0)
love.audio.play(music)
end
if gameState == "playing" then
musicInGame = love.audio.newSource("sounds/inGameMusic.mp3", "stream")
love.audio.setVolume(4.0)
love.audio.play(musicInGame)
love.audio.stop(music)
end
end
Link to download the file
https://www.dropbox.com/s/9jt6t69hecr7q ... tzzzz.love