Die event-Funktion wird von Entity-Events ausgeführt.
// The following example shows how to use events for an object that flies ahead until it collides with a block or entity.
// The event function then plays a collision sound and lets the object ricochet from the surface.
function bounce_event()
{
switch (event_type)
{
case EVENT_BLOCK:
ent_playsound(my,whamm,50);
vec_to_angle(my.pan,bounce); // change direction
return;
case EVENT_ENTITY:
ent_playsound(my,boingg,50); // play a different sound
vec_to_angle(my.pan,bounce); // change direction
return;
}
}
action bounceball()
{
my.emask |= (ENABLE_BLOCK | ENABLE_ENTITY); // make entity sensitive for block and entity collision
my.event = bounce_event;
while(1)
{
c_move(me,vector(5*time_step,0,0),nullvector,0); // move ahead until obstacle is hit
wait(1);
}
}
function bounce_event()
{
if (event_type == EVENT_BLOCK)
{
ent_playsound(my,whamm,50);
vec_to_angle (my.pan,bounce); // change direction
return;
}
if (event_type == EVENT_ENTITY)
{
ent_playsound(my,boingg,50); // play a different sound
vec_to_angle (my.pan,bounce); // change direction
return;
}
}
action bounceball()
{
my.ENABLE_BLOCK = ON; // make entity sensitive for block collision
my.ENABLE_ENTITY = ON; // make entity sensitive for entity collision
my.event = bounce_event;
while(1)
{
c_move(me,vector(5*time_step,0,0),nullvector,0); // move ahead until obstacle is hit
wait(1);
}
}