Page 1 of 1

Need help with a table/entity bullet problem.

Posted: Fri Jan 25, 2013 1:41 pm
by KenJammin
Okay so i'm new to both love and programming with lua so i'm having some difficulty getting started.
The basic game i'm working with now is a top down shooter. I'm trying to code everything on my own but i'm having a problem with the bullets all sharing trajectories. If i shoot 1 bullet its no problem but when there are more then 1 bullets fired from 2 different positions their trajectories are shared and i don't know how to make it so they're individually stored.
Anyway,
Left click shoots, mouse aims, and arrow keys move(plan to switch that to wasd at some point).

Thanks for any help, also i respect other solutions to the problem but i mostly want to solve it while gaining an understanding of table/entity dynamics.

Thanks for any help.

Re: Need help with a table/entity bullet problem.

Posted: Fri Jan 25, 2013 3:23 pm
by Pash
I can't open your love file at work. But a pointer:-

https://love2d.org/wiki/Tutorial:Fire_Toward_Mouse

You can modify the above code if you wanted to fire in directions or towards the mouse cursor. I use similar code in this example for the bullets and ducks that spawn:-

https://vimeo.com/57578774

Let us know if you need further assistance.

Re: Need help with a table/entity bullet problem.

Posted: Fri Jan 25, 2013 4:48 pm
by veethree
I was actually working on something similar a few days ago, After a rather brief glance at your code, It would appear that I've chosen a slightly different method.

Here's what i'm dealing with:

Updating:

Code: Select all

elseif self.class == "bullet" then
		self.x = self.x + math.cos(self.a) * self.s * dt
		self.y = self.y + math.sin(self.a) * self.s * dt
	end
"self" represents basically what v2 does in your love.update. I'd say this is the most important part of the code, But i'll attach my .love below so you can have a look at how i handled things and see the code in context. That snippet is inside mob.lua.

Keep in mind that the code is really dirty and might be hard to understand as this game is in very early development., If you have any questions regarding it, Just ask and I'll do my best to clarify.

Re: Need help with a table/entity bullet problem.

Posted: Fri Feb 01, 2013 2:56 pm
by KenJammin
I had no idea there were more tutorials on the wiki, very helpful. I solved my issue, and it mostly involved me getting used to creating entity tables. I see where i went wrong.

Anyway i made a little game out of it. Thank you for your help, now to decide what to make next...