Commit 9a3017d7 authored by alistert's avatar alistert

Further separation of the Player classes.

parent e8d61c9a
...@@ -37,7 +37,6 @@ ...@@ -37,7 +37,6 @@
#include "io/gfx/video.h" #include "io/gfx/video.h"
#include "io/sound.h" #include "io/sound.h"
#include "menu/menu.h" #include "menu/menu.h"
#include "player/player.h"
#include "player/bonusplayer.h" #include "player/bonusplayer.h"
#include "loop.h" #include "loop.h"
#include "util.h" #include "util.h"
...@@ -271,17 +270,6 @@ Bonus::Bonus (char * fileName, unsigned char diff) { ...@@ -271,17 +270,6 @@ Bonus::Bonus (char * fileName, unsigned char diff) {
delete[] buffer; delete[] buffer;
// Generate player's animation set references
string = new char[PANIMS];
for (count = 0; count < PANIMS; count++) string[count] = count & 31;
for (count = 0; count < nPlayers; count++) players[count].getBonusPlayer()->setAnims(string);
delete[] string;
// Load tiles // Load tiles
file->seek(2694, true); file->seek(2694, true);
...@@ -336,22 +324,29 @@ Bonus::Bonus (char * fileName, unsigned char diff) { ...@@ -336,22 +324,29 @@ Bonus::Bonus (char * fileName, unsigned char diff) {
x = file->loadShort(); x = file->loadShort();
y = file->loadShort(); y = file->loadShort();
if (game) game->setCheckpoint(x, y); // Generate player's animation set references
string = new char[PANIMS];
for (count = 0; count < PANIMS; count++) string[count] = count & 31;
// Set the players' initial values // Set the players' initial values
if (game) { if (game) {
for (x = 0; x < nPlayers; x++) game->setCheckpoint(x, y);
game->resetPlayer(players + x, true);
for (count = 0; count < nPlayers; count++) game->resetPlayer(players + count, true, string);
} else { } else {
localPlayer->reset(); localPlayer->reset(true, string, x, y);
localPlayer->getBonusPlayer()->setPosition(TTOF(x), TTOF(y));
} }
delete[] string;
delete file; delete file;
......
...@@ -398,7 +398,7 @@ int ClientGame::step (unsigned int ticks) { ...@@ -398,7 +398,7 @@ int ClientGame::step (unsigned int ticks) {
players[count].init((char *)recvBuffer + 9, players[count].init((char *)recvBuffer + 9,
recvBuffer + 5, recvBuffer[4]); recvBuffer + 5, recvBuffer[4]);
resetPlayer(players + count, false); resetPlayer(players + count, false, NULL);
printf("Player %d joined team %d.\n", count, recvBuffer[4]); printf("Player %d joined team %d.\n", count, recvBuffer[4]);
......
...@@ -284,15 +284,20 @@ void Game::setCheckpoint (unsigned char gridX, unsigned char gridY) { ...@@ -284,15 +284,20 @@ void Game::setCheckpoint (unsigned char gridX, unsigned char gridY) {
} }
void Game::resetPlayer (Player *player, bool bonus) { void Game::resetPlayer (LevelPlayer *player) {
player->reset(); player->reset(checkX, checkY);
return;
}
void Game::resetPlayer (Player *player, bool bonus, char* anims) {
player->reset(bonus, anims, checkX, checkY);
if (bonus) player->getBonusPlayer()->setPosition(TTOF(checkX), TTOF(checkY));
else player->getLevelPlayer()->setPosition(TTOF(checkX), TTOF(checkY));
return; return;
} }
...@@ -76,7 +76,7 @@ ...@@ -76,7 +76,7 @@
#define BUFFER_LENGTH 255 /* Should always be big enough to hold any message */ #define BUFFER_LENGTH 255 /* Should always be big enough to hold any message */
// Classes // Classes
class File; class File;
...@@ -103,7 +103,8 @@ class Game { ...@@ -103,7 +103,8 @@ class Game {
virtual int step (unsigned int ticks); virtual int step (unsigned int ticks);
virtual void score (unsigned char team); virtual void score (unsigned char team);
virtual void setCheckpoint (unsigned char gridX, unsigned char gridY); virtual void setCheckpoint (unsigned char gridX, unsigned char gridY);
void resetPlayer (Player *player, bool bonus); void resetPlayer (LevelPlayer *player);
void resetPlayer (Player *player, bool bonus, char* anims);
}; };
......
...@@ -25,27 +25,26 @@ ...@@ -25,27 +25,26 @@
#include "io/gfx/font.h" #include "io/gfx/font.h"
#include "level/level.h" #include "level/level.h"
#include "player/player.h" #include "player/levelplayer.h"
bool GameMode::hit (Player *source, Player *victim) { bool GameMode::hit (LevelPlayer *source, LevelPlayer *victim) {
return true; return true;
} }
bool GameMode::kill (Player *source, Player *victim) { bool GameMode::kill (LevelPlayer *source, LevelPlayer *victim) {
if (source && (victim == localPlayer)) game->score(source->getTeam()); if (source && (victim->player == localPlayer)) game->score(source->player->getTeam());
return true; return true;
} }
bool GameMode::endOfLevel (Player *player, unsigned char gridX, bool GameMode::endOfLevel (LevelPlayer *player, unsigned char gridX, unsigned char gridY) {
unsigned char gridY) {
game->setCheckpoint(gridX, gridY); game->setCheckpoint(gridX, gridY);
...@@ -154,8 +153,7 @@ GameModeType CoopGameMode::getMode () { ...@@ -154,8 +153,7 @@ GameModeType CoopGameMode::getMode () {
} }
bool CoopGameMode::endOfLevel (Player *player, unsigned char gridX, bool CoopGameMode::endOfLevel (LevelPlayer *player, unsigned char gridX, unsigned char gridY) {
unsigned char gridY) {
game->setCheckpoint(gridX, gridY); game->setCheckpoint(gridX, gridY);
...@@ -187,19 +185,18 @@ GameModeType RaceGameMode::getMode () { ...@@ -187,19 +185,18 @@ GameModeType RaceGameMode::getMode () {
} }
bool RaceGameMode::hit (Player *source, Player *victim) { bool RaceGameMode::hit (LevelPlayer *source, LevelPlayer *victim) {
return false; return false;
} }
bool RaceGameMode::endOfLevel (Player *player, unsigned char gridX, bool RaceGameMode::endOfLevel (LevelPlayer *player, unsigned char gridX, unsigned char gridY) {
unsigned char gridY) {
if (player == localPlayer) game->score(player->getTeam()); if (player->player == localPlayer) game->score(localPlayer->getTeam());
game->resetPlayer(player, false); game->resetPlayer(player);
return false; return false;
......
...@@ -44,7 +44,7 @@ enum GameModeType { ...@@ -44,7 +44,7 @@ enum GameModeType {
// Classes // Classes
class Font; class Font;
class Player; class LevelPlayer;
class GameMode { class GameMode {
...@@ -52,9 +52,9 @@ class GameMode { ...@@ -52,9 +52,9 @@ class GameMode {
virtual GameModeType getMode () = 0; virtual GameModeType getMode () = 0;
virtual unsigned char chooseTeam () = 0; virtual unsigned char chooseTeam () = 0;
virtual void drawScore (Font* font) = 0; virtual void drawScore (Font* font) = 0;
virtual bool hit (Player *source, Player *victim); virtual bool hit (LevelPlayer *source, LevelPlayer *victim);
virtual bool kill (Player *source, Player *victim); virtual bool kill (LevelPlayer *source, LevelPlayer *victim);
virtual bool endOfLevel (Player *player, unsigned char gridX, unsigned char gridY); virtual bool endOfLevel (LevelPlayer *player, unsigned char gridX, unsigned char gridY);
virtual void outOfTime (); virtual void outOfTime ();
}; };
...@@ -87,7 +87,7 @@ class CoopGameMode : public CooperativeGameMode { ...@@ -87,7 +87,7 @@ class CoopGameMode : public CooperativeGameMode {
public: public:
GameModeType getMode (); GameModeType getMode ();
bool endOfLevel (Player *player, unsigned char gridX, unsigned char gridY); bool endOfLevel (LevelPlayer *player, unsigned char gridX, unsigned char gridY);
}; };
...@@ -118,8 +118,8 @@ class RaceGameMode : public FreeForAllGameMode { ...@@ -118,8 +118,8 @@ class RaceGameMode : public FreeForAllGameMode {
public: public:
GameModeType getMode (); GameModeType getMode ();
bool hit (Player *source, Player *victim); bool hit (LevelPlayer *source, LevelPlayer *victim);
bool endOfLevel (Player *player, unsigned char gridX, unsigned char gridY); bool endOfLevel (LevelPlayer *player, unsigned char gridX, unsigned char gridY);
}; };
......
...@@ -255,10 +255,9 @@ int ServerGame::step (unsigned int ticks) { ...@@ -255,10 +255,9 @@ int ServerGame::step (unsigned int ticks) {
recvBuffers[count][4] = gameMode->chooseTeam(); recvBuffers[count][4] = gameMode->chooseTeam();
players[nPlayers].init((char *)(recvBuffers[count]) players[nPlayers].init((char *)(recvBuffers[count]) + 9,
+ 9, recvBuffers[count] + 5, recvBuffers[count] + 5, recvBuffers[count][4]);
recvBuffers[count][4]); resetPlayer(players + nPlayers, false, NULL);
players[nPlayers].reset();
printf("Player %d joined team %d.\n", nPlayers, recvBuffers[count][4]); printf("Player %d joined team %d.\n", nPlayers, recvBuffers[count][4]);
...@@ -297,12 +296,15 @@ int ServerGame::step (unsigned int ticks) { ...@@ -297,12 +296,15 @@ int ServerGame::step (unsigned int ticks) {
break; break;
case MC_PLAYER: case MC_PLAYER:
// Assign player byte based on sender if (clientPlayer[count] != -1) {
recvBuffers[count][2] = clientPlayer[count];
// Assign player byte based on sender
players[clientPlayer[count]]. recvBuffers[count][2] = clientPlayer[count];
receive(recvBuffers[count]);
players[clientPlayer[count]].receive(recvBuffers[count]);
}
break; break;
......
...@@ -32,14 +32,14 @@ ...@@ -32,14 +32,14 @@
#include "player/levelplayer.h" #include "player/levelplayer.h"
Bullet::Bullet (Player* sourcePlayer, bool lower, unsigned int ticks) { Bullet::Bullet (LevelPlayer* sourcePlayer, bool lower, unsigned int ticks) {
Anim* anim; Anim* anim;
// Properties based on the player // Properties based on the player
source = sourcePlayer; source = sourcePlayer;
type = source->getAmmo(false) + 1; type = source->player->getAmmo(false) + 1;
if (!lower && (level->getBullet(type)[B_XSPEED | 2] != 0)) { if (!lower && (level->getBullet(type)[B_XSPEED | 2] != 0)) {
...@@ -52,7 +52,7 @@ Bullet::Bullet (Player* sourcePlayer, bool lower, unsigned int ticks) { ...@@ -52,7 +52,7 @@ Bullet::Bullet (Player* sourcePlayer, bool lower, unsigned int ticks) {
} }
direction = source->getLevelPlayer()->getFacing()? 1: 0; direction = source->getFacing()? 1: 0;
direction |= lower? 2: 0; direction |= lower? 2: 0;
if (type == 4) { if (type == 4) {
...@@ -79,9 +79,9 @@ Bullet::Bullet (Player* sourcePlayer, bool lower, unsigned int ticks) { ...@@ -79,9 +79,9 @@ Bullet::Bullet (Player* sourcePlayer, bool lower, unsigned int ticks) {
} }
anim = level->getAnim(source->getLevelPlayer()->getAnim()); anim = level->getAnim(source->getAnim());
x = source->getLevelPlayer()->getX() + anim->getShootX() + PXO_MID - F4; x = source->getX() + anim->getShootX() + PXO_MID - F4;
y = source->getLevelPlayer()->getY() + anim->getShootY() - F4; y = source->getY() + anim->getShootY() - F4;
return; return;
...@@ -132,10 +132,10 @@ Bullet::Bullet (Bird* sourceBird, bool lower, unsigned int ticks) { ...@@ -132,10 +132,10 @@ Bullet::Bullet (Bird* sourceBird, bool lower, unsigned int ticks) {
} }
type = 30; type = 30;
direction = source->getLevelPlayer()->getFacing()? 1: 0; direction = source->getFacing()? 1: 0;
direction |= lower? 2: 0; direction |= lower? 2: 0;
sprite = level->getSprite(((unsigned char *)level->getBullet(type))[B_SPRITE + direction]); sprite = level->getSprite(((unsigned char *)level->getBullet(type))[B_SPRITE + direction]);
x = sourceBird->getX() + (source->getLevelPlayer()->getFacing()? PXO_R: PXO_L); x = sourceBird->getX() + (source->getFacing()? PXO_R: PXO_L);
y = sourceBird->getY(); y = sourceBird->getY();
dx = level->getBullet(type)[B_XSPEED + direction] * 500 * F1; dx = level->getBullet(type)[B_XSPEED + direction] * 500 * F1;
dy = level->getBullet(type)[B_YSPEED + direction] * 250 * F1; dy = level->getBullet(type)[B_YSPEED + direction] * 250 * F1;
...@@ -170,7 +170,7 @@ Bullet* Bullet::remove () { ...@@ -170,7 +170,7 @@ Bullet* Bullet::remove () {
} }
Player* Bullet::getSource () { LevelPlayer* Bullet::getSource () {
return source; return source;
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include "movable.h" #include "movable.h"
#include "OpenJazz.h" #include "OpenJazz.h"
...@@ -50,14 +51,14 @@ ...@@ -50,14 +51,14 @@
class Bird; class Bird;
class Event; class Event;
class Player; class LevelPlayer;
class Sprite; class Sprite;
class Bullet : public Movable { class Bullet : public Movable {
private: private:
Bullet* next; Bullet* next;
Player* source; // If NULL, was fired by an event LevelPlayer* source; // If NULL, was fired by an event
Sprite* sprite; Sprite* sprite;
int type; // -1 is TNT, otherwise indexes the bullet set int type; // -1 is TNT, otherwise indexes the bullet set
int direction; // 0: Left, 1: Right, 2: L (lower), 3: R (lower) int direction; // 0: Left, 1: Right, 2: L (lower), 3: R (lower)
...@@ -66,14 +67,14 @@ class Bullet : public Movable { ...@@ -66,14 +67,14 @@ class Bullet : public Movable {
Bullet* remove (); Bullet* remove ();
public: public:
Bullet (Player* sourcePlayer, bool lower, unsigned int ticks); Bullet (LevelPlayer* sourcePlayer, bool lower, unsigned int ticks);
Bullet (Event* sourceEvent, bool facing, unsigned int ticks); Bullet (Event* sourceEvent, bool facing, unsigned int ticks);
Bullet (Bird* sourceBird, bool lower, unsigned int ticks); Bullet (Bird* sourceBird, bool lower, unsigned int ticks);
~Bullet (); ~Bullet ();
Player* getSource (); LevelPlayer* getSource ();
Bullet* step (unsigned int ticks, int msps); Bullet* step (unsigned int ticks, int msps);
void draw (int change); void draw (int change);
}; };
......
...@@ -157,7 +157,7 @@ void Event::destroy (unsigned int ticks) { ...@@ -157,7 +157,7 @@ void Event::destroy (unsigned int ticks) {
} }
bool Event::hit (Player *source, unsigned int ticks) { bool Event::hit (LevelPlayer *source, unsigned int ticks) {
int hitsRemaining; int hitsRemaining;
......
...@@ -77,7 +77,7 @@ ...@@ -77,7 +77,7 @@
// Classes // Classes
class Player; class LevelPlayer;
class Event : public Movable { class Event : public Movable {
...@@ -109,7 +109,7 @@ class Event : public Movable { ...@@ -109,7 +109,7 @@ class Event : public Movable {
virtual ~Event (); virtual ~Event ();
Event* getNext (); Event* getNext ();
bool hit (Player *source, unsigned int ticks); bool hit (LevelPlayer *source, unsigned int ticks);
bool isEnemy (); bool isEnemy ();
bool isFrom (unsigned char gX, unsigned char gY); bool isFrom (unsigned char gX, unsigned char gY);
virtual bool overlap (fixed left, fixed top, fixed width, fixed height); virtual bool overlap (fixed left, fixed top, fixed width, fixed height);
......
...@@ -265,7 +265,7 @@ void Level::clearEvent (unsigned char gridX, unsigned char gridY) { ...@@ -265,7 +265,7 @@ void Level::clearEvent (unsigned char gridX, unsigned char gridY) {
} }
int Level::hitEvent (unsigned char gridX, unsigned char gridY, Player* source) { int Level::hitEvent (unsigned char gridX, unsigned char gridY, LevelPlayer* source) {
GridElement* ge; GridElement* ge;
unsigned char buffer[MTL_L_GRID]; unsigned char buffer[MTL_L_GRID];
...@@ -286,7 +286,7 @@ int Level::hitEvent (unsigned char gridX, unsigned char gridY, Player* source) { ...@@ -286,7 +286,7 @@ int Level::hitEvent (unsigned char gridX, unsigned char gridY, Player* source) {
// Notify the player that shot the bullet // Notify the player that shot the bullet
// If this returns false, ignore the hit // If this returns false, ignore the hit
if (!source->getLevelPlayer()->takeEvent(gridX, gridY, ticks)) { if (!source->takeEvent(gridX, gridY, ticks)) {
ge->hits--; ge->hits--;
...@@ -315,8 +315,7 @@ int Level::hitEvent (unsigned char gridX, unsigned char gridY, Player* source) { ...@@ -315,8 +315,7 @@ int Level::hitEvent (unsigned char gridX, unsigned char gridY, Player* source) {
} }
void Level::setEventTime (unsigned char gridX, unsigned char gridY, void Level::setEventTime (unsigned char gridX, unsigned char gridY, unsigned int time) {
unsigned int time) {
grid[gridY][gridX].time = time; grid[gridY][gridX].time = time;
......
...@@ -87,7 +87,7 @@ typedef struct { ...@@ -87,7 +87,7 @@ typedef struct {
class Bullet; class Bullet;
class Event; class Event;
class Font; class Font;
class Player; class LevelPlayer;
class Scene; class Scene;
class Level : public BaseLevel { class Level : public BaseLevel {
...@@ -142,7 +142,7 @@ class Level : public BaseLevel { ...@@ -142,7 +142,7 @@ class Level : public BaseLevel {
unsigned char getEventHits (unsigned char gridX, unsigned char gridY); unsigned char getEventHits (unsigned char gridX, unsigned char gridY);
unsigned int getEventTime (unsigned char gridX, unsigned char gridY); unsigned int getEventTime (unsigned char gridX, unsigned char gridY);
void clearEvent (unsigned char gridX, unsigned char gridY); void clearEvent (unsigned char gridX, unsigned char gridY);
int hitEvent (unsigned char gridX, unsigned char gridY, Player* source); int hitEvent (unsigned char gridX, unsigned char gridY, LevelPlayer* source);
void setEventTime (unsigned char gridX, unsigned char gridY, unsigned int time); void setEventTime (unsigned char gridX, unsigned char gridY, unsigned int time);
signed char* getBullet (unsigned char bullet); signed char* getBullet (unsigned char bullet);
Sprite* getSprite (unsigned char sprite); Sprite* getSprite (unsigned char sprite);
......
...@@ -157,7 +157,7 @@ int Level::step () { ...@@ -157,7 +157,7 @@ int Level::step () {
if (!gameMode) return LOST; if (!gameMode) return LOST;
game->resetPlayer(players + x, false); game->resetPlayer(players[x].getLevelPlayer());
} }
......
...@@ -327,7 +327,8 @@ int Level::load (char *fileName, unsigned char diff, bool checkpoint) { ...@@ -327,7 +327,8 @@ int Level::load (char *fileName, unsigned char diff, bool checkpoint) {
const char *ext; const char *ext;
char *string; char *string;
int tiles; int tiles;
int count, x, y, type; int count, x, y, type;
unsigned char startX, startY;
try { try {
...@@ -743,25 +744,9 @@ int Level::load (char *fileName, unsigned char diff, bool checkpoint) { ...@@ -743,25 +744,9 @@ int Level::load (char *fileName, unsigned char diff, bool checkpoint) {
file->seek(x + 366, true); file->seek(x + 366, true);
// The players' coordinates // The players' initial coordinates
x = file->loadShort(); startX = file->loadShort();
y = file->loadShort() + 1; startY = file->loadShort() + 1;
if (!checkpoint && game) game->setCheckpoint(x, y);
// Set the players' initial values
if (game) {
for (count = 0; count < nPlayers; count++)
game->resetPlayer(players + count, false);
} else {
localPlayer->reset();
localPlayer->getLevelPlayer()->setPosition(TTOF(x), TTOF(y));
}
// Next level // Next level
...@@ -791,8 +776,8 @@ int Level::load (char *fileName, unsigned char diff, bool checkpoint) { ...@@ -791,8 +776,8 @@ int Level::load (char *fileName, unsigned char diff, bool checkpoint) {
for (x = 0; x < PANIMS; x++) string[x + 3] = buffer[x << 1]; for (x = 0; x < PANIMS; x++) string[x + 3] = buffer[x << 1];
for (x = 0; x < nPlayers; x++) players[x].getLevelPlayer()->setAnims(string + 3); delete[] buffer;
if (gameMode) { if (gameMode) {
string[0] = MTL_P_ANIMS; string[0] = MTL_P_ANIMS;
...@@ -802,10 +787,22 @@ int Level::load (char *fileName, unsigned char diff, bool checkpoint) { ...@@ -802,10 +787,22 @@ int Level::load (char *fileName, unsigned char diff, bool checkpoint) {
} }
delete[] string; // Set the players' initial values
delete[] buffer; if (game) {
if (!checkpoint) game->setCheckpoint(startX, startY);
for (count = 0; count < nPlayers; count++) game->resetPlayer(players + count, false, string + 3);
} else {
localPlayer->reset(false, string + 3, startX, startY);
}
delete[] string;
// Load Skip to bullet set // Load Skip to bullet set
miscAnims[0] = file->loadChar(); miscAnims[0] = file->loadChar();
miscAnims[1] = file->loadChar(); miscAnims[1] = file->loadChar();
......
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
#include "level/level.h" #include "level/level.h"
Bird::Bird (Player *rescuer, unsigned char gX, unsigned char gY) { Bird::Bird (LevelPlayer *rescuer, unsigned char gX, unsigned char gY) {
player = rescuer; player = rescuer;
x = TTOF(gX); x = TTOF(gX);
...@@ -51,18 +51,7 @@ Bird::~Bird () { ...@@ -51,18 +51,7 @@ Bird::~Bird () {
} }
void Bird::reset () { LevelPlayer * Bird::getPlayer () {
x = player->getLevelPlayer()->getX();
y = player->getLevelPlayer()->getY() - F64;
fireTime = 0;
return;
}
Player * Bird::getPlayer () {
return player; return player;
...@@ -80,7 +69,6 @@ void Bird::hit () { ...@@ -80,7 +69,6 @@ void Bird::hit () {
bool Bird::step (unsigned int ticks, int msps) { bool Bird::step (unsigned int ticks, int msps) {
LevelPlayer* levelPlayer;
Event* event; Event* event;
bool target; bool target;
...@@ -97,16 +85,14 @@ bool Bird::step (unsigned int ticks, int msps) { ...@@ -97,16 +85,14 @@ bool Bird::step (unsigned int ticks, int msps) {
// Trajectory for flying towards the player // Trajectory for flying towards the player
levelPlayer = player->getLevelPlayer(); if ((x < player->getX() - F160) || (x > player->getX() + F160)) {
if ((x < levelPlayer->getX() - F160) || (x > levelPlayer->getX() + F160)) {
// Far away from the player // Far away from the player
// Approach the player at a speed proportional to the distance // Approach the player at a speed proportional to the distance
dx = levelPlayer->getX() - x; dx = player->getX() - x;
} else if (x < levelPlayer->getX()) { } else if (x < player->getX()) {
// To the left of the player, so move right // To the left of the player, so move right
...@@ -129,14 +115,14 @@ bool Bird::step (unsigned int ticks, int msps) { ...@@ -129,14 +115,14 @@ bool Bird::step (unsigned int ticks, int msps) {
} else { } else {
if ((y < levelPlayer->getY() - F100) || (y > levelPlayer->getY() + F100)) { if ((y < player->getY() - F100) || (y > player->getY() + F100)) {
// Far away from the player // Far away from the player
// Approach the player at a speed proportional to the distance // Approach the player at a speed proportional to the distance
dy = (levelPlayer->getY() - F64) - y; dy = (player->getY() - F64) - y;
} else if (y < levelPlayer->getY() - F64) { } else if (y < player->getY() - F64) {
// Above the player, so move downwards // Above the player, so move downwards
...@@ -161,7 +147,7 @@ bool Bird::step (unsigned int ticks, int msps) { ...@@ -161,7 +147,7 @@ bool Bird::step (unsigned int ticks, int msps) {
target = false; target = false;
event = level->events; event = level->events;
if (levelPlayer->getFacing()) { if (player->getFacing()) {
while (event && !target) { while (event && !target) {
...@@ -209,7 +195,7 @@ void Bird::draw (unsigned int ticks, int change) { ...@@ -209,7 +195,7 @@ void Bird::draw (unsigned int ticks, int change) {
Anim *anim; Anim *anim;
anim = level->getAnim((player->getLevelPlayer()->getFacing() || fleeing)? BIRD_RIGHTANIM: BIRD_LEFTANIM); anim = level->getAnim((player->getFacing() || fleeing)? BIRD_RIGHTANIM: BIRD_LEFTANIM);
anim->setFrame(ticks / 80, true); anim->setFrame(ticks / 80, true);
anim->draw(getDrawX(change), getDrawY(change)); anim->draw(getDrawX(change), getDrawY(change));
......
...@@ -40,24 +40,24 @@ ...@@ -40,24 +40,24 @@
// Classes // Classes
class Player; class LevelPlayer;
class Bird : public Movable { class Bird : public Movable {
private: private:
Player* player; LevelPlayer* player;
bool fleeing; bool fleeing;
unsigned int fireTime; unsigned int fireTime;
public: public:
Bird (Player* player, unsigned char gX, unsigned char gY); Bird (LevelPlayer* player, unsigned char gX, unsigned char gY);
~Bird (); ~Bird ();
void reset (); LevelPlayer* getPlayer ();
Player* getPlayer (); void hit ();
void hit ();
bool step (unsigned int ticks, int msps); bool step (unsigned int ticks, int msps);
void draw (unsigned int ticks, int change); void draw (unsigned int ticks, int change);
}; };
......
...@@ -37,27 +37,25 @@ ...@@ -37,27 +37,25 @@
#include <string.h> #include <string.h>
BonusPlayer::BonusPlayer (Player* parent) { BonusPlayer::BonusPlayer (Player* parent, char *newAnims, unsigned char startX, unsigned char startY) {
player = parent; player = parent;
return; memcpy(anims, newAnims, PANIMS);
}
x = TTOF(startX) + F16;
y = TTOF(startY) + F16;
BonusPlayer::~BonusPlayer () { direction = FQ;
dr = 0;
gems = 0;
return; return;
} }
void BonusPlayer::reset () { BonusPlayer::~BonusPlayer () {
direction = FQ;
dr = 0;
gems = 0;
return; return;
...@@ -101,25 +99,6 @@ fixed BonusPlayer::getY () { ...@@ -101,25 +99,6 @@ fixed BonusPlayer::getY () {
} }
void BonusPlayer::setAnims (char *newAnims) {
memcpy(anims, newAnims, PANIMS);
return;
}
void BonusPlayer::setPosition (fixed newX, fixed newY) {
x = newX + F16;
y = newY + F16;
return;
}
void BonusPlayer::step (unsigned int ticks, int msps, Bonus* bonus) { void BonusPlayer::step (unsigned int ticks, int msps, Bonus* bonus) {
fixed cdx, cdy; fixed cdx, cdy;
......
...@@ -68,18 +68,14 @@ class BonusPlayer { ...@@ -68,18 +68,14 @@ class BonusPlayer {
public: public:
Player* player; Player* player;
BonusPlayer (Player* parent); BonusPlayer (Player* parent, char* newAnims, unsigned char startX, unsigned char startY);
~BonusPlayer (); ~BonusPlayer ();
void reset ();
void addGem (); void addGem ();
fixed getDirection (); fixed getDirection ();
int getGems (); int getGems ();
fixed getX (); fixed getX ();
fixed getY (); fixed getY ();
void setAnims (char* newAnims);
void setPosition (fixed newX, fixed newY);
void step (unsigned int ticks, int msps, Bonus* bonus); void step (unsigned int ticks, int msps, Bonus* bonus);
void draw (unsigned int ticks, Anim* animSet); void draw (unsigned int ticks, Anim* animSet);
......
...@@ -38,10 +38,22 @@ ...@@ -38,10 +38,22 @@
#include <string.h> #include <string.h>
LevelPlayer::LevelPlayer (Player* parent) { LevelPlayer::LevelPlayer (Player* parent, char* newAnims, unsigned char startX, unsigned char startY, bool hasBird) {
player = parent; player = parent;
if (newAnims) memcpy(anims, newAnims, PANIMS);
else memset(anims, 0, PANIMS);
if (hasBird) bird = new Bird(this, startX, startY - 2);
else bird = NULL;
shield = 0;
enemies = items = 0;
gem = false;
reset(startX, startY);
return; return;
} }
...@@ -49,16 +61,17 @@ LevelPlayer::LevelPlayer (Player* parent) { ...@@ -49,16 +61,17 @@ LevelPlayer::LevelPlayer (Player* parent) {
LevelPlayer::~LevelPlayer () { LevelPlayer::~LevelPlayer () {
if (bird) delete bird;
return; return;
} }
void LevelPlayer::reset () { void LevelPlayer::reset (unsigned char startX, unsigned char startY) {
event = 0; event = 0;
energy = 4; energy = 4;
shield = 0;
floating = false; floating = false;
facing = true; facing = true;
reaction = PR_NONE; reaction = PR_NONE;
...@@ -69,8 +82,8 @@ void LevelPlayer::reset () { ...@@ -69,8 +82,8 @@ void LevelPlayer::reset () {
warpTime = 0; warpTime = 0;
dx = 0; dx = 0;
dy = 0; dy = 0;
enemies = items = 0; x = TTOF(startX);
gem = false; y = TTOF(startY);
return; return;
...@@ -132,6 +145,13 @@ int LevelPlayer::getItems () { ...@@ -132,6 +145,13 @@ int LevelPlayer::getItems () {
} }
bool LevelPlayer::hasBird () {
return bird;
}
bool LevelPlayer::hasGem () { bool LevelPlayer::hasGem () {
return gem; return gem;
...@@ -139,22 +159,22 @@ bool LevelPlayer::hasGem () { ...@@ -139,22 +159,22 @@ bool LevelPlayer::hasGem () {
} }
bool LevelPlayer::hit (Player *source, unsigned int ticks) { bool LevelPlayer::hit (LevelPlayer *source, unsigned int ticks) {
// Invulnerable if reacting to e.g. having been hit // Invulnerable if reacting to e.g. having been hit
if (reaction != PR_NONE) return false; if (reaction != PR_NONE) return false;
// Hits from the same team have no effect // Hits from the same team have no effect
if (source && (source->getTeam() == player->team)) return false; if (source && (source->player->getTeam() == player->team)) return false;
if (shield == 3) shield = 0; if (shield == 3) shield = 0;
else if (shield) shield--; else if (shield) shield--;
else if (!gameMode || gameMode->hit(source, player)) { else if (!gameMode || gameMode->hit(source, this)) {
energy--; energy--;
if (player->bird) player->bird->hit(); if (bird) bird->hit();
playSound(S_OW); playSound(S_OW);
...@@ -188,11 +208,11 @@ bool LevelPlayer::hit (Player *source, unsigned int ticks) { ...@@ -188,11 +208,11 @@ bool LevelPlayer::hit (Player *source, unsigned int ticks) {
} }
void LevelPlayer::kill (Player *source, unsigned int ticks) { void LevelPlayer::kill (LevelPlayer *source, unsigned int ticks) {
if (reaction != PR_NONE) return; if (reaction != PR_NONE) return;
if (!gameMode || gameMode->kill(source, player)) { if (!gameMode || gameMode->kill(source, this)) {
energy = 0; energy = 0;
player->lives--; player->lives--;
...@@ -235,15 +255,6 @@ PlayerReaction LevelPlayer::reacted (unsigned int ticks) { ...@@ -235,15 +255,6 @@ PlayerReaction LevelPlayer::reacted (unsigned int ticks) {
} }
void LevelPlayer::setAnims (char *newAnims) {
memcpy(anims, newAnims, PANIMS);
return;
}
void LevelPlayer::setEvent (unsigned char gridX, unsigned char gridY) { void LevelPlayer::setEvent (unsigned char gridX, unsigned char gridY) {
signed char *set; signed char *set;
...@@ -313,7 +324,7 @@ bool LevelPlayer::takeEvent (unsigned char gridX, unsigned char gridY, unsigned ...@@ -313,7 +324,7 @@ bool LevelPlayer::takeEvent (unsigned char gridX, unsigned char gridY, unsigned
level->setStage(LS_END); level->setStage(LS_END);
} else if (!(gameMode->endOfLevel(player, gridX, gridY))) return false; } else if (!(gameMode->endOfLevel(this, gridX, gridY))) return false;
break; break;
...@@ -437,7 +448,7 @@ bool LevelPlayer::takeEvent (unsigned char gridX, unsigned char gridY, unsigned ...@@ -437,7 +448,7 @@ bool LevelPlayer::takeEvent (unsigned char gridX, unsigned char gridY, unsigned
case 34: // Bird case 34: // Bird
if (!player->bird) player->bird = new Bird(player, gridX, gridY); if (!bird) bird = new Bird(this, gridX, gridY);
break; break;
...@@ -585,6 +596,7 @@ void LevelPlayer::send (unsigned char *buffer) { ...@@ -585,6 +596,7 @@ void LevelPlayer::send (unsigned char *buffer) {
// Copy data to be sent to clients/server // Copy data to be sent to clients/server
buffer[9] = bird? 1: 0;
buffer[23] = energy; buffer[23] = energy;
buffer[25] = shield; buffer[25] = shield;
buffer[26] = floating; buffer[26] = floating;
...@@ -619,12 +631,21 @@ void LevelPlayer::receive (unsigned char *buffer) { ...@@ -619,12 +631,21 @@ void LevelPlayer::receive (unsigned char *buffer) {
case MT_P_ANIMS: case MT_P_ANIMS:
setAnims((char *)buffer + 3); memcpy(anims, (char *)buffer + 3, PANIMS);
break; break;
case MT_P_TEMP: case MT_P_TEMP:
if ((buffer[9] & 1) && !bird) bird = new Bird(this, FTOT(x), FTOT(y) - 2);
if (!(buffer[9] & 1) && bird) {
delete bird;
bird = NULL;
}
energy = buffer[23]; energy = buffer[23];
shield = buffer[25]; shield = buffer[25];
floating = buffer[26]; floating = buffer[26];
......
...@@ -128,10 +128,12 @@ enum PlayerReaction { ...@@ -128,10 +128,12 @@ enum PlayerReaction {
// Classes // Classes
class Anim; class Anim;
class Bird;
class LevelPlayer : public Movable { class LevelPlayer : public Movable {
private: private:
Bird* bird;
char anims[PANIMS]; char anims[PANIMS];
int energy; int energy;
int shield; /* 0 = none, 1 = 1 yellow, 2 = 2 yellow, 3 = 1 orange, 4 = 2 orange, 5 = 3 orange, 6 = 4 orange */ int shield; /* 0 = none, 1 = 1 yellow, 2 = 2 yellow, 3 = 1 orange, 4 = 2 orange, 5 = 3 orange, 6 = 4 orange */
...@@ -156,10 +158,10 @@ class LevelPlayer : public Movable { ...@@ -156,10 +158,10 @@ class LevelPlayer : public Movable {
public: public:
Player* player; Player* player;
LevelPlayer (Player* parent); LevelPlayer (Player* parent, char* newAnims, unsigned char startX, unsigned char startY, bool hasBird);
~LevelPlayer (); ~LevelPlayer ();
void reset (); void reset (unsigned char startX, unsigned char startY);
void addItem (); void addItem ();
void clearEvent (unsigned char gridX, unsigned char gridY); void clearEvent (unsigned char gridX, unsigned char gridY);
...@@ -168,12 +170,12 @@ class LevelPlayer : public Movable { ...@@ -168,12 +170,12 @@ class LevelPlayer : public Movable {
int getEnergy (); int getEnergy ();
bool getFacing (); bool getFacing ();
int getItems (); int getItems ();
bool hasBird ();
bool hasGem (); bool hasGem ();
bool hit (Player* source, unsigned int ticks); bool hit (LevelPlayer* source, unsigned int ticks);
void kill (Player* source, unsigned int ticks); void kill (LevelPlayer* source, unsigned int ticks);
bool overlap (fixed left, fixed top, fixed width, fixed height); bool overlap (fixed left, fixed top, fixed width, fixed height);
PlayerReaction reacted (unsigned int ticks); PlayerReaction reacted (unsigned int ticks);
void setAnims (char* newAnims);
void setEvent (unsigned char gridX, unsigned char gridY); void setEvent (unsigned char gridX, unsigned char gridY);
void setPosition (fixed newX, fixed newY); void setPosition (fixed newX, fixed newY);
void setSpeed (fixed newDx, fixed newDy); void setSpeed (fixed newDx, fixed newDy);
......
...@@ -310,7 +310,7 @@ void LevelPlayer::control (unsigned int ticks, int msps) { ...@@ -310,7 +310,7 @@ void LevelPlayer::control (unsigned int ticks, int msps) {
if (platform) animType = facing? PA_RSHOOT: PA_LSHOOT; if (platform) animType = facing? PA_RSHOOT: PA_LSHOOT;
// Create new bullet // Create new bullet
level->bullets = new Bullet(player, false, ticks); level->bullets = new Bullet(this, false, ticks);
// Set when the next bullet can be fired // Set when the next bullet can be fired
if (player->fireSpeed) fireTime = ticks + (1000 / player->fireSpeed); if (player->fireSpeed) fireTime = ticks + (1000 / player->fireSpeed);
...@@ -344,12 +344,12 @@ void LevelPlayer::control (unsigned int ticks, int msps) { ...@@ -344,12 +344,12 @@ void LevelPlayer::control (unsigned int ticks, int msps) {
// Deal with the bird // Deal with the bird
if (player->bird) { if (bird) {
if (player->bird->step(ticks, msps)) { if (bird->step(ticks, msps)) {
delete player->bird; delete bird;
player->bird = NULL; bird = NULL;
} }
...@@ -790,14 +790,14 @@ void LevelPlayer::draw (unsigned int ticks, int change) { ...@@ -790,14 +790,14 @@ void LevelPlayer::draw (unsigned int ticks, int change) {
// Show the bird // Show the bird
if (player->bird) player->bird->draw(ticks, change); if (bird) bird->draw(ticks, change);
// Show the player's name // Show the player's name
if (gameMode) if (gameMode)
panelBigFont->showString(player->name, panelBigFont->showString(player->name,
FTOI(drawX + PXO_MID - viewX) - (panelBigFont->getStringWidth(player->name) >> 1), FTOI(drawX + PXO_MID) - (panelBigFont->getStringWidth(player->name) >> 1),
FTOI(drawY - F32 - F16 - viewY)); FTOI(drawY - F32 - F16));
return; return;
......
...@@ -46,13 +46,11 @@ ...@@ -46,13 +46,11 @@
Player::Player () { Player::Player () {
levelPlayer = new LevelPlayer(this); levelPlayer = NULL;
bonusPlayer = new BonusPlayer(this); bonusPlayer = NULL;
bird = NULL;
name = NULL; name = NULL;
return; return;
} }
...@@ -61,9 +59,6 @@ Player::Player () { ...@@ -61,9 +59,6 @@ Player::Player () {
Player::~Player () { Player::~Player () {
deinit(); deinit();
delete levelPlayer;
delete bonusPlayer;
return; return;
...@@ -92,6 +87,7 @@ void Player::init (char *playerName, unsigned char *playerCols, unsigned char ne ...@@ -92,6 +87,7 @@ void Player::init (char *playerName, unsigned char *playerCols, unsigned char ne
ammo[2] = 0; ammo[2] = 0;
ammo[3] = 0; ammo[3] = 0;
fireSpeed = 0; fireSpeed = 0;
bird = false;
team = newTeam; team = newTeam;
teamScore = 0; teamScore = 0;
...@@ -167,10 +163,12 @@ void Player::init (char *playerName, unsigned char *playerCols, unsigned char ne ...@@ -167,10 +163,12 @@ void Player::init (char *playerName, unsigned char *playerCols, unsigned char ne
void Player::deinit () { void Player::deinit () {
if (bird) delete bird; if (levelPlayer) delete levelPlayer;
bird = NULL; if (bonusPlayer) delete bonusPlayer;
levelPlayer = NULL;
bonusPlayer = NULL;
if (name) delete[] name; if (name) delete[] name;
name = NULL; name = NULL;
...@@ -179,14 +177,30 @@ void Player::deinit () { ...@@ -179,14 +177,30 @@ void Player::deinit () {
} }
void Player::reset () { void Player::reset (bool bonus, char* newAnims, unsigned char x, unsigned char y) {
int count; int count;
levelPlayer->reset(); if (levelPlayer) {
bonusPlayer->reset();
bird = levelPlayer->hasBird();
delete levelPlayer;
}
if (bird) bird->reset(); if (bonusPlayer) delete bonusPlayer;
if (bonus) {
levelPlayer = NULL;
bonusPlayer = new BonusPlayer(this, newAnims, x, y);
} else {
levelPlayer = new LevelPlayer(this, newAnims, x, y, bird);
bonusPlayer = NULL;
}
for (count = 0; count < PCONTROLS; count++) pcontrols[count] = false; for (count = 0; count < PCONTROLS; count++) pcontrols[count] = false;
...@@ -304,7 +318,7 @@ void Player::send (unsigned char *buffer) { ...@@ -304,7 +318,7 @@ void Player::send (unsigned char *buffer) {
buffer[6] = pcontrols[C_RIGHT]; buffer[6] = pcontrols[C_RIGHT];
buffer[7] = pcontrols[C_JUMP]; buffer[7] = pcontrols[C_JUMP];
buffer[8] = pcontrols[C_FIRE]; buffer[8] = pcontrols[C_FIRE];
buffer[9] = bird? 1: 0; if (!levelPlayer) buffer[9] = bird? 1: 0;
buffer[10] = ammo[0] >> 8; buffer[10] = ammo[0] >> 8;
buffer[11] = ammo[0] & 255; buffer[11] = ammo[0] & 255;
buffer[12] = ammo[1] >> 8; buffer[12] = ammo[1] >> 8;
...@@ -322,7 +336,7 @@ void Player::send (unsigned char *buffer) { ...@@ -322,7 +336,7 @@ void Player::send (unsigned char *buffer) {
buffer[28] = fireSpeed; buffer[28] = fireSpeed;
buffer[45] = pcontrols[C_SWIM]; buffer[45] = pcontrols[C_SWIM];
levelPlayer->send(buffer); if (levelPlayer) levelPlayer->send(buffer);
return; return;
...@@ -343,17 +357,7 @@ void Player::receive (unsigned char *buffer) { ...@@ -343,17 +357,7 @@ void Player::receive (unsigned char *buffer) {
pcontrols[C_SWIM] = buffer[45]; pcontrols[C_SWIM] = buffer[45];
pcontrols[C_FIRE] = buffer[8]; pcontrols[C_FIRE] = buffer[8];
pcontrols[C_CHANGE] = false; pcontrols[C_CHANGE] = false;
if (!levelPlayer) bird = buffer[9] & 1;
if ((buffer[9] & 1) && !bird)
bird = new Bird(this, FTOT(levelPlayer->getX()), FTOT(levelPlayer->getY()));
if (!(buffer[9] & 1) && bird) {
delete bird;
bird = NULL;
}
ammo[0] = (buffer[10] << 8) + buffer[11]; ammo[0] = (buffer[10] << 8) + buffer[11];
ammo[1] = (buffer[12] << 8) + buffer[13]; ammo[1] = (buffer[12] << 8) + buffer[13];
ammo[2] = (buffer[14] << 8) + buffer[15]; ammo[2] = (buffer[14] << 8) + buffer[15];
...@@ -365,7 +369,7 @@ void Player::receive (unsigned char *buffer) { ...@@ -365,7 +369,7 @@ void Player::receive (unsigned char *buffer) {
} }
levelPlayer->receive(buffer); if (levelPlayer) levelPlayer->receive(buffer);
return; return;
......
...@@ -60,13 +60,12 @@ ...@@ -60,13 +60,12 @@
#define CHAR_WBAND PC_ORANGE #define CHAR_WBAND PC_ORANGE
// General // General
#define PANIMS 38 /* Number of player animations. Is probably higher. */ #define PANIMS 38 /* Number of player animations. Is probably higher. */
#define PCONTROLS 8 /* Number of player controls. */ #define PCONTROLS 8 /* Number of player controls. */
// Classes // Classes
class Bird;
class BonusPlayer; class BonusPlayer;
class LevelPlayer; class LevelPlayer;
...@@ -75,7 +74,6 @@ class Player { ...@@ -75,7 +74,6 @@ class Player {
private: private:
LevelPlayer* levelPlayer; LevelPlayer* levelPlayer;
BonusPlayer* bonusPlayer; BonusPlayer* bonusPlayer;
Bird* bird;
char* name; char* name;
bool pcontrols[PCONTROLS]; bool pcontrols[PCONTROLS];
SDL_Color palette[256]; SDL_Color palette[256];
...@@ -84,7 +82,8 @@ class Player { ...@@ -84,7 +82,8 @@ class Player {
int ammoType; /* -1 = blaster, 0 = toaster, 1 = missiles, 2 = bouncer 3 = TNT */ int ammoType; /* -1 = blaster, 0 = toaster, 1 = missiles, 2 = bouncer 3 = TNT */
int score; int score;
int lives; int lives;
int fireSpeed; int fireSpeed;
bool bird;
unsigned char team; unsigned char team;
void addAmmo (int type, int amount); void addAmmo (int type, int amount);
...@@ -97,7 +96,7 @@ class Player { ...@@ -97,7 +96,7 @@ class Player {
void init (char* playerName, unsigned char* cols, unsigned char newTeam); void init (char* playerName, unsigned char* cols, unsigned char newTeam);
void deinit (); void deinit ();
void reset (); void reset (bool bonus, char* newAnims, unsigned char x, unsigned char y);
void addLife (); void addLife ();
void addScore (int addedScore); void addScore (int addedScore);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment