4 Replies - 805 Views - Last Post: 17 May 2010 - 12:02 PM Rate Topic: -----

#1 dodgevipert56  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 17-May 10

HOW TO STOP FOOD FROM SPAWNING UNDER THE SNAKE IN THE GAME

Posted 17 May 2010 - 08:13 AM

Hi all.
I am in the middle of a c++ game project snake. I currently have the snake and the food programmed and ready to work. But when i run the code the food sometimes randomly spawns "under the snake". Since this is just a random occurance i tired several ways to rectify this but it seems this little glitch doesn't seem to die down. Any ideas on how to rectify this will be highly appreciated
Is This A Good Question/Topic? 0
  • +

Replies To: HOW TO STOP FOOD FROM SPAWNING UNDER THE SNAKE IN THE GAME

#2 diego_pmc  Icon User is offline

  • D.I.C Addict

Reputation: 81
  • View blog
  • Posts: 565
  • Joined: 13-May 09

Re: HOW TO STOP FOOD FROM SPAWNING UNDER THE SNAKE IN THE GAME

Posted 17 May 2010 - 08:33 AM

1. Don't use CAPS.
2. This would probably be better off in the Game Programming forum.

What have you tried? The best way to fix it very likely depends on how you structured the game. If you are able to, one way to do it is to put the code that generates random positions for the food in a loop. The loop should repeat if the current position is occupied by a part of the snake's body.

This post has been edited by diego_pmc: 17 May 2010 - 08:36 AM

Was This Post Helpful? 0
  • +
  • -

#3 dodgevipert56  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 17-May 10

Re: HOW TO STOP FOOD FROM SPAWNING UNDER THE SNAKE IN THE GAME

Posted 17 May 2010 - 08:47 AM

sorry about the caps...kinda a newbie here...i will post the code here
Was This Post Helpful? 0
  • +
  • -

#4 IngeniousHax  Icon User is offline

  • |>|20-514<|{3|2

Reputation: 79
  • View blog
  • Posts: 1,366
  • Joined: 28-March 09

Re: HOW TO STOP FOOD FROM SPAWNING UNDER THE SNAKE IN THE GAME

Posted 17 May 2010 - 11:20 AM

Yes, as diego_pmc stated, just have it check whether the space is occupied by the snake.

Or if you wanna be really sneaky, have the snake only able to move on an even XY plane, and the food appear on an odd XY plane. ^.^ really frustrate the players.

NOTE::Don't forget your code tags when posting code. :code:
Was This Post Helpful? 1
  • +
  • -

#5 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1642
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: HOW TO STOP FOOD FROM SPAWNING UNDER THE SNAKE IN THE GAME

Posted 17 May 2010 - 12:02 PM

Moved to Game Programming :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1