home | et13 - game prototyping in Gamemaker | prev | next |
David
Javelosa |
|
week
12 - More
Scripting Examples
|
Create a red ball sprite. Name it sprBall
Create a ball object objBall, and attach the sprite.
Create an empty room, and place the ball exactly in the middle of it. (You
can check the coordinates at the bottom of the screen - if the game area is
640x480, the centre is at 320, 240
Add an event to the ball object for when the A key is pressed.
From the control tab, choose
If the number of instances is a value
Put objBall < 3000
(We don't want to create any more balls if there are already more than 3000
on the play area.)
From the control tab, choose
Execute a piece of code
counter=0 //initialize the counter
{ counter+=36 ball=instance_create(x,y,objBall) ball.direction=counter ball.speed=5 } |
When the balls leave the play area, we want them to wrap to the other side:
Add an event for when the ball is outside the room (From Other events
)
Choose the Wrap around the play area action (in both directions) from the
Move tab.
Try varying the degree intervals to change the pattern.
Modify the behavior with a collision event that randomly changes direction!
Try reducing the maximum amount of balls from 3000 to 1000; 500; 100.
You will need to look carefully at the code to work out what you need to change.
original code by Margaret Meijers; margaret.meijers@education.tas.gov.au.
Using the sprite randomization from last week, try randomizing sound playback:
Create 5 sound resources; naming them 0, 1, 2, 3, 4
Using a mouse left pressed event, select the control action execute a piece of code and enter:
{
sound_play(random(4))
}
This should playback the different sound resources at random.
Try different combinations with interactive or automatically generated events. Be carefull not to generate actions that overload the system's abillity to perform.
Copyright © 2001-2014, David Javelosa unless otherwise stated. |