A little help if possible

• 09-10-2005, 07:03 PM
XteticX
A little help if possible
Hello everybody.

I'm currently working on my next release of the crappy Gored game I made a while back :p . I'm kinda stuck now and I was hoping someone could maybe give me a hand for a sec. I wanna add a bullet function to the game so when I shoot it comes out of the barrel and leaves for the current cursor possition. I have made a simple function, but its far from beying what I need.

Code:

```function shotgunbullet() bulletX = x0 + 12   bullet = 1   bulletY = bulletY - 8   screen:blit(bulletX, bulletY, bulletimg)   if bulletY <= 0 then bullet = 0 bulletY = 250 end end```
This makes the bullet leave from the barrel to the end of the screen. Problem is, if I move the cursor, the bullet follows. :doh: That's because of the "x0" part wich is a reference for lots of things inside the script. (cursor position, gun position, etc..)

I'de need to somehow make "bulletX" = to current x0 position... and nothing more. I've tried useless stuff like this:

Code:

```bulletX = (x0 - dx) + 12 bulletX = (math.abs(dx)x0) + 12```
But like I said, useless, just makes the bullet jerk left and right when I press the analog stick. Anybody have a clue how I would specify this?

Thx.
• 09-11-2005, 11:07 AM
Yeldarb
You need to initialize the position of the bullet to x0+12 but when changing the position make it bulletX + 12 (I think that's what you're asking at least)
• 09-11-2005, 12:44 PM
XteticX
I"m not sure what I did but it worked.

Code:

```function shotgunshot()   shaketime = shaketime + 1   if shaketime >= 40 then shaketime = 0 gunshake = 0 end   if shaketime <= 5 then gunhight = gunhight - 1 end   if shaketime >= 6 then       if shaketime <= 10 then gunhight = gunhight + 2 end   end   if shaketime == 10 then shotgunsnd:play() bullet = 1 bulletX = x0 end   if shaketime >= 11 then       if shaketime <= 15 then gunhight = gunhight - 2 end   end   if shaketime >= 16 then       if shaketime <= 21 then gunhight = gunhight + 1 end   end end function shotgunbullet()   bullet = 1   bulletY = bulletY - 10   screen:blit(bulletX + 12, bulletY, bulletimg)   if bulletY <= 0 then bullet = 0 bulletY = 230 end end```
I"ve got it working but its just outta pure luck. The bullet leaves the barrel and keeps its X trajectory even if I move the cursor now. I'de like to know the real way of doing this. :confused:
• 09-11-2005, 03:21 PM
Jake
Quote:

Originally Posted by XteticX
I'de like to know the real way of doing this. :confused:

Don't ya just hate that? LOL! :)
• 09-11-2005, 07:55 PM
XteticX
Quote:

Originally Posted by MalumEnSe
Don't ya just hate that? LOL! :)

lol, yes and it anoyed me to the point where I finally understood. Thx to yeldarb's word "iNiTiAlIzE", I figured out how it works. And now I'm using it for alot more things. :dance: