Game Development Reference
In-Depth Information
12. Add an Other , Outside Room event and include the Wrap Screen action and set it to
wrap in both directions .
13. Finally, include an instance of obj_spaceship in the test room.
Result: Reference/Result/360_degree_movement.gmk
360-Degree Shooting
If you can move in every direction, chances are you want to shoot in every direction, too. We'll
use the spaceship we created in the previous feature and give it some firepower.
Start with: Reference/Framework/spaceship2.gmk
Creating 360-Degree Shooting
1.
Create a new object and call it obj_bullet . Set Sprite to spr_bullet and the Depth to 10
to make bullets appear under the spaceship.
2.
Add an Other , Outside Room event and include the Destroy Instance action.
3.
Now open obj_spaceship and add a Key Press , <Space> event. Include a Create
Moving action. Set Object to obj_bullet , X to lengthdir_x(12,image_angle) , and Y to
lengthdir_y(12,image_angle) . Set the Speed to 10 , the Direction to image_angle and
check the Relative box. This action takes care of placing the bullet in front of the
spaceship in the direction it is facing (explained after these steps). We're using
image_angle rather than direction because we want to shoot in the direction we are
facing, not in the direction we are moving!
In the same event, include a Play Sound event and set the Sound to snd_shoot and
Loop to false .
4.
Result: Reference/Result/360_degree_shooting1.gmk
In the 360-degree shooting example, the lengthdir_x and lengthdir_y functions are used to
create the bullet directly in front of the spaceship, which is 12 pixels away from the spaceship's
origin. This works fine if the gun is mounted on the front of the ship facing forward, but you'll
need to do a little more arithmetic if the guns are mounted in a different place (for example, if you
wish to shoot from the wings of the spaceship). We'll change the example to show you how.
Creating 360-Degree Shooting from Custom Gun Mounts
1.
The most important step is finding out where the bullets should be placed when
coming out of the gun mounts. Double-click spr_spaceship and click Edit Sprite , then
double-click on the first image.
2.
Zoom in on the picture using the magnifier button. It helps to toggle the grid so you
can see gridlines around the pixels.
 
 
Search WWH ::




Custom Search