Oxfam の書店で見つけた小さな本と大きな本のおかげで、私は 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]」を付けるのは間違っているように聞こえますが、それは正常に機能し、今まで問題なくコンパイルされていました. 単なるタイプミスか誤解か何かかもしれませんが、私には本当にわかりません。
あなたが見ることができるように、それは粒子システムでの試みであり、改善に関するヒントです(それは言葉ですか?)私のコードは大歓迎です:)
ありがとう。