Browse Source

Add files to repository

master
Alec Murphy 2 years ago
parent
commit
a467b42407
  1. 1554
      Actor.HC
  2. 1091
      Actor_Collision.HC
  3. 76
      Actor_Toss.HC
  4. 4793
      Actor_WorkType.HC
  5. 98
      Backdrop.HC
  6. 29
      Cartoon.HC
  7. 0
      Config.HC
  8. 20
      Define.HC
  9. 850
      Dialog.HC
  10. 562
      Effects.HC
  11. 169
      File.HC
  12. 57
      Font.HC
  13. 90
      Fullscreen_Image.HC
  14. 356
      Game.HC
  15. 115
      Input.HC
  16. 93
      Main.HC
  17. 362
      Map.HC
  18. 139
      Palette.HC
  19. 144
      Platforms.HC
  20. 1872
      Player.HC
  21. 33
      Run.HC
  22. 80
      Status.HC
  23. 210
      Tile.HC
  24. 12
      Util.HC
  25. 335
      Video.HC
  26. 123
      Vol.HC
  27. BIN
      screenshot.png

1554
Actor.HC

File diff suppressed because it is too large

1091
Actor_Collision.HC

File diff suppressed because it is too large

76
Actor_Toss.HC

@ -0,0 +1,76 @@
#define MAX_TOSSED_ACTORS 6
class ActorToss
{
I64 actorInfoIndex;
I64 x;
I64 y;
I64 counter;
};
ActorToss actorToss[MAX_TOSSED_ACTORS];
U0 actor_toss_add_new(I64 actorInfoIndex, I64 x_pos, I64 y_pos) {
I64 i;
for(i=0;i<MAX_TOSSED_ACTORS;i++)
{
if(actorToss[i].actorInfoIndex == 0)
{
actorToss[i].actorInfoIndex = actorInfoIndex;
actorToss[i].x = x_pos;
actorToss[i].y = y_pos;
actorToss[i].counter = 0;
return;
}
}
}
U0 actor_toss_update() {
I64 i;
for(i=0;i<MAX_TOSSED_ACTORS;i++)
{
ActorToss *at = &actorToss[i];
if (at->actorInfoIndex == 0)
goto actor_toss_update_cont;
at->counter = at->counter + 1;
at->y--;
if (sprite_blocking_check(0, at->actorInfoIndex, 0, at->x, at->y) == NOT_BLOCKED)
{
if (at->counter >= 9 || sprite_blocking_check(0, at->actorInfoIndex, 0, at->x, --at->y) == NOT_BLOCKED)
{
if(at->counter != 11)
{
display_actor_sprite_maybe(at->actorInfoIndex, 0, at->x, at->y, 4);
}
else
{
actor_add_new(at->actorInfoIndex, at->x, at->y);
display_actor_sprite_maybe(at->actorInfoIndex, 0, at->x, at->y, 4);
at->actorInfoIndex = 0;
}
}
else
{
actor_add_new(at->actorInfoIndex, at->x, at->y + 1);
display_actor_sprite_maybe(at->actorInfoIndex, 0, at->x, at->y + 1, 0);
at->actorInfoIndex = 0;
}
}
else
{
actor_add_new(at->actorInfoIndex, at->x, at->y + 1);
display_actor_sprite_maybe(at->actorInfoIndex, 0, at->x, at->y + 1, 0);
at->actorInfoIndex = 0;
}
actor_toss_update_cont:
}
}
U0 actor_toss_clear_all() {
I64 i;
for(i=0;i<MAX_TOSSED_ACTORS;i++)
{
actorToss[i].actorInfoIndex = 0;
}
}

4793
Actor_WorkType.HC

File diff suppressed because it is too large

98
Backdrop.HC

@ -0,0 +1,98 @@
extern U0 video_draw_tile_with_clip_rect(Tile *tile, uint16 x, uint16 y, uint16 clip_x, uint16 clip_y, uint16 clip_w, uint16 clip_h);
#define BACKGROUND_WIDTH 40
#define BACKGROUND_HEIGHT 18
//Data
uint16 backdrop_index = 0xff;
uint8 background_x_scroll_flag = 0;
uint8 background_y_scroll_flag = 0;
U8 backdrop_filename_tbl[26][13] = {
"BDBLANK.MNI",
"BDPIPE.MNI",
"BDREDSKY.MNI",
"BDROCKTK.MNI",
"BDJUNGLE.MNI",
"BDSTAR.MNI",
"BDWIERD.MNI",
"BDCAVE.MNI",
"BDICE.MNI",
"BDSHRUM.MNI",
"BDTECHMS.MNI",
"BDNEWSKY.MNI",
"BDSTAR2.MNI",
"BDSTAR3.MNI",
"BDFOREST.MNI",
"BDMOUNTN.MNI",
"BDGUTS.MNI",
"BDBRKTEC.MNI",
"BDCLOUDS.MNI",
"BDFUTCTY.MNI",
"BDICE2.MNI",
"BDCLIFF.MNI",
"BDSPOOKY.MNI",
"BDCRYSTL.MNI",
"BDCIRCUT.MNI",
"BDCIRCPC.MNI"
};
Tile *bg_tiles;
U0 load_backdrop_image(U8 *filename)
{
uint16 num_tiles;
bg_tiles = load_tiles(filename, SOLID, &num_tiles);
"Loading %d background tiles.\n", num_tiles;
}
Bool set_backdrop(uint16 new_backdrop_index)
{
uint8 cur_background_x_scroll_flag = 0;
uint8 cur_background_y_scroll_flag = 0;
if (new_backdrop_index != backdrop_index ||
cur_background_x_scroll_flag != background_x_scroll_flag ||
cur_background_y_scroll_flag != background_y_scroll_flag)
{
backdrop_index = new_backdrop_index;
cur_background_x_scroll_flag = background_x_scroll_flag;
cur_background_y_scroll_flag = background_y_scroll_flag;
load_backdrop_image(backdrop_filename_tbl[backdrop_index]);
}
return TRUE;
}
U0 backdrop_display()
{
I64 x_offset = 0;
I64 y_offset = 0;
I64 sub_tile_x = 0;
I64 sub_tile_y = 0;
I64 x, y;
//background scrolls in 4 pixel increments.
if(background_x_scroll_flag)
{
x_offset = mapwindow_x_offset % (BACKGROUND_WIDTH*2);
x_offset /= 2;
sub_tile_x = Cond(mapwindow_x_offset & 1, 4, 0);
}
if(background_y_scroll_flag)
{
y_offset = mapwindow_y_offset % (BACKGROUND_HEIGHT*2);
y_offset /= 2;
sub_tile_y = Cond(mapwindow_y_offset & 1, 4, 0);
}
for(y=0; y < MAP_WINDOW_HEIGHT + 1; y++)
{
for(x=0; x < MAP_WINDOW_WIDTH + 1; x++)
{
video_draw_tile_with_clip_rect(&bg_tiles[((x+x_offset) % BACKGROUND_WIDTH) + ((y+y_offset) % BACKGROUND_HEIGHT) * BACKGROUND_WIDTH], (x+1)*8 - sub_tile_x, (y+1)*8 - sub_tile_y, 8, 8, 8*MAP_WINDOW_WIDTH, 8*MAP_WINDOW_HEIGHT);
}
}
}

