多亏了我在乐施会书店找到的一本小书和一本大书,我一直在玩 C、C++ 和 Allegro。我现在很好理解,但我碰壁了......每当我编译时,我都会收到这些错误:
archiboldian@archiboldian:~/Documents/C++ Projects/particles$ g++ particles.c -lalleg -lnoise -o particles
particles.c:19: error: array bound is not an integer constant before ‘]’ token
particles.c:20: error: ‘Vector2D’ does not name a type
particles.c:21: error: ‘Vector2D’ does not name a type
particles.c: In function ‘int main()’:
particles.c:26: error: ‘nPos’ was not declared in this scope
particles.c:28: error: ‘nVel’ was not declared in this scope
particles.c:29: error: ‘nvel’ was not declared in this scope
particles.c:31: error: ‘addParticle’ was not declared in this scope
particles.c: At global scope:
particles.c:47: error: ‘Vector2D’ has not been declared
particles.c:47: error: ‘Color’ has not been declared
particles.c: In function ‘void addParticle(int, int, Vector2d, int, int, int)’:
particles.c:50: error: ‘particles’ was not declared in this scope
这是我的代码...
#include "allegro.h"
struct Vector2d{
double x;
double y;
};
struct Particle {
Vector2d Pos;
Vector2d Vel;
int age;
int LifeSpan;
int colour;
int size;
};
int max = 50;
int pcount = 0;
Particle particles[max];
int main(void) {
Vector2D nPos;
Vector2D nVel;
nPos.x = 320;
nPos.y = 240;
nVel.x = 2;
nvel.y = 0;
addParticle(10, nPos, nVel, 20, makecol(255,255,255), 2);
allegro_init();
install_keyboard();
set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0);
while(!key[KEY_ESC]) {
for(int i=0;i<pcount;i++){
}
}
allegro_exit();
}
void addParticle(int addp, Vector2D Pos, Vector2d Vel, int LifeSpan, Color colour, int size) {
for(int i=0;i<addp;i++){
pcount++;
particles[pcount].Pos = Pos;
particles[pcount].Vel = Vel;
particles[pcount].LifeSpan = LifeSpan;
particles[pcount].colour = colour;
particles[pcount].size = size;
}
}
END_OF_MAIN();
根据我从调试输出中收集到的信息,第一个错误是关于“粒子粒子 [max];”的问题。行和消息听起来好像在“粒子”的末尾有这个“[max]”是错误的,但直到现在它工作正常并且编译没有问题。这可能只是一个错字或误解或其他东西,但我真的无法弄清楚。
正如您所看到的,这是对粒子系统的尝试以及任何关于改进的提示(这是一个词吗?)我的代码非常感谢 :)
谢谢。