1
/***************************************************************************
2
* Copyright (C) 2004 by Bjorn Hansen *
3
* holomorph@users.sourceforge.net *
5
* This program is free software; you can redistribute it and/or modify *
6
* it under the terms of the GNU General Public License as published by *
7
* the Free Software Foundation; either version 2 of the License, or *
8
* (at your option) any later version. *
10
* This program is distributed in the hope that it will be useful, *
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13
* GNU General Public License for more details. *
15
* You should have received a copy of the GNU General Public License *
16
* along with this program; if not, write to the *
17
* Free Software Foundation, Inc., *
18
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19
***************************************************************************/
22
#include <SDL/SDL_image.h>
23
#include <SDL/SDL_gfxPrimitives.h>
24
#include "../include/player.h"
25
#include "../include/probe.h"
26
#include "../include/input.h"
27
#include "../include/gamemanager.h"
28
#include "SFont/Font.h"
31
using namespace Balder;
33
Font* Player::scoreFont = 0;
34
Font* Player::lifeFont = 0;
35
SDL_Surface* Player::scoreFontImage = 0;
36
SDL_Surface* Player::lifeFontImage = 0;
37
unsigned int Player::numPlayers = 0;
38
std::stringstream Player::stringConverter;
40
Player::Player(player_id id, GameManager* gm): game_manager(gm), id(id), probe(0), score(0)
43
scoreFontImage = IMG_Load("SFont/scorefont.png");
44
scoreFont = new Font(scoreFontImage);
47
lifeFontImage = IMG_Load("SFont/lifefont.png");
48
lifeFont = new Font(lifeFontImage);
59
scoreFont = lifeFont = 0;
60
SDL_FreeSurface(scoreFontImage);
61
SDL_FreeSurface(lifeFontImage);
64
void Player::DoControl ( input_states states )
66
if (!probe) throw "player has no probe!";
67
probe->RotateLeft(states & LEFT);
68
probe->RotateRight(states & RIGHT);
69
probe->Stick(states & STICK);
70
if (states & PUSH) {probe->PushOff();}
71
if (states & FIRE) {probe->Fire();}
74
void Player::SetProbe ( Probe* p )
79
const void Player::DrawStats(SDL_Surface *s)
81
Uint32 velocity = SDL_MapRGBA(s->format, 0xff, 0x88, 0x88, 0xff);
82
Uint32 scoreBG = SDL_MapRGBA(s->format, 0, 0, 0, 0xff);
83
Uint32 probeColor = probe->GetProbeColor();
84
SDL_Rect r = {0,0,9,9};
85
SDL_FillRect(s, 0, scoreBG);
86
rectangleColor(s, 2, 2, s->w-2, s->h-2, probeColor);
87
double speed = probe->GetPushOffSpeed();
88
if (speed > probe->GetMAXSPEED()) speed = probe->GetMAXSPEED();
91
for(double i = 0; i < speed; i += probe->GetMAXSPEED() / 8)
94
SDL_FillRect(s, &r, velocity);
96
stringConverter.str("");
97
stringConverter << score;
98
// align the bottom of the font is 10 pixels above the bottom of the box
99
int y = s->h - (scoreFont->getHeight() + 10);
100
// and 10 pixelsfrom the right
101
int x = s->w - (scoreFont->getTextWidth(stringConverter.str())+10);
102
scoreFont->write(s, stringConverter.str(), 50, y );
103
// check to see if limited lives should show.
104
if (game_manager->getMaxLives() >= 0) {
105
// clear the string again to write the lives remaining
106
stringConverter.str("");
107
stringConverter << game_manager->getMaxLives() - probe->GetDeaths();
108
// align the bottom of the font is 10 pixels above the top of the score
109
y = s->h - (scoreFont->getHeight() + lifeFont->getHeight() + 10);
110
// and 10 pixelsfrom the right
111
x = s->w - (lifeFont->getTextWidth(stringConverter.str())+10);
112
lifeFont->write(s, stringConverter.str(), 50, y);