我无法理解变量范围的概念。什么是可以接受的,什么是不可接受的?我知道,我已经离开了所有相关的代码的图形,而且我知道我有无限的游戏循环,但包涵:有关变量范围的问题
#include "LList.h"
#include "Snake.h"
#undef main
int main()
{
float dt; // time since last update.
int start_time;
bool paused = false;
float originalTime = 1.0f;
float timer = originalTime;
Snake p1Snake(10, false);
// Start the 'stopwatch'
start_time = SDL_GetTicks();
///////////////////////
// The 'game loop' //
///////////////////////
while (!done)
{
//////////////////////
// Update variables //
//////////////////////
// Update the dt value (to be the time since the last update)
dt = (SDL_GetTicks() - start_time)/1000.0f;
start_time = SDL_GetTicks();
//increment the movement timer
timer-=dt;
if(timer<=0) When timer hits zero the snake is moved north.
{
p1Snake.goNorth();
timer = originalTimer; //reset timer.
}
}
return 0;
}
好吧!所以我的问题是关于变量'originalTimer'。它在定时器重置的范围之外,所以我能做些什么不同?对不起,如果这是一个非常基本的问题。
你的意思是'originalTime'? –
假设你实际上是指'originalTime',那么你为什么认为它超出了范围? –
'#undef main'看起来很可疑,我甚至无法描述它。 – chris