1 /*----------------------------------------------------------------------------- 2 Copyright 2003, 2004 Milan Babuskov 3 4 This file is part of Njam (http://njam.sourceforge.net). 5 6 Njam is free software; you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation; either version 2 of the License, or 9 (at your option) any later version. 10 11 Njam is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with Njam in file COPYING; if not, write to the Free Software 18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 -----------------------------------------------------------------------------*/ 20 #ifndef NJAM_H 21 #define NJAM_H 22 #include "SDL.h" 23 #include "SDL_net.h" 24 #include "SDL_mixer.h" 25 #include "njammap.h" 26 //----------------------------------------------------------------------------- 27 // Maybe this can even be hardcoded, but just in case... 28 #define MAXDELAY 120 29 #define GHOSTMAX 8 30 //----------------------------------------------------------------------------- 31 // Data used in game: players, sprites, etc... 32 typedef enum { gtSMART = 0, gtSTUPID, gtCHASER } GhostType; 33 //----------------------------------------------------------------------------- 34 struct hiscore_data 35 { 36 char name[10]; 37 int points; 38 int level; 39 }; 40 //----------------------------------------------------------------------------- 41 struct indata_struct 42 { 43 int cookies; 44 int juices; 45 int kills; 46 int player_kills; 47 int deaths; 48 int invisibles; 49 }; 50 typedef struct NjamPlayer_struct 51 { 52 int MapPoints; 53 int GamePoints; // In a duel game 54 bool Playing; 55 int Juice; 56 int Invisible; 57 int Freeze; // player can get frozen, this is not used currently but it works 58 59 union stats_union 60 { 61 int data[6]; // dugmadi, juices, kills, ply-kills, deaths, invisib 62 struct indata_struct indata; 63 } stats; 64 } NjamPlayer; 65 //----------------------------------------------------------------------------- 66 typedef struct NjamSprite_struct 67 { 68 int x,y; // coord 1-26, 1-22 69 int xo,yo; // offset 0-4 70 int vx,vy; // speed -1 0 1 71 72 // animation 73 int frame; // current frame 74 int framemax; // total nr. of frames 75 int rotate; // current rotation (0-3) = (up, down, left or right) 76 int delay; // if ply/ghost is dead 77 78 // for ghost - hunter y/n 79 int special; 80 81 // graphics (x offset) 82 int SurfaceOffset; 83 } NjamSprite; 84 //----------------------------------------------------------------------------- 85 // the same order as in Main Menu, so it can be easily assigned (cast from int) 86 typedef enum { gtOnePlayer=0, gtTwoPlayer, gtDuel, gtHostDuel, gtJoinDuel } GameType; 87 typedef enum { mtMainMenu, mtOptionsMenu } MenuType; 88 typedef enum { etNetworkError = -5, etGameOver = -4, etGameWon = -3, etLevelWon = -2, etGameDraw = -1, etNone = 0 } EndingType; 89 //----------------------------------------------------------------------------- 90 typedef struct 91 { 92 bool PlayMusic; 93 bool PlaySound; 94 int UsedSkin; 95 char ServerIP[16]; // in format 255.255.255.255 96 } tGameOptions; 97 //----------------------------------------------------------------------------- 98 struct list_item 99 { 100 char item_text[50]; 101 char item_path[512]; 102 struct list_item *next; 103 struct list_item *prev; 104 }; 105 //----------------------------------------------------------------------------- 106 class NjamEngine 107 { 108 private: 109 struct hiscore_data TopTenScores[10]; 110 bool CheckHiscore(); 111 int m_LastHiscore; 112 113 bool m_SDL; // whether SDL is initialized or not 114 bool m_AudioAvailable; // so we know wheter to try to play music/sfx 115 char linux_sdl_driver[10]; 116 SDL_Surface *m_Screen; 117 118 tGameOptions m_GameOptions; 119 120 int m_NumberOfSkins; // Graphics resources 121 SDL_Surface **m_Skins; 122 SDL_Surface *m_Icon; 123 SDL_Surface *m_MainMenuImage; 124 SDL_Surface *m_OptionsMenuImage; 125 SDL_Surface *m_GameOverImage; 126 SDL_Surface *m_StatsImage; 127 SDL_Surface *m_SpriteImage; 128 SDL_Surface *m_HiScoresImage; 129 SDL_Surface *m_LevelsetImage; 130 SDL_Surface *m_NetSendImage; 131 SDL_Surface *m_NetEnterImage; 132 SDL_Surface *m_NetLobbyImage; 133 NjamFont *m_FontBlue; 134 NjamFont *m_FontYellow; 135 Mix_Music *m_MainMenuMusic; 136 Mix_Music *m_GameMusic1; 137 Mix_Music *m_GameMusic2; 138 Mix_Chunk *m_Sounds[17]; 139 140 int m_ScrollOffset; // main menu animations' & stuff 141 int m_ScriptDelay; 142 long m_ScriptFilePos; 143 long m_ScriptLastPos; 144 void DoScript(); 145 void ScrollText(); 146 bool MenuItemSelected(int& SelectedMenuItem); 147 int m_NumberOfMenuItems; 148 MenuType m_ActiveMenu; 149 FILE *script_file; 150 151 // -------------- GAME STUFF ------------------------------------ 152 double m_fps; // average frames per second 153 int m_Freeze; // how much longer the ghosts are frozen when player collects the freezer 154 int m_Bonus; 155 int m_LivesLeft; 156 bool m_TripleDinged; 157 int m_CurrentMap; // current level in a non-duel game 158 int m_Levels; // total nr. of levels in a non-duel game 159 GameType m_GameType; 160 NjamPlayer m_Player[4]; 161 int m_CookiesLeft; // on the screen 162 NjamMap m_Maps; 163 NjamSprite m_Sprite[4+GHOSTMAX]; 164 int m_Ghosts; // active (8 in duel, 5 in non-duel) 165 166 void StartGame(GameType); // game powering functions, implemented in njamgame.cpp 167 void SetupGame(); 168 int PlayMap(bool Allow_powerups=true); 169 void SetupMap(); 170 void RenderGameScreen(); 171 bool RenderLifeLostScreen(bool LifeAwarded=false); 172 void ReadySetGo(); 173 bool HandleKeyboard(); 174 void RenderSprites(); 175 void MovePlayers(); 176 void MoveGhosts(); 177 void UpdateWorld(); 178 EndingType Collide(bool&); 179 void DrawGameStats(); 180 void Animate(); 181 182 bool SetupNetwork(); // networking (njamnet.cpp) 183 void Disconnect(); 184 bool NetworkMap(); 185 bool ExchangeNetwork(); 186 bool EnterServerIP(bool HasTried); 187 void RenderNetworkScreen(bool GameStarting = false); 188 bool m_NetworkAvailable; 189 TCPsocket m_ServerSocket; 190 TCPsocket m_PeerSocket; 191 bool m_NetworkEscapedGame; 192 193 void LevelEditor(); // level editor (njamedit.cpp) 194 void RenderEditor(bool, int, int, int); 195 bool EnterFileName(char *file_name); 196 int SelectMap(char type, char *filename = NULL, int filename_size = 0); 197 struct list_item *SelectFromList(struct list_item *first); 198 void Message(char *text); 199 bool Query(char *text); 200 bool CheckForSave(); 201 int m_SwapLevel; 202 public: 203 NjamEngine(); 204 ~NjamEngine(); 205 bool Init(bool,bool,bool); // initialize everything except for networking 206 void Start(); // start the music and main menu loop 207 }; 208 //----------------------------------------------------------------------------- 209 #endif 210