Du bist nicht angemeldet.

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

GR-PA

Treue Seele

Beiträge: 326

Wohnort: Daheim

Beruf: Faulenzer

  • Private Nachricht senden

11

05.01.2010, 18:37

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.
Signaturen werden überbewertet

12

05.01.2010, 18:45

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.


und genau weil ich es so gemacht habe habe ich ja jetzt das problem....

dot

Supermoderator

Beiträge: 9 757

Wohnort: Graz

  • Private Nachricht senden

13

05.01.2010, 19:12

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 ;)

14

05.01.2010, 20:12

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??

drakon

Supermoderator

Beiträge: 6 513

Wohnort: Schweiz

Beruf: Entrepreneur

  • Private Nachricht senden

15

05.01.2010, 20:22

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. ;)

16

05.01.2010, 20:24

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. ;)



oooh danke ich bin soo ein depp XD das ist allesn och für mich neuland also c++ jetzt nicht aber das mit den SDL und STL

danke das ihr soviel gedult aufgebracht habt ^^

edit: naja doch nicht so ganz er hängt sich auf wen ein schuß aus der liste lösche wird mittels lShot.erase (i);

drakon

Supermoderator

Beiträge: 6 513

Wohnort: Schweiz

Beruf: Entrepreneur

  • Private Nachricht senden

17

05.01.2010, 20:50

Zeig mal, wie die Umgebung jetzt aussieht und was du genau für einen Fehler bekommst.

18

05.01.2010, 20:55

Zitat von »"drakon"«

Zeig mal, wie die Umgebung jetzt aussieht und was du genau für einen Fehler bekommst.


ok also es sieht so aus:

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;
 }


und das fenster sagt mir dan "keine rückmeldung" wen es zum löschen kommt! und abstürzen tut er erst nach den löschen habe es mit msgboxen überprüft!

edit:
ok problem gelöst wen ich ein break; rein hauhe in dei schleife feld es nicht auf und das programm läuft weiter ^^

thx trozdem an alle!

19

05.01.2010, 20:56

for (i=lShot.begin(); i!=lShot.end(); ++i)
{
if(((*i).update ())== false)
{
i = lShot.erase (i);
}
}

drakon

Supermoderator

Beiträge: 6 513

Wohnort: Schweiz

Beruf: Entrepreneur

  • Private Nachricht senden

20

05.01.2010, 21:03

@Mitsuomi-San:
E122 hat den Fehler gefunden und das sollte behoben werden. Weil was du da machst ist undefiniert (kann also ebenfalls funktionieren oder auch nicht).
Du inkrementierst im nächsten Schritt nämlich einen ungültigen Iterator.

Werbeanzeige