Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


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.

  • You cannot reply to this topic
1 reply to this topic

#1 lhandley660175   Members   -  Reputation: 101

Like
0Likes
Like

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

Attached Files



Sponsor:

#2 jms bc   Members   -  Reputation: 439

Like
0Likes
Like

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.



PARTNERS