Hi there!
(Sorry for my English. It's not my native language.)
I'm new to programing and love2d in particular) So this is my first attempt)
I want to get some advises and tips about coding and optimization. I will appreciate any help)
I had one problem. After collecting all 25 blocks twice, I was in the middle of the third time and it suddenly returned me to the menu. Is that supposed to happen?
You asked about improving performance, and I got one thing.
SpriteBatches, I would use them in any fast paced game ( or anything that is just not a proof of concept really ) that uses a for loop to draw things.
with this few things being drawn every frame its no big deal, but if you would have to draw... say 60000 tiles every frame ( If you could fit that many on the screen ) it would really help with a SpriteBatch.
Other than that it was fun playing, and the mechanics worked as they should.
If you can't fix it, Kill it with fire. ( Preferably before it lays eggs. )
I looked at your code really quickly, two things that come to mind :
. you use different images for the right and left facing marine... Maybe use scale (as in 1 and -1) for that.
. That Object Oriented approach of yours seems a bit off, if that is what you where going for anyway. If not, then just ignore the next part... When making more complicated objects, i think your way of doing the update and draw code of multiple objects will hinder you later on. Instead, it can (probably) be easier to go for a more "correct" OOP way: something like
function Enemy.Load()
local e = {}
setmetatable(e, {__index = Enemy}) -- now the table "e" becomes an Enemy
--your enemy load stuff here
e.doAFlip = true
...
return e
end
function Enemy:Update(dt)
self.x = self.x + self.vx * dt
-- etc.
end
-- and the same for Draw()
function love.load()
enemies = {}
for i=1,25 do
enemy = Enemy.Load()
table.insert(enemies, enemy)
end
end
function love.update(dt)
for k,e in pairs(enemies) do
e:Update(dt)
end
end
This way you can easily make other enemies that inherit basic functionality from enemy (basic OOP right?) . For example:
SuperEnemy = {}
function SuperEnemy.Load()
setmetatable(SuperEnemy,{__index = Enemy})
-- this is how SuperEnemy knows he/she has to look up functions/variables in Enemy when he can't find them here
local superenemy = Enemy.Load()
setmetatable(superenemy,{__index = SuperEnemy})
-- and finally linking the instance of enemy we just made with superenemy, giving him extra power or something
-- new superenemy stuff here
return superenemy
end
function SuperEnemy:Update(dt)
--extra superenemy stuff here
Enemy.Update(self,dt)
end
Etc... This is a lua way of making basic OOP.
Of course, if you don't know what I'm talking about, give a shout
Well, another way of doing this is using a library that does all this for you... Though I have not yet used one myself.
This is what I do anyway...
Please correct me if i'm wrong in any way, I am just a layman too
PS: First post... I need an obey avatar now right?