Game Development Reference
In-Depth Information
3. Hover the mouse in front of the top engine, which we will imagine to be the left gun.
Check the coordinates in the status bar at the bottom of the window. You'll see that at
position ( 33 , 9 ), the mouse cursor is in front of the engine. The bullet sprite is 7x7, with
its origin in the middle, so this coordinate would be the place to create the bullet.
4. Do the same for the bottom engine. The coordinates you find should be mirrored from
the top engine, at ( 33 , 38 ).
5. For each of these coordinates, we now need to find out how far they are from the
origin, both horizontally and vertically. We can do this using the function
point_distance . Double-click obj_spaceship , select the Create event, and include a Set
Variable action with Variable distgun1 and Value point_distance(24,24,33,9) . This
calculates the distance from the origin at ( 24 , 24 ) to the position where the bullet
should be created.
6. Include another Set Variable action with Variable distgun2 and Value
point_distance(24,24,33,38) . This does exactly the same for the other bullet position.
7. Again, include a Set Variable action, with Variable anglegun1 and Value
point_direction(24,24,33,9) . This calculates the difference between the angle of the
front of the spaceship, and the top gun.
8. Include a Set Variable action with variable anglegun2 and Value
point_direction(24,24,33,38) to do the same for the bottom gun.
9. Open the Press Space event and double-click the Create Moving action. Change X to
lengthdir_x(distgun1,anglegun1+image_angle) and Y to
lengthdir_y(distgun1,anglegun1+image_angle) . This creates the bullet at the distance
we've calculated in the Create event for the top engine. The angle of the gun is added
to the image angle to place it at the appropriate angle.
10. Copy the Create Moving action and paste it in the same event so that you now have a
duplicate.
11. Double-click the duplicate Create Moving action. Change X to
lengthdir_x(distgun2,anglegun2+image_angle ) and Y to
lengthdir_y(distgun2,anglegun2+image_angle ). This does the same as the previous
action, for the bottom engine.
Result: Reference/Result/360_degree_shooting2.gmk
Note In the real world, bullets would move at a speed relative to the speed you're moving at. In other
words, the speed and direction of the gunner is added to the speed and direction of the bullet. We're not
doing that here, because in a game, where bullets travel slow enough to see and dodge them, it doesn't
feel right to have bullets travelling at different speeds. We often happily ignore real-world physics
anyway—imagine playing a space game without sound….
 
 
Search WWH ::




Custom Search