29
Cartoon.HC

@ -0,0 +1,29 @@
Tile *cartoon_tiles;
Sprite *sprites;
U0 load_cartoon_images()
{
uint16 num_tile_info_records;
uint16 num_tiles;
cartoon_tiles = load_tiles("CARTOON.MNI", TRANSPARENT, &num_tiles);
"Loading %d cartoon tiles.\n", num_tiles;
sprites = load_tile_info("CARTINFO.MNI", &num_tile_info_records);
"Loading %d, cartoon tile info records.\n", num_tile_info_records;
}
U0 display_cartoon_sequence(uint16 frame_num, uint16 x_pos, uint16 y_pos)
{
TileInfo *info = &sprites[0].frames[frame_num];
Tile *tile = &cartoon_tiles[info->tile_num];
I64 x, y;
for(y=0; y < info->height; y++)
{
for(x=0; x < info->width; x++)
{
video_draw_tile(tile, (x_pos + x) * 8, (y_pos + y - info->height + 1) * 8);
tile++;
}
}
}

0
Config.HC

20
Define.HC

@ -0,0 +1,20 @@
#define uint8 U8
#define uint16 U16
#define uint32 U32
#define sint8 I8
#define sint16 I16
#define sint32 I32
// BlockingType
#define NOT_BLOCKED 0
#define BLOCKED 1
#define SLOPE 2
// Direction
#define UP 0
#define DOWN 1
#define LEFT 2
#define RIGHT 3
#define WB_SIZE 1048576

850
Dialog.HC

