vector collision problems

Started by
0 comments, last by jms bc 11 years, 2 months ago

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.biggrin.png

Advertisement

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.

This topic is closed to new replies.

Advertisement