你好,所以我正在做一个简单的落沙游戏,我得到了常量表达式预期的错误,我用 tcc 编译使用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
我无法分辨什么不是常量,也没有在我的代码中定义。谢谢你。
fallsand.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();
}
}
世界.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
世界.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 y, 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, 5, BLACK); break;
case SAND: DrawRectangleV(pos, 5, 5, YELLOW); break;
case WATER: DrawRectangleV(pos, 5, 5, BLUE); break;
default: DrawRectangleV(pos, 5, 5, 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