#includeThanks#include "SDL/SDL.h" #include "SDL/SDL_image.h" #include #include using namespace std; //Screen attributes const int SCREEN_WIDTH = 640; const int SCREEN_HEIGHT = 480; const int SCREEN_BPP = 32; //The surfaces SDL_Surface *map1 = NULL; SDL_Surface *start = NULL; SDL_Surface *screen = NULL; SDL_Event event; void sleep(unsigned int mseconds) { clock_t goal = mseconds + clock(); while (goal > clock()); } SDL_Surface *load_image( std::string filename ) { //The image that's loaded SDL_Surface* loadedImage = NULL; //The optimized image that will be used SDL_Surface* optimizedImage = NULL; //Load the image using SDL_image loadedImage = IMG_Load( filename.c_str() ); //If the image loaded if( loadedImage != NULL ) { //Create an optimized image optimizedImage = SDL_DisplayFormat( loadedImage ); //Free the old image SDL_FreeSurface( loadedImage ); } //Return the optimized image return optimizedImage; } void apply_surface( int x, int y, SDL_Surface* source, SDL_Surface* destination ) { //Rectangle to hold the offsets SDL_Rect offset; //Get offsets offset.x = x; offset.y = y; //Blit the surface SDL_BlitSurface( source, NULL, destination, &offset ); } bool init() { //Initialize all SDL subsystems if( SDL_Init( SDL_INIT_EVERYTHING ) == -1 ) { return false; } //Set up the screen screen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE ); //If there was an error in setting up the screen if( screen == NULL ) { return false; } //Set the window caption SDL_WM_SetCaption( "Battle Link", NULL ); //If everything initialized fine return true; } void clean_up() { //Free the surface SDL_FreeSurface( map1 ); //Quit SDL SDL_Quit(); } int main( int argc, char* args[] ) { //Initialize if( init() == false ) { cout << "There has been an error in intializing the screen. Try again.\n"; sleep(5); return 1; } map1 = load_image( "map1.bmp" ); if(!map1) { printf("IMG_Load: %s\n", IMG_GetError()); cout << "There has been an error intializing the file. Try again."; sleep(5); return 1; } start = load_image( "pics/start.jpg" ); if(!start) { printf("IMG_Load: %s\n", IMG_GetError()); cout << "There has been an error intializing the file. Try again."; sleep(5); return 1; } int stoploop = 0; int mousex; int mousey; while (1){ if( event.type == SDL_MOUSEBUTTONDOWN) { if( event.button.button == SDL_BUTTON_LEFT) { mousex = event.button.x; mousey = event.button.y; //if mouse is over the button if( (mousex > 50) && (mousex < 200) && (mousey > 50) && (mousey < 250)) { break; } } } apply_surface(50,50,start,screen); //Update screen if( SDL_Flip( screen) == -1) { return 1; } } //apply the surfaces to the screen apply_surface(0,48,map1,screen); //Update screen if( SDL_Flip( screen) == -1) { return 1; } SDL_Delay(5000); clean_up(); return 0; }
Re: SDL Help May 15, 2009 09:33AM | Registered: 15 years ago Posts: 58 |
Re: SDL Help May 15, 2009 04:16PM | Registered: 15 years ago Posts: 444 |
Re: SDL Help May 15, 2009 07:14PM | Registered: 15 years ago Posts: 8 |
#include#include "SDL/SDL.h" #include "SDL/SDL_image.h" #include using namespace std; //Screen attributes const int SCREEN_WIDTH = 640; const int SCREEN_HEIGHT = 480; const int SCREEN_BPP = 32; //The surfaces SDL_Surface *map1 = NULL; SDL_Surface *start = NULL; SDL_Surface *screen = NULL; SDL_Event event; void sleep(unsigned int mseconds) { clock_t goal = mseconds + clock(); while (goal > clock()); } SDL_Surface *load_image( std::string filename ) { //The image that's loaded SDL_Surface* loadedImage = NULL; //The optimized image that will be used SDL_Surface* optimizedImage = NULL; //Load the image using SDL_image loadedImage = IMG_Load( filename.c_str() ); //If the image loaded if( loadedImage != NULL ) { //Create an optimized image optimizedImage = SDL_DisplayFormat( loadedImage ); //Free the old image SDL_FreeSurface( loadedImage ); } //Return the optimized image return optimizedImage; } void apply_surface( int x, int y, SDL_Surface* source, SDL_Surface* destination ) { //Rectangle to hold the offsets SDL_Rect offset; //Get offsets offset.x = x; offset.y = y; //Blit the surface SDL_BlitSurface( source, NULL, destination, &offset ); } bool init() { //Initialize all SDL subsystems if( SDL_Init( SDL_INIT_EVERYTHING ) == -1 ) { return false; } //Set up the screen screen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE ); //If there was an error in setting up the screen if( screen == NULL ) { return false; } //Set the window caption SDL_WM_SetCaption( "Battle Link", NULL ); //If everything initialized fine return true; } void clean_up() { //Free the surface SDL_FreeSurface( map1 ); //Quit SDL SDL_Quit(); } int main( int argc, char* args[] ) { //Initialize if( init() == false ) { printf("There has been an error in intializing the screen. Try again.\n"); sleep(5); return 1; } map1 = load_image( "map1.bmp" ); if(!map1) { printf("IMG_Load: %s\n", IMG_GetError()); printf("There has been an error intializing the file. Try again."); sleep(5); return 1; } start = load_image( "pics/start.jpg" ); if(!start) { printf("IMG_Load: %s\n", IMG_GetError()); printf("There has been an error intializing the file. Try again."); sleep(5); return 1; } int stoploop = 0; int mousex; int mousey; bool quit=false; while (!quit) { if( SDL_PollEvent( &event ) ) { if( event.type == SDL_MOUSEBUTTONDOWN) { if( event.button.button == SDL_BUTTON_LEFT) { mousex = event.button.x; mousey = event.button.y; } } } //if mouse is over the button if( (mousex > 50) && (mousex < 400) && (mousey > 50) && (mousey < 450)) { SDL_WM_SetCaption( "Button Clicked, Exiting", NULL ); quit=true; } apply_surface(50,50,start,screen); //apply the surfaces to the screen apply_surface(0,48,map1,screen); //Update screen if( SDL_Flip( screen) == -1) { return 1; } SDL_Delay(100); } clean_up(); return 0; }
Re: SDL Help May 16, 2009 03:40AM | Registered: 15 years ago Posts: 444 |
SDL_Surface *load_image( string filename ) { //The image that's loaded SDL_Surface* loadedImage = NULL; //The optimized image that will be used SDL_Surface* optimizedImage = NULL; //Load the image using SDL_image loadedImage = IMG_Load( filename.c_str() ); //If the image loaded if( loadedImage != NULL ) { //Create an optimized image optimizedImage = SDL_DisplayFormat( loadedImage ); //Free the old image SDL_FreeSurface( loadedImage ); } //Return the optimized image return optimizedImage; }and Here:
class Linkman { public: Linkman(); ~Linkman(); void SetX(int xx) {x = xx;} void SetY(int yy) {y = yy;} int GetX() {return x;} int GetY() {return y;} void SetFace(bool b) {faceup = b;} bool GetFace() {return faceup;} void SetLink(bool b) {whichlink = b;} bool GetLink() {return whichlink;} private: int x; int y; bool faceup; bool whichlink; }
expected init-declarator before * token expected `,' or `;' before * token In function `int SDL_main(int, char**)'; `load_image' undeclared invalid use of member (did you forget the '&' ?) invalid use of member (did you forget the '&' ?) invalid use of member (did you forget the '&' ?) invalid use of member (did you forget the '&' ?) 257 D:\MinGW\Battle Link\main.cpp cannot convert `SDL_Rect' to `SDL_Rect*' for argument `5' to `void apply_surface(int, int, SDL_Surface*, SDL_Surface*, SDL_Rect*)' `voidI had to copy these by hand
Re: SDL Help May 16, 2009 08:15PM | Registered: 15 years ago Posts: 8 |
expected unqualified-id at end of input expected `,' or `;' at end of inputThat's from your Linkman class. You need to put a semicolon after the class definition.
class Linkman
{
public:
Linkman();
~Linkman();
void SetX(int xx) {x = xx;}
void SetY(int yy) {y = yy;}
int GetX() {return x;}
int GetY() {return y;}
void SetFace(bool b) {faceup = b;}
bool GetFace() {return faceup;}
void SetLink(bool b) {whichlink = b;}
bool GetLink() {return whichlink;}
private:
int x;
int y;
bool faceup;
bool whichlink;
}; // <---------- there
Re: SDL Help May 18, 2009 05:47AM | Registered: 15 years ago Posts: 444 |