Sign in to follow this  
lhandley660175

vector collision problems

Recommended Posts

lhandley660175    101

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

Share this post


Link to post
Share on other sites
jms bc    448

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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this