Dev C++ [Archive] - C Board

PDA

View Full Version : Dev C++


kas2002
07-02-2002, 09:08 AM
I am quite frustrated. For sum reason I cannot get any bitmap loading programs to work with Dev C++. It compiles fine but everytime the program runs it just gives me a "this program has preformed a illegal operation" and closes. I have located the bitmaps in the same folder as the program. I dunno here is my source



#include <allegro.h> // You must include the Allegro Header file


///////////
// TIMER //
///////////
volatile long speed_counter = 0;//A long integer which will store the value of the
//speed counter.

void increment_speed_counter() //A function to increment the speed counter
{
speed_counter++; // This will just increment the speed counter by one.
}
END_OF_FUNCTION(increment_speed_counter);
//function


///////////////////////
// The Main function //
///////////////////////
int main(int argc, char *argv[])
{



allegro_init(); // Initialize Allegro
install_keyboard(); // Initialize keyboard routines
install_timer(); // Initialize the timer routines

LOCK_VARIABLE(speed_counter); //Used to set the timer - which regulates the game's
LOCK_FUNCTION(increment_speed_counter);//speed.
install_int_ex(increment_speed_counter, BPS_TO_TIMER(60));//Set our BPS

set_color_depth(16); // Set the color depth

set_gfx_mode(GFX_AUTODETECT, 640,480,0,0); // Change our graphics mode to 640x480


BITMAP *frame1 = load_bitmap("frame1.bmp", NULL); // Declare a bitmap and Load our picture in one statement
BITMAP *frame2 = load_bitmap("frame2.bmp", NULL);
BITMAP *frame3 = load_bitmap("frame3.bmp", NULL);



BITMAP *buffer; //Declare a BITMAP called buffer.

buffer = create_bitmap(640,480); //Create an empty bitmap.

int my_pic_x = 0;// Holds our pictures X coorinate
int my_pic_y = 0;// Holds our picture's Y coordinate


int frame_counter = 0;// A counter for which frame to draw


while(!key[KEY_ESC])//If the user hits escape, quit the program
{

while(speed_counter > 0)
{
if(key[KEY_RIGHT])// If the user hits the right key, change the picture's X coordinate
{
my_pic_x ++;// Moving right so up the X coordinate by 1
}
else if(key[KEY_LEFT])// Ditto' - only for left key
{
my_pic_x --;// Moving left, so lower the X coordinate by 1
}
else if(key[KEY_UP])// If the user hits the up key, change the picture's Y coordinate
{
my_pic_y --;// Moving up, so lower the Y coordinate by 1
}
else if(key[KEY_DOWN])// Ditto' - only for down
{
my_pic_y ++;// Moving down, so up the Y coordinate by 1
}

speed_counter --;

frame_counter ++; //Increment our frame counter at the same speed of the
//speed counter

if(frame_counter > 240)
{
frame_counter = 0;
}
}

acquire_screen();// Get the screen



//In the first second, draw the first frame
if(frame_counter < 60)//Less than a full second
{
draw_sprite(buffer, frame1, my_pic_x, my_pic_y);//Draw the first frame
}
else if(frame_counter >= 60 && frame_counter < 120)//Between 1 and 2 seconds
{
draw_sprite(buffer, frame2, my_pic_x, my_pic_y);//Draw the second frame
}
else if(frame_counter >= 120 && frame_counter < 180)//If we are between 2 and 3 seconds
{
draw_sprite(buffer, frame1, my_pic_x, my_pic_y);//Draw the first frame again,
//to acheive better effect
}
else// If we are over 3 seconds
{
draw_sprite(buffer, frame3, my_pic_x, my_pic_y);//Draw the last frame,
}

blit(buffer, screen, 0,0,0,0,640,480);//Draw the buffer to the screen
clear_bitmap(buffer);
release_screen();// Release it
}

destroy_bitmap(frame1);//Release the bitmap data
destroy_bitmap(frame2);//Release the bitmap data
destroy_bitmap(frame3);//Release the bitmap data

destroy_bitmap(buffer);//Release the bitmap data


return(0);// Exit with no errors
}
END_OF_MAIN();

red_baron
07-02-2002, 12:23 PM
where do you ask for user input for key?

kas2002
07-02-2002, 12:30 PM
never mind I found th problem