Press G while walking left or right (with the arrow keys or WASD) to attack, after selecting the available characters.
Feedback would be greatly appreciated!

Code: Select all
function Enemy:checkRemove()
for i, instance in ipairs(ActiveEnemys) do
if instance.health <= 0 then
instance.toBeRemoved = true
end
if instance.toBeRemoved == true then
instance:remove()
end
end
end
function Enemy:remove()
for i, instance in ipairs(ActiveEnemys) do
if instance.health <= 0 then
instance.toSpawnNew = true
instance.physics.body:destroy()
table.remove(ActiveEnemys,i)
return true
else
return false
end
end
end
Code: Select all
function Hitbox.beginContact_PlayerToEnemy(a,b,collision)
for i,instance in ipairs(ActiveHitboxes) do
if a == instance.physics.fixture or b == instance.physics.fixture then
for v = 1, #ActiveEnemys do
if a == ActiveEnemys[v].physics.fixture or b == ActiveEnemys[v].physics.fixture then
return ActiveEnemys[v], true
end
end
end
end
end
function beginContact(a, b, collision)
if Enemy.beginContact(a,b,collision) then Enemy:getIntent() return end
if Hitbox.beginContact_PlayerToEnemy(a,b,collision) then --if player's hitbox contacts with enemy returns true then,
Enemy:takeDamage(Hitbox.beginContact_PlayerToEnemy(a,b,collision)) return end --Enemy takes damage
Player:beginContact(a, b, collision)
end
function Enemy:takeDamage()
for i,instance in ipairs(ActiveEnemys) do
instance.health = instance.health - Player.damageOutput
instance:checkRemove()
end
end
Code: Select all
function Enemy:takeDamage()
for i,instance in ipairs(ActiveEnemys) do
if instance == self then -- never passes this check
self.health = self.health - Player.damage --"a nil value?"
instance:checkRemove()
hoverSFX:play()
end
end
end
Code: Select all
local myTable = { x = 0 }
function myTable:myFunction ( )
-- just increment table's x value
self.x = self.x + 1 -- self is inferred from the colon syntax
end
myTable:myFunction ( )
-- is functionally equivalent to
local myTable = { x = 0 }
function myTable.myFunction ( tab ) -- "tab" could be named "self" or whatever you want
tab.x = tab.x + 1
end
myTable.myFunction ( myTable )
myTable:myFunction () -- can mix and match too, just need to be careful!
Code: Select all
Enemy:takeDamage(...)
Code: Select all
-- instead of this...
Enemy:takeDamage ( param1, param2, ... )
-- do this
Enemy.takeDamage (instanceOfEnemy, param1, param2, ... )
-- or this, assuming instances of your enemy class contain the takeDamage function
instanceOfEnemy:takeDamage ( param1, param2, ... )
Code: Select all
local function enemyCheckRemove(enemy)
if enemy.health <= 0 then
(...)
end
end
Users browsing this forum: No registered users and 4 guests