#### Archived

This topic is now archived and is closed to further replies.

# shoot-em-up: implementing laser shots

This topic is 6082 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

how to implement laser shots in shoot-em-up game like raiden? i don''t have any idea at all!! i''m thinking of using linked-list of pointer to hold the laser segments, perhaps a laser structure like the one below: typedef struct LASER { int x, y; // position int seg_length; // segment length float vx, vy; // velocity } LASER, *LASER_PTR well, i don''t know, it''s only a starting point, but could somebody tell me how to do this? i''m also planning to use STL queue. actually i''m thinking of storing velocity vector (float vx, vy) rather than the direction angle. in my game, i have 16 directions (22.5 degrees each) so, the laser will also have 16 direction angles. how should i do this, guys??? thanks in advance!!!

##### Share on other sites
There are multiple ways to do this, but one way could be like this: a player fires his/her gun, and a laser beam comes out. At this point, you add a laser structure to the linked list (make it a double linked list, with a queue you can only delete the item you added first, I''m not sure however).

Set the x and y variables of the new laser to the player''s position. If a player looks in direction 5 for example, calculate the velocity with

vx = cos(5.0 / 8.0 * M_PI)
vy = sin(5.0 / 8.0 * M_PI) // the direction angle should be converted to radians for cos and sin functions in c(++).

Set seg_length to anything you like, and that''s it for the laser "creation".

Then, in your function where you update all the enemies and stuff, loop trough the linked list of LASERs, and move the laser beams according to their velocities:

x += vx * frame_time
y += vy * frame_time

where frame_time is the time it took to draw the frame.
Hope this helps,

Nick

##### Share on other sites
That''s pretyt much how I am doing it for my asteroids clone. It seems to be working pretty well.

1. 1
Rutin
32
2. 2
3. 3
4. 4
5. 5

• 11
• 9
• 13
• 92
• 11
• ### Forum Statistics

• Total Topics
632973
• Total Posts
3009625
• ### Who's Online (See full list)

There are no registered users currently online

×

## Important Information

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!