Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Projectile Question

Author
Message
Spooter
16
Years of Service
User Offline
Joined: 27th May 2008
Location:
Posted: 16th Jun 2008 18:23
I need to make it so when a user left clicks, it will "shoot" an image towards the location of the mouse. I assume that I would use dbMouseClick()/dbMouseX/dbMouseY Its 2D so I don't need Z. My image is just a 1x16 pixel image of a red line, So i can use dbRotate and it will still look good(as far as i know). I was thinking of using dbLine, but this creates a line, not a line segment. If anyone can help please post.

/*================================================*\
| Lead Programmer/Owner===============Anti-Triangle Cult=====|
\*================================================*/
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 16th Jun 2008 18:43 Edited at: 16th Jun 2008 18:49
Edit: Removed due to not having thought out the answer.

In the words of Roseanne Rosanna Dana, "Never mind!"

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
Spooter
16
Years of Service
User Offline
Joined: 27th May 2008
Location:
Posted: 16th Jun 2008 18:44
how do you set a offset point and what do you mean "rotated line" is that using an image?

/*================================================*\
| Lead Programmer/Owner===============Anti-Triangle Cult=====|
\*================================================*/
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 16th Jun 2008 18:53
Actually I spoke before I thought that one out a bit. If you're using an image, I assumed you were displaying it and rotating it using a sprite. In my head I was picturing a rectangle with a line down it and now poorly it would rotate around the upper left corner.

Then I realized you were probably using an image one pixel wide, which would rotate fine and leave the point of contact at the same point of rotation.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
Spooter
16
Years of Service
User Offline
Joined: 27th May 2008
Location:
Posted: 16th Jun 2008 18:58
Yup, the making it fire towards the mouse locations is the important thing though, got any suggestions? Also I'm changing the projectile to a circle instead of a line, so rotation is no longer a problem.

/*================================================*\
| Lead Programmer/Owner===============Anti-Triangle Cult=====|
\*================================================*/
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 16th Jun 2008 19:08
In that case, offsetting probably would be an issue since the position of the sprite is determined by the upper left corner. Without an offset your circle would appear to the right of your firing point.

Look at the functions for setting speed and angle. You should be able to determine the angle fairly easily. If

xmouse = x coordinate of the mouse
ymouse = y coordinate of the mouse
xgun = x coordinate of the gun
ygun = y coordinate of the gun

tan (theta) = (ymouse - ygun)/(xmouse - xgun);

Solve for theta

theta = atan ((ymouse - ygun)/(xmouse - xgun));

I think. I've always moved my objects at angles using independent deltaX and deltaY values.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
Spooter
16
Years of Service
User Offline
Joined: 27th May 2008
Location:
Posted: 16th Jun 2008 19:13 Edited at: 16th Jun 2008 19:16
Sweet, so how do you offset the center point of a sprite then.

Also how do you find the coordinate of the mouse? I'm completely new to functions with the mouse.

/*================================================*\
| Lead Programmer/Owner===============Anti-Triangle Cult=====|
\*================================================*/
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 16th Jun 2008 19:22
void dbOffsetSprite ( int iSprite, int iX, int iY ) ;

offsets the tracking point. Imagine the left/top corner staying stable but the sprite shifting so that it's iX/iY coordinate moves to that position. I don't know if I can be much less murky than that.

Mouse is a bit more involved. The immediate x/y/z coordinates of the mouse are found using



However, as provided, the mouse clicks only tell you when the mouse button is down or up. You have to track the transitional states yourself.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 16th Jun 2008 19:34
You should use atan2, not atan due to atan only working for one quadrant!

Login to post a reply

Server time is: 2024-11-20 13:19:37
Your offset time is: 2024-11-20 13:19:37