@ -0,0 +1,850 @@
extern U0 video_update();
extern Tile *map_get_bg_tile(uint16 tile_num);
extern U8 get_episode_number();
extern U0 set_initial_game_state();
extern U0 display_fullscreen_image(uint8 image_number);
extern U0 fade_to_black_speed_3();
extern U0 video_fill_screen_with_black();
extern U0 fade_in_from_black_with_delay_3();
extern U0 fade_to_white(uint16 wait_time);
extern U0 fade_in_from_black(uint16 wait_time);
#define SDLK_UP 1
#define SDLK_DOWN 2
#define SDLK_LEFT 3
#define SDLK_RIGHT 4
#define PLAY_GAME 0
#define PLAY_DEMO 1
#define RECORD_DEMO 2
#define QUIT_GAME 3
class MenuItem {
uint16 x_pos;
uint16 y_pos;
U8 *text;
I64 action_key;
};
//Data
uint8 show_one_moment_screen_flag = 0;
uint8 byte_28BE3 = 0;
uint8 byte_2E21C = 0;
I64 cur_selected_item = 0;
//HintDialogInput
#define FAST_FORWARD 0
#define EXIT 1
#define NO_INPUT 2
I64 hint_dialog_get_input(I64 input)
{
if (Bt(kbd.down_bitmap, Char2ScanCode(' ')))
{
return FAST_FORWARD;
}
if (Bt(kbd.down_bitmap, SC_ESC))
{
return EXIT;
}
return NO_INPUT;
//return input;
}
U8 score_text_tbl[13][17] = {
" Not Bad! ",
" Way Cool ",
" Groovy ",
" Radical! ",
" Insane ",
" Gnarly ",
" Outrageous ",
" Incredible ",
" Awesome! ",
" Brilliant! ",
" Profound ",
" Towering ",
"Rocket Scientist"
};
U16 dialog_text_extract_num(U8 *text)
{
U8 buf[4];
buf[0] = text[0];
buf[1] = text[1];
buf[2] = text[2];
buf[3] = 0;
return Str2I64(&buf) & 0xFFFF;
}
U0 display_dialog_text_with_color(uint16 x_pos, uint16 y_pos, U8 *text, uint8 text_color)
{
I64 input = NO_INPUT;
uint16 typewriter_keys_count = 0;
uint16 typewriter_delay_counter = 0;
I64 len = StrLen(text);
I64 x=0;
I64 i;
for(i=0; i < len; i++)
{
U8 c = text[i];
if(c == '\n')
{
x = 0;
y_pos++;
goto display_dialog_text_with_color_cont;
}
if(c < 123)
{
if (typewriter_delay_counter > 0)
{
input = hint_dialog_get_input(input);
if(input == FAST_FORWARD)
{
cosmo_wait(1);
}
else
{
if(input == NO_INPUT)
{
for(; typewriter_keys_count > 0; typewriter_keys_count--)
{
cosmo_wait(3);
}
}
}
typewriter_keys_count = typewriter_delay_counter;
if (c != 0x20)
{
//play_sfx(0x2c);
}
video_update();
display_char(x_pos + x, y_pos, c, text_color);
}
else
{
display_char(x_pos + x, y_pos, c, text_color);
}
x++;
}
if(c >= 0xfb && c < 0xff)
{
uint16 frame_num = dialog_text_extract_num(&text[i+1]);
switch(c)
{
case 0xfb : display_cartoon_sequence(frame_num, x_pos + x, y_pos); break;
case 0xfc :
typewriter_keys_count = frame_num;
typewriter_delay_counter = frame_num;
break;
case 0xfd : display_player_sprite(frame_num, x_pos + x, y_pos, 6); break;
case 0xfe :
display_actor_sprite_maybe(frame_num, dialog_text_extract_num(&text[i+4]), x_pos + x - 1, y_pos, 6);
i += 3;
break;
}
i += 3;
}
display_dialog_text_with_color_cont:
}
video_update();
}
U0 display_dialog_text(uint16 x_pos, uint16 y_pos, U8 *text)
{
display_dialog_text_with_color(x_pos, y_pos, text, FONT_WHITE);
}
uint16 draw_dialog_frame(uint16 x_pos, uint16 y_pos, uint16 height, uint16 width, U8 *top_text, U8 *bottom_text, uint8 display_text)
{
video_draw_tile(map_get_bg_tile(1991), x_pos * TILE_WIDTH, y_pos * TILE_HEIGHT);
video_draw_tile(map_get_bg_tile(1992), (x_pos + width-1) * TILE_WIDTH, y_pos * TILE_HEIGHT);
I64 x, y, x1;
for(x=1;x < width-1;x++)
{
video_draw_tile(map_get_bg_tile(1995), (x_pos + x) * TILE_WIDTH, y_pos * TILE_HEIGHT);
video_draw_tile(map_get_bg_tile(1996), (x_pos + x) * TILE_WIDTH, (y_pos + height-1) * TILE_HEIGHT);
for(y=1;y < height-1;y++)
{
video_draw_tile(map_get_bg_tile(1997), x_pos * TILE_WIDTH, (y_pos + y) * TILE_HEIGHT);
video_draw_tile(map_get_bg_tile(1998), (x_pos + width-1) * TILE_WIDTH, (y_pos + y) * TILE_HEIGHT);
for(x1=1;x1 < width-1;x1++)
{
video_draw_tile(map_get_bg_tile(1999), (x_pos + x1) * TILE_WIDTH, (y_pos + y) * TILE_HEIGHT);
}
}
}
video_draw_tile(map_get_bg_tile(1993), x_pos * TILE_WIDTH, (y_pos + height-1) * TILE_HEIGHT);
video_draw_tile(map_get_bg_tile(1994), (x_pos + width-1) * TILE_WIDTH, (y_pos + height-1) * TILE_HEIGHT);
if(display_text)
{
display_dialog_text(0x14 - (StrLen(top_text)/2), y_pos + 1, top_text);
display_dialog_text(0x14 - (StrLen(bottom_text)/2), y_pos + height - 2, bottom_text);
}
video_update();
return x_pos + 1;
}
uint16 create_text_dialog_box(uint16 y_offset, uint16 height, uint16 width, U8 *top_message, U8 *bottom_message)
{
I64 dialog_x = 0x14 - (width / 2);
I64 var_4 = (height / 2) + y_offset;
I64 cur_width = 1;
I64 cur_x, cur_y;
for(cur_x = 0x13; cur_x > dialog_x; cur_x--)
{
cur_width = cur_width + 2;
draw_dialog_frame(cur_x, var_4, 2, cur_width, "", "", 0);
cosmo_wait(1);
}
I64 cur_height = 0;
for(cur_y = var_4;cur_y >= Cond((height & 1), 1, 2) + y_offset; cur_y--)
{
cur_height += 2;
draw_dialog_frame(dialog_x, cur_y, cur_height, width, "", "", 0);
cosmo_wait(1);
}
return draw_dialog_frame(dialog_x, y_offset, height, width, top_message, bottom_message, 1);
}
U0 display_clear_tile_to_gray(uint16 x, uint16 y)
{
video_draw_tile(map_get_bg_tile(1999), x * TILE_WIDTH, y * TILE_HEIGHT);
}
I64 wait_for_input_with_repeat(I64 spinner_x, I64 spinner_y, Bool allow_key_repeat)
{
video_update();
reset_player_control_inputs();
flush_input();
uint16 spinner_idx = 0;
I64 keycode = poll_for_key_press(allow_key_repeat);
while(keycode == SDLK_UNKNOWN && !Bt(kbd.down_bitmap, SC_ESC))
{
//Draw spinning cursor
video_draw_tile(map_get_bg_tile(1987+spinner_idx), spinner_x * TILE_WIDTH, spinner_y * TILE_HEIGHT);
video_update();
if(spinner_idx == 3)
spinner_idx = 0;
else
spinner_idx++;
cosmo_wait(5);
keycode = poll_for_key_press(allow_key_repeat);
}
display_clear_tile_to_gray(spinner_x, spinner_y);
return keycode;
}
I64 wait_for_input(I64 spinner_x, I64 spinner_y)
{
return wait_for_input_with_repeat(spinner_x, spinner_y, FALSE);
}
MenuItem main_menu_items[14] = {
{0, 5, " B)egin New Game", Char2ScanCode('b')},
{0, 6, " R)estore A Game", Char2ScanCode('r')},
{0, 7, " S)tory", Char2ScanCode('s')},
{0, 8, " I)nstructions", Char2ScanCode('i')},
{0, 9, " H)igh Scores", Char2ScanCode('h')},
{0, 10, " G)ame Redefine", Char2ScanCode('g')},
{0, 12, " O)rdering Info.", Char2ScanCode('o')},
{0, 14, " F)oreign Orders", Char2ScanCode('f')},
{0, 15, " A)pogee's BBS", Char2ScanCode('a')},
{0, 0x10, " D)emo", Char2ScanCode('d')},
{0, 0x11, " C)redits", Char2ScanCode('c')},
{0, 0x12, " T)itle Screen", Char2ScanCode('t')},
{0, 0x14, " Q)uit Game", Char2ScanCode('q')},
{0, 0, NULL, 0}
};
U0 ingame_hint_dialogs(uint16 hint_number) {
cosmo_wait(0x1e);
flush_input();
uint16 x;
if(hint_number != 0 && hint_number < 15)
{
x = create_text_dialog_box(2, 9, 0x1c, "COSMIC HINT!", "Press any key to exit.");
display_dialog_text(x, 8, " Press SPACE to hurry or");
}
switch (hint_number)
{
case 0:
x = create_text_dialog_box(2, 11, 0x1c, "COSMIC HINT!", "Press any key to exit.");
display_dialog_text(x, 10, " Press SPACE to hurry or");
display_dialog_text(x, 5, " These hint globes will\n"
" help you along your\n"
" journey. Press the up\n"
" key to reread them");
wait_for_input(x + 0x19, 11);
break;
case 1:
display_dialog_text(x, 5, " Bump head into switch\n above!");
break;
case 2:
display_dialog_text(x, 5, " The ice in this cave is\n very, very slippery.");
break;
case 3:
display_dialog_text(x, 5, " Use this shield for\n temporary invincibility.");
break;
case 4:
display_dialog_text(x, 5, " You found a secret\n area!!! Good job!");
break;
case 5:
display_dialog_text(x, 5, " In high places look up\n to find bonus objects.");
break;
case 6:
display_dialog_text(x, 5, " Out of Order...");
break;
case 7:
display_dialog_text(x, 5, " This might be a good\n time to save your game!");
break;
case 8:
display_dialog_text(x, 5, " Press your up key to\n use the transporter.");
break;
case 9:
display_dialog_text(x, 5, " (1) FOR...");
break;
case 10:
display_dialog_text(x, 5, " (2) EXTRA...");
break;
case 11:
display_dialog_text(x, 5, " (3) POINTS,...");
break;
case 12:
display_dialog_text(x, 5, " (4) DESTROY...");
break;
case 13:
display_dialog_text(x, 5, " (5) HINT...");
break;
case 14:
display_dialog_text(x, 5, " (6) GLOBES!!!");
break;
case 15:
x = create_text_dialog_box(2, 11, 0x1c, "COSMIC HINT!", "Press any key to exit.");
display_dialog_text(x + 0x16, 8, "");
display_dialog_text(x, 10, " Press SPACE to hurry or");
display_dialog_text(x, 5, " The Clam Plants won't\n hurt you if their\n mouths are closed.");
wait_for_input(x + 0x19, 11);
break;
case 16:
x = create_text_dialog_box(2, 10, 0x1c, "COSMIC HINT!", "Press any key to exit.");
display_dialog_text(x, 9, " Press SPACE to hurry or");
display_dialog_text(x + 0x17, 7, "\n Collect the STARS to\n advance to BONUS\n STAGES.");
wait_for_input(x + 0x19, 10);
break;
case 17:
x = create_text_dialog_box(2, 10, 0x1c, "COSMIC HINT!", "Press any key to exit.");
display_dialog_text(x, 9, " Press SPACE to hurry or");
display_dialog_text(x, 5, " Some creatures require\n more than one pounce\n to defeat!");
wait_for_input(x + 0x19, 10);
break;
case 18:
x = create_text_dialog_box(2, 9, 0x1e, "COSMIC HINT!", "Press any key to exit.");
display_dialog_text(x + 0x19, 8, "\xfd""032");
display_dialog_text(x, 8, " Press SPACE to hurry or");
display_dialog_text(x, 5, " Cosmo can climb wall's\n with his suction hands.");
wait_for_input(x + 0x1b, 9);
break;
}
if(hint_number != 0 && hint_number < 15)
{
wait_for_input(x + 0x19, 9);
}
}
/*
uint16 x = create_text_dialog_box(4, 13, 0x1a, "A game by", "Copyright (c) 1992");
display_dialog_text(x, 7, " Todd J Replogle");
display_dialog_text(x + 11, 9, "and");
display_dialog_text(x, 11, "\xfd""027 Stephen A Hornback""\xfd""004");
display_dialog_text(x, 13, " Version 1.20");
wait_for_time_or_key(0x2bc);
fade_to_black_speed_3();
}
*/
U0 end_game_dialog(uint16 dialog_number) {
if(get_episode_number() != 1)
{
return;
}
flush_input();
reset_player_control_inputs();
if(dialog_number == 0xa6)
{
finished_game_flag_maybe = 1;
return;
}
if(dialog_number == 0xa4 || dialog_number == 0xa5)
{
uint16 x = create_text_dialog_box(2, 8, 0x1c, "", "Press any key to exit.");
if(dialog_number == 0xa4)
{
display_dialog_text(x, 4, "\xfc003 What's happening? Is\n Cosmo falling to his\n Doom?");
}
else
{
display_dialog_text(x, 4, "\xfc003 Is there no end to this\n pit? And what danger\n awaits below?!");
}
wait_for_input(x + 0x19, 8);
}
}
U0 display_menu_items(I64 x_offset, MenuItem *menu_items)
{
MenuItem *item = menu_items;
I64 i;
for(i=0; item->text != NULL; item++, i++)
{
display_dialog_text_with_color(x_offset + item->x_pos, item->y_pos, item->text, Cond(i == cur_selected_item, 2, FONT_WHITE));
}
}
U0 menu_handle_arrow_key(I64 key, MenuItem *items) {
I64 num_items = 0;
MenuItem *item;
for(item = items; item->text != NULL; item++)
{
num_items++;
}
if(key == SDLK_DOWN)
{
cur_selected_item = (cur_selected_item + 1) % num_items;
}
if(key == SDLK_UP)
{
cur_selected_item = cur_selected_item - 1;
if(cur_selected_item < 0)
cur_selected_item = num_items - 1;
}
}
I64 display_menu_items_in_dialog(I64 x_offset,
MenuItem *menu_items,
I64 spinner_x, I64 spinner_y)
{
cur_selected_item = 0;
I64 key = 0;
do {
display_menu_items(x_offset, menu_items);
key = wait_for_input_with_repeat(spinner_x, spinner_y, TRUE);
if (Bt(kbd.down_bitmap, SC_CURSOR_UP))
key = SDLK_UP;
if (Bt(kbd.down_bitmap, SC_CURSOR_DOWN))
key = SDLK_DOWN;
if(key == SDLK_UP || key == SDLK_DOWN)
{
menu_handle_arrow_key(key, menu_items);
}
} while(key == SDLK_UP || key == SDLK_DOWN);
//if(is_return_key(key))
if (Bt(kbd.down_bitmap, SC_ENTER))
{
key = menu_items[cur_selected_item].action_key;
}
return key;
}
I64 quit_game_dialog()
{
uint16 x = create_text_dialog_box(11, 4, 0x12, "Are you sure you", "want to quit? ");
I64 key = wait_for_input(x + 14, 13);
//if (key == SDLK_y || is_return_key(key))
if (Bt(kbd.down_bitmap, Char2ScanCode('y')) || Bt(kbd.down_bitmap, SC_ENTER))
{
return 1;
}
return 0;
}
U0 main_menu_dialog()
{
cur_selected_item = 0;
I64 x = create_text_dialog_box(2, 0x15, 0x14, "MAIN MENU", "");
display_menu_items(x, main_menu_items);
}
U8 level_numbers_tbl[18] ={ 1, 2, 0, 0, 3, 4, 0, 0, 5, 6, 0, 0, 7, 8, 0, 0, 9, 10 };
U0 now_entering_level_n_dialog(uint16 level_number)
{
if(game_play_mode == 0)
{
uint16 x = create_text_dialog_box(7, 3, 0x18, " Now entering level ", "");
cosmo_wait(0x14);
//play_sfx(0x40);
if(level_numbers_tbl[level_number] != 10)
{
display_number(x + 0x14, 8, level_numbers_tbl[level_number]);
}
else
{
display_number(x + 0x15, 8, level_numbers_tbl[level_number]);
}
video_update();
}
}
I64 main_menu() {
set_initial_game_state();
show_one_moment_screen_flag = 0;
//load_music(0x12);
display_fullscreen_image(1);
flush_input();
I64 i, return_to_title;
Bool key_handled = FALSE;
I64 key;
for(i=0;i=i;i+=3)
{
if (Bt(kbd.down_bitmap, Char2ScanCode('q')) || Bt(kbd.down_bitmap, SC_ESC))
{
if (quit_game_dialog())
{
return QUIT_GAME;
}
}
uint16 restore_status = 0;
for(return_to_title=0;!return_to_title;)
{
main_menu_dialog();
//key_handled = TRUE;
while(!key_handled && !return_to_title)
{
key = display_menu_items_in_dialog(11, main_menu_items, 0x1c, 0x15);
//switch(key)
//{
//case SDLK_ESCAPE :
//case SDLK_q :
if (Bt(kbd.down_bitmap, Char2ScanCode('q')) ||
Bt(kbd.down_bitmap, SC_ESC))
{
if(quit_game_dialog())
{
return QUIT_GAME;
}
return_to_title = 1;
i = 0;
}
//case SDLK_b :
//case SDLK_SPACE :
if (Bt(kbd.down_bitmap, Char2ScanCode('b')) ||
Bt(kbd.down_bitmap, Char2ScanCode(' ')))
{
//stop_music();
show_one_moment_screen_flag = 1;
show_monster_attack_hint = 0;
//play_sfx(0x30);
return PLAY_GAME;
}
//case SDLK_r :
if (Bt(kbd.down_bitmap, Char2ScanCode('r')))
{
//restore_status = restore_savegame_dialog();
if(restore_status == 1)
{
//stop_music();
return PLAY_GAME;
}
if(restore_status == 0)
{
//missing_savegame_dialog();
}
//break;
}
//case SDLK_i :
if (Bt(kbd.down_bitmap, Char2ScanCode('i')))
{
//instructions_dialog();
}
//break;
//case SDLK_s :
if (Bt(kbd.down_bitmap, Char2ScanCode('s')))
{
//story_dialog();
}
//break;
//case SDLK_g :
if (Bt(kbd.down_bitmap, Char2ScanCode('g')))
{
//game_redefine();
}
//break;
//case SDLK_F11 :
if (Bt(kbd.down_bitmap, SC_F11))
{
//if (cheat_mode_flag)
//{
// return RECORD_DEMO;
//}
}
//break;
//case SDLK_o :
if (Bt(kbd.down_bitmap, Char2ScanCode('o')))
{
//ordering_info_dialog();
}
//break;
//case SDLK_f :
if (Bt(kbd.down_bitmap, Char2ScanCode('f')))
{
//foreign_orders_dialog();
}
//break;
//case SDLK_a :
if (Bt(kbd.down_bitmap, Char2ScanCode('a')))
{
//apogee_bbs_dialog();
}
//break;
//case SDLK_d :
if (Bt(kbd.down_bitmap, Char2ScanCode('d')))
{
return PLAY_DEMO;
}
//case SDLK_h :
if (Bt(kbd.down_bitmap, Char2ScanCode('h')))
{
fade_to_black_speed_3();
video_fill_screen_with_black();
//display_high_score_dialog(TRUE);
}
//break;
//case SDLK_c :
if (Bt(kbd.down_bitmap, Char2ScanCode('c')))
{
display_fullscreen_image(2);
while(poll_for_key_press(FALSE)==SDLK_UNKNOWN)
{}
}
//break;
//case SDLK_t :
if (Bt(kbd.down_bitmap, Char2ScanCode('t')))
{
return_to_title = 1;
i = 0;
}
//break;
//default :
// key_handled = FALSE;
// break;
}
if (i<600) display_fullscreen_image(1);
}
if(i==600)
{
display_fullscreen_image(2);
}
if(i == 1200)
{
return PLAY_DEMO;
}
cosmo_wait(3);
}
}
U0 no_bombs_dialog() {
if(game_play_mode == PLAY_GAME)
{
//play_sfx(0x1e);
uint16 x = create_text_dialog_box(2, 4, 0x1c, "", "");
x++;
display_dialog_text(x, 3, "You haven't found any");
display_dialog_text(x, 4, "bombs to use yet! ");
cosmo_wait(0x3c);
wait_for_input(x-1 + 0x19, 4);
}
}
U0 power_up_module_dialog()
{
if(game_play_mode == PLAY_GAME)
{
//play_sfx(0x1e);
I64 si = create_text_dialog_box(2, 5, 0x16, "", "");
display_dialog_text(si, 3, " Power Up modules");
display_dialog_text(si, 4, " increase Cosmo's");
display_dialog_text(si, 5, " health. ");
cosmo_wait(0x3c);
flush_input();
wait_for_input(si + 8, 5);
}
}
U0 monster_attack_hint_dialog()
{
if(game_play_mode == PLAY_GAME)
{
//play_sfx(0x1e);
uint16 si = create_text_dialog_box(2, 5, 0x16, "REMINDER: Jump on", "defend yourself. ");
display_dialog_text(si, 4, " top of creatures to");
cosmo_wait(0x3c);
wait_for_input(si + 0x13, 5);
si = create_text_dialog_box(2, 13, 0x14, "Like this...", "Press ANY key.");
display_dialog_text(si + 5, 9, " ");
display_dialog_text(si + 5, 11, " ");
cosmo_wait(0x3c);
wait_for_input(si + 0x11, 13);
}
}
U0 display_score_from_level()
{
//stop_music();
if(num_stars_collected == 0)
{
fade_in_from_black_with_delay_3();
return;
}
fade_to_white(3);
video_fill_screen_with_black();
create_text_dialog_box(2, 0xe, 0x1e, "Super Star Bonus!!!!", "");
display_actor_sprite_maybe(1, 2, 8, 8, 6);
display_dialog_text(0xe, 7, "X 1000 =");
display_number(0x1b, 7, num_stars_collected * 1000);
cosmo_wait(0x32);
display_dialog_text(0xa, 0xc, "YOUR SCORE = ");
display_number(0x1d, 0xc, score);
fade_in_from_black_with_delay_3();
cosmo_wait(0x64);
I64 star_counter = 0;
I64 i, j;
for(i=num_stars_collected; i > 0; i--)
{
score += 1000;
cosmo_wait(0xf);
for(j=0; j < 7; j++)
{
display_clear_tile_to_gray(0x17 + j, 0xc);
}
//play_sfx(1);
display_number(0x1d, 0xc, score);
if (star_counter / 6 < 13)
{
star_counter++;
}
for(j=0; j < 16; j++)
{
if(j < 7)
{
display_clear_tile_to_gray(0x16 + j, 7);
}
if((star_counter & 7) == 1)
{
display_clear_tile_to_gray(0xd + j, 0xe);
}
}
display_number(0x1b, 7, i * 1000);
video_update();
if((star_counter & 7) == 1)
{
uint8 score_text_idx = (star_counter/6);
if(score_text_idx > 12)
{
score_text_idx = 12;
}
display_dialog_text(0xd, 0xe, score_text_tbl[score_text_idx]);
}
video_update();
}
cosmo_wait(0x190);
num_stars_collected = 0;
}
U0 display_end_of_level_score_dialog(U8 *header_text, U8 *footer_text)
{
fade_to_black_speed_3();
video_fill_screen_with_black();
uint16 x = create_text_dialog_box(6, 4, 0x1e, header_text, footer_text);
fade_in_from_black_with_delay_3();
wait_for_input(x + 0x1b, 8);
display_score_from_level();
fade_to_black_speed_3();
video_fill_screen_with_black();
}

