Mail Archives: djgpp/1999/01/02/10:51:51
Help!! My program crashes if antal ( look at row **** This one ****) is over
12000. Can someone tell me wahts wrong.
#include <stdio.h>
#include <math.h>
#include "allegro.h"
class Star {
private:
int posX,posY;
int speedX,speedY;
int color;
public:
void set(int x,int y,int col,int size);
void operator ++ (int);
void clear();
void putStar();
};
void Star::set(int x,int y,int col,int size) {
posX=x<<16; posY=y<<16; color=col;
double speed=random()%size;
double vinkel=random();
speedX=speed*cos(vinkel);
speedY=speed*sin(vinkel);
}
void Star::operator++ (int) {
clear();
posX+=speedX; posY+=speedY;
putStar();
speedX-=speedX/70; speedY-=speedY/70;
speedY+=450;
}
void Star::clear() { putpixel(screen,posX>>16,posY>>16,0); }
void Star::putStar() { putpixel(screen,posX>>16,posY>>16,color); }
int main()
{
allegro_init();
install_keyboard();
set_color_depth(32);
if(set_gfx_mode(GFX_AUTODETECT, 1024, 768, 0, 0) != 0) {
set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
printf("Unable to select a 1024x768 32 bit screen mode\n");
return 0;
}
clear_keybuf();
int key=0;
while (key!=27) {
#define antal 1000 // **** This one ****
Star lista[antal];
for(int i=0; i<antal; i++) lista[i].set(500,350,random(),0x40000);
for(int a=0; a<250; a++) {
vsync();
for(int i=0; i<antal; i++) lista[i]++;
}
for(int i=0; i<antal; i++) lista[i].clear();
key=readkey()&0xff;
}
return 0;
}
- Raw text -