2011-12-26 51 views
0

我收到錯誤:
錯誤C2440:初始化:不能從「詮釋」轉化爲「const的球員
錯誤C2628:‘球員’,然後‘廉政’是非法的(沒你忘了';'?)
從第5行,const int WIDTH = 1280 但我不明白我做錯了什麼。播放器結構產生C2440錯誤

我聲明:

#include <allegro5\allegro.h> 
#include <allegro5\allegro_primitives.h> 
#include "objects.h" 

const int WIDTH = 1280; 
const int HEIGHT = 720; 
const float GRAVITY = 1.5; 
const float FORCE = 1.4; 
const float K = 0.25; 
enum KEYS{UP, DOWN, LEFT, RIGHT, SPACE}; 
bool keys[5] = {false, false, false, false, false}; 

void InitPlayer(); 
void DrawPlayer(); 

Player player; 

InitPlayer功能:

void InitPlayer() { 
    player.x = 0; 
    player.y = HEIGHT - 20; 
    player.vy = 0; 
    player.vx = 0; 
    player.fx = 0; 
    player.jumping = false; 
} 

播放器的結構:

struct Player { 
    float x; 
    float y; 
    float fx; 
    float vx; 
    float vy; 
    int direction; 
    bool jumping; 

    void Jump() { 
    if(!jumping) { 
     vy = -15; 
     jumping = true; 
     } 
    } 
} 

回答

3

你忘了把;Player定義的末尾:

struct Player { 
    // Stuff goes here 
}; 
^ 
^ 
^