562
Effects.HC

@ -0,0 +1,562 @@
extern U8 rain_flag;
extern U0 actor_add_new(I64 image_index, I64 x_pos, I64 y_pos);
extern U0 actor_toss_add_new(I64 actorInfoIndex, I64 x_pos, I64 y_pos);
extern U16 word_2E1E2;
extern TileInfo *actor_get_tile_info(I64 actorInfoIndex, I64 frame_num);
extern I64 sprite_blocking_check(I64 blocking_dir, I64 actorInfoIndex, I64 frame_num, I64 x_pos, I64 y_pos);
extern I64 is_sprite_on_screen(I64 actorInfoIndex, I64 frame_num, I64 x_pos, I64 y_pos);
extern uint16 brightness_effect_enabled_flag;
extern U0 video_draw_highlight_effect(uint16 x, uint16 y, uint8 type);
#define MAX_EFFECT_SPRITES 10
#define MAX_EXPLODE_EFFECT_SPRITES 16
#define MAX_STRUCT6_SPRITES 7
#define MAX_BRIGHTNESS_OBJS 0xc7
class effect_sprite
{
I64 is_active_flag;
I64 actorInfoIndex;
I64 frame_num;
I64 x;
I64 y;
I64 field_A;
I64 counter;
};
class explode_effect_sprite
{
I64 actorInfoIndex;
I64 x;
I64 y;
I64 frame_num;
I64 counter;
I64 direction;
I64 fall_through_floor;
};
class struc_6
{
I64 counter;
I64 x;
I64 y;
};
class Brightness
{
I64 type;
I64 x;
I64 y;
};
uint16 num_brightness_objs = 0;
Brightness brightness_tbl[MAX_BRIGHTNESS_OBJS + 1];
effect_sprite static_effect_sprites[MAX_EFFECT_SPRITES];
uint16 effect_frame_num_tbl[MAX_EFFECT_SPRITES];
explode_effect_sprite explode_effect_sprites[MAX_EXPLODE_EFFECT_SPRITES];
struc_6 struc6_sprites[MAX_STRUCT6_SPRITES];
U0 effect_add_sprite(I64 actorInfoIndex, I64 frame_num, I64 x_pos, I64 y_pos, I64 arg_8, I64 counter)
{
I64 i;
for(i=0;i<MAX_EFFECT_SPRITES;i++)
{
effect_sprite *sprite = &static_effect_sprites[i];
if(!sprite->is_active_flag)
{
sprite->is_active_flag = 1;
sprite->actorInfoIndex = actorInfoIndex;
sprite->frame_num = frame_num;
sprite->x = x_pos;
sprite->y = y_pos;
sprite->field_A = arg_8;
sprite->counter = counter;
effect_frame_num_tbl[i] = 0;
return;
}
}
}
U0 effect_clear_sprites()
{
I64 i;
for(i=0; i < MAX_EFFECT_SPRITES; i++)
{
static_effect_sprites[i].is_active_flag = 0;
}
}
U0 explode_effect_add_sprite(I64 actorInfoIndex, I64 frame_num, I64 x_pos, I64 y_pos)
{
uint8 explode_direction = 0;
I64 i;
explode_direction++;
if(explode_direction == 5)
{
explode_direction = 0;
}
for(i=0;i < MAX_EXPLODE_EFFECT_SPRITES; i++)
{
explode_effect_sprite *sprite = &explode_effect_sprites[i];
if(sprite->counter == 0)
{
sprite->actorInfoIndex = actorInfoIndex;
sprite->x = x_pos;
sprite->y = y_pos;
sprite->frame_num = frame_num;
sprite->counter = 1;
sprite->direction = explode_direction;
sprite->fall_through_floor = 0;
return;
}
}
return ;
}
U0 explode_effect_clear_sprites()
{
I64 i;
for(i=0;i < MAX_EXPLODE_EFFECT_SPRITES; i++)
{
explode_effect_sprites[i].counter = 0;
}
}
U0 update_rain_effect() //FIXME this rain doesn't look quite right. The lightning palette anim might need tweaking.
{
I64 x = (cosmo_rand % 38) + mapwindow_x_offset;
I64 y = (cosmo_rand % 18) + mapwindow_y_offset;
I64 map_tile_cell = map_get_tile_cell(x, y);
if((cosmo_rand & 1) != 0)
{
if((tileattr_mni_data[map_tile_cell / 8] & TILE_ATTR_SLIPPERY) != 0)
{
effect_add_sprite(0x63, 5, x, y, 0, 1);
}
}
if(rain_flag != 0)
{
y = mapwindow_y_offset + 1;
if(map_get_tile_cell(x, y) == 0)
{
effect_add_sprite(0x1b, 1, x, y, 6, 0x14);
}
}
return;
}
U0 exploding_balls_effect(I64 x_pos, I64 y_pos)
{
effect_add_sprite(0x15, 6, x_pos + 1, y_pos, 6, 2);
effect_add_sprite(0x15, 6, x_pos + 3, y_pos, 4, 2);
effect_add_sprite(0x15, 6, x_pos + 4, y_pos - 2, 3, 2);
effect_add_sprite(0x15, 6, x_pos + 3, y_pos - 4, 2, 2);
effect_add_sprite(0x15, 6, x_pos + 1, y_pos - 4, 8, 2);
effect_add_sprite(0x15, 6, x_pos, y_pos - 2, 7, 2);
}
I64 blow_up_actor_with_bomb(I64 actorInfoIndex, I64 frame_num, I64 x_pos, I64 y_pos)
{
switch (actorInfoIndex)
{
case 3:
case 4:
case 17:
case 18:
case 20:
case 25:
case 41:
case 46:
case 47:
case 51:
case 54:
case 55:
case 65:
case 69:
case 74:
case 75:
case 78:
case 80:
case 83:
case 84:
case 86:
case 87:
case 88:
case 89:
case 92:
case 95:
case 96:
case 101:
case 106:
case 111:
case 112:
case 113:
case 118:
case 124:
case 125:
case 126:
case 127:
case 128:
case 129:
case 187:
case 188:
if(actorInfoIndex == 0x7d)
{
actor_add_new(0xb8, x_pos, y_pos);
}
if((actorInfoIndex == 0x12 || actorInfoIndex == 0x58) && frame_num == 2)
{
return 0;
}
else
{
explode_effect_add_sprite(actorInfoIndex, frame_num, x_pos, y_pos);
player_add_score_for_actor(actorInfoIndex);
if(actorInfoIndex == 0x5f)
{
if(word_2E1E2 == 1)
{
actor_add_new(0xf6, player_x_pos - 1, player_y_pos - 5);
}
effect_add_sprite(0x17, 8, x_pos, y_pos, 0, 1);
actor_toss_add_new(0x39, x_pos, y_pos);
word_2E1E2--;
}
}
return 1;
default : break;
}
return 0;
}
Bool struct6_collision_check_maybe(I64 actorInfoIndex1, I64 actor_frame_num1, I64 actor1_x, I64 actor1_y, I64 actorInfoIndex2, I64 actor_frame_num2, I64 actor2_x, I64 actor2_y)
{
TileInfo *actor1_info = actor_get_tile_info(actorInfoIndex1, actor_frame_num1);
uint16 sprite1_width = actor1_info->width;
uint16 si = actor1_info->height;
TileInfo *actor2_info = actor_get_tile_info(actorInfoIndex2, actor_frame_num2);
uint16 sprite2_width = actor2_info->width;
uint16 di = actor2_info->height;
if(actor1_x > map_width_in_tiles && actor1_x <= -1)
{
sprite1_width = actor1_x + sprite1_width;
actor1_x = 0;
}
if(((actor2_x > actor1_x || actor2_x + sprite2_width <= actor1_x) && (actor2_x < actor1_x || actor1_x + sprite1_width <= actor2_x)) ||
((actor1_y - si >= actor2_y || actor2_y > actor1_y) && (actor2_y - di >= actor1_y || actor1_y > actor2_y)))
{
return 0;
}
return 1;
}
I64 struct6_1B4FC(I64 actorInfoIndex, I64 frame_num, I64 x_pos, I64 y_pos)
{
I64 i;
for(i=0; i < MAX_STRUCT6_SPRITES; i++)
{
struc_6 *sprite = &struc6_sprites[i];
if(sprite->counter != 0)
{
if(struct6_collision_check_maybe(0x1a, 0, sprite->x, sprite->y, actorInfoIndex, frame_num, x_pos, y_pos) != 0)
{
return 1;
}
}
}
return 0;
}
U0 struct6_clear_sprites()
{
I64 i;
for(i=0; i < MAX_STRUCT6_SPRITES; i++)
{
struc6_sprites[i].counter = 0;
}
}
U0 struct6_add_sprite(I64 x_pos, I64 y_pos)
{
I64 i;
for(i=0; i < MAX_STRUCT6_SPRITES; i++)
{
struc_6 *sprite = &struc6_sprites[i];
if (sprite->counter == 0)
{
sprite->counter = 1;
sprite->x = x_pos;
sprite->y = y_pos + 2;
//play_sfx(0xa);
return;
}
}
}
U0 add_brightness_obj(uint8 type, I64 x_pos, I64 y_pos)
{
if (num_brightness_objs != MAX_BRIGHTNESS_OBJS)
{
brightness_tbl[num_brightness_objs].type = type;
brightness_tbl[num_brightness_objs].x = x_pos;
brightness_tbl[num_brightness_objs].y = y_pos;
num_brightness_objs++;
}
}
U0 clear_brightness_objs()
{
num_brightness_objs = 0;
}
U0 explode_effect_update_sprites()
{
I64 i;
for(i=0;i < MAX_EXPLODE_EFFECT_SPRITES; i++)
{
explode_effect_sprite *sprite = &explode_effect_sprites[i];
if (sprite->counter == 0)
{
goto explode_while_cont2;
}
if(sprite->direction == 0 || sprite->direction == 3)
{
if(sprite_blocking_check(RIGHT, sprite->actorInfoIndex, sprite->frame_num, sprite->x + 1, sprite->y + 1) == NOT_BLOCKED)
{
sprite->x++;
if(sprite->direction == 3)
{
sprite->x++;
}
}
}
else
{
if(sprite->direction == 1 || sprite->direction == 4)
{
if(sprite_blocking_check(LEFT, sprite->actorInfoIndex, sprite->frame_num, sprite->x - 1, sprite->y + 1) == NOT_BLOCKED)
{
sprite->x--;
if(sprite->direction == 4)
{
sprite->x--;
}
}
}
}
//for(;;)
while(1)
{
if(sprite->counter < 5)
{
sprite->y -= 2;
}
if(sprite->counter == 5)
{
sprite->y--;
}
else if(sprite->counter == 8)
{
if (sprite_blocking_check(DOWN, sprite->actorInfoIndex, sprite->frame_num, sprite->x, sprite->y + 1) ==
NOT_BLOCKED)
{
sprite->y++;
}
else
{
sprite->counter = 3;
sprite->y += 2;
goto explode_while_cont1;
}
}
if(sprite->counter < 9)
{
if(sprite->counter == 1)
{
display_actor_sprite_maybe(sprite->actorInfoIndex, sprite->frame_num, sprite->x, sprite->y, 2);
}
else
{
display_actor_sprite_maybe(sprite->actorInfoIndex, sprite->frame_num, sprite->x, sprite->y, 4);
}
sprite->counter++;
if(sprite->counter > 40)
{
sprite->counter = 0;
}
break;
}
if(sprite->counter > 16 && is_sprite_on_screen(sprite->actorInfoIndex, sprite->frame_num, sprite->x, sprite->y) == 0)
{
sprite->counter = 0;
break;
}
if(sprite->fall_through_floor != 0 || sprite_blocking_check(DOWN, sprite->actorInfoIndex, sprite->frame_num, sprite->x, sprite->y + 1) == NOT_BLOCKED)
{
sprite->y++;
if(sprite->fall_through_floor != 0 || sprite_blocking_check(DOWN, sprite->actorInfoIndex, sprite->frame_num, sprite->x, sprite->y + 1) == NOT_BLOCKED)
{
if(sprite->counter == 1)
{
display_actor_sprite_maybe(sprite->actorInfoIndex, sprite->frame_num, sprite->x, sprite->y, 2);
}
else
{
display_actor_sprite_maybe(sprite->actorInfoIndex, sprite->frame_num, sprite->x, sprite->y, 4);
}
sprite->counter++;
if(sprite->counter > 40)
{
sprite->counter = 0;
}
break;
}
}
sprite->counter = 3;
sprite->fall_through_floor = 1;
//play_sfx(0x2e);
explode_while_cont1:
}
explode_while_cont2:
}
}
U0 struct6_update_sprites()
{
I64 i;
for(i=0; i < MAX_STRUCT6_SPRITES; i++)
{
struc_6 *sprite = &struc6_sprites[i];
if(sprite->counter != 0)
{
if(sprite->counter == 1)
{
effect_add_sprite(0x17, 8, sprite->x + 1 + 1, sprite->y - 2, 0, 1);
}
display_actor_sprite_maybe(0x1a, sprite->counter - 1 & 3, sprite->x, sprite->y, 0);
if(player_check_collision_with_actor(0x1a, sprite->counter - 1 & 3, sprite->x, sprite->y) != 0)
{
player_decrease_health();
}
sprite->counter++;
if(sprite->counter == 9)
{
sprite->counter = 0;
effect_add_sprite(0x62, 6, sprite->x + 1, sprite->y - 1, 1, 1);
}
}
}
}
U0 effect_update_sprites()
{
I64 i;
for(i=0; i < MAX_EFFECT_SPRITES; i++)
{
effect_sprite *sprite = &static_effect_sprites[i];
if(sprite->is_active_flag)
{
if(is_sprite_on_screen(sprite->actorInfoIndex, sprite->frame_num, sprite->x, sprite->y))
{
if(sprite->actorInfoIndex == 0x63)
{
display_actor_sprite_maybe(sprite->actorInfoIndex, effect_frame_num_tbl[i], sprite->x, sprite->y, 5);
}
else
{
display_actor_sprite_maybe(sprite->actorInfoIndex, effect_frame_num_tbl[i], sprite->x, sprite->y, 0);
}
if(sprite->actorInfoIndex == 0x1b)
{
sprite->x--;
sprite->y = sprite->y + (cosmo_rand() % 3);
}
sprite->x = sprite->x + player_x_offset_tbl[sprite->field_A];
sprite->y = sprite->y + player_y_offset_tbl[sprite->field_A];
effect_frame_num_tbl[i]++;
if(effect_frame_num_tbl[i] == sprite->frame_num)
{
effect_frame_num_tbl[i] = 0;
if(sprite->counter != 0)
{
sprite->counter--;
if(sprite->counter == 0)
{
sprite->is_active_flag = 0;
}
}
}
}
else
{
sprite->is_active_flag = 0;
}
}
}
return;
}
U0 update_brightness_objs()
{
if(brightness_effect_enabled_flag == 0)
return;
I64 i, j;
for(i=0;i<num_brightness_objs;i++)
{
Brightness *brightness = &brightness_tbl[i];
if(brightness->x >= mapwindow_x_offset && brightness->x < mapwindow_x_offset + MAP_WINDOW_WIDTH &&
brightness->y >= mapwindow_y_offset && brightness->y < mapwindow_y_offset + MAP_WINDOW_HEIGHT)
{
video_draw_highlight_effect((brightness->x - mapwindow_x_offset + 1) * TILE_WIDTH, (brightness->y - mapwindow_y_offset + 1) * TILE_HEIGHT, brightness->type);
uint16 tile_attr = tileattr_mni_data[map_get_tile_cell(brightness->x,brightness->y + 1)/8];
for(j = 1; !(tile_attr & TILE_ATTR_BLOCK_DOWN);)
{
if(brightness->x >= mapwindow_x_offset && brightness->x < mapwindow_x_offset + MAP_WINDOW_WIDTH &&
brightness->y + j >= mapwindow_y_offset && brightness->y + j < mapwindow_y_offset + MAP_WINDOW_HEIGHT)
{
video_draw_highlight_effect((brightness->x - mapwindow_x_offset + 1) * TILE_WIDTH,
(brightness->y + j - mapwindow_y_offset + 1) * TILE_HEIGHT, 1);
}
j++;
tile_attr = tileattr_mni_data[map_get_tile_cell(brightness->x,brightness->y + j)/8];
}
}
}
}

