/* * $Id: panel.cc,v 1.2 2002/09/18 21:46:22 stefan Exp $ * Copyright (c) 2002, Dominik Schnitzer * * JFK - JFK Fucking Killerz, a massive multiplayer 2d shoot'em-up game * http://relax.ath.cx/jfk/ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Library General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include #include #include #include "objects_c.h" #include "output.h" #include "panel.h" #include "debug.h" using namespace std; using namespace JFK::client; panel::panel(output* outp) { out = outp; player = new sprite(out, "bar", "player_@.png"); number = new sprite(out, "bar", "number_@.png"); weapons = new sprite(out, "bar", "weapon_@.png"); arrow = new sprite(out, "bar", "arrow.png"); bar = new sprite(out, "bar", "bar.png"); last_health = -1; last_ammo = -1; last_weapon = -1; last_weaponcount = -1; } panel::~panel() { delete player; delete number; delete weapons; delete arrow; delete bar; } void panel::draw(person *pers) { bool modified = false; /* TODO: throw exception on NULL player */ if (!pers) return; /* Check if the panel has to be redrawn. */ if ((pers->health != last_health) || (pers->ammo[0] != last_ammo) || (pers->curweapon != last_weapon)) { last_health = pers->health; last_ammo = pers->ammo[0]; last_weapon = pers->curweapon; modified = true; } int weaponcount = 0; for (int i = 0; i < MAX_WEAPON; i++) if (pers->hasweapon[i]) weaponcount++; if (weaponcount != last_weaponcount) { last_weaponcount = weaponcount; modified = true; } if (!modified) return; LOG(("Updating panel...")); /* TODO: dont hardcode things */ bar->draw(0, 600 - 96); draw_number(176, 600 - 96 + 18, pers->health); /* TODO: fix this, this should be ammo[currentweapon] */ draw_number(19, 600 - 96 + 18, pers->ammo[0]); int face = 4 - 4 * pers->health / MAX_HEALTH; player->set(face, 0, 0); player->draw(355, 600 - 96 + 17); for (int i = 0; i < 6; i++) { if (pers->hasweapon[i]) { weapons->set(i, 0, 0); weapons->draw(COORD_PANEL_WEAPONS[i][0], COORD_PANEL_WEAPONS[i][1]); } if ( pers->curweapon == i) { arrow->draw(COORD_PANEL_WEAPONS[i][0], COORD_PANEL_WEAPONS[i][1] + 5); } } } void panel::draw_number(int x, int y, int nr) { int xcoord = x; unsigned short current; stringstream num; num << nr; for (unsigned short i = 0; i < num.str().length(); i++) { /* Get the number to draw by using the ASCII code */ current = num.str().c_str()[i] - '0'; number->set(current, 0, 0); number->draw(xcoord, y); xcoord += out->get_image_width(number->get_current()) + 4; } }