Engine library
Embed:
(wiki syntax)
Show/hide line numbers
Engine.cpp
00001 #include "Engine.h" 00002 00003 00004 00005 void Engine::init() 00006 { 00007 level_index = 0;//initalises level_index to 0 00008 }; 00009 00010 00011 current_coordinate_struct Engine::handle_input(int new_x, int new_y, Gamepad &pad, N5110 &lcd,Character &character, Levels &levels, Science &science) 00012 { 00013 00014 current_coordinate_struct returned_current_coordinates;//creates an instance of the current coordinate struct 00015 00016 returned_current_coordinates.current_x = new_x;//sets the current_x equal to new_x so when new_x is recalculated a comparison can be done between the currently displayed coordinate aswell. 00017 00018 returned_current_coordinates.current_y = new_y;//sets the current_y equal to new_y so when new_y is recalculated a comparison can be done between the currently displayed coordinate aswell. 00019 00020 00021 //printf("Engine Handle Inputs complete"); 00022 00023 return returned_current_coordinates;//returns the struct 00024 }; 00025 00026 00027 00028 new_coordinate_struct Engine::update(int radius, int current_x, int current_y, Science &science, FXOS8700CQ &device, N5110 &lcd, Levels &levels, Gamepad &pad) 00029 { 00030 Data values = device.get_values();//gets the values from the device 00031 00032 new_coordinate_struct returned_new_coordinates; // creates an instance of the new_coordinate_struct 00033 00034 int x_velocity = science.calculate_x_velocity( device); //calculates the velocity in x 00035 00036 int y_velocity = science.calculate_y_velocity( device); // calculates the velocity in y 00037 //printf("\n update function %i = x vel, %i = y vel \n", x_velocity, y_velocity); 00038 00039 int new_x = science.x_boundary_limiter( science.calculate_next_x(current_x, x_velocity) , radius); // calculates the new position in x then is limited if exceeding the screen boundaries 00040 00041 int new_y = science.y_boundary_limiter( science.calculate_next_y(current_y, y_velocity) , radius); // calculates the new position in y then is limited if exceeding the screen boundaries 00042 //printf("\n update function %i = new_x, %i = new_y after boundary correction \n", new_x, new_y); 00043 00044 int next_y = science.y_collisions_correction (new_x, new_y, current_x, current_y, y_velocity, radius, levels);//next_x is created to prevent the collision corrections from being calculated from the wrong position 00045 00046 int next_x = science.x_collisions_correction (new_x, new_y, current_x, current_y, x_velocity, radius, levels);//next_y is created to prevent the collision corrections from being calculated from the wrong position 00047 //printf("\n update function %i = next x, %i = next y \n", next_x, next_y); 00048 00049 science.check_leds_flag_set_tone(pad, lcd);//checks if the LED flag is set 00050 00051 science.check_leds_off(pad);//checks if the flag for the leds_off is set 00052 00053 returned_new_coordinates.new_x = next_x; // sets the new_x object in the struct to equal next_x 00054 00055 returned_new_coordinates.new_y = next_y; // sets the new_y object in the struct to equal next_y 00056 //printf("\n update function %i = returned x, %i = returned y \n", returned_new_coordinates.new_x, returned_new_coordinates.new_y); 00057 00058 check_for_level_update( returned_new_coordinates.new_x, returned_new_coordinates.new_y, levels); 00059 00060 //printf("Engine Update complete"); 00061 return returned_new_coordinates; // returns the struct instance containing the new coordinates 00062 00063 }; 00064 00065 00066 00067 void Engine::draw(int new_x, int new_y, int radius, Character &character, Levels &levels, N5110 &lcd) 00068 { 00069 levels.draw_maze(lcd);//draws the maze 00070 00071 levels.draw_exit(lcd);//draws the exit 00072 00073 character.draw_ball_2D(new_x, new_y, radius, lcd);//draws the character last 00074 //printf("Engine Draw complete"); 00075 }; 00076 00077 00078 00079 void Engine::check_for_level_update( int new_x, int new_y, Levels &levels) 00080 { 00081 if(levels.check_exit_coordinates(new_x, new_y) ==1) { 00082 //printf("\n detected at exit\n"); 00083 00084 this->level_index ++; //intended for use with a fsm of levels containing the array of the maze, which would be printed to the lcd. 00085 00086 //printf("\n level index = %i\n", level_index); 00087 }; 00088 00089 }; 00090
Generated on Tue Jul 19 2022 23:47:38 by
1.7.2