我的代码片段来自 main.cpp
playerEntity::handle()
{
if( event.type == SDL_KEYDOWN )
{
switch( event.key.keysym.sym )
{
case SDLK_q:
running = false;
paused = true;
break;
case SDLK_ESCAPE:
paused = !paused;
break;
}
}
if( keystate[SDLK_UP] )
{
if( isJumping == false && isFreeFalling == false )
{
isJumping = true;
}
}
if( keystate[SDLK_LEFT] ) player.hitbox.x--;
if( keystate[SDLK_RIGHT] ) player.hitbox.x++;
if( player.hitbox.x < 0 ) {player.hitbox.x = 0;}
else if( player.hitbox.x > screen.WIDTH - player.hitbox.w ) {player.hitbox.x = screen.WIDTH - player.hitbox.w;}
if( player.hitbox.y < 0 ) {player.hitbox.y = 0;}
else if( player.hitbox.y > screen.HEIGHT - player.hitbox.h ) {player.hitbox.y = screen.HEIGHT - player.hitbox.h;}
}
在playerEntity
头文件中定义的位置:
#ifndef PLAYERENTITY_H
#define PLAYERENTITY_H
class playerEntity
{
private:
int jumpHeight;
int jump;
bool isJumping;
bool isFalling;
bool isFreeFalling;
SDL_Event event;
Uint8 *keystate;
public:
playerEntity();
void jump();
void handle();
void fall();
int health;
int damage;
SDL_Rect hitbox;
bool evolved;
};
#endif
当我尝试编译时,我得到了错误:ISO c++ forbids declaration of 'handle' with no type [-fpermissive] prototype for 'int playerEntity::handle()' does not match any in class 'playerEntity' 错误:候选人是: 无效 playerEntity::handle()。我还是头文件和类的新手,如何修复错误?