Page 1 of 1
Junk code
Posted: Sun Jan 10, 2010 6:48 pm
by High Overlord
Ok, I started learning love and wrote a simple move the tank "game". It works great, but I have a feeling that there is a lot of junk code in it. Could someone point me out how to write this "a bit shorter"?
PS Move on cursor keys, and change colors on 1, 2, 3, 4, 5, 6.
PPS Quads are easier to handle than AnAL.
PPPS If you don't know to make sprites(eg. myself) download spritelib gpl:
http://www.flyingyogi.com/fun/spritelib.html
Re: Junk code
Posted: Sun Jan 10, 2010 7:01 pm
by Robin
You can lose the variable "color". You're using it in only one place: to set the variable "tank". It would also be a good idea to move all the color checking to a different function, because this calls for using love.keypressed():
Code: Select all
function love.keypressed(k)
if k == "1" then
tank = ye
-- etc.
end
end
Also, what's the point of a and f? They appear to be completely unused.
Good luck.

Re: Junk code
Posted: Sun Jan 10, 2010 7:02 pm
by bartbes
Well, first you can move the quad definition to load, and use quad:setViewport in love.update.
Second, I'd delete all the color changing from love.update and use this:
Code: Select all
function love.keypressed(key)
local color = tonumber(key)
if not color or color < 1 or color > 6 then
return
end
if color == 1 then
tank = ye
elseif color == 2 then
tank = gr
elseif color == 3 then
tank = bl
elseif color == 4 then
tank = ora
elseif color == 5 then
tank = pu
elseif color == 6 then
tank = re
end
end
Oh, and I'd start indenting, makes your code way easier to read.
Re: Junk code
Posted: Sun Jan 10, 2010 7:12 pm
by High Overlord
@bartbes I was indenting at first(remains from learning python, but love2d is more pythonic than pygame), but forgetingTHEN.
Now I am adding THEN, but forgeting to indent.
@Robin a & f are used for switching frames of animation.
PS Gonna rearrange sprites. I figured out now that the algorythm for quad is using most of space.

Thank you all.
Re: Junk code
Posted: Sun Jan 10, 2010 7:30 pm
by bartbes
Maybe AnAL isn't so bad after all?

Re: Junk code
Posted: Sun Jan 10, 2010 7:42 pm
by High Overlord
Tried it. Great work coding it, but quads provide more control. And the name is a bit... well... you know... Imagine that someone makes a website for his/ her name, and in the credits he/ she says: "Thanks bartbes for AnAL".
Re: Junk code
Posted: Sun Jan 10, 2010 7:45 pm
by bartbes
Yes, quads do provide more control, and about the name, you could just write "Animations And LÖVE" (yes, it's actually an acronym.)