| 1 | |
| 2 | /** |
| 3 | * |
| 4 | * @file player.h |
| 5 | * |
| 6 | * Part of the OpenJazz project |
| 7 | * |
| 8 | * @par History: |
| 9 | * - 23rd August 2005: Created OpenJazz.h |
| 10 | * - 31st January 2006: Created player.h from parts of OpenJazz.h |
| 11 | * - 24th June 2010: Created levelplayer.h from parts of player.h |
| 12 | * - 24th June 2010: Created bonusplayer.h from parts of player.h |
| 13 | * |
| 14 | * @par Licence: |
| 15 | * Copyright (c) 2005-2013 AJ Thomson |
| 16 | * |
| 17 | * OpenJazz is distributed under the terms of |
| 18 | * the GNU General Public License, version 2.0 |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | |
| 23 | /* "Tile" is a flexible term. Here it is used to refer specifically to the |
| 24 | individual elements of the tile set. |
| 25 | "Tiles" in the context of level units are referred to as grid elements. */ |
| 26 | |
| 27 | |
| 28 | #ifndef _PLAYER_H |
| 29 | #define _PLAYER_H |
| 30 | |
| 31 | |
| 32 | #include "level/level.h" |
| 33 | |
| 34 | |
| 35 | // Constants |
| 36 | |
| 37 | // Player defaults |
| 38 | #define CHAR_NAME "jazz" |
| 39 | #define CHAR_FUR 4 |
| 40 | #define CHAR_BAND 3 |
| 41 | #define CHAR_GUN 2 |
| 42 | #define CHAR_WBAND 8 |
| 43 | |
| 44 | // General |
| 45 | #define PCONTROLS 8 /* Number of player controls. */ |
| 46 | |
| 47 | // Number of configurable player colour ranges |
| 48 | #define PCOLOURS 4 |
| 49 | |
| 50 | |
| 51 | // Enums |
| 52 | |
| 53 | /// Player colours |
| 54 | enum PlayerColour { |
| 55 | |
| 56 | PC_GREY = 0, |
| 57 | PC_SGREEN = 1, |
| 58 | PC_BLUE = 2, |
| 59 | PC_RED = 3, |
| 60 | PC_LGREEN = 4, |
| 61 | PC_LEVEL1 = 5, |
| 62 | PC_YELLOW = 6, |
| 63 | PC_LEVEL2 = 7, |
| 64 | PC_ORANGE = 8, |
| 65 | PC_LEVEL3 = 9, |
| 66 | PC_LEVEL4 = 10, |
| 67 | PC_SANIM = 11, |
| 68 | PC_LANIM = 12, |
| 69 | PC_LEVEL5 = 13 |
| 70 | |
| 71 | }; |
| 72 | |
| 73 | |
| 74 | // Classes |
| 75 | |
| 76 | class Anim; |
| 77 | class JJ1LevelPlayer; |
| 78 | class JJ1BonusLevelPlayer; |
| 79 | #ifdef ENABLE_JJ2 |
| 80 | class JJ2LevelPlayer; |
| 81 | #endif |
| 82 | class LevelPlayer; |
| 83 | |
| 84 | /// Game player |
| 85 | class Player { |
| 86 | |
| 87 | private: |
| 88 | Game* game; |
| 89 | LevelPlayer* levelPlayer; ///< Level player base class |
| 90 | LevelType levelPlayerType; |
| 91 | |
| 92 | char* name; ///< Name |
| 93 | bool pcontrols[PCONTROLS]; ///< Control status |
| 94 | unsigned char cols[PCOLOURS]; ///< Character colours |
| 95 | int ammo[5]; ///< Amount of ammo |
| 96 | int ammoType; ///< Ammo type. -1 = blaster, 0 = toaster, 1 = missiles, 2 = bouncer, 3 = unknown, 4 = TNT |
| 97 | int score; ///< Total score |
| 98 | int lives; ///< Remaining lives |
| 99 | int fireSpeed; ///< Rapid-fire rate |
| 100 | int flockSize; ///< Number of accompanying birds |
| 101 | unsigned char team; ///< Team ID |
| 102 | |
| 103 | void addAmmo (int type, int amount); |
| 104 | |
| 105 | public: |
| 106 | int teamScore; ///< Team's total score |
| 107 | |
| 108 | Player (); |
| 109 | ~Player (); |
| 110 | |
| 111 | void init (Game* owner, char* playerName, unsigned char* cols, unsigned char newTeam); |
| 112 | void deinit (); |
| 113 | void clearAmmo (); |
| 114 | void reset (int x, int y); |
| 115 | |
| 116 | void createLevelPlayer (LevelType levelType, Anim** anims, Anim** flippedAnims, unsigned char x, unsigned char y); |
| 117 | LevelPlayer* getLevelPlayer (); |
| 118 | JJ1BonusLevelPlayer* getJJ1BonusLevelPlayer (); |
| 119 | JJ1LevelPlayer* getJJ1LevelPlayer (); |
| 120 | #ifdef ENABLE_JJ2 |
| 121 | JJ2LevelPlayer* getJJ2LevelPlayer (); |
| 122 | #endif |
| 123 | |
| 124 | void addLife (); |
| 125 | void addScore (int addedScore); |
| 126 | bool endOfLevel (int gridX, int gridY); |
| 127 | int getAmmoType (); |
| 128 | int getAmmo (); |
| 129 | unsigned char* getCols (); |
| 130 | bool getControl (int control); |
| 131 | int getLives (); |
| 132 | char* getName (); |
| 133 | int getScore (); |
| 134 | unsigned char getTeam (); |
| 135 | bool hit (Player* source); |
| 136 | bool kill (Player* source); |
| 137 | void setCheckpoint (int gridX, int gridY); |
| 138 | void setControl (int control, bool state); |
| 139 | |
| 140 | void send (unsigned char* buffer); |
| 141 | void receive (unsigned char* buffer); |
| 142 | |
| 143 | friend class JJ1LevelPlayer; |
| 144 | #ifdef ENABLE_JJ2 |
| 145 | friend class JJ2LevelPlayer; |
| 146 | #endif |
| 147 | |
| 148 | }; |
| 149 | |
| 150 | |
| 151 | // Variables |
| 152 | |
| 153 | EXTERN Player* players; |
| 154 | EXTERN Player* localPlayer; |
| 155 | EXTERN int nPlayers; |
| 156 | |
| 157 | #endif |
| 158 |