Junk code

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
High Overlord
Prole
Posts: 6
Joined: Sat Dec 12, 2009 1:48 pm
Location: Uzice, Serbia

Junk code

Post 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
Attachments
Tanks.love
Rainbow tank
(114.61 KiB) Downloaded 243 times
My software never has bugs. It just develops random features.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Junk code

Post 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. :)
Help us help you: attach a .love.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Junk code

Post 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.
User avatar
High Overlord
Prole
Posts: 6
Joined: Sat Dec 12, 2009 1:48 pm
Location: Uzice, Serbia

Re: Junk code

Post 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.
My software never has bugs. It just develops random features.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Junk code

Post by bartbes »

Maybe AnAL isn't so bad after all? :P
User avatar
High Overlord
Prole
Posts: 6
Joined: Sat Dec 12, 2009 1:48 pm
Location: Uzice, Serbia

Re: Junk code

Post 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".
My software never has bugs. It just develops random features.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Junk code

Post 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.)
Post Reply

Who is online

Users browsing this forum: No registered users and 11 guests