gpt4 book ai didi

c++ - 播放器结构生成 C2440 错误

转载 作者:行者123 更新时间:2023-11-28 01:01:05 26 4
gpt4 key购买 nike

我收到错误:
错误 C2440:“正在初始化”:无法从“int”转换为“const Player”
错误 C2628:'Player' 后跟 'int' 是非法的(您是否忘记了 ';'?)
从第 5 行开始,const int WIDTH = 1280 但我不明白我做错了什么。

我的声明:

#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;

初始化播放器函数:

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;
}
}
}

最佳答案

你忘了在 Player 定义的末尾加上 ;:

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

关于c++ - 播放器结构生成 C2440 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8638876/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com