Jump to content

  • Log In with Google      Sign In   
  • Create Account

Calling all IT Pros from Canada and Australia.. we need your help! Support our site by taking a quick sponsored surveyand win a chance at a $50 Amazon gift card. Click here to get started!


MrZeo

Member Since 10 Apr 2013
Offline Last Active Apr 24 2013 01:04 AM

#5056288 Help with Worm Clone Draw() method

Posted by MrZeo on 24 April 2013 - 01:02 AM

Its hard to tell, maybe you are incorrectly substracting 1 when looping through your body parts in draw?

 

for (int i = 0; i < wormBodyTexture.Count; i++)

 

Have you considered making a simple BodyPart class, and making a list of those that would represent the worm. First object in the list would be the head and last one the tail. When the worm moves you would just remove the last item from the list and insert new one at the start of the list based on direction you are going. When you eat something you just dont remove the last item and thus the worm gets larger. For collision you can easily check if the new head position collides with any other BodyPart in the list or walls of the map. When drawing you would just loop through the list, drawing the first part with head texture, last with tail, and the rest with body texture. Later on when you have the basics down you could easily expand the class to do all kinds of neat stuff. I hope that wasn't too confusing. :>




#5055007 Help with Worm Clone

Posted by MrZeo on 19 April 2013 - 02:23 PM

Vector2 is a struct and therefore a value type. When you return value from list you actually get a copy of the value instead of reference. That is why you can't modify the original value in list.

 

EDIT: This should work not sure if it is a good way to do it though:

 

var temp = wormBodyPosition[i];

temp.X += wormBodyWidth;

wormBodyPosition[i] = temp;




PARTNERS