I am trying to get a character to move automatically at random and bounce of walls. Theoretically the code that I have should work however the character just isn't moving. I get no errors and have tried to find a problem but come short.
I fixed a couple of problems with declarations and some of the comparisons however I have not been able to find another issue that is stopping this code from running. I am running this on a 48x84 LCD screen.
The main function isn't exact but the order of how things are run currently is the same
int t_xy[27][2] = { {0,0}, {4,0}, {0,1}, {1,1}, {3,1}, {4,1}, {0,2}, {1,2}, {2,2}, {3,2}, {4,2}, {0,3}, {2,3}, {4,3}, {0,4}, {1,4}, {3,4}, {4,4}, {0,5}, {1,5}, {2,5}, {3,5}, {4,5}, {1,6}, {2,6}, {3,6} }; //27 pixels in bitmap
//Tom's positon
double t_x = LCD_X - 5, t_y = LCD_Y - 9, t_dx, t_dy;
void t_setup() {
double gait = 0.3;
double t_dir = rand() * 3.14 * 2 / RAND_MAX; // random direction
t_dx = gait * cos(t_dir);
t_dy = gait * sin(t_dir);
}
void t_move() {
int new_x = round(t_x + t_dx);
int new_y = round(t_y + t_dy);
int bounced = 0;
if (new_x == 0 || new_x == LCD_X - 5) {
t_dx = -t_dx;
bounced = 1;
}
if (new_y == 8 || new_y == LCD_Y - 7) {
t_dy = -t_dy;
bounced = 1;
}
if (!(bounced == 1)) {
t_x += t_dx;
t_y += t_dy;
}
void main()
t_setup();
while (!(game_over == 1))
{
t_move();
}
}
I expect tom to be able to move automatically and bounce off the borders of the screen and move in random directions but currently tom does not move at all but there are no errors appearing and every other game element works fine