Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/util/multiplayer_team_deathmatch.cc @ 7086

Last change on this file since 7086 was 7082, checked in by patrick, 20 years ago

trunk: respawn and death patch

File size: 3.5 KB
RevLine 
[7034]1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
10
11### File Specific:
12   main-programmer: Patrick Boenzli
13*/
14
15#define DEBUG_MODULE_GAME_RULES
16
17#include "multiplayer_team_deathmatch.h"
18
19#include "load_param.h"
[7035]20#include "factory.h"
[7034]21
[7039]22#include "render2D/billboard.h"
23#include "state.h"
[7034]24
[7044]25#include "player.h"
26#include "playable.h"
[7039]27
[7044]28
[7034]29using namespace std;
30
31
[7035]32CREATE_FACTORY(MultiplayerTeamDeathmatch, CL_MULTIPLAYER_TEAM_DEATHMATCH);
33
34
[7034]35/**
36 * constructor
37 */
[7035]38MultiplayerTeamDeathmatch::MultiplayerTeamDeathmatch(const TiXmlElement* root)
[7034]39  : GameRules(root)
[7035]40{
41  this->setClassID(CL_MULTIPLAYER_TEAM_DEATHMATCH, "MultiplayerTeamDeathmatch");
[7034]42
[7037]43  this->bLocalPlayerDead = false;
44  this->deathTimeout = 10.0f;     // 5 seconds
[7082]45  this->timeout = 0.0f;
[7040]46
[7039]47  this->deathScreen = new Billboard();
[7044]48  this->deathScreen->setSize(State::getResX()/4.0, State::getResY()/4.0);
[7040]49  this->deathScreen->setAbsCoor2D(State::getResX()/2.0f, State::getResY()/2.0f);
[7044]50  this->deathScreen->setVisibility(false);
[7037]51
[7044]52  this->localPlayer = State::getPlayer();
53
[7035]54  if( root != NULL)
55    this->loadParams(root);
56}
57
[7034]58/**
59 * decontsructor
60 */
61MultiplayerTeamDeathmatch::~MultiplayerTeamDeathmatch()
[7044]62{
63  if( this->deathScreen)
64    delete this->deathScreen;
65}
[7034]66
67
68
69void MultiplayerTeamDeathmatch::loadParams(const TiXmlElement* root)
[7035]70{
[7040]71  GameRules::loadParams(root) ;
[7037]72
73  LoadParam(root, "death-penalty-timeout", this, MultiplayerTeamDeathmatch, setDeathPenaltyTimeout)
74      .describe("sets the time in seconds a player has to wait for respawn");
75
76  LoadParam(root, "max-kills", this, MultiplayerTeamDeathmatch, setMaxKills)
77      .describe("sets the maximal kills for winning condition");
[7039]78
79  LoadParam(root, "death-screen-image", this, MultiplayerTeamDeathmatch, setDeathScreen)
80      .describe("sets the death screen image");
81
[7035]82}
83
84
[7039]85
86void MultiplayerTeamDeathmatch::setDeathScreen(const char* imageName)
87{
88  if( this->deathScreen)
89    this->deathScreen->setTexture(imageName);
90}
91
92
93
[7035]94/**
95 * called when the player enters the game
96 * @param player the spawned player
97 */
[7044]98void MultiplayerTeamDeathmatch::onPlayerSpawn()
[7039]99{
[7044]100  this->bLocalPlayerDead = false;
101  this->deathScreen->setVisibility(false);
[7039]102}
[7034]103
[7035]104
105/**
106 * when the player is killed
107 * @param player the killed player
108 */
[7044]109void MultiplayerTeamDeathmatch::onPlayerDeath()
[7039]110{
111  this->bLocalPlayerDead = true;
[7044]112  this->deathScreen->setVisibility(true);
[7039]113}
[7035]114
115
116/**
117 * time tick
118 * @param dt time
119 */
120void MultiplayerTeamDeathmatch::tick(float dt)
[7037]121{
[7039]122  this->checkGameRules();
[7035]123
[7039]124  // is the local player dead and inactive
125  if( unlikely(this->bLocalPlayerDead))
126  {
127    this->timeout += dt;
[7080]128    PRINTF(0)("TICK DEATH: %f of %f\n", dt, this->timeout);
[7039]129    // long enough dead?
[7044]130    if( this->timeout >= this->deathTimeout)
[7039]131    {
132      this->timeout = 0.0f;
133      // respawn
[7079]134      PRINTF(0)("RESPAWN\n");
[7044]135      (State::getPlayer())->getPlayable()->respawn();
[7080]136      this->onPlayerDeath();
[7039]137    }
138  }
[7037]139}
[7035]140
[7037]141
[7035]142/**
143 * draws the stuff
144 */
145void MultiplayerTeamDeathmatch::draw()
[7039]146{
147  if( unlikely( this->bLocalPlayerDead))
148  {
[7035]149
[7039]150  }
151}
[7035]152
[7039]153
[7035]154/**
155 * check the game rules for consistency
156 */
157void MultiplayerTeamDeathmatch::checkGameRules()
[7039]158{
159  //
160  // check for max killing count
161  if( this->teamAKills >= this->maxKills)
162  {
163    // team A winns
164  }
165  else if( this->teamBKills >= this->maxKills)
166  {
167    // team B winns
168  }
169}
[7035]170
171
172
173
174
175
Note: See TracBrowser for help on using the repository browser.