Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
#include <iostream> #include "SDL.h" #include "Sprite.h" #undef main using namespace std; bool bRun = true; bool bLeft = false; bool bRight = false; // Links/Rechts steuern int main () { Sprite *Tux, *BackImg; SDL_Surface *Screen, *Image, *Background; SDL_Event event; // SDL Init, VideoMode setzen und so Image = SDL_LoadBMP("Tux.bmp"); Background = SDL_LoadBMP("TuxBack.bmp"); SDL_SetColorKey(Image, SDL_SRCCOLORKEY, SDL_MapRGB(Image->format, 255, 0,0)); Tux = new Sprite(Image, 0, 370); BackImg = new Sprite(Background, 0, 0); //Schleife und Angaben zum Keyboard while (bRun) { while (SDL_PollEvent (&event)) { switch (event.type) { case SDL_KEYDOWN: if (event.key.keysym.sym == SDLK_ESCAPE) { bRun = false; } else if (event.key.keysym.sym == SDLK_SPACE) { bSpace = true; } else if (event.key.keysym.sym == SDLK_LEFT) { bLeft = true; } else if (event.key.keysym.sym == SDLK_RIGHT) { bRight = true; } break; case SDL_KEYUP: if (event.key.keysym.sym == SDLK_SPACE) { bSpace = false; } else if (event.key.keysym.sym == SDLK_LEFT) { bLeft = false; } else if (event.key.keysym.sym == SDLK_RIGHT) { bRight = false; } break; case SDL_QUIT: bRun = false; break; default: break; } } if (bLeft) { Tux->Move(-1, 0); } else if (bRight) { Tux->Move(1, 0); } SDL_FillRect(Screen, NULL, bgcolor); Tux->Draw(Background); BackImg->Draw(Screen); SDL_Flip(Screen); } return 0; } |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
#ifndef __SPRITE_H__ #define __SPRITE_H__ #include <SDL.h> class Sprite { public: Sprite (SDL_Surface *new_Image, int x, int y); void SetImage (SDL_Surface *new_Image); void SetPos (int x, int y); void Move (int move_x, int move_y); SDL_Rect *GetRect(void); void Draw (SDL_Surface *Target); protected: SDL_Surface *Image; SDL_Rect rRect; }; #endif |
C-/C++-Quelltext |
|
1 |
SDL_FillRect(Screen, NULL, SDL_MapRGB(Screen->format,0,0,0)); |
idontknow
unregistriert
Werbeanzeige