Need help with a table/entity bullet problem.

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
KenJammin
Prole
Posts: 3
Joined: Fri Jan 25, 2013 1:30 pm

Need help with a table/entity bullet problem.

Post 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.
Attachments
ChargeCircle.love
(982 Bytes) Downloaded 117 times
User avatar
Pash
Prole
Posts: 43
Joined: Sun Dec 30, 2012 8:04 am

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

Post 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.
Sagan Interactive - Looking forward to a creative 2013.
User avatar
veethree
Inner party member
Posts: 877
Joined: Sat Dec 10, 2011 7:18 pm

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

Post 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.
KenJammin
Prole
Posts: 3
Joined: Fri Jan 25, 2013 1:30 pm

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

Post 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...
Attachments
ChargeCircle.love
(76.55 KiB) Downloaded 116 times
Post Reply

Who is online

Users browsing this forum: Hydrogen Maniac and 2 guests