Code: Select all
--Zombeh Properties!:D
zombie = {}
zombie.x = 300
zombie.y = 500
zombie.speed = 100
zombie.health = 10
zombie.pic = love.graphics.newImage("pics/zombie.png")
zombie.reach = 55
zombie.damage = 2
Thanks in advanced:D
Code: Select all
--Zombeh Properties!:D
zombie = {}
zombie.x = 300
zombie.y = 500
zombie.speed = 100
zombie.health = 10
zombie.pic = love.graphics.newImage("pics/zombie.png")
zombie.reach = 55
zombie.damage = 2
Code: Select all
zombies = {}
zombie = {
x = 300,
y = 500,
speed = 100,
color = "255, 255, 255",
health = 10,
pic = love.graphics.newImage("pics/zombie.png"),
reach = 55,
damage = 2}
--now add the zombie
table.insert(zombies, zombie)
--now do what you need to
for i,v in ipairs(zombies) do
--put stuff in here to modify them like
if v.health < 0 then
table.remove(zombies, i)
end
Code: Select all
zombieType = {}
function zombieType:create(v)
local instance = {}
setmetatable(instance, {__index = self})
instance:reset(v)
return instance
end
function zombieType:reset(v)
v = v or {}
self.x = v.x or 300
self.y = v.y or 500
self.speed = v.speed or 100
self.color = v.color or { 255, 255, 255 }
self.health = v.health or 10
self.pic = v.img or zombImg
self.reach = v.reach or 55
self.damage = v.damage or 2
end
function zombieType:update(dt)
--ANY UPDATING LIKE MOVEMENT AND ATTACKING AND ANIMATION GOES HERE
end
function zombieType:draw()
--DRAWING CODE GOES HERE
end
Code: Select all
zombie[id] = zombieType:create({ x = ??, y = ??, etc... })
Code: Select all
for i, z in pairs(zombie) do
z:update(dt)
end
for i, z in pairs(zombie) do
z:draw()
end
Code: Select all
for i, z in pairs(zombie) do
z:update(dt)
end
So could I still draw more then one zombie though?SPlice wrote:try adding them to a table and use ipairs like soCode: Select all
zombies = {} zombie = { x = 300, y = 500, speed = 100, color = "255, 255, 255", health = 10, pic = love.graphics.newImage("pics/zombie.png"), reach = 55, damage = 2} --now add the zombie table.insert(zombies, zombie) --now do what you need to for i,v in ipairs(zombies) do --put stuff in here to modify them like if v.health < 0 then table.remove(zombies, i) end
Code: Select all
function draw_zombies()
for i,v in ipairs(zombies)
love.graphics.draw(v.image, v.x, v.y)
end
end
Code: Select all
player = { life = 100, x = 0, y = 0}
for i,v in ipairs(zombies) do
if v.x < player.x + 10 and v.x > player.x - 10 and v.y < player.y + 10 and v.y > player.y - 10 then
player.life = player.life -10
end
end
Like SPlice said you could deal with "steve"(your player) as multiple entities like your "zombehs" but problably is not needed. Depends of what what kind of your game is and the features of it. However if you pretend and want in the future have sidequest-companions, friendly summons, another second or more players perhaps you should consider right way use multiples "stevies" and use player[1] as default player in "solo" and when needed the engine is already prepare to deal with a player[2] and so on...baconhawka7x wrote:So Should I do the same with steve?(My Player?)
Users browsing this forum: Bing [Bot] and 135 guests