jegor377 Temat założony przez niniejszego użytkownika |
[C++, SDL] Wysypanie się programu po zakończeniu (SDL_Mixer) » 2015-01-03 12:53:21 Mam taki problem, otóż mój program po zamknięciu się wysypuje, a zaczęło się to od momentu kiedy dodałem bibliotekę sdl_mixer i w ogóle muzykę do gry... Nie wiem jak to naprawić i co jest źle w moim kodzie, więc liczę na szybką pomoc. :) Tutaj zamieszczam kod: main.cpp #include <SDL2/SDL.h> #include <SDL2/SDL_image.h> #include <SDL2/SDL_ttf.h> #include "source.h" #undef main
using namespace std;
int xmap = 20, ymap = 12, xmouse, ymouse, followx = 0, followy = 0, followOB =- 1, points = 30, max_fire_size = 150, hp = 100, level = 1, nextlevel = 100; int fps, frames; unsigned long long int fpsDelay = SDL_GetTicks(), createtimer = SDL_GetTicks(), movetime = SDL_GetTicks(), enemycreate = SDL_GetTicks(), fire = SDL_GetTicks(), powertime = SDL_GetTicks(), attacktime = SDL_GetTicks(), enemymovetimer = SDL_GetTicks(); bool isSelected = false, quit = false, debug = false, gameover = false;
string window_caption;
int main( int argc, char * argv[] ) { SDL_Init( SDL_INIT_EVERYTHING ); TTF_Init(); Mix_OpenAudio( 22050, MIX_DEFAULT_FORMAT, 2, 4096 ); SDL_Window * game_window = SDL_CreateWindow( "Fifty Levels", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 480, SDL_WINDOW_SHOWN ); SDL_Renderer * game_render = SDL_CreateRenderer( game_window, - 1, SDL_RENDERER_ACCELERATED ); SDL_Event * game_events = new SDL_Event(); Mix_Music * game_music; Mix_Chunk * strzelanie = Mix_LoadWAV( "laser_ray_cannon.wav" ); vector < GameObject > wojsko; vector < GameObject > wrogowie; vector < GameObject > pociski; GameObject createbutton( 7, 0, ymap, 192, 96, 0, 0, 128, 64, 0.0 ); GameObject bar( 8, 6, 12, 448, 96, 0, 0, 448, 64, 0.0 ); GameObject * stage = new GameObject[ 6 ]; stage[ 0 ] = GameObject( 5, 1, 0, 32, 32, 0, 0, 64, 64, 0.0 ); stage[ 1 ] = GameObject( 5, 1, 1, 32, 32, 0, 0, 64, 64, 0.0 ); stage[ 2 ] = GameObject( 5, 0, 1, 32, 32, 0, 0, 64, 64, 0.0 ); stage[ 3 ] = GameObject( 5, xmap - 2, ymap - 1, 32, 32, 0, 0, 64, 64, 0.0 ); stage[ 4 ] = GameObject( 5, xmap - 2, ymap - 2, 32, 32, 0, 0, 64, 64, 0.0 ); stage[ 5 ] = GameObject( 5, xmap - 1, ymap - 2, 32, 32, 0, 0, 64, 64, 0.0 ); CSprite * tekstura[ 11 ]; GameObject ** grass = new GameObject *[ xmap ]; for( int a = 0; a <= xmap - 1; a++ ) grass[ a ] = new GameObject[ ymap ]; GameObject mousepointer( 2, 0, 0, 32, 32, 0, 0, 64, 64, 0.0, false, 0, 0, 0, 0, 0, 0, 0 ); GameObject swoj( 3, 0, 0, 32, 32, 0, 0, 64, 64, 0.0, false, 0, 0, 0, 0, 0, 0, 0 ); GameObject wrog( 4, xmap - 1, ymap - 1, 32, 32, 0, 0, 64, 64, 0.0, false, 0, 0, 0, 0, 0, 0, 0 ); tekstura[ 0 ] = new CSprite( "grass.png", game_render ); tekstura[ 1 ] = new CSprite( "player.png", game_render ); tekstura[ 2 ] = new CSprite( "zaznaczenie.png", game_render ); tekstura[ 3 ] = new CSprite( "swoj.png", game_render ); tekstura[ 4 ] = new CSprite( "wrog.png", game_render ); tekstura[ 5 ] = new CSprite( "stage.png", game_render ); tekstura[ 6 ] = new CSprite( "button.png", game_render ); tekstura[ 7 ] = new CSprite( "button2.png", game_render ); tekstura[ 8 ] = new CSprite( "bar.png", game_render ); tekstura[ 9 ] = new CSprite( "enemy.png", game_render ); tekstura[ 10 ] = new CSprite( "fire.png", game_render ); for( int y = 0; y <= ymap - 1; y++ ) for( int x = 0; x <= xmap - 1; x++ ) grass[ x ][ y ] = GameObject( 0, x, y, 32, 32, 0, 0, 64, 64, 0.0, false, 0, 0, 0, 0, 0, 0, 0 ); while( quit == false && game_events->type != SDL_QUIT ) { SDL_PollEvent( game_events ); SDL_RenderClear( game_render ); if( debug == true ) ShowFPS( & fps, & fpsDelay, & frames ); for( int y = 0; y <= ymap - 1; y++ ) { for( int x = 0; x <= xmap - 1; x++ ) { tekstura[ 0 ]->Draw( & grass[ x ][ y ] ); } } enemyCreate( & wrogowie, xmap, ymap, & enemycreate, level ); MouseController( game_events, & xmouse, & ymouse, xmap, ymap, & mousepointer, & isSelected, & createbutton, & wojsko, & createtimer, & followx, & followy, & followOB, & points ); OnKeyDown( game_events, & quit, & debug ); strzal( & wrogowie, & wojsko, & pociski, & fire, max_fire_size, strzelanie ); pocisk( & pociski, & powertime ); CollisionWithFire( & pociski, & wrogowie, & attacktime ); Dead( & wrogowie, & points ); enemymove( & wrogowie, & enemymovetimer, & hp, level ); deletePlayer( & wojsko, & hp, & points ); gameOver( hp, points, & wojsko, game_render, & quit, & gameover ); uplevel( points, & level, & nextlevel ); for( int x = 0; x <= 5; x++ ) tekstura[ stage[ x ].type ]->Draw( & stage[ x ] ); if( isSelected == true ) tekstura[ mousepointer.type ]->Draw( & mousepointer ); Follow( followOB, & wojsko, followx, followy, & movetime ); if( pociski.size() > 0 ) for( int a = 0; a <= pociski.size() - 1; a++ ) tekstura[ pociski[ a ].type ]->Draw( & pociski[ a ] ); if( wojsko.size() > 0 ) for( int a = 0; a <= wojsko.size() - 1; a++ ) tekstura[ wojsko[ a ].type ]->Draw( & wojsko[ a ] ); if( wrogowie.size() > 0 ) for( int a = 0; a <= wrogowie.size() - 1; a++ ) tekstura[ wrogowie[ a ].type ]->Draw( & wrogowie[ a ] ); tekstura[ swoj.type ]->Draw( & swoj ); tekstura[ wrog.type ]->Draw( & wrog ); tekstura[ bar.type ]->Draw( & bar ); tekstura[ createbutton.type ]->Draw( & createbutton ); aboutObject( followOB, & wojsko, game_render ); if( debug == true ) TextOn( "FPS : " + intToStr( frames ), 10, 10, 12, "Tahoma.ttf", 255, 0, 0, game_render ); if( debug == true ) TextOn( "Mouse Position: x = " + intToStr( xmouse / 32 ) + " y = " + intToStr( ymouse / 32 ), 10, 30, 12, "Tahoma.ttf", 255, 0, 0, game_render ); if( debug == true ) TextOn( "FOLLOW_X : " + intToStr( followx ) + " FOLLOW_Y : " + intToStr( followy ), 10, 50, 12, "Tahoma.ttf", 0, 0, 0, game_render ); TextOn( "HP : " + intToStr( hp ) + " Level : " + intToStr( level ) + " Points : " + intToStr( points ), 640 / 2 - 120, 10, 20, "Tahoma.ttf", 0, 0, 255, game_render ); if( gameover ) TextOn( "GAME OVER", 640 / 2 - 70, 480 / 2 - 30, 30, "Tahoma.ttf", 255, 0, 0, game_render ); Mix_PlayMusic( game_music, - 1 ); SDL_RenderPresent( game_render ); } if( gameover == true ) SDL_Delay( 5000 ); cout << "END" << endl; Mix_CloseAudio(); Mix_FreeChunk( strzelanie ); Mix_FreeMusic( game_music ); delete strzelanie; delete game_music; strzelanie = NULL; game_music = NULL; SDL_DestroyRenderer( game_render ); game_render = NULL; delete game_render; SDL_DestroyWindow( game_window ); game_window = NULL; delete game_window; game_events = NULL; delete game_events; delete[] stage; for( int x = 0; x <= 10; x++ ) delete tekstura[ x ]; wojsko.clear(); wrogowie.clear(); pociski.clear(); TTF_Quit(); Mix_Quit(); SDL_Quit(); return 0; }
source.h #include <SDL2/SDL.h> #include <SDL2/SDL_image.h> #include <SDL2/SDL_ttf.h> #include <SDL2/SDL_mixer.h> #include <iostream> #include <vector>
using namespace std;
class GameObject { public: int type, hp; int xpos, ypos, xsize, ysize, xcpos, ycpos, xcsize, ycsize; int ximagesize, yimagesize, animstart, animend, animrow, currentframe, animspeed; unsigned long long int animDelay; double angle; bool animation; SDL_Rect pos, cut; string kierunek; GameObject( int = 0, int = 0, int = 0, int = 0, int = 0, int = 0, int = 0, int = 0, int = 0, double = 0.0, bool = false, int = 0, int = 0, int = 0, int = 0, int = 0, int = 0, int = 0, string = "none" ); };
class CSprite { public: const char * name; SDL_Texture * image; SDL_Renderer * render; SDL_RendererFlip flip; SDL_Rect pos, cut; double angle; CSprite( const char * n = NULL, SDL_Renderer * r = NULL ); ~CSprite(); void Draw( GameObject * object ); void PlayAnimation( GameObject * animate_object ); };
void ShowFPS( int * fps, unsigned long long int * fpsDelay, int * frames );
string intToStr( int n );
void MouseController( SDL_Event * zdarzenie, int * xm, int * ym, int xmap, int ymap, GameObject * object, bool * isSelected, GameObject * button, vector < GameObject > * obiekty , unsigned long long int * createtimer, int * fx, int * fy, int * followob, int * points );
void ShowText( string textmessage, int xpos, int ypos, int fontsize, const char * fontname, int r, int b, int g, SDL_Renderer * render );
void TextOn( string textm, int xp, int yp, int fontsize, const char * fontname, int r, int g, int b, SDL_Renderer * render );
void Follow( int numofobject, vector < GameObject > * objects, int followx, int followy, unsigned long long int * movetime );
void OnKeyDown( SDL_Event * events, bool * quit, bool * debug );
void aboutObject( int numofobject, vector < GameObject > * objects, SDL_Renderer * render );
void enemyCreate( vector < GameObject > * enemys, int xpos, int ypos, unsigned long long int * createtime, int level );
void pocisk( vector < GameObject > * pociski, unsigned long long int * powertime );
void strzal( vector < GameObject > * enemys, vector < GameObject > * army, vector < GameObject > * fire, unsigned long long int * firetimer, int max_fire_size, Mix_Chunk * music );
void CollisionWithFire( vector < GameObject > * fire, vector < GameObject > * enemys, unsigned long long int * attacktime );
void Dead( vector < GameObject > * enemys, int * points );
void enemymove( vector < GameObject > * enemys, unsigned long long int * timer, int * hp, int level );
void deletePlayer( vector < GameObject > * army, int * hp, int * points );
void gameOver( int hp, int points, vector < GameObject > * army, SDL_Renderer * render, bool * quit, bool * gameover );
void uplevel( int points, int * lvl, int * uplvl );
source.cpp #include "source.h"
using namespace std;
GameObject::GameObject( int t, int xp, int yp, int xs, int ys, int xcp, int ycp, int xcs, int ycs, double a, bool anim, int xis, int yis, int as, int ae, int ar, int asp, int cf, string kier ) { kierunek = kier; hp = 100; type = t; xpos = xp; ypos = yp; xsize = xs; ysize = ys; xcpos = xcp; ycpos = ycp; xcsize = xcs; ycsize = ycs; angle = a; animation = anim; ximagesize = xis; yimagesize = yis; animstart = as; animend = ae; animrow = ar; animspeed = asp; currentframe = cf; pos.x = xpos * 32; pos.y = xpos * 32; pos.w = xsize; pos.h = ysize; cut.x = xcpos; cut.y = ycpos; cut.w = xcsize; cut.h = ycsize; animDelay = SDL_GetTicks(); }
CSprite::CSprite( const char * n, SDL_Renderer * r ) { name = n; render = r; image = IMG_LoadTexture( render, name ); if( image == NULL ) cout << "[CSprite->Konstruktor] Nie uda³o siê za³adowaæ tekstury do pamiêci." << endl; flip = SDL_FLIP_NONE; }
CSprite::~CSprite() { SDL_DestroyTexture( image ); }
void CSprite::Draw( GameObject * object ) { object->pos.x = object->xpos * 32; object->pos.y = object->ypos * 32; pos = object->pos; angle = object->angle; if( object->animation == true ) PlayAnimation( object ); else cut = object->cut; SDL_RenderCopyEx( render, image, & cut, & pos, angle, NULL, flip ); }
void CSprite::PlayAnimation( GameObject * animate_object ) { if( animate_object->animDelay + animate_object->animspeed < SDL_GetTicks() ) { if( animate_object->animend <= animate_object->currentframe ) animate_object->currentframe = animate_object->animstart; else animate_object->currentframe = animate_object->currentframe + 1; cut.x = animate_object->currentframe *( animate_object->xcsize / animate_object->ximagesize ); cut.y = animate_object->animrow *( animate_object->ycsize / animate_object->yimagesize ); cut.w =( animate_object->xcsize / animate_object->ximagesize ); cut.h =( animate_object->ycsize / animate_object->yimagesize ); animate_object->animDelay = SDL_GetTicks(); } }
void ShowFPS( int * fps, unsigned long long int * fpsDelay, int * frames ) { * fps =* fps + 1; if( * fpsDelay + 1000 <= SDL_GetTicks() ) { * fpsDelay = SDL_GetTicks(); * frames =* fps; * fps = 0; } }
void OnKeyDown( SDL_Event * events, bool * quit, bool * debug ) { if( events->type == SDL_KEYDOWN ) { switch( events->key.keysym.sym ) { case SDLK_ESCAPE: * quit = true; break; case SDLK_d: if( * debug == false ) * debug = true; else * debug = false; break; } } }
string intToStr( int n ) { string tmp, ret; if( n < 0 ) { ret = "-"; n = - n; } do { tmp += n % 10 + 48; n -= n % 10; } while( n /= 10 ); for( int i = tmp.size() - 1; i >= 0; i-- ) ret += tmp[ i ]; return ret; }
void MouseController( SDL_Event * zdarzenie, int * xm, int * ym, int xmap, int ymap, GameObject * object, bool * isSelected, GameObject * button , vector < GameObject > * obiekty, unsigned long long int * createtimer, int * fx, int * fy, int * followob, int * points ) { SDL_GetMouseState( xm, ym ); if( * ym / 32 <= ymap - 1 ) { * isSelected = true; } else { * isSelected = false; } object->xpos =* xm / 32; object->ypos =* ym / 32; if( * xm / 32 >= 0 && * xm / 32 <= 5 && * ym / 32 >= 12 && * ym / 32 <= 14 ) button->type = 6; else button->type = 7; switch( zdarzenie->type ) { case SDL_MOUSEBUTTONDOWN: switch( zdarzenie->button.button ) { case SDL_BUTTON_LEFT: if( * createtimer + 100 < SDL_GetTicks() ) { if( * xm / 32 >= 0 && * xm / 32 <= 5 && * ym / 32 >= 12 && * ym / 32 <= 14 && * points - 10 >= 0 ) { bool create1 = true; bool create2 = true; bool create3 = true; button->type = 7; if( obiekty->size() > 0 ) { for( int a = 0; a <= obiekty->size() - 1; a++ ) { if(( * obiekty )[ a ].xpos == 1 &&( * obiekty )[ a ].ypos == 0 ) create1 = false; if(( * obiekty )[ a ].xpos == 1 &&( * obiekty )[ a ].ypos == 1 ) create2 = false; if(( * obiekty )[ a ].xpos == 0 &&( * obiekty )[ a ].ypos == 1 ) create3 = false; } } if( create1 == true ) { * points =* points - 10; obiekty->push_back( GameObject( 1, 1, 0, 32, 32, 0, 0, 64, 64, 0.0 ) ); } else if( create2 == true ) { * points =* points - 10; obiekty->push_back( GameObject( 1, 1, 1, 32, 32, 0, 0, 64, 64 ) ); } else if( create3 == true ) { * points =* points - 10; obiekty->push_back( GameObject( 1, 0, 1, 32, 32, 0, 0, 64, 64 ) ); } } * createtimer = SDL_GetTicks(); } if( * ym / 32 <= 11 ) { if( obiekty->size() > 0 ) { for( int a = 0; a <= obiekty->size() - 1; a++ ) { if( * xm / 32 ==( * obiekty )[ a ].xpos && * ym / 32 ==( * obiekty )[ a ].ypos ) { * followob = a; } } } * fx =* xm / 32; * fy =* ym / 32; } break; case SDL_BUTTON_RIGHT: * followob =- 1; break; } break; } }
void Follow( int numofobject, vector < GameObject > * objects, int followx, int followy, unsigned long long int * movetime ) { if( * movetime + 50 < SDL_GetTicks() ) { if( numofobject !=- 1 ) { if(( * objects )[ numofobject ].xpos < followx ) { string lastkierunek =( * objects )[ numofobject ].kierunek; ( * objects )[ numofobject ].xpos =( * objects )[ numofobject ].xpos + 1; ( * objects )[ numofobject ].kierunek = "right"; if(( * objects )[ numofobject ].xpos == 19 &&( * objects )[ numofobject ].ypos == 11 ) { ( * objects )[ numofobject ].kierunek = lastkierunek; ( * objects )[ numofobject ].xpos =( * objects )[ numofobject ].xpos - 1; } } if(( * objects )[ numofobject ].xpos > followx ) { string lastkierunek =( * objects )[ numofobject ].kierunek; ( * objects )[ numofobject ].xpos =( * objects )[ numofobject ].xpos - 1; ( * objects )[ numofobject ].kierunek = "left"; if(( * objects )[ numofobject ].xpos == 0 &&( * objects )[ numofobject ].ypos == 0 ) { ( * objects )[ numofobject ].kierunek = lastkierunek; ( * objects )[ numofobject ].xpos =( * objects )[ numofobject ].xpos + 1; } } if(( * objects )[ numofobject ].ypos < followy ) { string lastkierunek =( * objects )[ numofobject ].kierunek; ( * objects )[ numofobject ].ypos =( * objects )[ numofobject ].ypos + 1; ( * objects )[ numofobject ].kierunek = "down"; if(( * objects )[ numofobject ].xpos == 19 &&( * objects )[ numofobject ].ypos == 11 ) { ( * objects )[ numofobject ].kierunek = lastkierunek; ( * objects )[ numofobject ].ypos =( * objects )[ numofobject ].ypos - 1; } } if(( * objects )[ numofobject ].ypos > followy ) { string lastkierunek =( * objects )[ numofobject ].kierunek; ( * objects )[ numofobject ].ypos =( * objects )[ numofobject ].ypos - 1; ( * objects )[ numofobject ].kierunek = "up"; if(( * objects )[ numofobject ].xpos == 0 &&( * objects )[ numofobject ].ypos == 0 ) { ( * objects )[ numofobject ].kierunek = lastkierunek; ( * objects )[ numofobject ].ypos =( * objects )[ numofobject ].ypos + 1; } } } * movetime = SDL_GetTicks(); } }
void TextOn( string textm, int xp, int yp, int fontsize, const char * fontname, int r, int g, int b, SDL_Renderer * render ) { TTF_Font * font = TTF_OpenFont( fontname, fontsize ); if( font == NULL ) cout << "FONT == NULL" << endl; if( render == NULL ) cout << "RENDER == NULL" << endl; SDL_Color kolor; kolor.r = r; kolor.g = g; kolor.b = b; SDL_Surface * wiadomos = TTF_RenderText_Solid( font, textm.c_str(), kolor ); int w = 0, h = 0; SDL_Texture * tekstura = SDL_CreateTextureFromSurface( render, wiadomos ); SDL_QueryTexture( tekstura, NULL, NULL, & w, & h ); SDL_Rect pos; pos.x = xp; pos.y = yp; pos.w = w; pos.h = h; SDL_RenderCopy( render, tekstura, NULL, & pos ); SDL_DestroyTexture( tekstura ); tekstura = NULL; delete tekstura; SDL_FreeSurface( wiadomos ); wiadomos = NULL; delete wiadomos; TTF_CloseFont( font ); font = NULL; delete font; }
void aboutObject( int numofobject, vector < GameObject > * objects, SDL_Renderer * render ) { if( numofobject !=- 1 ) { TextOn( "ID : " + intToStr( numofobject ), 6 * 32 + 20, 12 * 32 + 20, 14, "Tahoma.ttf", 255, 255, 255, render ); TextOn( "HP : " + intToStr(( * objects )[ numofobject ].hp ), 6 * 32 + 20, 12 * 32 + 40, 14, "Tahoma.ttf", 255, 255, 255, render ); } }
void enemyCreate( vector < GameObject > * enemys, int xpos, int ypos, unsigned long long int * createtime, int level ) { int speed = 500 - level * 20; if( speed < 0 ) speed = 0; if( * createtime + speed < SDL_GetTicks() ) { bool create1 = true, create2 = true, create3 = true; if( enemys->size() > 0 ) { for( int a = 0; a <= enemys->size() - 1; a++ ) { if(( * enemys )[ a ].xpos == xpos - 2 &&( * enemys )[ a ].ypos == ypos - 1 ) create1 = false; if(( * enemys )[ a ].xpos == xpos - 2 &&( * enemys )[ a ].ypos == ypos - 2 ) create2 = false; if(( * enemys )[ a ].xpos == xpos - 1 &&( * enemys )[ a ].ypos == ypos - 2 ) create3 = false; } } if( create1 == true ) enemys->push_back( GameObject( 9, xpos - 2, ypos - 1, 32, 32, 0, 0, 64, 64, 0.0 ) ); else if( create2 == true ) enemys->push_back( GameObject( 9, xpos - 2, ypos - 2, 32, 32, 0, 0, 64, 64, 0.0 ) ); else if( create3 == true ) enemys->push_back( GameObject( 9, xpos - 1, ypos - 2, 32, 32, 0, 0, 64, 64, 0.0 ) ); * createtime = SDL_GetTicks(); } }
void pocisk( vector < GameObject > * pociski, unsigned long long int * powertime ) { if( * powertime + 30 < SDL_GetTicks() ) { if( pociski->size() > 0 ) { for( int a = 0; a <= pociski->size() - 1; a++ ) { if(( * pociski )[ a ].kierunek == "left" )( * pociski )[ a ].xpos =( * pociski )[ a ].xpos - 1; if(( * pociski )[ a ].kierunek == "right" )( * pociski )[ a ].xpos =( * pociski )[ a ].xpos + 1; if(( * pociski )[ a ].kierunek == "up" )( * pociski )[ a ].ypos =( * pociski )[ a ].ypos - 1; if(( * pociski )[ a ].kierunek == "down" )( * pociski )[ a ].ypos =( * pociski )[ a ].ypos + 1; } } * powertime = SDL_GetTicks(); } }
void strzal( vector < GameObject > * enemys, vector < GameObject > * army, vector < GameObject > * fire, unsigned long long int * firetimer, int max_fire_size, Mix_Chunk * music ) { if( * firetimer + 250 < SDL_GetTicks() ) { if( enemys->size() > 0 && army->size() > 0 ) { if( fire->size() > max_fire_size ) fire->clear(); for( int a = 0; a <= army->size() - 1; a++ ) { for( int b = 0; b <= enemys->size() - 1; b++ ) { if(( * army )[ a ].xpos ==( * enemys )[ b ].xpos ) { if(( * army )[ a ].ypos <( * enemys )[ b ].ypos ) fire->push_back( GameObject( 10,( * army )[ a ].xpos,( * army )[ a ].ypos, 32, 32, 0, 0, 64, 64, 0.0, false, 0, 0, 0, 0, 0, 0, 0, "down" ) ); if(( * army )[ a ].ypos >( * enemys )[ b ].ypos ) fire->push_back( GameObject( 10,( * army )[ a ].xpos,( * army )[ a ].ypos, 32, 32, 0, 0, 64, 64, 0.0, false, 0, 0, 0, 0, 0, 0, 0, "up" ) ); Mix_PlayChannel( - 1, music, 0 ); } if(( * army )[ a ].ypos ==( * enemys )[ b ].ypos ) { if(( * army )[ a ].xpos <( * enemys )[ b ].xpos ) fire->push_back( GameObject( 10,( * army )[ a ].xpos,( * army )[ a ].ypos, 32, 32, 0, 0, 64, 64, 0.0, false, 0, 0, 0, 0, 0, 0, 0, "right" ) ); if(( * army )[ a ].xpos >( * enemys )[ b ].xpos ) fire->push_back( GameObject( 10,( * army )[ a ].xpos,( * army )[ a ].ypos, 32, 32, 0, 0, 64, 64, 0.0, false, 0, 0, 0, 0, 0, 0, 0, "left" ) ); Mix_PlayChannel( - 1, music, 0 ); } } } } * firetimer = SDL_GetTicks(); } }
void CollisionWithFire( vector < GameObject > * fire, vector < GameObject > * enemys, unsigned long long int * attacktime ) { if( * attacktime + 20 < SDL_GetTicks() ) { if( fire->size() > 0 && enemys->size() > 0 ) { for( int a = 0; a <= fire->size() - 1; a++ ) { for( int b = 0; b <= enemys->size() - 1; b++ ) { if(( * fire )[ a ].xpos ==( * enemys )[ b ].xpos &&( * fire )[ a ].ypos ==( * enemys )[ b ].ypos ) { ( * enemys )[ b ].hp =( * enemys )[ b ].hp - 10; } } } } * attacktime = SDL_GetTicks(); } }
void Dead( vector < GameObject > * enemys, int * points ) { if( enemys->size() > 0 ) { for( int a = 0; a <= enemys->size() - 1; a++ ) { if(( * enemys )[ a ].hp <= 0 ) { if( enemys->size() - 1 > 0 ) { enemys->erase( enemys->begin() + a ); * points =* points + 5; } } } } }
void enemymove( vector < GameObject > * enemys, unsigned long long int * timer, int * hp, int level ) { int speed = 355 - level * 20; if( speed < 0 ) speed = 0; if( * timer + speed < SDL_GetTicks() ) { if( enemys->size() > 0 ) { for( int a = 0; a <= enemys->size() - 1; a++ ) { if(( * enemys )[ a ].xpos > 0 )( * enemys )[ a ].xpos =( * enemys )[ a ].xpos - 1; if(( * enemys )[ a ].ypos > 0 )( * enemys )[ a ].ypos =( * enemys )[ a ].ypos - 1; if(( * enemys )[ a ].xpos == 0 &&( * enemys )[ a ].ypos == 0 ) * hp =* hp - 2; } } * timer = SDL_GetTicks(); } }
void deletePlayer( vector < GameObject > * army, int * hp, int * points ) { if( * hp <= 0 ) { if( army->size() > 0 ) army->erase( army->end() ); * hp = 100; * points =* points - 20; } }
void gameOver( int hp, int points, vector < GameObject > * army, SDL_Renderer * render, bool * quit, bool * gameover ) { if( points <= 0 && army->size() <= 0 ) { * gameover = true; * quit = true; } }
void uplevel( int points, int * lvl, int * uplvl ) { if( points ==* uplvl ) { * lvl =* lvl + 1; * uplvl =* uplvl + 50; } }
PS z góry dziękuję za pomoc :) PS.2 przerzuciłem przez debuger i wynik jest taki (nie ogarniam) : #0 0040488B main(argc=<error reading variable: Cannot access memory at address 0xffffffec>, argv=<error reading variable: Cannot access memory at address 0xffffffec>) (C:\Users\jegor_000\Desktop\Pulpit\Projekty C++\sdl_game2\main.cpp:148) i pokazał mi na ostatnią klamrę w programie... |