Newer
Older
/** @AGDB
* level_name: Interrupteurs
* program_name: main
* level_number: 1107
* available_commands: next step continue
* map_height: 7
*
* alias: map_array mstack.maps[mstack.length - 1].floor
* alias: exit_x mstack.maps[mstack.length - 1].exit_x
* alias: exit_y mstack.maps[mstack.length - 1].exit_y
* alias: left 4
* alias: right 6
* alias: up 8
* alias: down 2
*
* watch: player_direction player_x player_y
* track: load_map:mstack load_map:player_x load_map:player_y
* BUG: several bugs. One is a string comparison forgetting the \0, one is a template used instead of malloc, one is a stack alloc, the last one is an inversion of y and x
* tag: inverse_xy stack_alloc template string_comparison
* HINT1: What is the value of current_map()->entities for switches?
*/
/**
* Entry point of the game. Manages the main loop, and apart from
* that only calls functions.
*
* Initialization:
* 1) load the map and possible items
* 2) load all events
* 3) initialize the player's position and data
* 4) start the main loop
*
* Main loop:
* 1) apply the player's input (move or action)
* 2) observe triggers, apply each resolution function or applying triggers
* 3) read the next input (file) or wait for the next frame and buffer an input during the wait (real time)
*
* Endgame:
* 1) receive signal from level_success or level_failure
* 2) free all allocated memory
* 3) exit properly
*
* Game design related tip:
* If you want to create a game, note all your ideas, they may serve later.
* Video game is an art as cinema or literature: play lots of games to get a solid culture.
* But beside game design, several fields exist in video games creation:
* - level design
* - storytelling and writing
* - music and sound effets
* - worldbuilding
* - ... and many others!
*/
#include "../../engines/fullgame/agdbentures.h"
#include "events_map.h"
#include "input_manager.h"
#include "custom_map.h"
int main(int argc, char ** argv) {
bool manual_mode = true;
if (argc > 1)
manual_mode = false;
if (manual_mode) {
printf("Manual mode. Available commands: UP, DOWN, LEFT, RIGHT and *_N variants; TOUCH.\nUse Ctrl+C to quit.\n");
if (!init_inputs_file(argv[1])) {
printf("Error while reading the inputs!\n");
return EXIT_FAILURE;
}
init_map(load_map("overworld", str_map));
add_event(verify_exit);
add_event(verify_switch_order);
add_event(drown);
if (manual_mode) {
show_map();
command * com = get_next_input();
// The Holy Main Loop
while (!exit_main_loop) {
/* since the events may be applied if the input is FORWARD_N,
we need to check to avoid triggering the same event twice*/
if (!exit_main_loop)
apply_events();
if (manual_mode)
show_map();
if (!exit_main_loop)
com = get_and_free_input(com);
// plus aucun input mais on a pas encore gagné ou perdu -> défaite
if (!manual_mode && com == NULL && !exit_main_loop)
remove_all_events();
free_map_stack();
return EXIT_SUCCESS;