[Balder-cvs] SF.net SVN: balder: [65] src/menu
Status: Beta
Brought to you by:
holomorph
From: <hol...@us...> - 2007-10-01 05:48:17
|
Revision: 65 http://balder.svn.sourceforge.net/balder/?rev=65&view=rev Author: holomorph Date: 2007-09-30 22:48:19 -0700 (Sun, 30 Sep 2007) Log Message: ----------- added imageloader to abstract the loading of images from the rest of the code, which will make it easier to make things location independant Modified Paths: -------------- SConstruct src/collisionmask.cpp src/main.cpp src/menu/animationwidget.cpp src/menu/samplemapwidget.cpp src/menu/skinnedbuttonwidget.cpp src/player.cpp src/powerupfactory.cpp src/probefactory.cpp src/projectilefactory.cpp src/renderer.cpp Added Paths: ----------- include/imageloader.h src/imageloader.cpp Modified: SConstruct =================================================================== --- SConstruct 2007-08-19 07:41:03 UTC (rev 64) +++ SConstruct 2007-10-01 05:48:19 UTC (rev 65) @@ -1,5 +1,5 @@ # SConstruct for building balder2d with scons -includepath = ['/usr/include/python2.4'] +includepath = ['/usr/include/python2.4','include'] env = Environment(CPPPATH=includepath) #avoid leaving .sconsign files all over the place, put all signatures in: env.SConsignFile("scons-signatures") Added: include/imageloader.h =================================================================== --- include/imageloader.h (rev 0) +++ include/imageloader.h 2007-10-01 05:48:19 UTC (rev 65) @@ -0,0 +1,34 @@ +/*************************************************************************** + * Copyright (C) 2007 by Bjorn Hansen * + * hol...@us... * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#ifndef IMAGELOADER_H +#define IMAGELOADER_H + +#include <SDL/SDL_image.h> + +namespace Balder{ + +class ImageLoader{ +public: + static SDL_Surface* LoadImage(const char* imagename); +}; +} +#endif // LOG_H + Modified: src/collisionmask.cpp =================================================================== --- src/collisionmask.cpp 2007-08-19 07:41:03 UTC (rev 64) +++ src/collisionmask.cpp 2007-10-01 05:48:19 UTC (rev 65) @@ -21,6 +21,7 @@ #include <SDL/SDL.h> #include <SDL/SDL_image.h> #include "../include/collisionmask.h" +#include "../include/imageloader.h" #include <string> using namespace Balder; @@ -31,13 +32,13 @@ filename += mapname; filename += "/"; filename += "geometry.png"; - SDL_Surface *field = IMG_Load(filename.c_str()); + SDL_Surface *field = ImageLoader::LoadImage(filename.c_str()); if (!field) throw "invalid surface used to create collision mask"; width = field->w; height = field->h; // allocate memory for the mask mask = new bool[width * height]; - + int bpp = field->format->BytesPerPixel; for (int x = 0; x < width; x++) { Added: src/imageloader.cpp =================================================================== --- src/imageloader.cpp (rev 0) +++ src/imageloader.cpp 2007-10-01 05:48:19 UTC (rev 65) @@ -0,0 +1,30 @@ +/*************************************************************************** + * Copyright (C) 2007 by Bjorn Hansen * + * hol...@us... * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include "../include/imageloader.h" +#include "../include/log.h" +#include <physfs.h> + +using namespace Balder; + +SDL_Surface* ImageLoader::LoadImage(const char* imagename) +{ + return IMG_Load(imagename); +} Modified: src/main.cpp =================================================================== --- src/main.cpp 2007-08-19 07:41:03 UTC (rev 64) +++ src/main.cpp 2007-10-01 05:48:19 UTC (rev 65) @@ -27,6 +27,7 @@ #include "../include/soundmanager.h" #include "../include/configmanager.h" #include "../include/menu/menu.h" +#include "../include/imageloader.h" #include "../include/log.h" using namespace std; @@ -51,7 +52,7 @@ fflush(stdout); exit(1); } - + Log::output("Initializing SDL." ); /* Initializes Audio and Video */ if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK)< 0) @@ -65,11 +66,11 @@ Log::output("Audio & video initialized correctly" ); } atexit(SDL_Quit); - SDL_WM_SetIcon(IMG_Load("icon.png"), NULL); + SDL_WM_SetIcon(ImageLoader::LoadImage("icon.png"), NULL); SDL_WM_SetCaption("Balder 2D","balder2d"); // We want unicode SDL_EnableUNICODE(1); - + // create the renderer Renderer *render; try @@ -88,7 +89,7 @@ Log::output("failed to create renderer" ); exit(1); } - + // create the sound manager SoundManager* sound; try @@ -102,14 +103,14 @@ fflush(stdout); exit(1); } - + catch (const char *message) { Log::output(message ); fflush(stdout); exit(1); } - + // create the menu Menu* menu; try @@ -123,9 +124,9 @@ fflush(stdout); exit(1); } - - // open the menu, let the user configure the game, then create a - // new GameManager for each game, run the game, delete the GameManager + + // open the menu, let the user configure the game, then create a + // new GameManager for each game, run the game, delete the GameManager // and open the menu again. Repeat until the user wants to quit while(menu->Run()) { Modified: src/menu/animationwidget.cpp =================================================================== --- src/menu/animationwidget.cpp 2007-08-19 07:41:03 UTC (rev 64) +++ src/menu/animationwidget.cpp 2007-10-01 05:48:19 UTC (rev 65) @@ -23,6 +23,7 @@ #include <SDL/SDL.h> #include <SDL/SDL_image.h> #include "../../include/menu/animationwidget.h" +#include "../../include/imageloader.h" using namespace Balder; AnimationWidget::AnimationWidget(std::string aFileName, bool aHasBaseFrame, @@ -45,7 +46,7 @@ frameCurrent = 0; // Load Animation Frame Strip from File. - animationFrameStrip = IMG_Load(animationFileName.c_str()); + animationFrameStrip = ImageLoader::LoadImage(animationFileName.c_str()); if (animationFrameStrip == 0) { throw "could not load animation!"; } Modified: src/menu/samplemapwidget.cpp =================================================================== --- src/menu/samplemapwidget.cpp 2007-08-19 07:41:03 UTC (rev 64) +++ src/menu/samplemapwidget.cpp 2007-10-01 05:48:19 UTC (rev 65) @@ -25,6 +25,7 @@ #include <SDL/SDL_image.h> #include <SDL/SDL_rotozoom.h> #include "../../include/menu/samplemapwidget.h" +#include "../../include/imageloader.h" using namespace Balder; @@ -48,7 +49,7 @@ { // load map background. std::string mapFileName = "maps/" + name + "/background.png"; - SDL_Surface* tempSurf = IMG_Load(mapFileName.c_str()); + SDL_Surface* tempSurf = ImageLoader::LoadImage(mapFileName.c_str()); if (tempSurf == 0) { throw "could not load sample background!"; } Modified: src/menu/skinnedbuttonwidget.cpp =================================================================== --- src/menu/skinnedbuttonwidget.cpp 2007-08-19 07:41:03 UTC (rev 64) +++ src/menu/skinnedbuttonwidget.cpp 2007-10-01 05:48:19 UTC (rev 65) @@ -23,16 +23,17 @@ #include <guichan/font.hpp> #include <SDL/SDL.h> #include <SDL/SDL_image.h> -#include "../../include/menu/skinnedbuttonwidget.h" +#include "menu/skinnedbuttonwidget.h" +#include "imageloader.h" using namespace Balder; -SkinnedButtonWidget::SkinnedButtonWidget(std::string bC, std::string sFN, unsigned int sSL): +SkinnedButtonWidget::SkinnedButtonWidget(std::string bC, std::string sFN, unsigned int sSL): gcn::Button(bC), skinFileName(sFN), skinStripLocation(sSL), buttonState(buttonUp) { setBorderSize(0); // Load Skin Frame Strip from File. - skinFrameStrip = IMG_Load(skinFileName.c_str()); + skinFrameStrip = ImageLoader::LoadImage(skinFileName.c_str()); if (skinFrameStrip == 0) { throw "could not load button skin!"; } Modified: src/player.cpp =================================================================== --- src/player.cpp 2007-08-19 07:41:03 UTC (rev 64) +++ src/player.cpp 2007-10-01 05:48:19 UTC (rev 65) @@ -25,6 +25,7 @@ #include "../include/probe.h" #include "../include/input.h" #include "../include/gamemanager.h" +#include "../include/imageloader.h" #include "SFont/Font.h" #include <sstream> @@ -40,11 +41,11 @@ Player::Player(player_id id, GameManager* gm): game_manager(gm), id(id), probe(0), score(0) { if (!scoreFont){ - scoreFontImage = IMG_Load("SFont/scorefont.png"); + scoreFontImage = ImageLoader::LoadImage("SFont/scorefont.png"); scoreFont = new Font(scoreFontImage); } if (!lifeFont){ - lifeFontImage = IMG_Load("SFont/lifefont.png"); + lifeFontImage = ImageLoader::LoadImage("SFont/lifefont.png"); lifeFont = new Font(lifeFontImage); } ++numPlayers; Modified: src/powerupfactory.cpp =================================================================== --- src/powerupfactory.cpp 2007-08-19 07:41:03 UTC (rev 64) +++ src/powerupfactory.cpp 2007-10-01 05:48:19 UTC (rev 65) @@ -17,7 +17,7 @@ * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ - + #include <stdlib.h> #include <math.h> #include <SDL/SDL.h> @@ -26,13 +26,14 @@ #include "../include/renderer.h" #include "../include/powerup.h" #include "../include/collisionmask.h" +#include "../include/imageloader.h" using namespace Balder; // class constructor PowerUpFactory::PowerUpFactory(Renderer* render) { - sprite = IMG_Load("powerups.png"); + sprite = ImageLoader::LoadImage("powerups.png"); if (sprite == 0) { throw "could not load PowerUp sprite!"; @@ -57,10 +58,10 @@ { srand(seed); int x = rand()%collision_mask->GetWidth(); - int y = rand()%collision_mask->GetHeight(); + int y = rand()%collision_mask->GetHeight(); while (collision_mask->TestPixel(x, y)) { x = rand()%collision_mask->GetWidth(); - y = rand()%collision_mask->GetHeight(); + y = rand()%collision_mask->GetHeight(); } int type = static_cast<int>(pow(2,rand()%NUM_POWERUP_TYPES)); return new PowerUp(gm, x, y, 0.5-rand()%10/10.0, 0.5-rand()%10/10.0, type); Modified: src/probefactory.cpp =================================================================== --- src/probefactory.cpp 2007-08-19 07:41:03 UTC (rev 64) +++ src/probefactory.cpp 2007-10-01 05:48:19 UTC (rev 65) @@ -24,13 +24,14 @@ #include "../include/renderer.h" #include "../include/soundmanager.h" #include "../include/probe.h" +#include "../include/imageloader.h" using namespace Balder; // class constructor ProbeFactory::ProbeFactory(Renderer* render, SoundManager* sound) { - sprite = IMG_Load("probe.png"); + sprite = ImageLoader::LoadImage("probe.png"); if (sprite == 0) { throw "could not load Probe sprite!"; @@ -55,7 +56,7 @@ /** * creates a Probe */ -Probe* ProbeFactory::CreateProbe(GameManager* gm, double x_position, double y_position, +Probe* ProbeFactory::CreateProbe(GameManager* gm, double x_position, double y_position, double x_velocity, double y_velocity, bool stuck, probe_color color, player_id pid) { return new Probe(gm, x_position, y_position, x_velocity, y_velocity, stuck, color, pid); Modified: src/projectilefactory.cpp =================================================================== --- src/projectilefactory.cpp 2007-08-19 07:41:03 UTC (rev 64) +++ src/projectilefactory.cpp 2007-10-01 05:48:19 UTC (rev 65) @@ -23,13 +23,14 @@ #include "../include/projectilefactory.h" // class's header file #include "../include/renderer.h" #include "../include/projectile.h" +#include "../include/imageloader.h" using namespace Balder; // class constructor ProjectileFactory::ProjectileFactory(Renderer* render) { - sprite = IMG_Load("projectile.png"); + sprite = ImageLoader::LoadImage("projectile.png"); if (sprite == 0) { throw "could not load Projectile sprite!"; @@ -45,7 +46,7 @@ /** * creates a Projectile */ -Projectile* ProjectileFactory::CreateProjectile(GameManager* gm, double x_position, double y_position, +Projectile* ProjectileFactory::CreateProjectile(GameManager* gm, double x_position, double y_position, double x_velocity, double y_velocity, player_id pid) { return new Projectile(gm, x_position, y_position, x_velocity, y_velocity, pid); Modified: src/renderer.cpp =================================================================== --- src/renderer.cpp 2007-08-19 07:41:03 UTC (rev 64) +++ src/renderer.cpp 2007-10-01 05:48:19 UTC (rev 65) @@ -23,6 +23,7 @@ #include "SFont/Font.h" #include "../include/renderer.h" #include "../include/entity.h" +#include "../include/imageloader.h" #include <string> using namespace Balder; @@ -32,7 +33,7 @@ Renderer::Renderer() { SetScreen(800, 600); - fontImage = IMG_Load("SFont/scorefont.png"); + fontImage = ImageLoader::LoadImage("SFont/scorefont.png"); font = new Font(fontImage); } @@ -64,12 +65,12 @@ filename += mapname; filename += "/"; filename += "background.png"; - background = IMG_Load(filename.c_str()); + background = ImageLoader::LoadImage(filename.c_str()); if (background == 0) { return false; } - // render the background to the screen + // render the background to the screen SDL_BlitSurface(background, 0, screen, 0); return true; } @@ -84,7 +85,7 @@ void Renderer::DisplayText(int x, int y, std::string text) { //first, clear the area to be written on (mostly for the game timer) - + EraseArea(x-5,y, font->getTextWidth(text)+10, font->getHeight()); font->write(screen, text, x, y); } @@ -108,7 +109,7 @@ } void Renderer::EraseEntity ( Entity* e ) -{ +{ SDL_Rect *ebbox = e->GetFrame(); SDL_Rect source = {e->GetX() - ebbox->w, e->GetY() - ebbox->h, 2*ebbox->w, 2*ebbox->h}; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |