#include "app/globals.h"
+namespace SuperTux {
+
/** The datadir prefix prepended when loading game data file */
std::string datadir;
return 0;
}
+
+} //namespace SuperTux
#include "gui/menu.h"
#include "gui/mousecursor.h"
-extern std::string datadir;
-
-struct JoystickKeymap
-{
- int a_button;
- int b_button;
- int start_button;
-
- int x_axis;
- int y_axis;
-
- int dead_zone;
-
- JoystickKeymap();
-};
-
-extern JoystickKeymap joystick_keymap;
-
-extern SDL_Surface* screen;
-extern Font* gold_text;
-extern Font* white_text;
-extern Font* blue_text;
-extern Font* gray_text;
-extern Font* white_small_text;
-extern Font* white_big_text;
-extern Font* yellow_nums;
-
-extern MouseCursor * mouse_cursor;
-
-extern bool use_gl;
-extern bool use_joystick;
-extern bool use_fullscreen;
-extern bool debug_mode;
-extern bool show_fps;
-
-/** The number of the joystick that will be use in the game */
-extern int joystick_num;
-extern char* level_startup_file;
-extern bool launch_leveleditor_mode;
-extern bool launch_worldmap_mode;
-
-/* SuperTux directory ($HOME/.supertux) and save directory($HOME/.supertux/save) */
-extern char* st_dir;
-extern char* st_save_dir;
-
-extern float game_speed;
-extern SDL_Joystick * js;
-
-int wait_for_event(SDL_Event& event,unsigned int min_delay = 0, unsigned int max_delay = 0, bool empty_events = false);
+namespace SuperTux
+ {
+
+ extern std::string datadir;
+
+ struct JoystickKeymap
+ {
+ int a_button;
+ int b_button;
+ int start_button;
+
+ int x_axis;
+ int y_axis;
+
+ int dead_zone;
+
+ JoystickKeymap();
+ };
+
+ extern JoystickKeymap joystick_keymap;
+
+ extern SDL_Surface* screen;
+ extern Font* gold_text;
+ extern Font* white_text;
+ extern Font* blue_text;
+ extern Font* gray_text;
+ extern Font* white_small_text;
+ extern Font* white_big_text;
+ extern Font* yellow_nums;
+
+ extern MouseCursor * mouse_cursor;
+
+ extern bool use_gl;
+ extern bool use_joystick;
+ extern bool use_fullscreen;
+ extern bool debug_mode;
+ extern bool show_fps;
+
+ /** The number of the joystick that will be use in the game */
+ extern int joystick_num;
+ extern char* level_startup_file;
+ extern bool launch_leveleditor_mode;
+ extern bool launch_worldmap_mode;
+
+ /* SuperTux directory ($HOME/.supertux) and save directory($HOME/.supertux/save) */
+ extern char* st_dir;
+ extern char* st_save_dir;
+
+ extern float game_speed;
+ extern SDL_Joystick * js;
+
+ int wait_for_event(SDL_Event& event,unsigned int min_delay = 0, unsigned int max_delay = 0, bool empty_events = false);
+
+} //namespace SuperTux
#endif /* SUPERTUX_GLOBALS_H */
#include "audio/sound_manager.h"
#include "app/gettext.h"
+using namespace SuperTux;
#ifdef WIN32
#define mkdir(dir, mode) mkdir(dir)
void usage(char * prog, int ret);
/* Does the given file exist and is it accessible? */
-int faccessible(const char *filename)
+int SuperTux::faccessible(const char *filename)
{
struct stat filestat;
if (stat(filename, &filestat) == -1)
}
/* Can we write to this location? */
-int fwriteable(const char *filename)
+int SuperTux::fwriteable(const char *filename)
{
FILE* fi;
fi = fopen(filename, "wa");
}
/* Makes sure a directory is created in either the SuperTux home directory or the SuperTux base directory.*/
-int fcreatedir(const char* relative_dir)
+int SuperTux::fcreatedir(const char* relative_dir)
{
char path[1024];
snprintf(path, 1024, "%s/%s/", st_dir, relative_dir);
}
}
-FILE * opendata(const char * rel_filename, const char * mode)
+FILE * SuperTux::opendata(const char * rel_filename, const char * mode)
{
char * filename = NULL;
FILE * fi;
/* Get all names of sub-directories in a certain directory. */
/* Returns the number of sub-directories found. */
/* Note: The user has to free the allocated space. */
-string_list_type dsubdirs(const char *rel_path,const char* expected_file)
+string_list_type SuperTux::dsubdirs(const char *rel_path,const char* expected_file)
{
DIR *dirStructP;
struct dirent *direntp;
return sdirs;
}
-string_list_type dfiles(const char *rel_path, const char* glob, const char* exception_str)
+string_list_type SuperTux::dfiles(const char *rel_path, const char* glob, const char* exception_str)
{
DIR *dirStructP;
struct dirent *direntp;
return sdirs;
}
-void free_strings(char **strings, int num)
+void SuperTux::free_strings(char **strings, int num)
{
int i;
for(i=0; i < num; ++i)
/* --- SETUP --- */
/* Set SuperTux configuration and save directories */
-void st_directory_setup(void)
+void SuperTux::st_directory_setup(void)
{
char *home;
char str[1024];
printf("Datadir: %s\n", datadir.c_str());
}
-void st_general_setup(void)
+void SuperTux::st_general_setup(void)
{
/* Seed random number generator: */
}
-void st_general_free(void)
+void SuperTux::st_general_free(void)
{
/* Free global images: */
/* Free mouse-cursor */
delete mouse_cursor;
- /* Free menus */
- delete main_menu;
- delete game_menu;
- delete options_menu;
- delete options_keys_menu;
- delete options_joystick_menu;
- delete highscore_menu;
- delete contrib_menu;
- delete contrib_subset_menu;
- delete save_game_menu;
- delete load_game_menu;
}
-void st_video_setup(void)
+void SuperTux::st_video_setup(void)
{
/* Init SDL Video: */
if (SDL_Init(SDL_INIT_VIDEO) < 0)
SDL_WM_SetCaption("SuperTux " VERSION, "SuperTux");
}
-void st_video_setup_sdl(void)
+void SuperTux::st_video_setup_sdl(void)
{
if (use_fullscreen)
{
}
}
-void st_video_setup_gl(void)
+void SuperTux::st_video_setup_gl(void)
{
#ifndef NOOPENGL
}
-void st_joystick_setup(void)
+void SuperTux::st_joystick_setup(void)
{
/* Init Joystick: */
}
}
-void st_audio_setup(void)
+void SuperTux::st_audio_setup(void)
{
/* Init SDL Audio silently even if --disable-sound : */
/* --- SHUTDOWN --- */
-void st_shutdown(void)
+void SuperTux::st_shutdown(void)
{
close_audio();
SDL_Quit();
/* --- ABORT! --- */
-void st_abort(const std::string& reason, const std::string& details)
+void SuperTux::st_abort(const std::string& reason, const std::string& details)
{
fprintf(stderr, "\nError: %s\n%s\n\n", reason.c_str(), details.c_str());
st_shutdown();
/* Parse command-line arguments: */
-void parseargs(int argc, char * argv[])
+void SuperTux::parseargs(int argc, char * argv[])
{
int i;
exit(ret);
}
-std::vector<std::string> read_directory(const std::string& pathname)
+std::vector<std::string> SuperTux::read_directory(const std::string& pathname)
{
std::vector<std::string> dirnames;
#include "audio/sound.h"
#include "special/base.h"
+namespace SuperTux {
+
int faccessible(const char *filename);
int fcreatedir(const char* relative_dir);
int fwriteable(const char *filename);
void parseargs(int argc, char * argv[]);
+}
+
#endif /*SUPERTUX_SETUP_H*/
#include "audio/musicref.h"
+using namespace SuperTux;
+
MusicRef::MusicRef()
: music(0)
{
#include "audio/sound_manager.h"
-/** This class holds a reference to a music file and maintains a correct
- * refcount for that file.
- */
-class MusicRef
-{
-public:
- MusicRef();
- MusicRef(const MusicRef& other);
- ~MusicRef();
-
- MusicRef& operator= (const MusicRef& other);
-
-private:
- friend class SoundManager;
- MusicRef(SoundManager::MusicResource* music);
-
- SoundManager::MusicResource* music;
-};
+namespace SuperTux
+ {
+
+ /** This class holds a reference to a music file and maintains a correct
+ * refcount for that file.
+ */
+ class MusicRef
+ {
+ public:
+ MusicRef();
+ MusicRef(const MusicRef& other);
+ ~MusicRef();
+
+ MusicRef& operator= (const MusicRef& other);
+
+ private:
+ friend class SoundManager;
+ MusicRef(SoundManager::MusicResource* music);
+
+ SoundManager::MusicResource* music;
+ };
+
+} //namespace SuperTux
#endif /*SUPERTUX_MUSICREF_H*/
#include "app/setup.h"
#include "special/moving_object.h"
+using namespace SuperTux;
+
SoundManager::SoundManager()
: current_music(0), music_enabled(true)
{
#include "SDL_mixer.h"
#include "math/vector.h"
-class MusicRef;
-class MovingObject;
-
-/// Sound manager
-/** This class handles all sounds that are played
- */
-class SoundManager
-{
-public:
- SoundManager();
- ~SoundManager();
-
- /// Play sound.
- void play_sound(Mix_Chunk* sound);
- /// Play sound relative to two Vectors.
- void play_sound(Mix_Chunk* sound, const Vector& pos, const Vector& pos2);
- /// Play sound relative to a MovingObject and a Vector.
- void play_sound(Mix_Chunk* sound, const MovingObject* object, const Vector& pos);
-
- /// Load music.
- /** Is used to load the music for a MusicRef. */
- MusicRef load_music(const std::string& file);
- /// Test if a certain music file exists.
- bool exists_music(const std::string& filename);
-
- /// Play music.
- /** @Param loops: Defaults to -1, which means endless loops. */
- void play_music(const MusicRef& music, int loops = -1);
-
- /// Halt music.
- void halt_music();
-
- /// Enable/Disable music.
- void enable_music(bool enable);
-
-private:
- // music part
- friend class MusicRef;
-
- /// Resource for music.
- /** Contains the raw music data and
- information for music reference
- counting. */
- class MusicResource
+namespace SuperTux
{
- public:
- ~MusicResource();
- SoundManager* manager;
- Mix_Music* music;
- int refcount;
- };
+ class MusicRef;
+ class MovingObject;
- void free_music(MusicResource* music);
+ /// Sound manager
+ /** This class handles all sounds that are played
+ */
+ class SoundManager
+ {
+ public:
+ SoundManager();
+ ~SoundManager();
- std::map<std::string, MusicResource> musics;
- MusicResource* current_music;
- bool music_enabled;
-};
+ /// Play sound.
+ void play_sound(Mix_Chunk* sound);
+ /// Play sound relative to two Vectors.
+ void play_sound(Mix_Chunk* sound, const Vector& pos, const Vector& pos2);
+ /// Play sound relative to a MovingObject and a Vector.
+ void play_sound(Mix_Chunk* sound, const MovingObject* object, const Vector& pos);
+
+ /// Load music.
+ /** Is used to load the music for a MusicRef. */
+ MusicRef load_music(const std::string& file);
+ /// Test if a certain music file exists.
+ bool exists_music(const std::string& filename);
+
+ /// Play music.
+ /** @param loops: Defaults to -1, which means endless loops. */
+ void play_music(const MusicRef& music, int loops = -1);
+
+ /// Halt music.
+ void halt_music();
+
+ /// Enable/Disable music.
+ void enable_music(bool enable);
+
+ private:
+ // music part
+ friend class MusicRef;
+
+ /// Resource for music.
+ /** Contains the raw music data and
+ information for music reference
+ counting. */
+ class MusicResource
+ {
+ public:
+ ~MusicResource();
+
+ SoundManager* manager;
+ Mix_Music* music;
+ int refcount;
+ };
+
+ void free_music(MusicResource* music);
+
+ std::map<std::string, MusicResource> musics;
+ MusicResource* current_music;
+ bool music_enabled;
+ };
+
+} // namespace SuperTux
#endif /*SUPERTUX_SOUND_MANAGER_H*/
/// Dispatch button events.
Button* event(SDL_Event &event);
/// Add a button to the panel.
- /** @Param tag: Can be used to identify a button. */
+ /** @param tag: Can be used to identify a button. */
void additem(Button* pbutton, int tag);
/// Set the default size of contained buttons.
void set_button_size(int w, int h);
#include "audio/sound.h"
#include "special/timer.h"
#include "app/gettext.h"
+#include "math/vector.h"
+
+using namespace SuperTux;
#define FLICK_CURSOR_TIME 500
-Surface* checkbox;
-Surface* checkbox_checked;
-Surface* back;
-Surface* arrow_left;
-Surface* arrow_right;
-
-Menu* main_menu = 0;
-Menu* game_menu = 0;
-Menu* options_menu = 0;
-Menu* options_keys_menu = 0;
-Menu* options_joystick_menu = 0;
-Menu* highscore_menu = 0;
-Menu* load_game_menu = 0;
-Menu* save_game_menu = 0;
-Menu* contrib_menu = 0;
-Menu* contrib_subset_menu = 0;
+Surface* SuperTux::checkbox;
+Surface* SuperTux::checkbox_checked;
+Surface* SuperTux::back;
+Surface* SuperTux::arrow_left;
+Surface* SuperTux::arrow_right;
std::vector<Menu*> Menu::last_menus;
Menu* Menu::current_ = 0;
/* just displays a Yes/No text that can be used to confirm stuff */
-bool confirm_dialog(Surface *background, std::string text)
+bool SuperTux::confirm_dialog(Surface *background, std::string text)
{
//Surface* cap_screen = Surface::CaptureScreen();
#include "special/stringlist.h"
#include "gui/mousecursor.h"
+namespace SuperTux
+ {
-/* Joystick menu delay */
+ /* Joystick menu delay */
#define JOYSTICK_MENU_DELAY 500
-/* IDs for menus */
-
-bool confirm_dialog(Surface* background, std::string text);
-
-/* Kinds of menu items */
-enum MenuItemKind {
- MN_ACTION,
- MN_GOTO,
- MN_TOGGLE,
- MN_BACK,
- MN_DEACTIVE,
- MN_TEXTFIELD,
- MN_NUMFIELD,
- MN_CONTROLFIELD_KB,
- MN_CONTROLFIELD_JS,
- MN_STRINGSELECT,
- MN_LABEL,
- MN_HL, /* horizontal line */
-};
-
-class Menu;
-
-class MenuItem
-{
-public:
- MenuItemKind kind;
- int toggled;
- char *text;
- char *input;
- int *int_p; // used for setting keys (can be used for more stuff...)
- int id; // item id
- string_list_type* list;
- Menu* target_menu;
-
- void change_text (const char *text);
- void change_input(const char *text);
-
- static MenuItem* create(MenuItemKind kind, const char *text, int init_toggle, Menu* target_menu, int id, int* int_p);
-
- std::string get_input_with_symbol(bool active_item); // returns the text with an input symbol
-private:
- bool input_flickering;
- Timer input_flickering_timer;
-};
-
-class Menu
-{
-private:
- static std::vector<Menu*> last_menus;
- static Menu* current_;
-
- static void push_current(Menu* pmenu);
- static void pop_current();
-
-public:
- /** Set the current menu, if pmenu is NULL, hide the current menu */
- static void set_current(Menu* pmenu);
-
- /** Return the current active menu or NULL if none is active */
- static Menu* current() { return current_; }
-
-private:
- /* Action done on the menu */
- enum MenuAction {
- MENU_ACTION_NONE = -1,
- MENU_ACTION_UP,
- MENU_ACTION_DOWN,
- MENU_ACTION_LEFT,
- MENU_ACTION_RIGHT,
- MENU_ACTION_HIT,
- MENU_ACTION_INPUT,
- MENU_ACTION_REMOVE
+ /* IDs for menus */
+
+ bool confirm_dialog(Surface* background, std::string text);
+
+ /* Kinds of menu items */
+ enum MenuItemKind {
+ MN_ACTION,
+ MN_GOTO,
+ MN_TOGGLE,
+ MN_BACK,
+ MN_DEACTIVE,
+ MN_TEXTFIELD,
+ MN_NUMFIELD,
+ MN_CONTROLFIELD_KB,
+ MN_CONTROLFIELD_JS,
+ MN_STRINGSELECT,
+ MN_LABEL,
+ MN_HL, /* horizontal line */
};
- /** Number of the item that got 'hit' (ie. pressed) in the last
- event()/action() call, -1 if none */
- int hit_item;
-
- // position of the menu (ie. center of the menu, not top/left)
- int pos_x;
- int pos_y;
-
- /** input event for the menu (up, down, left, right, etc.) */
- MenuAction menuaction;
-
- /* input implementation variables */
- int delete_character;
- char mn_input_char;
- Timer joystick_timer;
-
-public:
- Timer effect;
- int arrange_left;
- int active_item;
-
- std::vector<MenuItem> item;
-
- Menu();
- ~Menu();
-
- void additem(MenuItem* pmenu_item);
- void additem(MenuItemKind kind, const std::string& text, int init_toggle, Menu* target_menu, int id = -1, int *int_p = NULL);
-
- void action ();
-
- /** Remove all entries from the menu */
- void clear();
-
- /** Return the index of the menu item that was 'hit' (ie. the user
- clicked on it) in the last event() call */
- int check ();
-
- MenuItem& get_item(int index) { return item[index]; }
- MenuItem& get_item_by_id(int id);
-
- int get_active_item_id();
-
- bool isToggled(int id);
-
- void Menu::get_controlfield_key_into_input(MenuItem *item);
- void Menu::get_controlfield_js_into_input(MenuItem *item);
-
- void draw(DrawingContext& context);
- void draw_item(DrawingContext& context,
- int index, int menu_width, int menu_height);
- void set_pos(int x, int y, float rw = 0, float rh = 0);
-
- /** translate a SDL_Event into a menu_action */
- void event(SDL_Event& event);
-
- int get_width() const;
- int get_height() const;
-
- bool is_toggled(int id) const;
-};
-
-extern Surface* checkbox;
-extern Surface* checkbox_checked;
-extern Surface* back;
-extern Surface* arrow_left;
-extern Surface* arrow_right;
-
-extern Menu* contrib_menu;
-extern Menu* contrib_subset_menu;
-extern Menu* main_menu;
-extern Menu* game_menu;
-extern Menu* options_menu;
-extern Menu* options_keys_menu;
-extern Menu* options_joystick_menu;
-extern Menu* highscore_menu;
-extern Menu* load_game_menu;
-extern Menu* save_game_menu;
+ class Menu;
+
+ class MenuItem
+ {
+ public:
+ MenuItemKind kind;
+ int toggled;
+ char *text;
+ char *input;
+ int *int_p; // used for setting keys (can be used for more stuff...)
+ int id; // item id
+ string_list_type* list;
+ Menu* target_menu;
+
+ void change_text (const char *text);
+ void change_input(const char *text);
+
+ static MenuItem* create(MenuItemKind kind, const char *text, int init_toggle, Menu* target_menu, int id, int* int_p);
+
+ std::string get_input_with_symbol(bool active_item); // returns the text with an input symbol
+ private:
+ bool input_flickering;
+ Timer input_flickering_timer;
+ };
+
+ class Menu
+ {
+ private:
+ static std::vector<Menu*> last_menus;
+ static Menu* current_;
+
+ static void push_current(Menu* pmenu);
+ static void pop_current();
+
+ public:
+ /** Set the current menu, if pmenu is NULL, hide the current menu */
+ static void set_current(Menu* pmenu);
+
+ /** Return the current active menu or NULL if none is active */
+ static Menu* current()
+ {
+ return current_;
+ }
+
+ private:
+ /* Action done on the menu */
+ enum MenuAction {
+ MENU_ACTION_NONE = -1,
+ MENU_ACTION_UP,
+ MENU_ACTION_DOWN,
+ MENU_ACTION_LEFT,
+ MENU_ACTION_RIGHT,
+ MENU_ACTION_HIT,
+ MENU_ACTION_INPUT,
+ MENU_ACTION_REMOVE
+ };
+
+ /** Number of the item that got 'hit' (ie. pressed) in the last
+ event()/action() call, -1 if none */
+ int hit_item;
+
+ // position of the menu (ie. center of the menu, not top/left)
+ int pos_x;
+ int pos_y;
+
+ /** input event for the menu (up, down, left, right, etc.) */
+ MenuAction menuaction;
+
+ /* input implementation variables */
+ int delete_character;
+ char mn_input_char;
+ Timer joystick_timer;
+
+ public:
+ Timer effect;
+ int arrange_left;
+ int active_item;
+
+ std::vector<MenuItem> item;
+
+ Menu();
+ ~Menu();
+
+ void additem(MenuItem* pmenu_item);
+ void additem(MenuItemKind kind, const std::string& text, int init_toggle, Menu* target_menu, int id = -1, int *int_p = NULL);
+
+ void action ();
+
+ /** Remove all entries from the menu */
+ void clear();
+
+ /** Return the index of the menu item that was 'hit' (ie. the user
+ clicked on it) in the last event() call */
+ int check ();
+
+ MenuItem& get_item(int index)
+ {
+ return item[index];
+ }
+ MenuItem& get_item_by_id(int id);
+
+ int get_active_item_id();
+
+ bool isToggled(int id);
+
+ void Menu::get_controlfield_key_into_input(MenuItem *item);
+ void Menu::get_controlfield_js_into_input(MenuItem *item);
+
+ void draw(DrawingContext& context);
+ void draw_item(DrawingContext& context,
+ int index, int menu_width, int menu_height);
+ void set_pos(int x, int y, float rw = 0, float rh = 0);
+
+ /** translate a SDL_Event into a menu_action */
+ void event(SDL_Event& event);
+
+ int get_width() const;
+ int get_height() const;
+
+ bool is_toggled(int id) const;
+ };
+
+ extern Surface* checkbox;
+ extern Surface* checkbox_checked;
+ extern Surface* back;
+ extern Surface* arrow_left;
+ extern Surface* arrow_right;
+
+} //namespace SuperTux
#endif /*SUPERTUX_MENU_H*/
#include "video/drawing_context.h"
#include "gui/mousecursor.h"
+using namespace SuperTux;
+
MouseCursor* MouseCursor::current_ = 0;
MouseCursor::MouseCursor(std::string cursor_file, int frames) : mid_x(0), mid_y(0)
#include "special/timer.h"
#include "video/surface.h"
-#define MC_FRAME_PERIOD 800 // in ms
+namespace SuperTux
+ {
-#define MC_STATES_NB 3
-enum {
- MC_NORMAL,
- MC_CLICK,
- MC_LINK,
- MC_HIDE
-};
+ #define MC_FRAME_PERIOD 800 // in ms
-/// Mouse cursor.
-/** Used to create mouse cursors.
- The mouse cursors can be animated
- and can be used in four different states.
- (MC_NORMAL, MC_CLICK, MC_LINK or MC_HIDE) */
-class MouseCursor
-{
-public:
- /// Constructor of MouseCursor.
- /** Expects an imagefile for the cursor and the number of animation frames it contains. */
- MouseCursor(std::string cursor_file, int frames);
- ~MouseCursor();
- /// Get MouseCursor state.
- /** (MC_NORMAL, MC_CLICK, MC_LINK or MC_HIDE) */
- int state();
- /// Set MouseCursor state.
- /** (MC_NORMAL, MC_CLICK, MC_LINK or MC_HIDE) */
- void set_state(int nstate);
- /// Define the middle of a MouseCursor.
- /** Useful for cross mouse cursor images in example. */
- void set_mid(int x, int y);
-
- /// Draw MouseCursor on screen.
- void draw(DrawingContext& context);
-
- /// Return the current cursor.
- static MouseCursor* current() { return current_; };
- /// Set current cursor.
- static void set_current(MouseCursor* pcursor) { current_ = pcursor; };
-
-private:
- int mid_x, mid_y;
- static MouseCursor* current_;
- int state_before_click;
- int cur_state;
- int cur_frame, tot_frames;
- Surface* cursor;
- Timer timer;
-};
+ #define MC_STATES_NB 3
+
+ enum {
+ MC_NORMAL,
+ MC_CLICK,
+ MC_LINK,
+ MC_HIDE
+ };
+
+ /// Mouse cursor.
+ /** Used to create mouse cursors.
+ The mouse cursors can be animated
+ and can be used in four different states.
+ (MC_NORMAL, MC_CLICK, MC_LINK or MC_HIDE) */
+ class MouseCursor
+ {
+ public:
+ /// Constructor of MouseCursor.
+ /** Expects an imagefile for the cursor and the number of animation frames it contains. */
+ MouseCursor(std::string cursor_file, int frames);
+ ~MouseCursor();
+ /// Get MouseCursor state.
+ /** (MC_NORMAL, MC_CLICK, MC_LINK or MC_HIDE) */
+ int state();
+ /// Set MouseCursor state.
+ /** (MC_NORMAL, MC_CLICK, MC_LINK or MC_HIDE) */
+ void set_state(int nstate);
+ /// Define the middle of a MouseCursor.
+ /** Useful for cross mouse cursor images in example. */
+ void set_mid(int x, int y);
+
+ /// Draw MouseCursor on screen.
+ void draw(DrawingContext& context);
+
+ /// Return the current cursor.
+ static MouseCursor* current()
+ { return current_; };
+ /// Set current cursor.
+ static void set_current(MouseCursor* pcursor)
+ { current_ = pcursor; };
+
+ private:
+ int mid_x, mid_y;
+ static MouseCursor* current_;
+ int state_before_click;
+ int cur_state;
+ int cur_frame, tot_frames;
+ Surface* cursor;
+ Timer timer;
+ };
+
+} // namespace SuperTux
#endif /*SUPERTUX_MOUSECURSOR_H*/
#include "math/physic.h"
#include "special/timer.h"
+using namespace SuperTux;
+
Physic::Physic()
: ax(0), ay(0), vx(0), vy(0), gravity_enabled(true)
{
#include "math/vector.h"
-/// Physics engine.
-/** This is a very simplistic physics engine handling accelerated and constant
- * movement along with gravity.
- */
-class Physic
-{
-public:
- Physic();
- ~Physic();
-
- /// Resets all velocities and accelerations to 0.
- void reset();
-
- /// Sets velocity to a fixed value.
- void set_velocity(float vx, float vy);
-
- void set_velocity_x(float vx);
- void set_velocity_y(float vy);
-
- /// Velocities invertion.
- void inverse_velocity_x();
- void inverse_velocity_y();
-
- float get_velocity_x();
- float get_velocity_y();
-
- /// Set acceleration.
- /** Sets acceleration applied to the object. (Note that gravity is
- * eventually added to the vertical acceleration)
- */
- void set_acceleration(float ax, float ay);
-
- void set_acceleration_x(float ax);
- void set_acceleration_y(float ay);
-
- float get_acceleration_x();
- float get_acceleration_y();
-
- /// Enables or disables handling of gravity.
- void enable_gravity(bool gravity_enabled);
-
- /// Applies the physical simulation to given x and y coordinates.
- void apply(float frame_ratio, float &x, float &y, float gravity = 10.0f);
-
- /// applies the physical simulation to given x and y coordinates.
- void apply(Vector& vector, float frame_ratio, float gravity = 10.0f);
-
-private:
- /// horizontal and vertical acceleration
- float ax, ay;
- /// horizontal and vertical velocity
- float vx, vy;
- /// should we respect gravity in out calculations?
- bool gravity_enabled;
-};
+namespace SuperTux
+ {
+
+ /// Physics engine.
+ /** This is a very simplistic physics engine handling accelerated and constant
+ * movement along with gravity.
+ */
+ class Physic
+ {
+ public:
+ Physic();
+ ~Physic();
+
+ /// Resets all velocities and accelerations to 0.
+ void reset();
+
+ /// Sets velocity to a fixed value.
+ void set_velocity(float vx, float vy);
+
+ void set_velocity_x(float vx);
+ void set_velocity_y(float vy);
+
+ /// Velocities invertion.
+ void inverse_velocity_x();
+ void inverse_velocity_y();
+
+ float get_velocity_x();
+ float get_velocity_y();
+
+ /// Set acceleration.
+ /** Sets acceleration applied to the object. (Note that gravity is
+ * eventually added to the vertical acceleration)
+ */
+ void set_acceleration(float ax, float ay);
+
+ void set_acceleration_x(float ax);
+ void set_acceleration_y(float ay);
+
+ float get_acceleration_x();
+ float get_acceleration_y();
+
+ /// Enables or disables handling of gravity.
+ void enable_gravity(bool gravity_enabled);
+
+ /// Applies the physical simulation to given x and y coordinates.
+ void apply(float frame_ratio, float &x, float &y, float gravity = 10.0f);
+
+ /// applies the physical simulation to given x and y coordinates.
+ void apply(Vector& vector, float frame_ratio, float gravity = 10.0f);
+
+ private:
+ /// horizontal and vertical acceleration
+ float ax, ay;
+ /// horizontal and vertical velocity
+ float vx, vy;
+ /// should we respect gravity in out calculations?
+ bool gravity_enabled;
+ };
+
+} //namespace SuperTux
#endif /*SUPERTUX_PHYSIC_H*/
#include "math/vector.h"
+using namespace SuperTux;
+
Vector Vector::unit() const
{
return *this / norm();
#ifndef SUPERTUX_VECTOR_H
#define SUPERTUX_VECTOR_H
-/// 2D Vector.
-/** Simple two dimensional vector. */
-class Vector
-{
-public:
- Vector(float nx, float ny)
- : x(nx), y(ny)
- { }
- Vector(const Vector& other)
- : x(other.x), y(other.y)
- { }
- Vector()
- : x(0), y(0)
- { }
-
- bool operator ==(const Vector& other) const
+namespace SuperTux
{
- return x == other.x && y == other.y;
- }
- const Vector& operator=(const Vector& other)
- {
- x = other.x;
- y = other.y;
- return *this;
- }
-
- Vector operator+(const Vector& other) const
- {
- return Vector(x + other.x, y + other.y);
- }
-
- Vector operator-(const Vector& other) const
- {
- return Vector(x - other.x, y - other.y);
- }
-
- Vector operator*(float s) const
- {
- return Vector(x * s, y * s);
- }
-
- Vector operator/(float s) const
- {
- return Vector(x / s, y / s);
- }
-
- Vector operator-() const
- {
- return Vector(-x, -y);
- }
-
- const Vector& operator +=(const Vector& other)
- {
- x += other.x;
- y += other.y;
- return *this;
- }
-
- /// Scalar product of 2 vectors
- float operator*(const Vector& other) const
- {
- return x*other.x + y*other.y;
- }
-
- float norm() const;
- Vector unit() const;
-
- // ... add the other operators as needed, I'm too lazy now ...
-
- float x, y; // leave this public, get/set methods just give me headaches
- // for such simple stuff :)
-};
+ /// 2D Vector.
+ /** Simple two dimensional vector. */
+ class Vector
+ {
+ public:
+ Vector(float nx, float ny)
+ : x(nx), y(ny)
+ { }
+ Vector(const Vector& other)
+ : x(other.x), y(other.y)
+ { }
+ Vector()
+ : x(0), y(0)
+ { }
+
+ bool operator ==(const Vector& other) const
+ {
+ return x == other.x && y == other.y;
+ }
+
+ const Vector& operator=(const Vector& other)
+ {
+ x = other.x;
+ y = other.y;
+ return *this;
+ }
+
+ Vector operator+(const Vector& other) const
+ {
+ return Vector(x + other.x, y + other.y);
+ }
+
+ Vector operator-(const Vector& other) const
+ {
+ return Vector(x - other.x, y - other.y);
+ }
+
+ Vector operator*(float s) const
+ {
+ return Vector(x * s, y * s);
+ }
+
+ Vector operator/(float s) const
+ {
+ return Vector(x / s, y / s);
+ }
+
+ Vector operator-() const
+ {
+ return Vector(-x, -y);
+ }
+
+ const Vector& operator +=(const Vector& other)
+ {
+ x += other.x;
+ y += other.y;
+ return *this;
+ }
+
+ /// Scalar product of 2 vectors
+ float operator*(const Vector& other) const
+ {
+ return x*other.x + y*other.y;
+ }
+
+ float norm() const;
+ Vector unit() const;
+
+ // ... add the other operators as needed, I'm too lazy now ...
+
+ float x, y; // leave this public, get/set methods just give me headaches
+ // for such simple stuff :)
+ };
+
+} //namespace SuperTux
#endif /*SUPERTUX_VECTOR_H*/
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
-#ifndef SUPERTUX_TYPE_H
-#define SUPERTUX_TYPE_H
+#ifndef SUPERTUX_BASE_H
+#define SUPERTUX_BASE_H
#include <string>
#include "SDL.h"
-/// 'Base' type for game objects.
-/** Mainly for layered use in game objects.
- Containts upper left X and Y coordinates of an
- object along with its width and height. */
-struct base_type
-{
- float x;
- float y;
- float width;
- float height;
-};
+namespace SuperTux
+ {
+ /// 'Base' type for game objects.
+ /** Mainly for layered use in game objects.
+ Containts upper left X and Y coordinates of an
+ object along with its width and height. */
+ struct base_type
+ {
+ float x;
+ float y;
+ float width;
+ float height;
+ };
-#endif /*SUPERTUX_TYPE_H*/
+}
+
+#endif /*SUPERTUX_BASE_H*/
#include "special/game_object.h"
+using namespace SuperTux;
+
GameObject::GameObject()
: wants_to_die(false)
{
#include <string>
-class DrawingContext;
+namespace SuperTux
+ {
-/**
- * Base class for all game objects. This contains functions for:
- * -querying the actual type of the object
- * -a flag that indicates if the object wants to be removed. Objects with this
- * flag will be removed at the end of each frame. This is alot safer than
- * having some uncontrollable "delete this" in the code.
- * -an action function that is called once per frame and allows the object to
- * update it's state.
- *
- * Most GameObjects will also implement the DrawableObject interface so that
- * they can actually be drawn on screen.
- */
-class GameObject // TODO rename this once the game has been converted
-{
-public:
- GameObject();
- virtual ~GameObject();
+ class DrawingContext;
- /** This function is called once per frame and allows the object to update
- * it's state. The elapsed_time is the time since the last frame and should be
- * the base for all timed things.
+ /**
+ * Base class for all game objects. This contains functions for:
+ * -querying the actual type of the object
+ * -a flag that indicates if the object wants to be removed. Objects with this
+ * flag will be removed at the end of each frame. This is alot safer than
+ * having some uncontrollable "delete this" in the code.
+ * -an action function that is called once per frame and allows the object to
+ * update it's state.
+ *
+ * Most GameObjects will also implement the DrawableObject interface so that
+ * they can actually be drawn on screen.
*/
- virtual void action(float elapsed_time) = 0;
+ class GameObject // TODO rename this once the game has been converted
+ {
+ public:
+ GameObject();
+ virtual ~GameObject();
- /** The GameObject should draw itself onto the provided DrawingContext if this
- * function is called.
- */
- virtual void draw(DrawingContext& context) = 0;
+ /** This function is called once per frame and allows the object to update
+ * it's state. The elapsed_time is the time since the last frame and should be
+ * the base for all timed things.
+ */
+ virtual void action(float elapsed_time) = 0;
- /** returns true if the object is not scheduled to be removed yet */
- bool is_valid() const
- { return !wants_to_die; }
- /** schedules this object to be removed at the end of the frame */
- void remove_me()
- { wants_to_die = true; }
-
-private:
- /** this flag indicates if the object should be removed at the end of the
- * frame
- */
- bool wants_to_die;
-};
+ /** The GameObject should draw itself onto the provided DrawingContext if this
+ * function is called.
+ */
+ virtual void draw(DrawingContext& context) = 0;
+
+ /** returns true if the object is not scheduled to be removed yet */
+ bool is_valid() const
+ {
+ return !wants_to_die;
+ }
+ /** schedules this object to be removed at the end of the frame */
+ void remove_me()
+ {
+ wants_to_die = true;
+ }
+
+ private:
+ /** this flag indicates if the object should be removed at the end of the
+ * frame
+ */
+ bool wants_to_die;
+ };
+}
#endif /*SUPERTUX_GAMEOBJECT_H*/
#include "special/moving_object.h"
+using namespace SuperTux;
+
MovingObject::MovingObject()
{
base.x = base.y = base.width = base.height = 0;
#include "math/vector.h"
//#include "rectangle.h"
-/**
- * Base class for all dynamic/moving game objects. This class contains things
- * for handling the bounding boxes and collision feedback.
- */
-class MovingObject : public GameObject
-{
-public:
- MovingObject();
- virtual ~MovingObject();
-
- /** this function is called when the object collided with any other object
+namespace SuperTux
+ {
+
+ /**
+ * Base class for all dynamic/moving game objects. This class contains things
+ * for handling the bounding boxes and collision feedback.
*/
- virtual void collision(const MovingObject& other_object,
- int collision_type) = 0;
+ class MovingObject : public GameObject
+ {
+ public:
+ MovingObject();
+ virtual ~MovingObject();
+
+ /** this function is called when the object collided with any other object
+ */
+ virtual void collision(const MovingObject& other_object,
+ int collision_type) = 0;
- Vector get_pos() const
- { return Vector(base.x, base.y); }
+ Vector get_pos() const
+ {
+ return Vector(base.x, base.y);
+ }
- base_type base;
- base_type old_base;
+ base_type base;
+ base_type old_base;
-protected:
+ protected:
#if 0 // this will be used in my collision detection rewrite later
- /// the current position of the object
- Vector pos;
- /// the position we want to move until next frame
- Vector new_pos;
- /// the bounding box relative to the current position
- Rectangle bounding_box;
+ /// the current position of the object
+ Vector pos;
+ /// the position we want to move until next frame
+ Vector new_pos;
+ /// the bounding box relative to the current position
+ Rectangle bounding_box;
#endif
-};
+ };
+
+} //namespace SuperTux
#endif /*SUPERTUX_MOVING_OBJECT_H*/
#include "special/sprite.h"
#include "video/drawing_context.h"
+using namespace SuperTux;
+
Sprite::Sprite(lisp_object_t* cur)
{
init_defaults();
#include "video/surface.h"
#include "math/vector.h"
-class Sprite
-{
- private:
- std::string name;
-
- int x_hotspot;
- int y_hotspot;
-
- /** Frames per second */
- float fps;
-
- /** Number of seconds that a frame is displayed until it is switched
- to the next frame */
- float frame_delay;
-
- float time;
-
- std::vector<Surface*> surfaces;
-
- void init_defaults();
- public:
- /** cur has to be a pointer to data in the form of ((x-hotspot 5)
- (y-hotspot 10) ...) */
- Sprite(lisp_object_t* cur);
- ~Sprite();
-
- void reset();
-
- /** Update the sprite and process to the next frame */
- void update(float delta);
- void draw(DrawingContext& context, const Vector& pos, int layer,
- Uint32 drawing_effect = NONE_EFFECT);
- int get_current_frame() const;
-
- float get_fps() { return fps; } ;
- int get_frames() { return surfaces.size(); } ;
-
- std::string get_name() const { return name; }
- int get_width() const;
- int get_height() const;
-
- Surface* get_frame(unsigned int frame)
- { if(frame < surfaces.size()) return surfaces[frame];
- else return surfaces[0]; }
-};
+namespace SuperTux
+ {
+
+ class Sprite
+ {
+ private:
+ std::string name;
+
+ int x_hotspot;
+ int y_hotspot;
+
+ /** Frames per second */
+ float fps;
+
+ /** Number of seconds that a frame is displayed until it is switched
+ to the next frame */
+ float frame_delay;
+
+ float time;
+
+ std::vector<Surface*> surfaces;
+
+ void init_defaults();
+ public:
+ /** cur has to be a pointer to data in the form of ((x-hotspot 5)
+ (y-hotspot 10) ...) */
+ Sprite(lisp_object_t* cur);
+ ~Sprite();
+
+ void reset();
+
+ /** Update the sprite and process to the next frame */
+ void update(float delta);
+ void draw(DrawingContext& context, const Vector& pos, int layer,
+ Uint32 drawing_effect = NONE_EFFECT);
+ int get_current_frame() const;
+
+ float get_fps()
+ {
+ return fps;
+ } ;
+ int get_frames()
+ {
+ return surfaces.size();
+ } ;
+
+ std::string get_name() const
+ {
+ return name;
+ }
+ int get_width() const;
+ int get_height() const;
+
+ Surface* get_frame(unsigned int frame)
+ {
+ if(frame < surfaces.size())
+ return surfaces[frame];
+ else
+ return surfaces[0];
+ }
+ };
+
+} //namespace SuperTux
#endif /*SUPERTUX_SPRITE_H*/
#include "utils/lispreader.h"
#include "special/sprite_manager.h"
+using namespace SuperTux;
+
SpriteManager::SpriteManager(const std::string& filename)
{
load_resfile(filename);
#include "special/sprite.h"
-class SpriteManager
-{
- private:
- typedef std::map<std::string, Sprite*> Sprites;
- Sprites sprites;
- public:
- SpriteManager(const std::string& filename);
- ~SpriteManager();
-
- void load_resfile(const std::string& filename);
- /** loads a sprite.
- * WARNING: You must not delete the returned object.
- */
- Sprite* load(const std::string& name);
-};
+namespace SuperTux
+ {
+
+ class SpriteManager
+ {
+ private:
+ typedef std::map<std::string, Sprite*> Sprites;
+ Sprites sprites;
+ public:
+ SpriteManager(const std::string& filename);
+ ~SpriteManager();
+
+ void load_resfile(const std::string& filename);
+ /** loads a sprite.
+ * WARNING: You must not delete the returned object.
+ */
+ Sprite* load(const std::string& name);
+ };
+
+} //namespace SuperTux
#endif /*SUPERTUX_SPRITE_MANAGER_H*/
#include "stdlib.h"
#include "special/stringlist.h"
-void string_list_init(string_list_type* pstring_list)
+using namespace SuperTux;
+
+void SuperTux::string_list_init(string_list_type* pstring_list)
{
pstring_list->num_items = 0;
pstring_list->active_item = -1;
pstring_list->item = NULL;
}
-char* string_list_active(string_list_type* pstring_list)
+char* SuperTux::string_list_active(string_list_type* pstring_list)
{
if(pstring_list == NULL)
return "";
return "";
}
-void string_list_add_item(string_list_type* pstring_list,const char* str)
+void SuperTux::string_list_add_item(string_list_type* pstring_list,const char* str)
{
char *pnew_string;
pnew_string = (char*) malloc(sizeof(char)*(strlen(str)+1));
pstring_list->active_item = 0;
}
-void string_list_copy(string_list_type* pstring_list, string_list_type pstring_list_orig)
+void SuperTux::string_list_copy(string_list_type* pstring_list, string_list_type pstring_list_orig)
{
int i;
string_list_free(pstring_list);
string_list_add_item(pstring_list,pstring_list_orig.item[i]);
}
-int string_list_find(string_list_type* pstring_list,const char* str)
+int SuperTux::string_list_find(string_list_type* pstring_list,const char* str)
{
int i;
for(i = 0; i < pstring_list->num_items; ++i)
return -1;
}
-void string_list_sort(string_list_type* pstring_list)
+void SuperTux::string_list_sort(string_list_type* pstring_list)
{
int i,j,y;
}
-void string_list_free(string_list_type* pstring_list)
+void SuperTux::string_list_free(string_list_type* pstring_list)
{
if(pstring_list != NULL)
{
#ifndef SUPERTUX_STRINGLIST_H
#define SUPERTUX_STRINGLIST_H
-struct string_list_type
-{
- int num_items;
- int active_item;
- char **item;
-};
+namespace SuperTux
+ {
-void string_list_init(string_list_type* pstring_list);
-char* string_list_active(string_list_type* pstring_list);
-void string_list_copy(string_list_type* pstring_list, string_list_type pstring_list_orig);
-int string_list_find(string_list_type* pstring_list, const char* str);
-void string_list_sort(string_list_type* pstring_list);
-void string_list_add_item(string_list_type* pstring_list, const char* str);
-void string_list_free(string_list_type* pstring_list);
+ struct string_list_type
+ {
+ int num_items;
+ int active_item;
+ char **item;
+ };
+ void string_list_init(string_list_type* pstring_list);
+ char* string_list_active(string_list_type* pstring_list);
+ void string_list_copy(string_list_type* pstring_list, string_list_type pstring_list_orig);
+ int string_list_find(string_list_type* pstring_list, const char* str);
+ void string_list_sort(string_list_type* pstring_list);
+ void string_list_add_item(string_list_type* pstring_list, const char* str);
+ void string_list_free(string_list_type* pstring_list);
+} //namespace SuperTux
#endif /*SUPERTUX_STRINGLIST_H*/
#include "SDL.h"
#include "special/timer.h"
-unsigned int st_pause_ticks, st_pause_count;
+using namespace SuperTux;
-unsigned int st_get_ticks(void)
+unsigned int SuperTux::st_pause_ticks, SuperTux::st_pause_count;
+
+unsigned int SuperTux::st_get_ticks(void)
{
if(st_pause_count != 0)
return /*SDL_GetTicks()*/ - st_pause_ticks /*- SDL_GetTicks()*/ + st_pause_count;
return SDL_GetTicks() - st_pause_ticks;
}
-void st_pause_ticks_init(void)
+void SuperTux::st_pause_ticks_init(void)
{
st_pause_ticks = 0;
st_pause_count = 0;
}
-void st_pause_ticks_start(void)
+void SuperTux::st_pause_ticks_start(void)
{
if(st_pause_count == 0)
st_pause_count = SDL_GetTicks();
}
-void st_pause_ticks_stop(void)
+void SuperTux::st_pause_ticks_stop(void)
{
if(st_pause_count == 0)
return;
st_pause_count = 0;
}
-bool st_pause_ticks_started(void)
+bool SuperTux::st_pause_ticks_started(void)
{
if(st_pause_count == 0)
return false;
#ifndef SUPERTUX_TIMER_H
#define SUPERTUX_TIMER_H
-extern unsigned int st_pause_ticks, st_pause_count;
-
-/// Time a game is running. (Non-pause mode, etc.)
-unsigned int st_get_ticks(void);
-
-void st_pause_ticks_init(void);
-void st_pause_ticks_start(void);
-void st_pause_ticks_stop(void);
-bool st_pause_ticks_started(void);
-
-/// Timer
-/** This class can be used as stop watch
- for example. It's also possible to calculate
- frames per seconds and things like that with it.
- It's a general timing class, but it
- can esspecially be used together with st_get_ticks(). */
-class Timer
-{
- public:
- unsigned int period;
- unsigned int time;
- unsigned int (*get_ticks) (void);
-
- public:
- Timer();
-
- /// Initialize the timer.
- /** @Param st_ticks: If true internally st_get_ticks() is used, else SDL_GetTicks() is used. */
- void init(bool st_ticks);
-
- /// Start the timer with the given period (in ms).
- void start(unsigned int period);
-
- /// Stop the timer.
- void stop();
-
- /// Check if the timer is started and within its period.
- /** If one of these requirements isn't the case the timer
- is automatically reseted. */
- int check();
-
- /// Is the timer started?
- int started();
-
- /// Get time left until the last timing period is finished.
- /** The returned value can be negative. */
- int get_left();
-
- /// Get the gone time, since last timer start.
- /** The returned value can be negative. */
- int get_gone();
-
- /// Write the timer value to a file (For save games in example).
- void fwrite(FILE* fi);
- /// Read a timer value from a file (From save games in example).
- void fread(FILE* fi);
-};
+namespace SuperTux
+ {
+
+ extern unsigned int st_pause_ticks, st_pause_count;
+
+ /// Time a game is running. (Non-pause mode, etc.)
+ unsigned int st_get_ticks(void);
+
+ void st_pause_ticks_init(void);
+ void st_pause_ticks_start(void);
+ void st_pause_ticks_stop(void);
+ bool st_pause_ticks_started(void);
+
+ /// Timer
+ /** This class can be used as stop watch
+ for example. It's also possible to calculate
+ frames per seconds and things like that with it.
+ It's a general timing class, but it
+ can esspecially be used together with st_get_ticks(). */
+ class Timer
+ {
+ public:
+ unsigned int period;
+ unsigned int time;
+ unsigned int (*get_ticks) (void);
+
+ public:
+ Timer();
+
+ /// Initialize the timer.
+ /** @param st_ticks: If true internally st_get_ticks() is used, else SDL_GetTicks() is used. */
+ void init(bool st_ticks);
+
+ /// Start the timer with the given period (in ms).
+ void start(unsigned int period);
+
+ /// Stop the timer.
+ void stop();
+
+ /// Check if the timer is started and within its period.
+ /** If one of these requirements isn't the case the timer
+ is automatically reseted. */
+ int check();
+
+ /// Is the timer started?
+ int started();
+
+ /// Get time left until the last timing period is finished.
+ /** The returned value can be negative. */
+ int get_left();
+
+ /// Get the gone time, since last timer start.
+ /** The returned value can be negative. */
+ int get_gone();
+
+ /// Write the timer value to a file (For save games in example).
+ void fwrite(FILE* fi);
+ /// Read a timer value from a file (From save games in example).
+ void fread(FILE* fi);
+ };
+
+} //namespace SuperTux
#endif /*SUPERTUX_TIMER_H*/
#include "app/setup.h"
#include "app/globals.h"
+using namespace SuperTux;
+
#ifdef WIN32
const char * config_filename = "/st_config.dat";
#else
const char * config_filename = "/config";
#endif
-Config* config = 0;
+Config* SuperTux::config = 0;
static void defaults ()
{
#include "utils/lispreader.h"
+namespace SuperTux {
+
class Config {
public:
void load ();
extern Config* config;
+} //namespace SuperTux
#endif
#include <exception>
#include <string>
-class SuperTuxException : public std::exception
-{
- public:
- SuperTuxException(const char* _message, const char* _file = "", const unsigned int _line = 0)
- : message(_message), file(_file), line(_line) { };
- virtual ~SuperTuxException() throw() { };
-
- const char* what() const throw() { return message; };
- const char* what_file() const throw() { return file; };
- const unsigned int what_line() const throw() { return line; };
-
- private:
- const char* message;
- const char* file;
- const unsigned int line;
-};
+namespace SuperTux
+ {
+
+ class SuperTuxException : public std::exception
+ {
+ public:
+ SuperTuxException(const char* _message, const char* _file = "", const unsigned int _line = 0)
+ : message(_message), file(_file), line(_line) { };
+ virtual ~SuperTuxException() throw() { };
+
+ const char* what() const throw() { return message; };
+ const char* what_file() const throw() { return file; };
+ const unsigned int what_line() const throw() { return line; };
+
+ private:
+ const char* message;
+ const char* file;
+ const unsigned int line;
+ };
+
+}
#endif /*SUPERTUX_EXCEPTIONS_H*/
#include "app/setup.h"
#include "utils/lispreader.h"
+using namespace SuperTux;
+
#define TOKEN_ERROR -1
#define TOKEN_EOF 0
#define TOKEN_OPEN_PAREN 1
}
lisp_stream_t*
-lisp_stream_init_file (lisp_stream_t *stream, FILE *file)
+SuperTux::lisp_stream_init_file (lisp_stream_t *stream, FILE *file)
{
stream->type = LISP_STREAM_FILE;
stream->v.file = file;
}
lisp_stream_t*
-lisp_stream_init_string (lisp_stream_t *stream, char *buf)
+SuperTux::lisp_stream_init_string (lisp_stream_t *stream, char *buf)
{
stream->type = LISP_STREAM_STRING;
stream->v.string.buf = buf;
}
lisp_stream_t*
-lisp_stream_init_any (lisp_stream_t *stream, void *data,
+SuperTux::lisp_stream_init_any (lisp_stream_t *stream, void *data,
int (*next_char) (void *data),
void (*unget_char) (char c, void *data))
{
}
lisp_object_t*
-lisp_make_integer (int value)
+SuperTux::lisp_make_integer (int value)
{
lisp_object_t *obj = lisp_object_alloc(LISP_TYPE_INTEGER);
}
lisp_object_t*
-lisp_make_real (float value)
+SuperTux::lisp_make_real (float value)
{
lisp_object_t *obj = lisp_object_alloc(LISP_TYPE_REAL);
}
lisp_object_t*
-lisp_make_symbol (const char *value)
+SuperTux::lisp_make_symbol (const char *value)
{
lisp_object_t *obj = lisp_object_alloc(LISP_TYPE_SYMBOL);
}
lisp_object_t*
-lisp_make_string (const char *value)
+SuperTux::lisp_make_string (const char *value)
{
lisp_object_t *obj = lisp_object_alloc(LISP_TYPE_STRING);
}
lisp_object_t*
-lisp_make_cons (lisp_object_t *car, lisp_object_t *cdr)
+SuperTux::lisp_make_cons (lisp_object_t *car, lisp_object_t *cdr)
{
lisp_object_t *obj = lisp_object_alloc(LISP_TYPE_CONS);
}
lisp_object_t*
-lisp_make_boolean (int value)
+SuperTux::lisp_make_boolean (int value)
{
lisp_object_t *obj = lisp_object_alloc(LISP_TYPE_BOOLEAN);
}
lisp_object_t*
-lisp_read (lisp_stream_t *in)
+SuperTux::lisp_read (lisp_stream_t *in)
{
int token = _scan(in);
lisp_object_t *obj = lisp_nil();
}
void
-lisp_free (lisp_object_t *obj)
+SuperTux::lisp_free (lisp_object_t *obj)
{
if (obj == 0)
return;
}
lisp_object_t*
-lisp_read_from_string (const char *buf)
+SuperTux::lisp_read_from_string (const char *buf)
{
lisp_stream_t stream;
}
int
-lisp_compile_pattern (lisp_object_t **obj, int *num_subs)
+SuperTux::lisp_compile_pattern (lisp_object_t **obj, int *num_subs)
{
int index = 0;
int result;
}
int
-lisp_match_pattern (lisp_object_t *pattern, lisp_object_t *obj, lisp_object_t **vars, int num_subs)
+SuperTux::lisp_match_pattern (lisp_object_t *pattern, lisp_object_t *obj, lisp_object_t **vars, int num_subs)
{
int i;
}
int
-lisp_match_string (const char *pattern_string, lisp_object_t *obj, lisp_object_t **vars)
+SuperTux::lisp_match_string (const char *pattern_string, lisp_object_t *obj, lisp_object_t **vars)
{
lisp_object_t *pattern;
int result;
}
int
-lisp_type (lisp_object_t *obj)
+SuperTux::lisp_type (lisp_object_t *obj)
{
if (obj == 0)
return LISP_TYPE_NIL;
}
int
-lisp_integer (lisp_object_t *obj)
+SuperTux::lisp_integer (lisp_object_t *obj)
{
if (obj->type != LISP_TYPE_INTEGER)
throw LispReaderException("lisp_integer()", __FILE__, __LINE__);
}
char*
-lisp_symbol (lisp_object_t *obj)
+SuperTux::lisp_symbol (lisp_object_t *obj)
{
if (obj->type != LISP_TYPE_SYMBOL)
throw LispReaderException("lisp_symbol()", __FILE__, __LINE__);
}
char*
-lisp_string (lisp_object_t *obj)
+SuperTux::lisp_string (lisp_object_t *obj)
{
if (obj->type != LISP_TYPE_STRING)
throw LispReaderException("lisp_string()", __FILE__, __LINE__);
}
int
-lisp_boolean (lisp_object_t *obj)
+SuperTux::lisp_boolean (lisp_object_t *obj)
{
if (obj->type != LISP_TYPE_BOOLEAN)
throw LispReaderException("lisp_boolean()", __FILE__, __LINE__);
}
float
-lisp_real (lisp_object_t *obj)
+SuperTux::lisp_real (lisp_object_t *obj)
{
if (obj->type != LISP_TYPE_REAL && obj->type != LISP_TYPE_INTEGER)
throw LispReaderException("lisp_real()", __FILE__, __LINE__);
}
lisp_object_t*
-lisp_car (lisp_object_t *obj)
+SuperTux::lisp_car (lisp_object_t *obj)
{
if (obj->type != LISP_TYPE_CONS && obj->type != LISP_TYPE_PATTERN_CONS)
throw LispReaderException("lisp_car()", __FILE__, __LINE__);
}
lisp_object_t*
-lisp_cdr (lisp_object_t *obj)
+SuperTux::lisp_cdr (lisp_object_t *obj)
{
if (obj->type != LISP_TYPE_CONS && obj->type != LISP_TYPE_PATTERN_CONS)
throw LispReaderException("lisp_cdr()", __FILE__, __LINE__);
}
lisp_object_t*
-lisp_cxr (lisp_object_t *obj, const char *x)
+SuperTux::lisp_cxr (lisp_object_t *obj, const char *x)
{
int i;
}
int
-lisp_list_length (lisp_object_t *obj)
+SuperTux::lisp_list_length (lisp_object_t *obj)
{
int length = 0;
}
lisp_object_t*
-lisp_list_nth_cdr (lisp_object_t *obj, int index)
+SuperTux::lisp_list_nth_cdr (lisp_object_t *obj, int index)
{
while (index > 0)
{
}
lisp_object_t*
-lisp_list_nth (lisp_object_t *obj, int index)
+SuperTux::lisp_list_nth (lisp_object_t *obj, int index)
{
obj = lisp_list_nth_cdr(obj, index);
}
void
-lisp_dump (lisp_object_t *obj, FILE *out)
+SuperTux::lisp_dump (lisp_object_t *obj, FILE *out)
{
if (obj == 0)
{
return lst;
}
-lisp_object_t* lisp_read_from_file(const std::string& filename)
+lisp_object_t* SuperTux::lisp_read_from_file(const std::string& filename)
{
FILE* in = fopen(filename.c_str(), "r");
#include "utils/exceptions.h"
+namespace SuperTux {
+
#define LISP_STREAM_FILE 1
#define LISP_STREAM_STRING 2
#define LISP_STREAM_ANY 3
lisp_object_t* get_lisp();
};
+} //namespace SuperTux
+
#endif /*SUPERTUX_LISPREADER_H*/
#include "utils/lispwriter.h"
+using namespace SuperTux;
+
LispWriter::LispWriter(std::ostream& newout)
: out(newout), indent_depth(0)
{
#include <string>
#include <vector>
-class LispWriter
-{
-public:
- LispWriter(std::ostream& out);
- ~LispWriter();
-
- void write_comment(const std::string& comment);
-
- void start_list(const std::string& listname);
-
- void write_int(const std::string& name, int value);
- void write_float(const std::string& name, float value);
- void write_string(const std::string& name, const std::string& value);
- void write_bool(const std::string& name, bool value);
- void write_int_vector(const std::string& name, const std::vector<int>& value);
- void write_int_vector(const std::string& name, const std::vector<unsigned int>& value);
- // add more write-functions when needed...
-
- void end_list(const std::string& listname);
-
-private:
- void indent();
-
- std::ostream& out;
- int indent_depth;
- std::vector<std::string> lists;
-};
-
-#endif
+namespace SuperTux
+ {
+
+ class LispWriter
+ {
+ public:
+ LispWriter(std::ostream& out);
+ ~LispWriter();
+
+ void write_comment(const std::string& comment);
+
+ void start_list(const std::string& listname);
+
+ void write_int(const std::string& name, int value);
+ void write_float(const std::string& name, float value);
+ void write_string(const std::string& name, const std::string& value);
+ void write_bool(const std::string& name, bool value);
+ void write_int_vector(const std::string& name, const std::vector<int>& value);
+ void write_int_vector(const std::string& name, const std::vector<unsigned int>& value);
+ // add more write-functions when needed...
+
+ void end_list(const std::string& listname);
+
+ private:
+ void indent();
+
+ std::ostream& out;
+ int indent_depth;
+ std::vector<std::string> lists;
+ };
+
+} //namespace SuperTux
+
+#endif //SUPERTUX_LISPWRITER_H
#include "app/globals.h"
#include "video/font.h"
+using namespace SuperTux;
+
DrawingContext::DrawingContext()
{
transform.draw_effect = NONE_EFFECT;
#include "math/vector.h"
#include "video/screen.h"
+#include "video/surface.h"
-class Surface;
-class Font;
-
-// some constants for predefined layer values
-enum {
- LAYER_BACKGROUND0 = -300,
- LAYER_BACKGROUND1 = -200,
- LAYER_BACKGROUNDTILES = -100,
- LAYER_TILES = 0,
- LAYER_OBJECTS = 100,
- LAYER_FOREGROUNDTILES = 200,
- LAYER_FOREGROUND0 = 300,
- LAYER_FOREGROUND1 = 400,
- LAYER_GUI = 500
-};
-
-/**
- * This class provides functions for drawing things on screen. It also
- * maintains a stack of transforms that are applied to graphics.
- */
-class DrawingContext
-{
-public:
- DrawingContext();
- ~DrawingContext();
-
- /** Adds a drawing request for a surface into the request list */
- void draw_surface(const Surface* surface, const Vector& position, int layer,
- Uint32 drawing_effect = NONE_EFFECT);
- /** Adds a drawing request for part of a surface */
- void draw_surface_part(const Surface* surface, const Vector& source,
- const Vector& size, const Vector& dest, int layer,
- Uint32 drawing_effect = NONE_EFFECT);
- /** draws a text */
- void draw_text(Font* font, const std::string& text, const Vector& position,
- int layer, Uint32 drawing_effect = NONE_EFFECT);
- /** draws aligned text */
- void draw_text_center(Font* font, const std::string& text,
- const Vector& position, int layer, Uint32 drawing_effect = NONE_EFFECT);
- /** draws a color gradient onto the whole screen */
- void draw_gradient(Color from, Color to, int layer);
- /** fills a rectangle */
- void draw_filled_rect(const Vector& topleft, const Vector& size,
- Color color, int layer);
-
- /** Processes all pending drawing requests and flushes the list */
- void do_drawing();
-
- const Vector& get_translation() const
- { return transform.translation; }
- void set_translation(const Vector& newtranslation)
- { transform.translation = newtranslation; }
-
- void push_transform();
- void pop_transform();
-
- /** apply that effect in the next draws (effects are listed on surface.h) */
- void set_drawing_effect(int effect);
-
-private:
- class Transform
+namespace SuperTux
{
- public:
- Vector translation; // only translation for now...
- Vector apply(const Vector& v) const
- {
- return v - translation;
- }
-
- int draw_effect;
- };
-
- /// the transform stack
- std::vector<Transform> transformstack;
- /// the currently active transform
- Transform transform;
-
- enum RequestType
- {
- SURFACE, SURFACE_PART, TEXT, GRADIENT, FILLRECT
- };
-
- struct SurfacePartRequest
- {
- const Surface* surface;
- Vector source, size;
- };
-
- struct TextRequest
- {
- Font* font;
- std::string text;
+ class Surface;
+ class Font;
+
+ // some constants for predefined layer values
+ enum {
+ LAYER_BACKGROUND0 = -300,
+ LAYER_BACKGROUND1 = -200,
+ LAYER_BACKGROUNDTILES = -100,
+ LAYER_TILES = 0,
+ LAYER_OBJECTS = 100,
+ LAYER_FOREGROUNDTILES = 200,
+ LAYER_FOREGROUND0 = 300,
+ LAYER_FOREGROUND1 = 400,
+ LAYER_GUI = 500
};
- struct GradientRequest
- {
- Color top, bottom;
- Vector size;
- };
-
- struct FillRectRequest
- {
- Color color;
- Vector size;
- };
-
- struct DrawingRequest
- {
- int layer;
- Uint32 drawing_effect;
-
- RequestType type;
- Vector pos;
-
- void* request_data;
-
- bool operator<(const DrawingRequest& other) const
+ /**
+ * This class provides functions for drawing things on screen. It also
+ * maintains a stack of transforms that are applied to graphics.
+ */
+ class DrawingContext
{
- return layer < other.layer;
- }
- };
-
- void draw_surface_part(DrawingRequest& request);
- void draw_text(DrawingRequest& request);
- void draw_gradient(DrawingRequest& request);
- void draw_filled_rect(DrawingRequest& request);
-
- typedef std::vector<DrawingRequest> DrawingRequests;
- DrawingRequests drawingrequests;
-};
+ public:
+ DrawingContext();
+ ~DrawingContext();
+
+ /** Adds a drawing request for a surface into the request list */
+ void draw_surface(const Surface* surface, const Vector& position, int layer,
+ Uint32 drawing_effect = NONE_EFFECT);
+ /** Adds a drawing request for part of a surface */
+ void draw_surface_part(const Surface* surface, const Vector& source,
+ const Vector& size, const Vector& dest, int layer,
+ Uint32 drawing_effect = NONE_EFFECT);
+ /** draws a text */
+ void draw_text(Font* font, const std::string& text, const Vector& position,
+ int layer, Uint32 drawing_effect = NONE_EFFECT);
+ /** draws aligned text */
+ void draw_text_center(Font* font, const std::string& text,
+ const Vector& position, int layer, Uint32 drawing_effect = NONE_EFFECT);
+ /** draws a color gradient onto the whole screen */
+ void draw_gradient(Color from, Color to, int layer);
+ /** fills a rectangle */
+ void draw_filled_rect(const Vector& topleft, const Vector& size,
+ Color color, int layer);
+
+ /** Processes all pending drawing requests and flushes the list */
+ void do_drawing();
+
+ const Vector& get_translation() const
+ {
+ return transform.translation;
+ }
+ void set_translation(const Vector& newtranslation)
+ {
+ transform.translation = newtranslation;
+ }
+
+ void push_transform();
+ void pop_transform();
+
+ /** apply that effect in the next draws (effects are listed on surface.h) */
+ void set_drawing_effect(int effect);
+
+ private:
+ class Transform
+ {
+ public:
+ Vector translation; // only translation for now...
+
+ Vector apply(const Vector& v) const
+ {
+ return v - translation;
+ }
+
+ int draw_effect;
+ };
+
+ /// the transform stack
+ std::vector<Transform> transformstack;
+ /// the currently active transform
+ Transform transform;
+
+ enum RequestType
+ {
+ SURFACE, SURFACE_PART, TEXT, GRADIENT, FILLRECT
+ };
+
+ struct SurfacePartRequest
+ {
+ const Surface* surface;
+ Vector source, size;
+ };
+
+ struct TextRequest
+ {
+ Font* font;
+ std::string text;
+ };
+
+ struct GradientRequest
+ {
+ Color top, bottom;
+ Vector size;
+ };
+
+ struct FillRectRequest
+ {
+ Color color;
+ Vector size;
+ };
+
+ struct DrawingRequest
+ {
+ int layer;
+ Uint32 drawing_effect;
+
+ RequestType type;
+ Vector pos;
+
+ void* request_data;
+
+ bool operator<(const DrawingRequest& other) const
+ {
+ return layer < other.layer;
+ }
+ };
+
+ void draw_surface_part(DrawingRequest& request);
+ void draw_text(DrawingRequest& request);
+ void draw_gradient(DrawingRequest& request);
+ void draw_filled_rect(DrawingRequest& request);
+
+ typedef std::vector<DrawingRequest> DrawingRequests;
+ DrawingRequests drawingrequests;
+ };
+
+} //namespace SuperTux
#endif /*SUPERTUX_DRAWINGCONTEXT_H*/
#include "video/drawing_context.h"
#include "utils/lispreader.h"
+using namespace SuperTux;
+
Font::Font(const std::string& file, FontType ntype, int nw, int nh,
int nshadowsize)
: chars(0), shadow_chars(0), type(ntype), w(nw), h(nh),
#define SCROLL 60
#define ITEMS_SPACE 4
-void display_text_file(const std::string& file, float scroll_speed)
+void SuperTux::display_text_file(const std::string& file, float scroll_speed)
{
std::string text;
std::vector<std::string> names;
#include "video/surface.h"
#include "math/vector.h"
-/** Reads a text file (using LispReader, so it as to be in its formatting)
- and displays it in a StarTrek fashion */
-void display_text_file(const std::string& file, float scroll_speed);
+namespace SuperTux
+ {
-/* Text type */
-class Font
-{
-public:
- /* Kinds of texts. */
- enum FontType {
- TEXT, // images for all characters
- NUM // only images for numbers
- };
-
- Font(const std::string& file, FontType type, int w, int h, int shadowsize=2);
- ~Font();
+ /** Reads a text file (using LispReader, so it as to be in its formatting)
+ and displays it in a StarTrek fashion */
+ void display_text_file(const std::string& file, float scroll_speed);
- /** returns the height of the font */
- float get_height() const;
- /** returns the width of a given text. (Note that I won't add a normal
- * get_width function here, as we might switch to variable width fonts in the
- * future.
- */
- float get_text_width(const std::string& text) const;
+ /* Text type */
+ class Font
+ {
+ public:
+ /* Kinds of texts. */
+ enum FontType {
+ TEXT, // images for all characters
+ NUM // only images for numbers
+ };
-private:
- friend class DrawingContext;
-
- void draw(const std::string& text, const Vector& pos,
- Uint32 drawing_effect = NONE_EFFECT);
- void draw_chars(Surface* pchars, const std::string& text,
- const Vector& position, Uint32 drawing_effect);
+ Font(const std::string& file, FontType type, int w, int h, int shadowsize=2);
+ ~Font();
- Surface* chars;
- Surface* shadow_chars;
- FontType type;
- int w;
- int h;
- int shadowsize;
+ /** returns the height of the font */
+ float get_height() const;
+ /** returns the width of a given text. (Note that I won't add a normal
+ * get_width function here, as we might switch to variable width fonts in the
+ * future.
+ */
+ float get_text_width(const std::string& text) const;
- /// the number of the first character that is represented in the font
- int first_char;
- /// the number of the last character that is represented in the font
- int last_char;
-};
+ private:
+ friend class DrawingContext;
+
+ void draw(const std::string& text, const Vector& pos,
+ Uint32 drawing_effect = NONE_EFFECT);
+ void draw_chars(Surface* pchars, const std::string& text,
+ const Vector& position, Uint32 drawing_effect);
+
+ Surface* chars;
+ Surface* shadow_chars;
+ FontType type;
+ int w;
+ int h;
+ int shadowsize;
+
+ /// the number of the first character that is represented in the font
+ int first_char;
+ /// the number of the last character that is represented in the font
+ int last_char;
+ };
+
+} //namespace SuperTux
#endif /*SUPERTUX_FONT_H*/
#include <ctype.h>
#endif
-#include "app/globals.h"
#include "video/screen.h"
+#include "app/globals.h"
#include "video/drawing_context.h"
#include "special/base.h"
+#include "math/vector.h"
+
+using namespace SuperTux;
/* 'Stolen' from the SDL documentation.
* Set the pixel at (x, y) to the given value
* NOTE: The surface must be locked before calling this!
*/
-void putpixel(SDL_Surface *surface, int x, int y, Uint32 pixel)
+void SuperTux::putpixel(SDL_Surface *surface, int x, int y, Uint32 pixel)
{
int bpp = surface->format->BytesPerPixel;
/* Here p is the address to the pixel we want to set */
}
/* Draw a single pixel on the screen. */
-void drawpixel(int x, int y, Uint32 pixel)
+void SuperTux::drawpixel(int x, int y, Uint32 pixel)
{
/* Lock the screen for direct access to the pixels */
if ( SDL_MUSTLOCK(screen) )
/* --- FILL A RECT --- */
-void fillrect(float x, float y, float w, float h, int r, int g, int b, int a)
+void SuperTux::fillrect(float x, float y, float w, float h, int r, int g, int b, int a)
{
if(w < 0)
{
#define SGN(x) ((x)>0 ? 1 : ((x)==0 ? 0:(-1)))
#define ABS(x) ((x)>0 ? (x) : (-x))
-void
-draw_line(float x1, float y1, float x2, float y2, int r, int g, int b, int a)
+void SuperTux::draw_line(float x1, float y1, float x2, float y2, int r, int g, int b, int a)
{
#ifndef NOOPENGL
if(use_gl)
#define LOOP_DELAY 20.0
-void fadeout(int fade_time)
+void SuperTux::fadeout(int fade_time)
{
float alpha_inc = 256 / (fade_time / LOOP_DELAY);
float alpha = 256;
context.do_drawing();
}
-void shrink_fade(const Vector& point, int fade_time)
+void SuperTux::shrink_fade(const Vector& point, int fade_time)
{
float left_inc = point.x / ((float)fade_time / LOOP_DELAY);
float right_inc = (screen->w - point.x) / ((float)fade_time / LOOP_DELAY);
#include <SDL_opengl.h>
#endif
#include <iostream>
-class Color
-{
-public:
- Color()
- : red(0), green(0), blue(0), alpha(255)
- {}
-
- Color(Uint8 red_, Uint8 green_, Uint8 blue_, Uint8 alpha_ = 255)
- : red(red_), green(green_), blue(blue_), alpha(alpha_)
- {}
- Color(const Color& o)
- : red(o.red), green(o.green), blue(o.blue), alpha(o.alpha)
- { }
+namespace SuperTux
+ {
+
+ /// Color RGBA
+ /** Stores 8bit RGBA values. */
+ class Color
+ {
+ public:
+ Color()
+ : red(0), green(0), blue(0), alpha(255)
+ {}
- bool operator==(const Color& o)
- { if(red == o.red && green == o.green &&
- blue == o.blue && alpha == o.alpha)
- return true;
- return false; }
+ Color(Uint8 red_, Uint8 green_, Uint8 blue_, Uint8 alpha_ = 255)
+ : red(red_), green(green_), blue(blue_), alpha(alpha_)
+ {}
- Uint8 red, green, blue, alpha;
-};
+ Color(const Color& o)
+ : red(o.red), green(o.green), blue(o.blue), alpha(o.alpha)
+ { }
-#include "video/surface.h"
+ bool operator==(const Color& o)
+ {
+ if(red == o.red && green == o.green &&
+ blue == o.blue && alpha == o.alpha)
+ return true;
+ return false;
+ }
-class Vector;
+ Uint8 red, green, blue, alpha;
+ };
-void putpixel(SDL_Surface *surface, int x, int y, Uint32 pixel);
-void drawpixel(int x, int y, Uint32 pixel);
-void fillrect(float x, float y, float w, float h, int r, int g, int b, int a = 255);
-void draw_line(float x1, float y1, float x2, int r, int g, int b, int a = 255);
-void fadeout(int fade_time);
-void shrink_fade(const Vector& point, int fade_time);
+ class Vector;
+
+ void putpixel(SDL_Surface *surface, int x, int y, Uint32 pixel);
+ void drawpixel(int x, int y, Uint32 pixel);
+ void fillrect(float x, float y, float w, float h, int r, int g, int b, int a = 255);
+ void draw_line(float x1, float y1, float x2, float y2, int r, int g, int b, int a = 255);
+
+ void fadeout(int fade_time);
+ void shrink_fade(const Vector& point, int fade_time);
+
+} //namespace SuperTux
#endif /*SUPERTUX_SCREEN_H*/
#include "app/globals.h"
#include "app/setup.h"
+using namespace SuperTux;
+
Surface::Surfaces Surface::surfaces;
SurfaceData::SurfaceData(SDL_Surface* temp, bool use_alpha_)
}
SDL_Surface*
-sdl_surface_from_sdl_surface(SDL_Surface* sdl_surf, bool use_alpha)
+SuperTux::sdl_surface_from_sdl_surface(SDL_Surface* sdl_surf, bool use_alpha)
{
SDL_Surface* sdl_surface;
Uint32 saved_flags;
#include "SDL.h"
-#include "video/screen.h"
#include "math/vector.h"
+#include "video/screen.h"
-SDL_Surface* sdl_surface_from_sdl_surface(SDL_Surface* sdl_surf, bool use_alpha);
-SDL_Surface* sdl_surface_from_nothing();
-
-class SurfaceImpl;
-class SurfaceSDL;
-class SurfaceOpenGL;
-class DrawingContext;
-
-/// bitset for drawing effects
-enum {
- /** Don't apply anything */
- NONE_EFFECT = 0x0000,
- /** Draw the Surface upside down */
- VERTICAL_FLIP = 0x0001,
- /** Draw the Surface with alpha equal to 128 */
- SEMI_TRANSPARENT = 0x0002
- };
-
-/** This class holds all the data necessary to construct a surface */
-class SurfaceData
-{
-public:
- enum ConstructorType { LOAD, LOAD_PART, SURFACE, GRADIENT };
- ConstructorType type;
- SDL_Surface* surface;
- std::string file;
- bool use_alpha;
- int x;
- int y;
- int w;
- int h;
- Color top_gradient;
- Color bottom_gradient;
-
- SurfaceData(SDL_Surface* surf, bool use_alpha_);
- SurfaceData(const std::string& file_, bool use_alpha_);
- SurfaceData(const std::string& file_, int x_, int y_, int w_, int h_, bool use_alpha_);
- SurfaceData(Color top_gradient_, Color bottom_gradient_, int w_, int h_);
- ~SurfaceData();
-
- SurfaceSDL* create_SurfaceSDL();
- SurfaceOpenGL* create_SurfaceOpenGL();
- SurfaceImpl* create();
-};
-
-/** Container class that holds a surface, necessary so that we can
- switch Surface implementations (OpenGL, SDL) on the fly */
-class Surface
-{
-public:
- SurfaceData data;
- SurfaceImpl* impl;
- int w;
- int h;
-
- typedef std::list<Surface*> Surfaces;
- static Surfaces surfaces;
-public:
- static void reload_all();
- static void debug_check();
-
- Surface(SDL_Surface* surf, bool use_alpha);
- Surface(const std::string& file, bool use_alpha);
- Surface(const std::string& file, int x, int y, int w, int h, bool use_alpha);
- Surface(Color top_gradient, Color bottom_gradient, int w_, int h_);
- ~Surface();
+namespace SuperTux
+ {
- /** Reload the surface, which is necesarry in case of a mode swich */
- void reload();
-
- void resize(int widht, int height);
-};
-
-/** Surface implementation, all implementation have to inherit from
- this class */
-class SurfaceImpl
-{
-protected:
- SDL_Surface* sdl_surface;
-
-public:
- int w;
- int h;
-
-public:
- SurfaceImpl();
- virtual ~SurfaceImpl();
+ SDL_Surface* sdl_surface_from_sdl_surface(SDL_Surface* sdl_surf, bool use_alpha);
+ SDL_Surface* sdl_surface_from_nothing();
+
+ class SurfaceImpl;
+ class SurfaceSDL;
+ class SurfaceOpenGL;
+ class DrawingContext;
- /** Return 0 on success, -2 if surface needs to be reloaded */
- virtual int draw(float x, float y, Uint8 alpha, Uint32 effect = NONE_EFFECT) = 0;
- virtual int draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha, Uint32 effect = NONE_EFFECT) = 0;
+ /// bitset for drawing effects
+ enum {
+ /** Don't apply anything */
+ NONE_EFFECT = 0x0000,
+ /** Draw the Surface upside down */
+ VERTICAL_FLIP = 0x0001,
+ /** Draw the Surface with alpha equal to 128 */
+ SEMI_TRANSPARENT = 0x0002
+ };
+
+ /** This class holds all the data necessary to construct a surface */
+ class SurfaceData
+ {
+ public:
+ enum ConstructorType { LOAD, LOAD_PART, SURFACE, GRADIENT };
+ ConstructorType type;
+ SDL_Surface* surface;
+ std::string file;
+ bool use_alpha;
+ int x;
+ int y;
+ int w;
+ int h;
+ Color top_gradient;
+ Color bottom_gradient;
+
+ SurfaceData(SDL_Surface* surf, bool use_alpha_);
+ SurfaceData(const std::string& file_, bool use_alpha_);
+ SurfaceData(const std::string& file_, int x_, int y_, int w_, int h_, bool use_alpha_);
+ SurfaceData(Color top_gradient_, Color bottom_gradient_, int w_, int h_);
+ ~SurfaceData();
+
+ SurfaceSDL* create_SurfaceSDL();
+ SurfaceOpenGL* create_SurfaceOpenGL();
+ SurfaceImpl* create();
+ };
+
+
+ /// Surface
+ /** Container class that holds a surface, necessary so that we can
+ switch Surface implementations (OpenGL, SDL) on the fly */
+ class Surface
+ {
+ public:
+ SurfaceData data;
+ SurfaceImpl* impl;
+ int w;
+ int h;
+
+ typedef std::list<Surface*> Surfaces;
+ static Surfaces surfaces;
+ public:
+ static void reload_all();
+ static void debug_check();
+
+ Surface(SDL_Surface* surf, bool use_alpha);
+ Surface(const std::string& file, bool use_alpha);
+ Surface(const std::string& file, int x, int y, int w, int h, bool use_alpha);
+ Surface(Color top_gradient, Color bottom_gradient, int w_, int h_);
+ ~Surface();
+
+ /** Reload the surface, which is necesarry in case of a mode swich */
+ void reload();
+
+ void resize(int widht, int height);
+ };
+
+ /** Surface implementation, all implementation have to inherit from
+ this class */
+ class SurfaceImpl
+ {
+ protected:
+ SDL_Surface* sdl_surface;
+
+ public:
+ int w;
+ int h;
+
+ public:
+ SurfaceImpl();
+ virtual ~SurfaceImpl();
+
+ /** Return 0 on success, -2 if surface needs to be reloaded */
+ virtual int draw(float x, float y, Uint8 alpha, Uint32 effect = NONE_EFFECT) = 0;
+ virtual int draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha, Uint32 effect = NONE_EFFECT) = 0;
#if 0
- virtual int draw_stretched(float x, float y, int w, int h, Uint8 alpha, bool update) = 0;
+
+ virtual int draw_stretched(float x, float y, int w, int h, Uint8 alpha, bool update) = 0;
#endif
- int resize(int w_, int h_);
-
- SDL_Surface* get_sdl_surface() const; // @evil@ try to avoid this function
-};
-
-class SurfaceSDL : public SurfaceImpl
-{
-public:
- SurfaceSDL(SDL_Surface* surf, bool use_alpha);
- SurfaceSDL(const std::string& file, bool use_alpha);
- SurfaceSDL(const std::string& file, int x, int y, int w, int h, bool use_alpha);
- SurfaceSDL(Color top_gradient, Color bottom_gradient, int w, int h);
- virtual ~SurfaceSDL();
-
- int draw(float x, float y, Uint8 alpha, Uint32 effect = NONE_EFFECT);
- int draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha, Uint32 effect = NONE_EFFECT);
+
+ int resize(int w_, int h_);
+
+ SDL_Surface* get_sdl_surface() const; // @evil@ try to avoid this function
+ };
+
+ class SurfaceSDL : public SurfaceImpl
+ {
+ public:
+ SurfaceSDL(SDL_Surface* surf, bool use_alpha);
+ SurfaceSDL(const std::string& file, bool use_alpha);
+ SurfaceSDL(const std::string& file, int x, int y, int w, int h, bool use_alpha);
+ SurfaceSDL(Color top_gradient, Color bottom_gradient, int w, int h);
+ virtual ~SurfaceSDL();
+
+ int draw(float x, float y, Uint8 alpha, Uint32 effect = NONE_EFFECT);
+ int draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha, Uint32 effect = NONE_EFFECT);
#if 0
- int draw_stretched(float x, float y, int w, int h, Uint8 alpha);
+
+ int draw_stretched(float x, float y, int w, int h, Uint8 alpha);
#endif
-};
+ };
#ifndef NOOPENGL
-class SurfaceOpenGL : public SurfaceImpl
-{
-public:
- GLuint gl_texture;
+ class SurfaceOpenGL : public SurfaceImpl
+ {
+ public:
+ GLuint gl_texture;
-public:
- SurfaceOpenGL(SDL_Surface* surf, bool use_alpha);
- SurfaceOpenGL(const std::string& file, bool use_alpha);
- SurfaceOpenGL(const std::string& file, int x, int y, int w, int h, bool use_alpha);
- SurfaceOpenGL(Color top_gradient, Color bottom_gradient, int w, int h);
+ public:
+ SurfaceOpenGL(SDL_Surface* surf, bool use_alpha);
+ SurfaceOpenGL(const std::string& file, bool use_alpha);
+ SurfaceOpenGL(const std::string& file, int x, int y, int w, int h, bool use_alpha);
+ SurfaceOpenGL(Color top_gradient, Color bottom_gradient, int w, int h);
- virtual ~SurfaceOpenGL();
+ virtual ~SurfaceOpenGL();
- int draw(float x, float y, Uint8 alpha, Uint32 effect = NONE_EFFECT);
- int draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha, Uint32 effect = NONE_EFFECT);
+ int draw(float x, float y, Uint8 alpha, Uint32 effect = NONE_EFFECT);
+ int draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha, Uint32 effect = NONE_EFFECT);
#if 0
- int draw_stretched(float x, float y, int w, int h, Uint8 alpha);
+
+ int draw_stretched(float x, float y, int w, int h, Uint8 alpha);
+#endif
+
+ private:
+ void create_gl(SDL_Surface * surf, GLuint * tex);
+ };
#endif
-private:
- void create_gl(SDL_Surface * surf, GLuint * tex);
-};
-#endif
+} //namespace SuperTux
#endif /*SUPERTUX_TEXTURE_H*/
#include "serializable.h"
#include "scene.h"
+using namespace SuperTux;
+
/* Timing constants (in ms): */
#define KICKING_TIME 200
#include "app/globals.h"
#include "sector.h"
+using namespace SuperTux;
+
Camera::Camera(Sector* newsector)
: sector(newsector), do_backscrolling(true), scrollchange(NONE),
auto_idx(0), auto_t(0)
#include "app/defines.h"
#include "math/vector.h"
#include "special/game_object.h"
+#include "video/drawing_context.h"
#include "serializable.h"
+using namespace SuperTux;
+
+namespace SuperTux {
class LispReader;
+}
+
class Sector;
class Camera : public GameObject, public Serializable
#include "special/base.h"
+using namespace SuperTux;
+
class Tile;
/* Collision objects */
#include "video/drawing_context.h"
#include "app/globals.h"
+using namespace SuperTux;
+
/** data images */
Sprite* door;
Surface* door_opening[DOOR_OPENING_FRAMES];
#include "serializable.h"
#include "special/timer.h"
+namespace SuperTux {
class Sprite;
-
class LispReader;
+}
/** data images */
#define DOOR_OPENING_TIME 1500
#include "audio/sound.h"
#include "special/base.h"
+using namespace SuperTux;
+
/* GameLoop modes */
#define ST_GL_PLAY 0
#define ST_GL_LOAD_LEVEL_FILE 3
#define ST_GL_DEMO_GAME 4
-
enum GameMenuIDs {
MNID_CONTINUE,
MNID_ABORTLEVEL
class Level;
class Sector;
+
+namespace SuperTux {
class DrawingContext;
+}
/** The GameSession class controlls the controll flow of a World, ie.
present the menu on specifc keypresses, render and update it while
#define NO_BOUNCE 0
#define BOUNCE 1
+namespace SuperTux {
class Sprite;
+}
struct TileId;
#include "video/surface.h"
#include "app/setup.h"
#include "utils/lispreader.h"
+#include "resources.h"
+
+using namespace SuperTux;
#ifdef WIN32
const char * highscore_filename = "/st_highscore.dat";
#include "special/game_object.h"
#include "special/base.h"
+using namespace SuperTux;
+
enum InteractionType
{
INTERACTION_TOUCH, INTERACTION_ACTIVATE // more to come
#include "video/font.h"
#include "video/screen.h"
+using namespace SuperTux;
+
void draw_intro()
{
display_text_file("intro.txt", 1);
#include <map>
#include <string>
+using namespace SuperTux;
+
class Sector;
+
+namespace SuperTux {
class LispReader;
+}
class Level
{
#include "video/surface.h"
#include "level_subset.h"
+using namespace SuperTux;
+
static bool has_suffix(const std::string& data, const std::string& suffix)
{
if (data.length() >= suffix.length())
#include <string>
#include "utils/lispreader.h"
+using namespace SuperTux;
+
+namespace SuperTux {
class Surface;
+};
/** This type holds meta-information about a level-subset.
It could be extended to handle manipulation of subsets. */
highscore_menu->additem(MN_TEXTFIELD,_("Enter your name:"),0,0);
}
+/* Free menus */
void st_menu_free()
{
delete worldmap_menu;
+ delete main_menu;
+ delete game_menu;
+ delete options_menu;
+ delete options_keys_menu;
+ delete options_joystick_menu;
+ delete highscore_menu;
+ delete contrib_menu;
+ delete contrib_subset_menu;
+ delete save_game_menu;
+ delete load_game_menu;
}
#include "special/game_object.h"
#include "serializable.h"
+using namespace SuperTux;
+
+namespace SuperTux {
class LispReader;
+}
+
class DisplayManager;
/**
#include "math/physic.h"
#include "app/defines.h"
+using namespace SuperTux;
+
class BadGuy;
/* Times: */
void player_input_init(player_input_type* pplayer_input);
+namespace SuperTux {
class Sprite;
+}
class Camera;
extern Surface* tux_life;
Surface* img_cloud[2][4];
Surface* img_distro[4];
+Menu* main_menu = 0;
+Menu* game_menu = 0;
+Menu* options_menu = 0;
+Menu* options_keys_menu = 0;
+Menu* options_joystick_menu = 0;
+Menu* highscore_menu = 0;
+Menu* load_game_menu = 0;
+Menu* save_game_menu = 0;
+Menu* contrib_menu = 0;
+Menu* contrib_subset_menu = 0;
+
MusicRef herring_song;
MusicRef level_end_song;
#define SUPERTUX_RESOURCES_H
#include "audio/musicref.h"
+#include "gui/menu.h"
+using namespace SuperTux;
+
+namespace SuperTux {
class SpriteManager;
class SoundManager;
+}
/* Sound files: */
enum {
extern SpriteManager* sprite_manager;
extern SoundManager* sound_manager;
+extern Menu* contrib_menu;
+extern Menu* contrib_subset_menu;
+extern Menu* main_menu;
+extern Menu* game_menu;
+extern Menu* options_menu;
+extern Menu* options_keys_menu;
+extern Menu* options_joystick_menu;
+extern Menu* highscore_menu;
+extern Menu* load_game_menu;
+extern Menu* save_game_menu;
+
void loadshared();
void unloadshared();
#include "audio/musicref.h"
#include "video/drawing_context.h"
+using namespace SuperTux;
+
+namespace SuperTux {
class GameObject;
+class LispReader;
+}
+
class InteractiveObject;
class Background;
class Player;
class Upgrade;
class Bullet;
class BadGuy;
-class Vector;
-class LispReader;
class Tile;
struct SpawnPoint
#ifndef SUPERTUX_SERIALIZABLE_H
#define SUPERTUX_SERIALIZABLE_H
+using namespace SuperTux;
+
+namespace SuperTux {
class LispWriter;
+}
class Serializable
{
#include "SDL.h"
#include "video/surface.h"
-class Vector;
+using namespace SuperTux;
+
+namespace SuperTux {
class LispReader;
+}
/**
Tile Class
#include "serializable.h"
#include "math/vector.h"
+using namespace SuperTux;
+
+namespace SuperTux {
+class LispReader;
+}
+
class Level;
class TileManager;
-class LispReader;
class Tile;
struct TileId