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
Zitat von »"GR-PA"«
Mach's doch einfach so wie ich es dir empfohlen hab (oder so ähnlich) dann hast du das Problem nicht.
Außerdem hast du den Sinn von Containern scheinbar nicht begriffen. Sie sind dazu gedacht, Daten zu speichern und nicht dazu, zu einer sinnlosen und nutzlosen Zeigersammlung zu werden.
Zitat von »"dot"«
Wenn dus so gemacht hast wie er sagt dann brauchst du ja aber auch kein delete mehr weil du die Dinger ja nicht mit new erzeugst
Zitat von »"Mitsuomi-San"«
Zitat von »"dot"«
Wenn dus so gemacht hast wie er sagt dann brauchst du ja aber auch kein delete mehr weil du die Dinger ja nicht mit new erzeugst
nadan muss ich sie nurnoch aus der liste entfernen oder wie??
Zitat von »"drakon"«
Zitat von »"Mitsuomi-San"«
Zitat von »"dot"«
Wenn dus so gemacht hast wie er sagt dann brauchst du ja aber auch kein delete mehr weil du die Dinger ja nicht mit new erzeugst
nadan muss ich sie nurnoch aus der liste entfernen oder wie??
Jop. So einfach ist das dann.
Zitat von »"drakon"«
Zeig mal, wie die Umgebung jetzt aussieht und was du genau für einen Fehler bekommst.
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 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 |
#include <iostream> #include <windows.h> #include <SDL/SDL.h> #include <time.h> #include <list> using namespace std; float time3 = 0; //int shotzahl = 0; float shottime = 0; SDL_Surface *screen, *shot; class cShot { public: SDL_Rect shotrec; bool live; cShot (int x) { shotrec.y = 512; shotrec.h = shot->h; shotrec.w = shot->w; shotrec.x = x; live = true; } ~cShot () {} bool update () { SDL_BlitSurface(shot, NULL, screen, &shotrec); shotrec.y -= 150.0f * time3; if (shotrec.y <= 0) { shotrec.y = -60; live = false; } return live; } }; int main(int argc, char *argv[]) { //var SDL_Surface *image, *bgimg; SDL_Rect dst, dstblue, drect, srect; SDL_Event event; Uint8 *keys; int tuxX = 288, tuxY = 416; int done = 0; //zeit float time1 = 0, time2 = 0; //klasse shot list<cShot> lShot; list<cShot>::iterator i; //cShot *Temp = NULL; shot = SDL_LoadBMP("Laser.bmp"); if (shot == NULL) { MessageBoxA(NULL,"Can't load image of Shot","",0); } SDL_SetColorKey(shot, SDL_SRCCOLORKEY, SDL_MapRGB(shot->format, 255, 0, 255)); time1 = SDL_GetTicks() / 1000.0f; if (SDL_Init(SDL_INIT_VIDEO) == -1) { MessageBoxA(NULL,"Can't init SDL","",0); return 0; } atexit(SDL_Quit); screen = SDL_SetVideoMode(640, 480, 16, SDL_HWSURFACE | SDL_DOUBLEBUF); SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 255)); if (screen == NULL) { MessageBoxA(NULL,"Can't set video mode","",0); return 0; } bgimg = SDL_LoadBMP("bg.bmp"); if (image == NULL) { MessageBoxA(NULL,"Can't load image of BG","",0); return 0; } image = SDL_LoadBMP("Player.bmp"); if (image == NULL) { MessageBoxA(NULL,"Can't load image of Player","",0); return 0; } dst.w = image->w; dst.h = image->h; dstblue.w = image->w + 1; dstblue.h = image->h + 1; SDL_SetColorKey(image, SDL_SRCCOLORKEY, SDL_MapRGB(image->format, 255, 0, 255)); // Setzen des Quellbereichs srect.x = 320; srect.y = 0; srect.w = 64; // das halbe Bild srect.h = image->h; // das gesamte Bild while (!done) { while (SDL_PollEvent(&event)) { switch(event.type) { case SDL_QUIT: done = 1; break; } } dstblue.x = tuxX; dstblue.y = tuxY; keys = SDL_GetKeyState(NULL); /*if (keys[SDLK_UP]) { if (tuxY > 10) { tuxY--; } } if (keys[SDLK_DOWN]) { if (tuxY < 470 - image->h) { tuxY++; } }*/ if (keys[SDLK_RIGHT]) { if(tuxX < 640 - 64) { tuxX += 230.0f * time3; if (srect.x < 640) { srect.x += 64.0f; } } } else if (keys[SDLK_LEFT]) { if (tuxX > 10) { tuxX -= 150.0f * time3; if (srect.x > 0) { srect.x -= 64.0f; } } } else { srect.x = 320; } if (keys[SDLK_ESCAPE]) { done = 1; } //schießen wuhaaa if (keys[SDLK_SPACE]) { shottime += time3; if (shottime >= 0.2f) { i++; lShot.push_back(cShot(tuxX)); shottime = 0; } } // Setzen des Zielbereichs drect.x = tuxX; drect.y = tuxY; drect.w = 64; drect.h = image->h; dst.x = tuxX; dst.y = tuxY; SDL_FillRect(screen, &dstblue, SDL_MapRGB(screen->format, 0, 0, 255)); SDL_BlitSurface(bgimg, NULL, screen, NULL); //SDL_BlitSurface(image, NULL, screen, &dst); SDL_BlitSurface(image, &srect, screen, &drect); //für shoot for (i=lShot.begin(); i!=lShot.end(); ++i) { if(((*i).update ())== false) { lShot.erase (i); } } SDL_UpdateRects(screen,1,&drect); SDL_Flip(screen); time2 = SDL_GetTicks() / 1000.0f; time3 = time2 - time1; time1 = time2; } SDL_FreeSurface(image); SDL_FreeSurface(bgimg); SDL_QUIT; return 0; } |
Werbeanzeige