/* orxonox - the future of 3D-vertical-scrollers Copyright (C) 2004 orx 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, or (at your option) any later version. ### File Specific: main-programmer: Patrick Boenzli */ #define DEBUG_MODULE_GAME_RULES #include "multiplayer_team_deathmatch.h" #include "load_param.h" #include "factory.h" #include "render2D/billboard.h" #include "state.h" #include "player.h" #include "playable.h" using namespace std; CREATE_FACTORY(MultiplayerTeamDeathmatch, CL_MULTIPLAYER_TEAM_DEATHMATCH); /** * constructor */ MultiplayerTeamDeathmatch::MultiplayerTeamDeathmatch(const TiXmlElement* root) : GameRules(root) { this->setClassID(CL_MULTIPLAYER_TEAM_DEATHMATCH, "MultiplayerTeamDeathmatch"); this->bLocalPlayerDead = false; this->deathTimeout = 10.0f; // 5 seconds this->deathScreen = new Billboard(); this->deathScreen->setSize(State::getResX()/4.0, State::getResY()/4.0); this->deathScreen->setAbsCoor2D(State::getResX()/2.0f, State::getResY()/2.0f); this->deathScreen->setVisibility(false); this->localPlayer = State::getPlayer(); if( root != NULL) this->loadParams(root); } /** * decontsructor */ MultiplayerTeamDeathmatch::~MultiplayerTeamDeathmatch() { if( this->deathScreen) delete this->deathScreen; } void MultiplayerTeamDeathmatch::loadParams(const TiXmlElement* root) { GameRules::loadParams(root) ; LoadParam(root, "death-penalty-timeout", this, MultiplayerTeamDeathmatch, setDeathPenaltyTimeout) .describe("sets the time in seconds a player has to wait for respawn"); LoadParam(root, "max-kills", this, MultiplayerTeamDeathmatch, setMaxKills) .describe("sets the maximal kills for winning condition"); LoadParam(root, "death-screen-image", this, MultiplayerTeamDeathmatch, setDeathScreen) .describe("sets the death screen image"); } void MultiplayerTeamDeathmatch::setDeathScreen(const char* imageName) { if( this->deathScreen) this->deathScreen->setTexture(imageName); } /** * called when the player enters the game * @param player the spawned player */ void MultiplayerTeamDeathmatch::onPlayerSpawn() { this->bLocalPlayerDead = false; this->deathScreen->setVisibility(false); } /** * when the player is killed * @param player the killed player */ void MultiplayerTeamDeathmatch::onPlayerDeath() { this->bLocalPlayerDead = true; this->deathScreen->setVisibility(true); } /** * time tick * @param dt time */ void MultiplayerTeamDeathmatch::tick(float dt) { this->checkGameRules(); // is the local player dead and inactive if( unlikely(this->bLocalPlayerDead)) { this->timeout += dt; // long enough dead? if( this->timeout >= this->deathTimeout) { this->timeout = 0.0f; // respawn (State::getPlayer())->getPlayable()->respawn(); } } } /** * draws the stuff */ void MultiplayerTeamDeathmatch::draw() { if( unlikely( this->bLocalPlayerDead)) { } } /** * check the game rules for consistency */ void MultiplayerTeamDeathmatch::checkGameRules() { // // check for max killing count if( this->teamAKills >= this->maxKills) { // team A winns } else if( this->teamBKills >= this->maxKills) { // team B winns } }