|
Falling Problems |
SkaxCo
Member #8,323
February 2007
|
I have a little game called Zombie Onslaught with zombies coming in (can you guess?) an onslaught. I went back to my original killing method of clicking on them. To make a long story short, I wanted to add in a new device (or 3) so I reanimated it. In the code for animating a zombie, I had: (well, this is the whole zombie class)
Despite the fact that everything is floats, everything falls at an integer speed, so everything at the same speed. If I bump it too ((rand() % 20) / 20) +1;, then everything falls at two speeds. Here is the movement code: for(int i = 0; i < ZOMBIE_MAX; i++){ if(horde<i>.alive){ horde<i>.y += horde<i>.fall_speed; } } Anyone see anything blatantly wrong? |
Rampage
Member #3,035
December 2002
|
SkaxCo
Member #8,323
February 2007
|
So? I divide it by 10. Should I have the divide by ten in another line? |
Rampage
Member #3,035
December 2002
|
You can do it in the same line. See my edit. -R |
Tobias Dammers
Member #2,604
August 2002
|
Just a hint: Make it a habit to put all float constants (read: all numbers within a float context) as actual floats, and cast explicitly. I'd have put your statement like this: fall_speed = ((float)(rand() % 10) / 10.0f) + 1.0f;
--- |
|