/* ixGamer.c --> Core functioning _______________________ Created by Daniel Shaw _______________________ Version : Alpha ( 0.0.1 ) Last Updated : 15/10/2006 */ /* Core Libraries & References*/ #include #include #include /* Windows */ TWindow *main_scene; // --> Dummy sequence /* Widgets */ TWidget *splash_image; // --> Splash picture TWidget *title_image; // --> Title image TWidget *map_screen; // --> Map screen /* Surfaces */ ttk_surface main_surface; // --> Main surface for writing ttk_surface splash_surface; // --> Splash image surface ttk_surface title_surface; // --> Title surface ttk_surface map_tiles; // --> Map tileset /* Game Data & Configuration Settings */ char generation[1], game_name[20], *map_id[3], *char_a[25], *logo[104], *title_logo[50], *wskin[50]; int player_x = 0, player_y = 0, facing = 0, title_selector_position = 0, title_xa = 5, title_xb = 50; /* Files */ FILE *data_cfg, *game_data, *map_file; // OLD -- REDOOOOOOOOOOOOOOOOOOOO int max_x; int max_y; int max; char *tileset; int ***get; /* Character Data */ typedef struct character { char *Name; /* Name */ int HP; /* Hit Points */ int MP; /* Magic Points */ int Level; /* Level of abilities */ int X; /* X Co-ordinate */ int Y; /* Y Co-ordinate */ int Dir; /* Facing Direction */ int Visible; /* Visible State */ } character; /* Declare all functions */ void load_map(char id[3]); void start_new_game(); void rmtitle_func(); int titlein_func(TWidget *title_image, int input_type); void title_func(TWidget *title_image, ttk_surface title_surface); void rmsplash_func(); int splashin_func(TWidget *splash_image, int input_type); void splash_func(TWidget *splash_image, ttk_surface splash_surface); void load_fonts(); void check_files(); int main(int argc, char **argv); /* Draw Layer 1 */ // REDOOOOOOOOOOOOOO void draw_layer_one(ttk_surface srf) { int unsigned x_row_get = 0; int unsigned y_row_get = 0; for (y_row_get = 0; y_row_get < max_y; y_row_get++) { for (x_row_get = 0; x_row_get < max_x; x_row_get++) { ttk_blit_image_ex(map_tiles, get[0][y_row_get][x_row_get] * 32, get[1][y_row_get][x_row_get] * 32 , 32, 32, srf, x_row_get * 32, y_row_get * 32); } } } /* Load Map */ // REDOOOOOOOOOOOOO void load_map(char id[3]) { char map_path_name[48]; int unsigned x_row_get = 0; int unsigned y_row_get = 0; sprintf(map_path_name, "game_data/Maps/Map%s.igame", map_id); // Forge path and tileset name into one map_file = fopen(map_path_name, "r"); fscanf(map_file, "%s", tileset); // Get limit counts fscanf(map_file, "%d", &max_x); fscanf(map_file, "%d", &max_y); // Make the limit max = max_x * max_y; // Get the maps for (y_row_get = 0; y_row_get < max_y; y_row_get++) { for (x_row_get = 0; x_row_get < max_x; x_row_get++) { // Load the map data fscanf(map_file, "%d %d %d %d %d %d %d", &get[0][y_row_get][x_row_get], &get[1][y_row_get][x_row_get], &get[2][y_row_get][x_row_get], &get[3][y_row_get][x_row_get], &get[4][y_row_get][x_row_get], &get[5][y_row_get][x_row_get], &get[6][y_row_get][x_row_get]); } } fclose(map_file); // Close the file } /* New Game */ void start_new_game(TWidget *map_screen, ttk_surface main_surface) { // Make player using character attributes character player; // Give the player default stats (HP, MP, etc, etc) player.Name = "Daniel"; player.HP = 60; player.MP = 10; player.Level = 1; player.X = player_x; player.Y = player_y; player.Dir = facing; player.Visible = 1; // Load map file data co-ordinates load_map("3"); // Make tileset path char *tileset_path; sprintf(tileset_path, "game_data/Visuals/Tiles/%s", tileset); // Load map tiles map_tiles = ttk_load_image(tileset_path); // Draw layer one draw_layer_one(main_surface); } /* Remove title function */ void rmtitle_func() { // Add map widget ttk_add_widget(main_scene, map_screen); // Remove title widget ttk_remove_widget(main_scene, title_image); map_screen->draw = start_new_game; map_screen->dirty++; // Start the game! //start_new_game(); } /* Title input functionality */ int titlein_func(TWidget *title_image, int input_type) { // Create default return mode int input_return; // Skip splash screen on the Action Button press switch (input_type) { case TTK_BUTTON_ACTION: // Center / Action switch (title_selector_position) { case 0: // New Game // Remove widget and start game rmtitle_func(); // Return key input_return = TTK_EV_CLICK; break; case 1: // Load Game // Return key input_return = TTK_EV_CLICK; break; case 2: // Quit Game // Return key input_return = TTK_EV_DONE; break; } break; case TTK_BUTTON_PREVIOUS: // Rewind // Make selector go back one if (title_selector_position > 0) title_selector_position--; // Return key input_return = TTK_EV_CLICK; break; case TTK_BUTTON_NEXT: // Fast Forward // Make selector go forward one if (title_selector_position < 2) title_selector_position++; // Return key input_return = TTK_EV_CLICK; break; default: // No input or invalid input // Return no key input_return = TTK_EV_UNUSED; break; } // Refresh title screen title_image->dirty++; // Return raw click data return input_return; } /* Show title function */ void title_func(TWidget *title_image, ttk_surface main_surface) { // Combine title image filename into path char tmptitleimage[105]; sprintf(tmptitleimage, "game_data/Visuals/Title/%s", title_logo); // Load logo if((title_surface = ttk_load_image(tmptitleimage)) == NULL) { // Error message printf("File Error: Unable to open title image\n--------------\n%s\n--------------\n", tmptitleimage); } else { // Display title image on surface ttk_blit_image(title_surface, main_surface, 0, 0); // Load default title options ttk_text(main_surface, ttk_menufont, 10, main_scene->h - 32, ttk_makecol(BLACK), "Begin"); ttk_text(main_surface, ttk_menufont, 68, main_scene->h - 32, ttk_makecol(BLACK), "Load"); ttk_text(main_surface, ttk_menufont, 128, main_scene->h - 32, ttk_makecol(BLACK), "Exit!"); // Draw selector ttk_rect(main_surface, title_xa, main_scene->h - 34, title_xb, main_scene->h - 15, ttk_makecol(0, 255, 0)); // Determine which option to select switch (title_selector_position) { // New Game case 0: title_xa = 50; title_xb = 5; break; // Load Game case 1: title_xa = 108; title_xb = 63; break; // Quit Game case 2: title_xa = 168; title_xb = 123; break; } } } /* Remove splash function */ void rmsplash_func() { // Remove the splash screen widget ttk_remove_widget(main_scene, splash_image); // Assign widget properties to title widget title_image = ttk_new_widget(main_scene->x, main_scene->y); // Add drawing & input properties to title_image & allow input title_image->focusable = 1; title_image->draw = title_func; title_image->down = titlein_func; // Add new title screen widget ttk_add_widget(main_scene, title_image); } /* Splash input functionality */ int splashin_func(TWidget *splash_image, int input_type) { // Create default return mode int input_return; // Skip splash screen on the Action Button press if (input_type == TTK_BUTTON_ACTION) { // Remove splash screen and go to title rmsplash_func(); // Return key input_return = TTK_EV_CLICK; } else { // Return no key input_return = TTK_EV_UNUSED; } // Return raw click data return input_return; } /* Splash function */ void splash_func(TWidget *splash_image, ttk_surface main_surface) { // Add splash timer ttk_create_timer(2400, rmsplash_func); // Show splash image ttk_blit_image(splash_surface, main_surface, ((main_surface->w - splash_surface->w) / 2), ((main_surface->h - splash_surface->h) / 2)); } /* Load Default Fonts */ void load_fonts() { // Load fonts ttk_menufont = ttk_get_font ("Chicago", 12); } /* Check for necessary files */ void check_files() { // iGamer Configuration if ((data_cfg = fopen("igamer.cfg", "r")) == NULL) { // Warning message printf("Warning: No configuration file is detected, Default settings will be used!\n"); } else { // Add generation fscanf(data_cfg, "%s", &generation); // -- \\ fclose(data_cfg); } // -------------------------------------------|Game|Data|-------------------------------------------- // // Game Configuration if ((game_data = fopen("game_data/gdata.igame", "r")) == NULL) { // Error message printf ("Error: Unable to locate project data!\n"); } else { // Add Gamename fscanf(game_data, "%s", game_name); // Add start map id and positions fscanf(game_data, "%s", &map_id); fscanf(game_data, "%d", &player_x); fscanf(game_data, "%d", &player_y); fscanf(game_data, "%d", &facing); fscanf(game_data, "%s", &char_a); fscanf(game_data, "%s", &logo); fscanf(game_data, "%s", &title_logo); fscanf(game_data, "%s", &wskin); // -- \\ fclose(game_data); } } /* Start Function */ int main(int argc, char **argv) { // Tell TTK Where to find the schemes #define SCHEMESDIR "/gamer/share/schemes/" // Show screen ttk_set_emulation(176, 132, 16); // Set initializing screen if ((main_scene = ttk_init()) == 0) { // Error message printf("Critical Error: Failed to initialize ttk\n"); return 0; } // Change default title to loading ttk_window_title(main_scene, "iGamer - Loading..."); // Load fonts load_fonts(); // Check for files check_files(); // Make fullscreen ttk_window_hide_header(main_scene); // Combine logo filename into path char tmplogo[105]; sprintf(tmplogo, "game_data/Visuals/Logos/%s", logo); // Load logo if((splash_surface = ttk_load_image(tmplogo)) == NULL) { // Error message printf("File Error: Unable to open logo\n--------------\n%s\n--------------\n", tmplogo); return 0; } else { // Give splash image, image view properties splash_image = ttk_new_widget(main_scene->x, main_scene->y); // Assign draw & input properties to appropriate splash function and allow input splash_image->focusable = 1; splash_image->draw = splash_func; splash_image->down = splashin_func; // Add Widget to screen ttk_add_widget(main_scene, splash_image); } // Change title to game name ttk_window_title(main_scene, game_name); // Run ttk_run(); // Remove follow elements from memory before ending application: // --> Windows ttk_free_window(main_scene); // --> Widgets ttk_free_widget(splash_image); ttk_free_widget(title_image); ttk_free_widget(map_screen); // --> Surfaces ttk_free_surface(main_surface); ttk_free_surface(splash_surface); ttk_free_surface(title_surface); ttk_free_surface(map_tiles); // Quit igamer ttk_quit(); }