169
File.HC

@ -0,0 +1,169 @@
class File {
U8 *filename;
U8 *data;
U8 *idata;
U8 *mode;
U32 size;
U32 pos;
U32 initial_offset;
};
U0 file_close(File *file) {
if (!StrCmp("wb", file->mode))
{
if(file->data)
{
FileWrite(file->filename, file->data, file->size);
}
}
if(file->idata)
{
Free(file->idata);
return;
}
if(file->data)
{
Free(file->data);
}
}
U32 file_get_current_position(File *file)
{
if (file)
return file->pos;
return 0;
}
U32 file_get_filesize(File *file)
{
if (file)
return file->size;
return 0;
}
Bool file_open(U8 *filename, U8 *mode, File *file) {
if (!StrCmp("rb", mode))
{
if (!FileFind(filename))
{
"Failed opening '%s'\n", filename;
return FALSE;
}
file->filename = StrNew(filename);
file->data = FileRead(filename, &file->size);
file->idata = NULL;
file->mode = StrNew(mode);
file->pos = 0;
file->initial_offset = 0;
return TRUE;
}
// FIXME: add "wb" mode
if (!StrCmp("wb", mode))
{
file->filename = StrNew(filename);
file->data = CAlloc(WB_SIZE);
file->idata = NULL;
file->mode = StrNew(mode);
file->pos = 0;
file->size = 0;
file->initial_offset = 0;
return TRUE;
}
return FALSE;
}
Bool file_open_at_offset(U8 *filename, U8 *mode, File *file, uint32 offset, uint32 size)
{
if (!file_open(filename, mode, file))
{
"Failed opening '%s'\n", filename;
return FALSE;
}
if(offset + size >= file->size)
{
"Failed opening '%s' offset + size >= actual_size\n", filename;
file_close(file);
return FALSE;
}
file->idata = file->data;
file->data = file->idata + offset;
file->size = size;
file->pos = 0;
//file->pos = offset;
return TRUE;
}
U0 file_seek(File *file, uint32 new_position) {
if(file->data && new_position <= file->size)
{
file->pos = new_position;
}
return;
}
U32 file_read_to_buffer(File *file, U8 *buf, uint32 num_bytes) {
if(file->pos + num_bytes > file->size)
num_bytes = file->size - file->pos;
MemCpy(buf, file->data + file->pos, num_bytes);
file->pos += num_bytes;
return num_bytes;
}
U8 file_read1(File *file) {
if(!file->data || file->pos >= file->size)
return 0;
U64 b0 = file->data[file->pos++];
return b0;
}
U16 file_read2(File *file) {
if(!file->data || file->pos >= file->size)
return 0;
U64 b0 = file->data[file->pos++];
U64 b1 = file->data[file->pos++];
return (b0 + (b1<<8));
}
U32 file_read4(File *file) {
if(!file->data || file->pos >= file->size)
return 0;
U64 b0 = file->data[file->pos++];
U64 b1 = file->data[file->pos++];
U64 b2 = file->data[file->pos++];
U64 b3 = file->data[file->pos++];
return (b0 + (b1<<8) + (b2<<16) + (b3<<24));
}
U0 file_write1(U8 byte, File *file) {
file->data[file->pos++] = byte;
if(file->pos > file->size)
file->size = file->pos;
}
U0 file_write2(U16 word, File *file)
{
file->data[file->pos++] = word & 0xff;
file->data[file->pos++] = (word >> 8) & 0xff;
if(file->pos > file->size)
file->size = file->pos;
}
U0 file_write4(U32 double_word, File *file)
{
file->data[file->pos++] = double_word & 0xff;
file->data[file->pos++] = (double_word >> 8) & 0xff;
file->data[file->pos++] = (double_word >> 16) & 0xff;
file->data[file->pos++] = (double_word >> 24) & 0xff;
if(file->pos > file->size)
file->size = file->pos;
}

