好的,我需要进行碰撞测试。这种方式似乎最简单,但我的编译器不这么认为。感谢您的回复!
C++ 代码:
int sqrd(int num) { return (num*num); } //squares a number
bool checkColShip() {
for(int x = 0;x < 10;x++) {
double distance = 0; //use to be int tried to change it
distance = abs( sqrt( sqrd((one.getXPos() - asteroid[x].getXPos()) +
sqrd((one.getYPos() - asteroid[x].getYPos()))
); //include cmath
distance -= 20;//ship radius
distance -= 20;//asteroid radius
if (distance<=0) return true;//collision true
}
//no collision
return false;
}
编译器错误:
c:\documents and settings\all users\documents\c++ projects\learn sdl\learn sdl\main.cpp(702): error C2668: 'sqrt' : ambiguous call to overloaded function
c:\program files\microsoft visual studio 10.0\vc\include\math.h(589): could be 'long double sqrt(long double)'
c:\program files\microsoft visual studio 10.0\vc\include\math.h(541): or 'float sqrt(float)'
c:\program files\microsoft visual studio 10.0\vc\include\math.h(127): or 'double sqrt(double)'
while trying to match the argument list '(int)'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
PS我通常缩进我的代码,但第一次在这里发布,它一直给我带来问题。