Thread: Maze

  1. #1
    Registered User
    Join Date
    Jan 2011
    Posts
    1

    Maze

    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

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    So define "can't go to a coordinate". Are you just talking about walking off the edge of the LCD display? If so, just check whether x and y are on the edges of the display. If you've got some other condition in mind, you'll have to check that condition.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Having trouble solving maze.
    By eurus in forum C Programming
    Replies: 3
    Last Post: 02-17-2006, 01:52 AM
  2. Q: Recursion to find all paths of a maze
    By reti in forum C Programming
    Replies: 7
    Last Post: 11-26-2002, 09:28 AM
  3. My Maze Game --- A Few Questions
    By TechWins in forum Game Programming
    Replies: 18
    Last Post: 04-24-2002, 11:00 PM
  4. Algorithm to walk through a maze.
    By Nutshell in forum C Programming
    Replies: 30
    Last Post: 01-21-2002, 01:54 AM
  5. Maze game, complete with maze editor and an example maze!
    By Brian in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 01-20-2002, 03:27 AM