57
Font.HC

@ -0,0 +1,57 @@
extern U0 video_draw_font_tile(Tile *tile, uint16 x, uint16 y, uint8 font_color);
#define FONT_WHITE 0xf
Tile *font_tiles;
U0 font_load_tiles()
{
uint16 num_tiles;
font_tiles = load_tiles("FONTS.MNI", FONT, &num_tiles);
"Loading %d font tiles.\n", num_tiles;
}
U0 display_number(I64 x_pos, I64 y_pos, uint32 number)
{
uint8 font_color = FONT_WHITE;
I64 i;
U8 buf[32];
StrPrint(buf, "%d", number);
for(i=0;i < StrLen(buf); i++)
{
video_draw_font_tile(&font_tiles[buf[i]-48+26], (x_pos - StrLen(buf) + i + 1) * 8, y_pos * 8, font_color);
}
}
U0 display_char(I64 x_pos, I64 y_pos, U8 c, uint8 font_color)
{
if(c == 0x18 || c == 0x19 || c == 0x1b || c == 0x1c) //FIXME hack to get arrow key font to render.
{
video_draw_font_tile(&font_tiles[c-25 + 3], x_pos * 8, y_pos * 8, font_color);
return;
}
if(c >= 32 && c < 91)
{
video_draw_font_tile(&font_tiles[c-48+26], x_pos * 8, y_pos * 8, font_color);
}
else
{
video_draw_font_tile(&font_tiles[c-97+69], x_pos * 8, y_pos * 8, font_color);
}
}
U0 display_text_with_color(I64 x_pos, I64 y_pos, U8 *text, uint8 color)
{
I64 len = StrLen(text);
I64 i;
for(i=0; i < len; i++)
{
display_char(x_pos + i, y_pos, text[i], color);
}
}
U0 display_text(I64 x_pos, I64 y_pos, U8 *text)
{
display_text_with_color(x_pos, y_pos, text, 0xf);
}

