-2
工作后,我不得不使用FMOD的功能,而不是%的这段代码:%不兰特()C++
int prob = rand();// % 4;
prob = fmod(prob,4);
if (prob == 0) {
shoot = true;
}
else shoot = false;
如果我使用%,概率变量不会得到任何debuger价值。
第二个问题是它从来没有进入内部如果我把断点放在if上,另一个放在另一个上,另一个放在shoot = true上;该debuger说: :断点目前不会被击中。没有调试器的目标代码类型的可执行代码关联。
在其他计算机上,第二个问题不存在。
全功能:
void cVoladorEstatico::Logic(int *map)
{
double t1 = glutGet(GLUT_ELAPSED_TIME);
if (t1 - moveDelaySteering > 20 * 20) {
random_variable = rand();
moveDelaySteering = t1;
}
if (t1 - moveDelay > 20) {
int aux = y;
y += random_variable%speed - 3;
//Whats next tile?
if ((y % TILE_SIZE) <= 1)
{
/*y += speedY;
x += speedX;*/
//si choca con tile, se autodestruye muy fuerte
if (CollidesMapWall(map, false)) y = aux; //delete this;
}
//Advance, no problem
else
{
/*y += speedY;
x += speedX;*/
//TODO: si choca, hace magia
}
moveDelay = t1;
}
//should i shoot
//if (t1 - lastShootDec > shootChance) {
int prob = rand();// % 4;
prob = fmod(prob,4);
if (prob == 0) {
shoot = true;
}
else shoot = false;
//}
}
你重新编译了你的代码吗? –
为什么要在'int'上使用'fmod'? – Logicrat
你应该使用'(value&3)'而不是''''或'fmod'。一些编译器可能比'%4'更高效地编写'&3',具体取决于优化级别。 –