Hello!
I'm making a maze game(which I'm controlling with my USBkey) with C in AVR studio. The problem I'm having is that I'm not really sure how to let my program check if the dot I'm controlling can go to a certain spot(x, y coordinate).
Code:
lcd_set_pixel(U16 X, U16 Y, U8 R, U8 G, U8 B)
lcd_set_pixel(5, 10, 255, 255, 255) // example
That's the way to set pixels.
Now I got my dot moving, but it can still go everywhere
Code:
static U16 y = 0; // starting position
static U16 x = 0;
if(Is_joy_right())
{
_delay_ms(75);
lcd_set_pixel(x, y, 250,128,114); // setting last pixel to background color
x++; // changing the dot's position
lcd_set_pixel(x, y, 0, 0, 255); // drawing the dot
}
if(Is_joy_left())
{
_delay_ms(75);
lcd_set_pixel(x, y, 250,128,114);
x--;
lcd_set_pixel(x, y, 0, 0, 255);
}
if(Is_joy_down())
{
_delay_ms(75);
lcd_set_pixel(x, y, 250,128,114);
y++;
lcd_set_pixel(x, y, 0, 0, 255);
}
if(Is_joy_up())
{
_delay_ms(75);
lcd_set_pixel(x, y, 250,128,114);
y--;
lcd_set_pixel(x, y, 0, 0, 255);
}
Does any of you have an idea how to keep my code a bit compact(because if i have to draw every pixel with the set_pixel it will get messy + I wouldn't be sure how to check if it can go to a certain x, y coordinate), I was thinking of using an array, but I wasn't sure how to use it in this situation.
Regards,
Roflpantoffel
PS: yes, the RGB of my background color is salmon