90
Fullscreen_Image.HC

@ -0,0 +1,90 @@
extern U0 video_draw_fullscreen_image(uint8 *pixels);
U8 filename_ep1_tbl[6][13] = {
"PRETITLE.MNI",
"TITLE1.MNI",
"CREDIT.MNI",
"BONUS.MNI",
"END1.MNI",
"ONEMOMNT.MNI"
};
U8 filename_ep2_tbl[6][13] = {
"PRETITLE.MNI",
"TITLE2.MNI",
"CREDIT.MNI",
"BONUS.MNI",
"END2.MNI",
"ONEMOMNT.MNI"
};
U8 filename_ep3_tbl[6][13] = {
"PRETITLE.MNI",
"TITLE3.MNI",
"CREDIT.MNI",
"BONUS.MNI",
"END3.MNI",
"ONEMOMNT.MNI"
};
#define NUM_PIXELS (320 * 200)
U8 *get_filename(uint8 image_number)
{
switch(get_episode_number())
{
case 1 : return filename_ep1_tbl[image_number];
case 2 : return filename_ep2_tbl[image_number];
case 3 : return filename_ep3_tbl[image_number];
default : break;
}
return NULL;
}
U8 *load_image(U8 *filename)
{
uint8 *pixels = MAlloc(320*200);
I64 c, i, j;
File image;
if(!open_file(filename, &image)) {
"failed to open %s\n", filename;
}
for(c=0;c<4;c++) {
for (i = 0; i < NUM_PIXELS / 8; i++) {
uint8 data = file_read1(&image);
for (j = 0; j < 8; j++) {
if(c==0)
{
pixels[i * 8 + j] = (data >> (7 - j)) & 1;
}
else
{
pixels[i * 8 + j] |= ((data >> (7 - j)) & 1) << c;
}
}
}
}
file_close(&image);
return pixels;
}
U0 display_fullscreen_image(uint8 image_number)
{
//assert(image_number < 6);
if(image_number != 1 && image_number != 2)
{
//stop_music();
}
fade_to_black_speed_3();
uint8 *image = load_image(get_filename(image_number));