/* * $Id: objects_c.cc,v 1.5 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 "objects_c.h" #include "level.h" #include "debug.h" #include "font.h" using namespace std; using namespace JFK::client; object::object(level *lvl) { lv = lvl; image = NULL; } void object::draw() { if (!image) return; image->update(dx, dy, 0); int ix = (int) floor(x - lv->get_posx()); int iy = (int) floor(y - lv->get_posy()); image->draw_centered(ix, iy); } weapon::weapon(level *lvl, int type) : JFK::client::object(lvl), JFK::weapon(type) { image = lv->get_image(JFK::OBJECT_WEAPON, type); LOG(("New object: %s", classname().c_str())); } weapon::weapon(level *lvl, const string data) : JFK::client::object(lvl), JFK::weapon(-1) { fromstring(data); image = lv->get_image(JFK::OBJECT_WEAPON, type); LOG(("New object: %s", classname().c_str())); } person::person(level *lvl, const string data) : JFK::client::object(lvl), JFK::person("uninitialized") { fromstring(data); image = lv->get_image(JFK::OBJECT_PERSON, 0); LOG(("New object: %s", classname().c_str())); } void person::draw() { int ix = (int) floor(x - lv->get_posx()); int iy = (int) floor(y - lv->get_posy()); object::draw(); lv->get_font()->draw_text(ix - (lv->get_font()->get_textwidth(name) / 2), iy - 40, name); } obstacle::obstacle(level *lvl, int type) : JFK::client::object(lvl), JFK::obstacle(type) { image = lv->get_image(JFK::OBJECT_OBSTACLE, type); LOG(("New object: %s", classname().c_str())); } obstacle::obstacle(level *lvl, const string data) : JFK::client::object(lvl), JFK::obstacle(-1) { fromstring(data); if (type != OBS_BOUNDINGBOX) image = lv->get_image(JFK::OBJECT_OBSTACLE, type); else image = NULL; LOG(("New object: %s", classname().c_str())); } item::item(level *lvl, int type) : JFK::client::object(lvl), JFK::item(type) { image = lv->get_image(JFK::OBJECT_ITEM, type); LOG(("New object: %s", classname().c_str())); } item::item(level *lvl, const string data) : JFK::client::object(lvl), JFK::item(-1) { fromstring(data); image = lv->get_image(JFK::OBJECT_ITEM, type); if (type == GRAVE) { double r = -PI + (PI * 2 * rand() / (RAND_MAX+1.0)); dx = cos(r); dy = sin(r); } LOG(("New object: %s", classname().c_str())); } explosion::explosion(level *lvl) : JFK::client::object(lvl) { image = lv->get_image(JFK::OBJECT_EXPLOSION, 0); LOG(("New object: %s", classname().c_str())); } explosion::explosion(level *lvl, const string data) : JFK::client::object(lvl) { fromstring(data); image = lv->get_image(JFK::OBJECT_EXPLOSION, 0); LOG(("New object: %s", classname().c_str())); } bullet::bullet(level *lvl, int type) : JFK::client::object(lvl), JFK::bullet(type) { image = lv->get_image(JFK::OBJECT_BULLET, type); LOG(("New object: %s", classname().c_str())); } bullet::bullet(level *lvl, const string data) : JFK::client::object(lvl), JFK::bullet(-1) { fromstring(data); image = lv->get_image(JFK::OBJECT_BULLET, 0); LOG(("New object: %s", classname().c_str())); }