/* * game_logic.h * * Created: 2022-05-11 10:43:40 * Author: cid12bel */ #include #ifndef GAME_LOGIC_H_ #define GAME_LOGIC_H_ /* Screen width max values for x and y */ #define MAX_X 63 #define MAX_Y 127 //#define BALL_POSITIONS { 0, 0, 1, 3 } uint8_t BALL_POSITIONS[] = { 0b00000011, 0b00000110, 0b00001100, 0b00011000, 0b00110000, 0b01100000, 0b11000000, 0b10000000}; /******************************************** * this struct contains the ball used in the * labyrinth. The ball is 2x2 pixels in size. * When collision detecting you should check * posx + 1 when v_x is positive and posy + 1 * when v_y is positive. For negative speeds * check posx and posy directly. * * posx - the X-position of the ball: 0 -- 63 * posy - the Y-position of the ball: 0 -- 127 * v_x - the ball's velocity in pixels direction x: -128 -- 127 * v_y - the ball's velocity in pixels direction y: -128 -- 127 * */ typedef struct { int8_t posx; int8_t posy; int8_t v_x; int8_t v_y; int8_t prevx; int8_t prevy; } ball; /* parameters helpful to keep track of the ball, manly for drawing */ int8_t curr_x = 0; int8_t curr_y = 0; int8_t curr_page = 0; int8_t curr_tile_x = 0; int8_t curr_tile_y = 0; uint8_t ball_prev_x = 0; uint8_t ball_prev_y = 0; /* to keep score: game time and best time * 2^32 * 16us should be enough... */ uint32_t GAME_TIME = 0; uint32_t BEST_TIME = 0; typedef enum MODES { GAME_START, GAME_RUN, GAME_END } GAME_MODE; /* just sets up the scaling for timer 1 . 256 is used. * roughly 1 second should be enough for the game loop * and then some.*/ void timer_setup(); /* ADC Initialization function */ void ADC_Init(); /************************************************ * Read a value from an input pin and do * A/D conversion * * @param channel - the number of the input you want to read * * @return - the converted value as an int ***********************************************/ int ADC_Read(char channel); /************************************************ * Use this to get a horizontal ball acceleration * value from the accelerometer * * * @return - acceleration in g ***********************************************/ double getXValues(); /************************************************ * Use this to get a vertical ball acceleration * value from the accelerometer * * * @return - acceleration in g ***********************************************/ double getYValues(); /****************************************************** * Use this to convert 16 us ticks to seconds * * @param time_ticks - the number of 16 us ticks you want to convert * * @return - time in seconds *************************************/ double get_time_s(uint32_t time_ticks); /********************************************************** * Convert a time in seconds into whole minutes. * NOTE: no more than 256 minutes. * * @param t_s - double time in seconds. Do not input more * than 256 minutes if you want it to work. * * @return - time in whole minutes **********************************************************/ uint8_t get_minutes(double t_s); /********************************************************* * Convert a time in seconds into whole seconds. * * @param t_s - double time in seconds. * * * @return - input time modulo 60 to get the seconds * part of the time ********************************************************/ uint8_t get_seconds(double t_s); /** * Convert a time in seconds into tenths. * * @param t_s - double time in seconds. * * @return - time tenths. **********************/ uint8_t get_tenths(double t_s); /** * Convert a time in seconds into hundredths. * * @param t_s - double time in seconds. * * @return - time hundredths. Note that >= 0.005 always gets rounded up. **********************/ uint8_t get_hundredths(double t_s); #endif /* GAME_LOGIC_H_ */