I wrote this script for my classmates where we shoot at each other, but after it compiles it says that there was an error and exits out. heres my script, if there is anything in there that needs to be fixed please help me.

#include <allegro.h>
#include <process.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

bool Indian;
int x;
int y;
int Score = 0;
int Timer;
BITMAP* Switch;

int GeneratePicture();
void Menu();
void Fire();
void Time(void* ISeeYou);
void UpdateScreen(void* Hi_Zach);

int main(){
allegro_init();
install_keyboard();
install_mouse();
install_keyboard();
set_color_depth(16);
install_sound (DIGI_AUTODETECT, MIDI_AUTODETECT, "A");
set_gfx_mode( GFX_AUTODETECT, 1280, 960, 0, 0);

    Menu();
    _beginthread( UpdateScreen, 0, 0);
    _beginthread( Time, 0, 0);
    while(!key[KEY_ESC] || !Timer == 0){ 
                      GeneratePicture();
                      Fire();
                      }
                      
}
    
END_OF_MAIN();


void Menu(){
     BITMAP* Menu = load_bitmap("Menu", NULL);
     draw_sprite(screen, Menu, 0, 0);
     readkey();}

int GeneratePicture(){
    int RandomPic;

    srand ( time(NULL) );
    RandomPic = rand() % 10 + 1;
    x = rand() % 1180 + 1;
    y = rand() % 860 + 1;
    
    if (RandomPic == 1 || RandomPic == 2 || RandomPic == 3){
                  Switch = load_bitmap("Kyie1", NULL);}
    if (RandomPic == 4 || RandomPic == 5 || RandomPic == 6){
                  Switch = load_bitmap("Kyie2", NULL);}
    if (RandomPic == 7 || RandomPic == 8 || RandomPic == 9){
                  Switch = load_bitmap("Kyie3", NULL);}
    if (RandomPic == 10){
                  Switch = load_bitmap("Indian", NULL);
                  Indian = true;}
    return 0;
                  }
                  
void UpdateScreen(void* Hi_Zach){
     BITMAP* Background = load_bitmap("Background", NULL);
     BITMAP* Buffer = create_bitmap(1280, 960);
     while(!key[KEY_ESC] || !Timer == 0){
                       draw_sprite(Buffer, Background, 0, 0);
                       draw_sprite(Buffer, Switch, x, y);
                       line( Buffer, mouse_x, 0, mouse_x, 960, makecol( 0, 0, 0));
                       line( Buffer, 0, mouse_y, 1280, mouse_y, makecol( 0, 0, 0));
                       textprintf_ex(Buffer, font, 0, 0, makecol(0,0,0), -1, "Score: %i   Time: %i", Score, Timer);
                       draw_sprite(screen, Buffer, 0, 0);
                       rest(100);}
                       _endthread();}
     
void Time(void *ISeeYou){
     Timer = 30;
     while(Timer != 0){
                 rest(1000);
                 Timer--;
                 }
                 _endthread();
     }


void Fire(){
SAMPLE *Boom = load_sample ("BOOM.wav");
bool hit = false;
     while(!hit){
     rest(100);
     if (mouse_b & 1 && mouse_x > x && mouse_x < x+100 && mouse_y > y && mouse_y < y+100){
                 hit=true;
                 play_sample (Boom, 100, 128, 1000, false);}}
     if (Indian)Score=Score+25;
     else Score=Score+10;}

Recommended Answers

All 7 Replies

>>I wrote this script for my classmates where we shoot at each other
Remind me never to go to your school.

Please help me. I wanted to make this as an end of the year gift to my friends and there are only 10 days left of school.

Can you post the errors ?

BITMAP* Switch;

switch is a keyword. Variables in the name of keywords are not allowed.

It doesn't flag any errors, its just that when I run the program it says "program.exe has stopped working." I usually look through the code and find the problem, but i can't find anything. the only thing I've seen and fixed was that i forgot the .bmp extension.

what compiler?

Why do you have a switch statement as a variable and you even pass it to a function. You use switch as

switch(something) { case 1: dosomething; case 2

Also what does your END_OF_MAIN() function do? Can you post all your source code here and please tell us what compiler are you using. This is a really wierd game!

ok thanks, i got the script to work

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.