Skip to content

Commit

Permalink
Going to sleep
Browse files Browse the repository at this point in the history
  • Loading branch information
MikiLoz92 committed Feb 17, 2014
1 parent f336172 commit 41359c2
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 13 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ lib/libS2M.so
lib/libS2M.a
test/platformer/test
test/blackwindow/blackwindow
test/pmates/pmates

# Packages #
############
Expand Down
6 changes: 6 additions & 0 deletions src/S2M.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,10 @@ void S2M_UpdateRoom() {
void S2M_Update() {
S2M_UpdateRoom();
S2M_UpdateGraphics();
}

void S2M_ExitGame() {
delete gGraphics;
delete gRoom;
cout << "Exiting SDL2Me... Goodbye!" << endl;
}
7 changes: 1 addition & 6 deletions src/graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,12 @@ Graphics::Graphics(int logWidth, int logHeight, string winCaption, Options * opt
}

Graphics::~Graphics() {
cout << "Exiting game... Bye!";
/**/ cout << "Cleaning Graphics" << endl;
for (int i = 0; i < sprites.size(); i++) {
delete sprites[i];
}
for (int i = 0; i < gRoom->backgrounds.size(); i++) {
delete gRoom->backgrounds[i];
}
SDL_DestroyRenderer( renderer );
SDL_DestroyWindow( window );
window = NULL;
renderer = NULL;
IMG_Quit();
SDL_Quit();
}
Expand Down
3 changes: 2 additions & 1 deletion src/object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ Object::Object(float x, float y) {
}

Object::~Object() {

/**/cout << "$";
if (sprite) delete sprite;
}

void Object::setAnimation(int i) {
Expand Down
21 changes: 18 additions & 3 deletions src/room.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,32 @@ Room::Room() {
width = gGraphics->getGameWidth();
height = gGraphics->getGameHeight();
camera = nullptr;
nextRoom = nullptr;
prevRoom = nullptr;
}

Room::Room(int w, int h) {
width = w;
height = h;
camera = nullptr;
nextRoom = nullptr;
prevRoom = nullptr;
}

Room::~Room() {
/**/cout << "Cleaning Room" << endl;
if (nextRoom) { cout << "-> Cleaning next Room" << endl; delete nextRoom; }
if (prevRoom) { cout << "-> Cleaning previous Room" << endl; delete prevRoom; }
/**/cout << "-> Cleaning Objects (if any): ";
for (int i = 0; i < objects.size(); i++) {
delete objects[i];
//delete objects[i];
}
/**/cout << endl;
/**/cout << "-> Cleaning Backgrounds (if any): ";
for (int i = 0; i < backgrounds.size(); i++) {
//delete backgrounds[i]; // Backgrounds are not dynamically created yet.
}
/**/cout << endl;
}

int Room::getWidth() {
Expand Down Expand Up @@ -392,8 +406,9 @@ Background::Background(string filename, char s, float xspe, float yspe, float d)
}

Background::~Background() {
/*SDL_DestroyTexture(texture);
SDL_DestroyTexture(image);*/ //Da SegFault si una no está inicializada
/**/cout << "|";
SDL_DestroyTexture(texture);
//SDL_DestroyTexture(image); //Da SegFault si una no está inicializada
}

int Background::getWidth() {
Expand Down
7 changes: 4 additions & 3 deletions test/platformer/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ int main( int argc, char* args[] ) {

CreditRoom *r = dynamic_cast<CreditRoom*>(gRoom);
if (r) {
if (r->mode) S2M_GoToRoom<TFlipExpo>(room2);
if (r->mode) S2M_GoToRoom<TFlipExpo>(room);
}

if (SDL_PollEvent(&e) != 0) {
Expand Down Expand Up @@ -148,12 +148,13 @@ int main( int argc, char* args[] ) {
}

if (gJoystick->getBtnPressed(2)) {
S2M_GoToRoom<TFlipExpo>(room2);
S2M_GoToRoom<TFlipExpo>(room);
}

S2M_Update();
}

exit(0);
S2M_ExitGame();
return 0;
}

1 change: 1 addition & 0 deletions test/pmates/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ int main( int argc, char* args[] ) {

}

S2M_ExitGame();
return 0;

}

0 comments on commit 41359c2

Please sign in to comment.