Jump to content
  • Advertisement

petelta

Member
  • Content Count

    59
  • Joined

  • Last visited

Community Reputation

140 Neutral

About petelta

  • Rank
    Member
  1. petelta

    Key Presses

    I found a table by googling it.
  2. petelta

    Key Presses

    Using SDL, I have done key presses for up, down, left, and right keys. how do I do a key press for the rest of the keys. I am just trying to have the "a" key be pushed but can't figure it out. this is what I use for up: if (SDL_PollEvent( &event )) { if ( event.type == SDL_KEYDOWN ) { switch( event.key.keysym.sym ) { case SDLK_UP: message = up; break; if I try and SDLK_A:.... its doesn't work. what do I need to put here for the A key to be pushed?
  3. petelta

    Setting multiple colorkeys

    I forgot to mention that the way I got it to work was by making another load_image function that sets a different colorkey and just call a different load_image function depending on the image. Is there a better way to go about this?
  4. On the Lazy Foo tutorial, I am setting a color key so that the background of my image is transperant. Right now I am playing around with this new function call and am throwing multiple bitmaps onto one screen. each bitmap has a different background color. I am wondering how I can have a different colorkey depending on the image. right now I am using the SDL_SetColorKey() in a load_image function: SDL_Surface *load_image( std::string filename ) { //The image that's loaded SDL_Surface* loadedImage = NULL; //The optimized surface that will be used SDL_Surface* optimizedImage = NULL; //Load the image loadedImage = IMG_Load( filename.c_str() ); //If the image loaded if( loadedImage != NULL ) { //Create an optimized surface optimizedImage = SDL_DisplayFormat( loadedImage ); //Free the old surface SDL_FreeSurface( loadedImage ); //If the surface was optimized if( optimizedImage != NULL ) { //Color key surface SDL_SetColorKey( optimizedImage, SDL_RLEACCEL | SDL_SRCCOLORKEY, SDL_MapRGB( optimizedImage->format, 0xFF, 0xFF, 0xFF ) ); } } //Return the optimized surface return optimizedImage; } if i try and add another SetColorKey line it just goes for the last one written.
  5. petelta

    SDL problem

    I didn't have the lazy.ttf text file...That was my problem. Thanks alot for the help.
  6. petelta

    SDL problem

    I have been going thru the SDL tutorials at Lazy Foo productions. I have made it to the true type font and key press tutorials. When I have gone thru and compile my program, it just flashes up and flashes away. it doesn't allow me to do anything. I have tried adding a SDL_Delay() just to see some output and nothing. Here is my code: #include "SDL/SDL.h" #include "SDL/SDL_image.h" #include "SDL/SDL_ttf.h" #include <string> const int SCREEN_WIDTH = 640; const int SCREEN_HEIGHT = 480; const int SCREEN_BPP = 32; SDL_Surface *background = NULL; SDL_Surface *up = NULL; SDL_Surface *down = NULL; SDL_Surface *left = NULL; SDL_Surface *right = NULL; SDL_Surface *message = NULL; SDL_Surface *screen = NULL; SDL_Event event; TTF_Font *font = NULL; SDL_Color textColor = { 0, 0, 0 }; SDL_Surface *load_image( std::string filename ) { SDL_Surface* loadedImage = NULL; SDL_Surface* optimizedImage = NULL; loadedImage = IMG_Load( filename.c_str() ); if( loadedImage != NULL ) { optimizedImage = SDL_DisplayFormat( loadedImage ); SDL_FreeSurface( loadedImage ); if( optimizedImage != NULL ) { SDL_SetColorKey( optimizedImage, SDL_RLEACCEL | SDL_SRCCOLORKEY, SDL_MapRGB( optimizedImage->format, 0, 0xFF, 0xFF ) ); } } return optimizedImage; } void apply_surface( int x, int y, SDL_Surface* source, SDL_Surface* destination, SDL_Rect* clip = NULL ) { SDL_Rect offset; offset.x = x; offset.y = y; SDL_BlitSurface( source, clip, destination, &offset ); } bool init() { if( SDL_Init( SDL_INIT_EVERYTHING ) == -1 ) { return false; } screen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE ); if( screen == NULL ) { return false; } if( TTF_Init() == -1 ) { return false; } SDL_WM_SetCaption( "Press an Arrow Key", NULL ); return true; } bool load_files() { background = load_image( "background.png" ); font = TTF_OpenFont( "lazy.ttf", 72 ); if( background == NULL ) { return false; } if( font == NULL ) { return false; } return true; } void clean_up() { SDL_FreeSurface( background ); SDL_FreeSurface( message ); SDL_FreeSurface( up ); SDL_FreeSurface( down ); SDL_FreeSurface( left ); SDL_FreeSurface( right ); TTF_CloseFont( font ); TTF_Quit(); SDL_Quit(); } int main( int argc, char* args[] ) { bool quit = false; if( init() == false ) { return 1; } if( load_files() == false ) { return 1; } up = TTF_RenderText_Solid( font, "Up was pressed.", textColor ); down = TTF_RenderText_Solid( font, "Down was pressed.", textColor ); left = TTF_RenderText_Solid( font, "Left was pressed", textColor ); right = TTF_RenderText_Solid( font, "Right was pressed", textColor ); apply_surface( 0, 0, background, screen ); while( quit == false ) { if( SDL_PollEvent( &event ) ) { if( event.type == SDL_KEYDOWN ) { switch( event.key.keysym.sym ) { case SDLK_UP: message = up; break; case SDLK_DOWN: message = down; break; case SDLK_LEFT: message = left; break; case SDLK_RIGHT: message = right; break; } } else if( event.type == SDL_QUIT ) { //Quit the program quit = true; } } if( message != NULL ) { apply_surface( 0, 0, background, screen ); apply_surface( ( SCREEN_WIDTH - message->w ) / 2, ( SCREEN_HEIGHT - message->h ) / 2, message, screen ); message = NULL; } if( SDL_Flip( screen ) == -1 ) { return 1; } } clean_up(); return 0; } what am I doing wrong
  7. petelta

    SDL color keying

    alright, thanks. That makes sense.
  8. petelta

    SDL color keying

    Im doing the Lazy Foo tutorials right now and am doing the color keying. I am wondering where I can find the color codes so that I can make the background colors be transperant. On the tutorial, it has: Uint32 colorkey = SDL_MapRGB( optimizedImage->format, 0, 0xFF, 0xFF ); and that is for a light blue background. I have a few images with other colors I would like to use.
  9. I know there is a function that allows you to pause the game for X amount of seconds. I can't remember what it is and can't find it. Anyone know what Im talking about? Im trying to display information but each line only 2 seconds at a time.
  10. is it possible to pass in 2 class paramters to a function. I have a Character class, one is the player, and the other is the enemy. Now I have a battle function, and was wondering if I can pass both character classes into the battle function so I can keep track of there hit points and things like that. What Im thinking is: void battle(character player, character enemy) { player.GetHitPoints(); enemy.GetHitPoints(); } just wondering if something like that is possible.
  11. to answer my own question. instead of calling a class function within a class function with Warrior.ShowStats(), etc. I just put ShowStats(). Im an idiot heh. thanks
  12. I have a class Character, Ive called that class in int main() as: Character Warrior. Later I call a function within the class. Within that funciton I try and call another function within the class. It says that Warrior is undefined. Here is parts of the code to further explain my problem: void Character::ShowStats() { cout << endl << "Stats:" << endl; cout << "Strength: " << itsStrength << endl; cout << "Vitality: " << itsVitality << endl; cout << "Wisdom: " << itsWisdom << endl << endl; Warrior.AnswerStats(); } void Character::AnswerStats() { int answer; cout << "Are you happy with these stats? (0 = yes or 1 = no): "; cin >> answer; cout << endl; if (answer == 1) { Warrior.ShowStats(); } if (answer > 1) { cout << endl << "Incorrect Choice." << endl << endl; Warrior.AnswerStats(); } if (answer == 0) { cout << endl << endl << "Your Character has been completed." << endl << endl; } } Just wondering how to call upon a class function within another class function. Without it being a class function, within a ShowStats() function I can of course call upon a AnswerStats() function. And also, within an AnswerStats() function I can recall AnswerStats() function. Thanks
  13. petelta

    String.h

    alright, i think i understand what your saying now glak. I didn't know that i was creating a \n and needed to clear it out. Thanks alot for the help.
  14. petelta

    String.h

    ok using this code it is doing almost exactly what I want it to do: #include <iostream> #include <string> using namespace std; class Character { public: Character(){}; ~Character() {}; void SetName(string name){itsName = name;} void GetName(){cout << itsName << endl;} private: string itsName; }; int menu(); int main() { srand( (unsigned)time( NULL ) ); string name; Character Dave; cout << "\t\t\t* * * * Banishment * * * *" << endl << endl << endl; bool exit = false; while (!exit) { int choice = menu(); switch(choice) { case (1): cout << "Characters Name: "; cin >> name; Dave.SetName(name); case (2): Dave.GetName(); break; case (3): break; case (4): exit = true; break; default: cout << "Please select an appropriate choice." << endl << endl; continue; break; } if (exit == true) break; } cout << "Thank you for playing."; char response; cin >> response; return 0; } int menu() { int choice; cout << "* * * * Menu * * * *" << endl << endl; cout << "(1) Create Character " << endl; cout << "(2) See character name" << endl; cout << "(3) ..." << endl; cout << "(4) Quit " << endl << endl; cout << "= "; cin >> choice; cout << endl; return choice; } the problem i have is where i have cin >> name. it works jsut like i would like it to with cin, but I would like to use to two words if possible. so i would think like before use getline(cin, name), but it doesn't allow me to enter anything when using this in that position.
  15. petelta

    String.h

    i was using Dave.SetName(cin) and then Dave.GetName(cout) to be able to ask to name a character then print the name out. i took out GetName(cout) right now just to be able to enter a name. It is not allowing me to enter a name at all
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!