home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ISV Strong Games
/
ISV_STRONG_GAMES.iso
/
shootemup
/
hive
/
!Hive
/
c
/
game
< prev
next >
Wrap
Text File
|
2000-11-27
|
8KB
|
296 lines
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "DeskLib:h.Error"
#include "DeskLib:h.File"
#include "DeskLib:h.GFX"
#include "DeskLib:h.Hourglass"
#include "DeskLib:h.Kbd"
#include "DeskLib:h.SWI"
#include "Popcorn:h.Popcorn"
#include "h.sound"
#include "h.useful"
#include "h.waves"
#define random(limit) (rand() % (limit))
struct object_table *ship_table, *missile_table, *alien_table,
*fx_table, *alien_swoop_table, *alien_missile_table,
*token_table;
void **ship_sprite[9], **alphabet_sprite[57];
void *backdrop;
BOOL quit = FALSE, dirty_rotten_cheat = FALSE,
hit_bottom = FALSE;
int fired = 0, max_fired = 10;
int wave = 0, aliens_left = 0, last_killed_at = -1;
int ship_pos = 28, fire_freq = 50, fire_again = 0,
special = 0, invulnerable = 0, ship_x;
int score, hi_score=0, lives, next_life_time = -1;
int screenshot_number = 0;
void exit_handler(void)
{
kill_sound();
SWI(2, 0, SWI_OS_Byte, 112, 1);
SWI(2, 0, SWI_OS_Byte, 113, 1);
SWI(0, 0, 256+12);
SWI(0, 0, SWI_OS_RestoreCursors);
SWI(2, 0, SWI_OS_Byte, 229, 0);
}
void title_handler(struct game_object *obj, union object_flags reason, void *data)
{
if (reason.bits.attn_every)
{
if (Kbd_KeyDown(-99))
{
Popcorn_DeleteObject(obj);
next_life_time = 0;
aliens_left = 0;
wave = 1; wave_initialise(wave);
hit_bottom = FALSE;
score = 0; lives = 6;
}
}
}
void misc_every_handler(struct game_object *obj, union object_flags reason, void *data)
{
void **special_sprite;
char string[64];
int time;
if (reason.bits.attn_plot)
{
switch (wave)
{
case 0 :
print_message("PRESS SPACE TO PLAY", 25, 150, TRUE);
sprintf(string, "BEST SCORE... %06d", hi_score);
print_message(string, 20, 236, FALSE);
break;
case -1 :
print_message("GAME OVER", 100, 100, TRUE);
break;
default :
if (last_killed_at == -1)
{
sprintf(string, "%06d", score);
print_message(string, 10, 10, TRUE);
sprintf(string, "%d", lives);
print_message(string, 10, 236, FALSE);
switch (special)
{
case 1 :
special_sprite = Popcorn_FindResource("<Hive$Dir>.Graphics.spiral.0");
Popcorn_PlotSprite(*special_sprite, 300, 226);
break;
case 2 :
special_sprite = Popcorn_FindResource("<Hive$Dir>.Graphics.msl.0");
Popcorn_PlotSprite(*special_sprite, 300, 226);
break;
}
}
else
{
sprintf(string, "WAVE %d\0", wave+1);
print_message(string, 120, 100, TRUE);
}
break;
}
}
check_newwave();
sine_value = sine_value + 5;
if (sine_value > 359)
sine_value = sine_value - 360;
if (dirty_rotten_cheat && special == 0)
{
if (Kbd_KeyDown(-49))
{
special = 1;
make_sound("<Hive$Dir>.Sounds.Token");
}
if (Kbd_KeyDown(-72))
{
special = 2;
make_sound("<Hive$Dir>.Sounds.Token");
}
}
if (Kbd_KeyDown(-114)) dirty_rotten_cheat = TRUE;
if (Kbd_KeyDown(-115)) dirty_rotten_cheat = FALSE;
if (wave != 0 && next_life_time != -1)
{
SWI(0, 1, SWI_OS_ReadMonotonicTime, &time);
if (time - next_life_time > 250)
{
Popcorn_NewPrototype(ship_table, 'PIHS', 160<<12, 255<<12);
fire_freq = 50;
next_life_time = -1;
}
}
}
void game_finish(void)
{
FILE *hi_score_file;
if (score > hi_score)
{
hi_score = score;
hi_score_file = fopen("<Hive$Dir>.Data.HiScore", "wb");
if (hi_score_file == NULL)
return;
fprintf(hi_score_file, "%d", hi_score);
fclose(hi_score_file);
}
}
void game_initialise(void)
{
FILE *hi_score_file;
int c, rand_seed;
char temp_filename[255];
Hourglass_On();
ship_table = Popcorn_NewTable(10, TRUE);
missile_table = Popcorn_NewTable(50, TRUE);
alien_table = Popcorn_NewTable(100, TRUE);
alien_swoop_table = Popcorn_NewTable(50, TRUE);
alien_missile_table = Popcorn_NewTable(50, TRUE);
token_table = Popcorn_NewTable(50, TRUE);
fx_table = Popcorn_NewTable(200, TRUE);
alien_missile_table->grav_y = 512;
token_table->grav_y = 1024;
game_window.x0 = game_window.y0 = 0;
game_window.x1 = 320; game_window.y1 = 256;
user_window.x0 = user_window.y0 = -50;
user_window.x1 = 370; user_window.y1 = 306;
strcpy(symbol_table_filename, "<Hive$Dir>.Data.Symbols");
Error_CheckFatal(Popcorn_LoadResourceFile("<Hive$Dir>.Data.Resources"));
Error_CheckFatal(Popcorn_LoadPrototypes("<Hive$Dir>.Data.Prototypes"));
Error_CheckFatal(Popcorn_LoadGroup('LTIT'));
Error_CheckFatal(Popcorn_LoadGroup('EROC'));
Error_CheckFatal(Popcorn_LoadGroup('NILA'));
/* Error_CheckFatal(Popcorn_LoadGroup('2DAB')); */
/* Error_CheckFatal(Popcorn_LoadGroup('NOIS')); */
Error_CheckFatal(Popcorn_LoadGroup('HPLA'));
Error_CheckFatal(Popcorn_LoadGroup('NUOS'));
backdrop = malloc(File_Size("<Hive$Dir>.Graphics.back.1"));
init_sound();
SWI(2, 0, SWI_OS_Byte, 229, 1);
atexit(exit_handler);
load_scoring();
wave_initialise(0);
Popcorn_NewPrototype(fx_table, 'CSIM', 0, 0);
for (c=0; c!=9; c++)
{
sprintf(temp_filename, "<Hive$Dir>.Graphics.ship.%d", c);
ship_sprite[c] = Popcorn_FindResource(temp_filename);
}
for (c=32; c!=91; c++)
{
sprintf(temp_filename, "<Hive$Dir>.Graphics.alphabet.%d", c);
alphabet_sprite[c-32] = Popcorn_FindResource(temp_filename);
}
Error_CheckFatal(File_LoadTo("<Hive$Dir>.Data.Sine", sine_table, NULL));
hi_score_file = fopen("<Hive$Dir>.Data.HiScore", "rb");
if (hi_score_file == NULL)
{
hi_score = 1000;
}
else
{
fscanf(hi_score_file, "%d", &hi_score);
fclose(hi_score_file);
}
SWI(0, 1, SWI_OS_ReadMonotonicTime, &rand_seed);
srand(rand_seed);
Hourglass_Off();
SWI(2, 0, SWI_OS_Byte, 114, 0);
GFX_Mode(13);
SWI(2, 0, SWI_OS_Byte, 114, 1);
SWI(0, 0, SWI_OS_RemoveCursors);
Popcorn_ReadScreenDetails();
Popcorn_ClearScreen(0);
}
BOOL check_pause(void)
{
char cmd[256];
if (Kbd_KeyDown(-56))
{
while (Kbd_KeyDown(-56));
while (!Kbd_KeyDown(-56))
{
if (Kbd_KeyDown(-99))
{
while (!Kbd_KeyDown(-99));
sprintf(cmd, "Screensave $.Screen%d", screenshot_number);
system(cmd);
screenshot_number++;
}
}
while (Kbd_KeyDown(-56));
return(TRUE);
}
return(FALSE);
}
int main(void)
{
int start_time, end_time, frames=1;
game_initialise();
do {
SWI(0, 1, SWI_OS_ReadMonotonicTime, &start_time);
if (check_pause())
SWI(0, 1, SWI_OS_ReadMonotonicTime, &start_time);
Popcorn_PlotBackdrop(backdrop);
Popcorn_Process(missile_table, TRUE, frames);
Popcorn_Process(fx_table, TRUE, frames);
Popcorn_Process(ship_table, TRUE, frames);
Popcorn_Process(alien_table, TRUE, frames);
Popcorn_Process(alien_swoop_table, TRUE, frames);
Popcorn_Process(alien_missile_table, TRUE, frames);
Popcorn_Process(token_table, TRUE, frames);
Popcorn_CollisionCheck(missile_table, alien_table);
Popcorn_CollisionCheck(missile_table, alien_swoop_table);
Popcorn_CollisionCheck(token_table, ship_table);
if (!dirty_rotten_cheat)
{
Popcorn_CollisionCheck(ship_table, alien_missile_table);
Popcorn_CollisionCheck(ship_table, alien_swoop_table);
}
SWI(1, 0, SWI_OS_Byte, 19);
Popcorn_SwapBanks();
do
{
SWI(0, 1, SWI_OS_ReadMonotonicTime, &end_time);
frames = (end_time - start_time) >> 1;
} while (frames == 0);
} while (!(Kbd_KeyDown(-113) && Kbd_KeyDown(-2)));
return(0);
}