刚刚发现了Go,到目前为止我非常好奇.我知道我只是懒惰,但我想知道是否可以在if语句中初始化多个变量.我知道以下是可能的:
if x := 5; x == 5 {
fmt.Printf("Whee!\n")
}
Run Code Online (Sandbox Code Playgroud)
我尝试过以下方法:
if x := 5, y := 38; x == 5 {
fmt.Printf("Whee! %d\n", y)
}
if x := 5 && y := 38; x == 5 {
fmt.Printf("Whee! %d\n", y)
}
Run Code Online (Sandbox Code Playgroud)
但都没有奏效.我查看了Go网站上的文档,所以我有什么遗漏或者这根本不可能吗?
因此,经过数小时的谷歌搜索和阅读,我发现使用SAT检测碰撞的基本过程是:
for each edge of poly A
project A and B onto the normal for this edge
if intervals do not overlap, return false
end for
for each edge of poly B
project A and B onto the normal for this edge
if intervals do not overlap, return false
end for
Run Code Online (Sandbox Code Playgroud)
但是,尽管我尝试在代码中实现这一点的方法很多,但我无法让它检测到碰撞.我目前的代码如下:
for (unsigned int i = 0; i < asteroids.size(); i++) {
if (asteroids.valid(i)) {
asteroids[i]->Update();
// Player-Asteroid collision detection
bool collision = true;
SDL_Rect asteroidBox = asteroids[i]->boundingBox;
// …Run Code Online (Sandbox Code Playgroud)