2011-11-21 62 views
-1

我試圖在C和SDL中創建一個小型遊戲,以有趣的方式開始使用SDL。我會粘貼我的計時器結構和函數,將用於在我的主要遊戲循環中封頂fps。在總共約25個錯誤地獄般的語法錯誤

這是的,但我得到了很多的「預期‘(’跟隨‘T’錯誤C2054」:?

#include <stdio.h> 
#include <stdlib.h> 
#include <string.h> 

#include "SDL.h" 

struct Timer { 

    int startTicks; 
    int pausedTicks; 

    int paused; 
    int started; 

}; 

void Init(Timer *t) 
{ 
    t->startTicks = 0; 
    t->pausedTicks = 0; 
    t->paused = 0; 
    t->started = 0; 
} 

void StartTimer(Timer *t) 
{ 
    t->started = 1; 
    t->paused = 0; 

    t->startTicks = SDL_GetTicks(); 
} 

void StopTimer(Timer *t) 
{ 
    t->started = 0; 

    t->paused = 0; 
} 

void PauseTimer(Timer *t) 
{ 
    if(t->started == 1 && t->paused == 0) 
    { 
     t->paused = 1; 
     t->pausedTicks = SDL_GetTicks() - t->startTicks; 
    } 
} 

void UnpauseTimer(Timer *t) 
{ 
    if(t->paused == 1) 
    { 
     t->paused = 0; 
     t->startTicks = SDL_GetTicks() - t->pausedTicks; 

     t->pausedTicks = 0; 
    } 
} 

int GetTicks(Timer *t) 
{ 
    if(t->started == 1) 
    { 
     return t->pausedTicks; 
    } 
    else 
    { 
     return SDL_GetTicks() - t->startTicks; 
    } 

    return 0; 
} 

請告訴我錯在這裏先感謝!

+0

是否找到了所有包含的文件? –

+0

請仔細閱讀錯誤信息 - 哪一行是「錯誤C2054」?我會開始尋找錯誤:) – kol

回答

4

所有這些t變量應該是struct Timer類型,而不是Timer

,或者,將其定義爲:

typedef struct sTimer { 
    int startTicks; 
    int pausedTicks; 
    int paused; 
    int started; 
} Timer; 

使Timer成爲「第一類」類型。

+0

謝謝隊友!發現! – Jason94

1

在C語言中,你要麼需要這樣做:

struct Foo 
{ 
    ... 
}; 

... 

void bar(struct Foo *p); 
     ^

或本:

typedef struct Foo 
{^
    ... 
} Foo; 
^
... 

void bar(Foo *p); 

[我喜歡第二個版本;它節省了不得不寫struct到處。]

1

找到第一個錯誤,並從中工作。通常,其他許多是第一個的後果。

+0

s /通常/很多/ – glglgl

+0

@glglgl:謝謝,修正。 – mouviciel