home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ISV Strong Games
/
ISV_STRONG_GAMES.iso
/
shootemup
/
hive
/
!Hive
/
c
/
alien_hnd
next >
Wrap
Text File
|
2000-11-27
|
6KB
|
215 lines
#include <stdlib.h>
#include "DeskLib:h.Kbd"
#include "Popcorn:h.Popcorn"
#include "h.game"
#include "h.sound"
#define random(limit) (rand() % (limit))
void dull_alien_handler(struct game_object *obj, union object_flags reason, void *data)
{
int turn, xvel;
if (reason.bits.attn_gameout)
{
xvel = obj->xv*-1;
obj->x = obj->x + xvel;
for (turn = 0; turn != alien_table->max_objects; turn++)
{
if (alien_table->object[turn].object_id != NULL)
{
if (!hit_bottom)
alien_table->object[turn].y = alien_table->object[turn].y + 4096;
alien_table->object[turn].xv = xvel;
if (alien_table->object[turn].y > (180<<12))
hit_bottom = TRUE;
}
}
}
if (reason.bits.collide)
{
if (obj->xv > 0)
xvel = obj->xv + 512;
else
xvel = obj->xv - 512;
for (turn = 0; turn != alien_table->max_objects; turn++)
if (alien_table->object[turn].object_id != 0)
alien_table->object[turn].xv = xvel;
}
}
void bomby_alien_handler(struct game_object *obj, union object_flags reason, void *data)
{
struct game_object *bomb;
if (reason.bits.attn_gameout || reason.bits.collide)
dull_alien_handler(obj, reason, data);
if (random(100) == 1)
{
bomb = Popcorn_NewPrototype(alien_missile_table, 'BMBB', obj->x, obj->y);
bomb->xv = random(8192)-4096;
bomb->yv = random(4096);
}
}
void bigblue_alien_handler(struct game_object *obj, union object_flags reason, void *data)
{
struct game_object *bomb;
if (reason.bits.attn_gameout || reason.bits.collide)
dull_alien_handler(obj, reason, data);
if (random(100) == 1)
{
bomb = Popcorn_NewPrototype(alien_missile_table, 'ULBB', obj->x, obj->y+40960);
if (bomb == NULL)
return;
}
}
void bigblue_handler(struct game_object *obj, union object_flags reason, void *data)
{
struct game_object *expl;
expl = Popcorn_NewPrototype(alien_missile_table, 'LPXE', obj->x, obj->y);
Popcorn_DeleteObject(obj);
if (expl == NULL)
return;
expl->timer.value = 20;
expl->timer.decrement = 1;
expl->flags.bits.collide = TRUE;
}
void swoopy_alien_handler(struct game_object *obj, union object_flags reason, void *data)
{
struct game_object *swoop;
int ox, oy, speed;
if (obj->user_data == NULL)
{
if (random(1000) == 1)
{
swoop = Popcorn_NewPrototype(alien_swoop_table, obj->object_id, obj->x, obj->y);
swoop->xv = random(16384)-8192; swoop->yv = random(8192)+8192;
swoop->user_data = obj;
swoop->timer.value = 300; swoop->timer.decrement = 1;
obj->flags.bits.attn_every = obj->flags.bits.std_plot = obj->flags.bits.collide = 0;
obj->handler = (object_handler) dull_alien_handler;
}
else
{
dull_alien_handler(obj, reason, data);
}
}
else
{
if (obj->timer.decrement == 1)
{
if (obj->timer.value == 0)
obj->timer.decrement = 0;
speed = 128;
}
else
speed = 12288;
if (obj->x > ((struct game_object*) obj->user_data)->x && obj->xv > -12288)
obj->xv = obj->xv - speed;
if (obj->x < ((struct game_object*) obj->user_data)->x && obj->xv < 12288)
obj->xv = obj->xv + speed;
if (obj->y > ((struct game_object*) obj->user_data)->y && obj->yv > -12288)
obj->yv = obj->yv - speed;
if (obj->y < ((struct game_object*) obj->user_data)->y && obj->yv < 12288)
obj->yv = obj->yv + speed;
ox = obj->x - ((struct game_object*) obj->user_data)->x + 32768;
oy = obj->y - ((struct game_object*) obj->user_data)->y + 32768;
if ( (ox > 0 && ox < 32768) && (oy > 0 && oy < 32768) )
{
((struct game_object*) obj->user_data)->flags.bits.attn_every = ((struct game_object*) obj->user_data)->flags.bits.std_plot = ((struct game_object*) obj->user_data)->flags.bits.attn_gameout = ((struct game_object*) obj->user_data)->flags.bits.collide = 1;
((struct game_object*) obj->user_data)->handler = (object_handler) swoopy_alien_handler;
Popcorn_DeleteObject(obj);
}
if (reason.bits.collide)
{
Popcorn_DeleteObject(((struct game_object*)obj->user_data));
}
}
}
void divebomb_alien_handler(struct game_object *obj, union object_flags reason, void *data)
{
struct game_object *swoop;
if (obj->user_data == NULL)
{
if (random(1000) == 1)
{
make_sound("<Hive$Dir>.Sounds.DiveBomb");
swoop = Popcorn_NewPrototype(alien_swoop_table, obj->object_id, obj->x, obj->y);
swoop->xv = (ship_x - obj->x) / 50;
swoop->yv = ((255<<12) - obj->y) / 50;
swoop->user_data = obj;
obj->flags.bits.attn_every = obj->flags.bits.std_plot = obj->flags.bits.collide = 0;
obj->handler = (object_handler) dull_alien_handler;
}
else
{
dull_alien_handler(obj, reason, data);
}
}
else
{
if (reason.bits.collide)
{
Popcorn_DeleteObject(((struct game_object*)obj->user_data));
}
if (reason.bits.attn_gameout)
{
if ( (obj->x>>12) < game_window.x0 || (obj->x>>12) > game_window.x1 )
obj->xv = -obj->xv;
if ( (obj->y>>12) > game_window.y1)
obj->yv = -obj->yv;
}
if (reason.bits.attn_userout)
{
((struct game_object*) obj->user_data)->flags.bits.attn_every = ((struct game_object*) obj->user_data)->flags.bits.std_plot = ((struct game_object*) obj->user_data)->flags.bits.attn_gameout = ((struct game_object*) obj->user_data)->flags.bits.collide = 1;
((struct game_object*) obj->user_data)->handler = (object_handler) divebomb_alien_handler;
Popcorn_DeleteObject(obj);
}
}
}
void laser_alien_handler(struct game_object *obj, union object_flags reason, void *data)
{
struct game_object *laser;
int c, xv, yv;
if (reason.bits.collide || reason.bits.attn_gameout)
dull_alien_handler(obj, reason, data);
if (reason.bits.attn_every)
{
if (random(2000) == 0)
{
xv = (ship_x - obj->x) / 400;
yv = ((255<<12) - obj->y) / 400;
for (c=5; c!=11; c++)
{
make_sound("<Hive$Dir>.Sounds.Laser");
laser = Popcorn_NewPrototype(alien_missile_table, 'RSAL', obj->x, obj->y);
if (laser != NULL)
{
laser->xv = xv*c;
laser->yv = yv*c;
}
}
}
}
}