• FEATURED

View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# vector collision problems

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

1 reply to this topic

### #1lhandley660175  Members

Posted 08 February 2013 - 09:24 AM

hi im fairly new to c# and have been tasked with creating a snake game. I've come to a point in the project where i need to add collision both the walls and the snake itself however im having some problems with the vector system i've implemented in order to keep track of my snakes position. It appears that when i get 18 tiles down i walk off the end of the array i have set up for the game area however if i comment out the vector collision i no longer do so, im slightly stumped. As i said im reasonably new to c# so even if you can't figure out the problem feel free to give me any constructive criticism you think will be helpful and any help would be greatly appreciated.

### #2jms bc  Members

Posted 08 February 2013 - 01:57 PM

Looking at

if (level[player.ypos + player.vec.y, player.xpos + player.vec.x] != TileType.WALL && level[player.ypos + player.vec.y, player.xpos + player.vec.x] != TileType.PLAYER)

I'm thinking that here you expect ypos + vec.y to be the next y coordinate, but I don't think it is. From what I see, vec.y is, all by itself, the next y coord, so then your calculated index is way off.

I'm guessing you should assign values of {-1,0,1} to vec.x and vec.y.   eg, vec.x = 1 instead of vec.x = xpos + 1

The Four Horsemen of Happiness have left.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.