Game Development Reference
Finally, you can use the PeianArajp class's PEIAN[?KILHAPA property to trigger an event when the
This is a very basic introduction to how timers work, but I'm sure you can see that they are used often
in games. You can use a Peian object to create a countdown timer, make an object mover intermit-
tently, or calculate a player's score based on how long it takes to complete a task.
Using a timer to fire bullets
Now that you know how a timer works, it should be quite obvious how one has been used in the
Nk^kp[Odkkp class. The [peian object has been set up to trigger an event every second. However, it's
not started when the class is initialized. Instead, it waits until the target object is within range (which
is 250 pixels).
The event that the timer calls is the kjOdkkp>qhhap bullet event. It's identical to the kjOdkkp>qhhap
method from the Lh]uan class, except that _en_ha is provided as an argument instead of op]n. It's
no more difficult than that!
Shooting at random intervals
There's one small modification you can make that will make the robot's shooting behavior much more
realistic. As it's been coded, the robot shoots right on cue every 1000 milliseconds. You can use the
Peian class's `ah]u property to randomize this. Add the following code to the kjOdkkp>qhhap event
handler to see the effect: