• Advertisement


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

shoot-em-up: implementing laser shots

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

If you intended to correct an error in the post then please contact us.

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 this post

Link to post
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,


Share this post

Link to post
Share on other sites

  • Advertisement