Game Development Reference
In-Depth Information
Now, create a new object and name it obj_Enemy . Link the new sprite to it; then, add a
create event and drag in a code block.
There are three essential variables we need to create for this object: one to control the
speed, another to control the direction it moves in, and one more to control its up/down or
left/right state. Let's name them spd , dir , and dir2 . We are going to use the choose
function on the dir variable and the dir2 variable. The choose function will randomly
pick between a set of 16 or less arguments that we enter. In this case, for the dir variable,
we will enter two arguments; 0 and 1 . 0 will mean horizontal movement and 1 will mean
vertical movement. For the dir2 variable, we will enter -1 and 1 for left and right, re-
spectively. For the speed variable, we will use the random_range function again and
put in a range of 1 to 8 .
Here is our create event code:
Search WWH ::




Custom Search