制作落沙游戏时C raylib中的常量表达式错误

问题描述

你好,我正在开发一个简单的落沙游戏,我在使用 tcc -o fallingsand.exe fallingsand.c world.c C:\raylib\raylib\src\raylib.rc.data -Os -std=c99 -Wall -Iextenal -dplATFORM_DESKTOP -msvcrt -lraylib -lopengl32 -lwinmm -lkernel32 -lshell32 -luser32 -Wl 与 tcc 编译时得到了常量表达式预期错误
我不知道什么不是常量,也没有在我的代码中定义。谢谢。

fallingsand.c(主文件)

#include "world.h"
int main(int argc,char** argv){
    const int WIDTH = 800;
    const int HEIGHT = 600;
    Initwindow(WIDTH,HEIGHT,"Falling Sand");
    SetTargetFPS(144);
    init();
    Vector2 mousePos = {1.0f,1.0f};
    while(!WindowShouldClose()){
        mousePos = GetMousePosition();
        if(IsMouseButtonpressed(MOUSE_LEFT_BUTTON)) place(
        mousePos.x,mousePos.y,SAND);
        draw();
    }
}

world.h

#include "raylib.h"
#include <stdlib.h>
#ifndef WORLD_H
#define WORLD_H
const int AIR = 0;
const int SAND = 1;
const int WATER = 2;
int world[800][600];
int worldF[800][600];
void init();
void place(int x,int y,int type);
void draw();
void drop();
#endif

world.c

#include "world.h"
void init(){
    for(int y = 0; y < 600; y++){
        for(int x = 0; x < 800; x++){
            world[x][y] = AIR;
            worldF[x][y] = 0;
        }
    }
}
void place(int x,int type){
    if(worldF[x][y] == 0) {
        world[x][y] = type;
        worldF[x][y] = 1;
    }
    else {}
}
void draw(){
    for(int y = 0; y < 600; y += 5){
        for(int x = 0; x < 800; x += 5){
            switch(world[x][y]){
                Vector2 pos = {x,y};
                case AIR: DrawRectangleV(pos,5,BLACK); break;
                case SAND: DrawRectangleV(pos,YELLOW); break;
                case WATER: DrawRectangleV(pos,BLUE); break;
                default: DrawRectangleV(pos,RED); break;
            }
        }
    }
}

错误,这是编辑

world.c:22: error: constant expression expected
world.c: error: 'AIR' defined twice
world.c: error: 'SAND' defined twice
world.c: error: 'WATER' defined twice

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)