Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 7051 was 7044, checked in by patrick, 19 years ago

trunk: death screen now works

File size: 3.3 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
[7040]45
[7039]46  this->deathScreen = new Billboard();
[7044]47  this->deathScreen->setSize(State::getResX()/4.0, State::getResY()/4.0);
[7040]48  this->deathScreen->setAbsCoor2D(State::getResX()/2.0f, State::getResY()/2.0f);
[7044]49  this->deathScreen->setVisibility(false);
[7037]50
[7044]51  this->localPlayer = State::getPlayer();
52
[7035]53  if( root != NULL)
54    this->loadParams(root);
55}
56
[7034]57/**
58 * decontsructor
59 */
60MultiplayerTeamDeathmatch::~MultiplayerTeamDeathmatch()
[7044]61{
62  if( this->deathScreen)
63    delete this->deathScreen;
64}
[7034]65
66
67
68void MultiplayerTeamDeathmatch::loadParams(const TiXmlElement* root)
[7035]69{
[7040]70  GameRules::loadParams(root) ;
[7037]71
72  LoadParam(root, "death-penalty-timeout", this, MultiplayerTeamDeathmatch, setDeathPenaltyTimeout)
73      .describe("sets the time in seconds a player has to wait for respawn");
74
75  LoadParam(root, "max-kills", this, MultiplayerTeamDeathmatch, setMaxKills)
76      .describe("sets the maximal kills for winning condition");
[7039]77
78  LoadParam(root, "death-screen-image", this, MultiplayerTeamDeathmatch, setDeathScreen)
79      .describe("sets the death screen image");
80
[7035]81}
82
83
[7039]84
85void MultiplayerTeamDeathmatch::setDeathScreen(const char* imageName)
86{
87  if( this->deathScreen)
88    this->deathScreen->setTexture(imageName);
89}
90
91
92
[7035]93/**
94 * called when the player enters the game
95 * @param player the spawned player
96 */
[7044]97void MultiplayerTeamDeathmatch::onPlayerSpawn()
[7039]98{
[7044]99  this->bLocalPlayerDead = false;
100  this->deathScreen->setVisibility(false);
[7039]101}
[7034]102
[7035]103
104/**
105 * when the player is killed
106 * @param player the killed player
107 */
[7044]108void MultiplayerTeamDeathmatch::onPlayerDeath()
[7039]109{
110  this->bLocalPlayerDead = true;
[7044]111  this->deathScreen->setVisibility(true);
[7039]112}
[7035]113
114
115/**
116 * time tick
117 * @param dt time
118 */
119void MultiplayerTeamDeathmatch::tick(float dt)
[7037]120{
[7039]121  this->checkGameRules();
[7035]122
[7039]123  // is the local player dead and inactive
124  if( unlikely(this->bLocalPlayerDead))
125  {
126    this->timeout += dt;
127
128    // long enough dead?
[7044]129    if( this->timeout >= this->deathTimeout)
[7039]130    {
131      this->timeout = 0.0f;
132      // respawn
[7044]133      (State::getPlayer())->getPlayable()->respawn();
[7039]134    }
135  }
[7037]136}
[7035]137
[7037]138
[7035]139/**
140 * draws the stuff
141 */
142void MultiplayerTeamDeathmatch::draw()
[7039]143{
144  if( unlikely( this->bLocalPlayerDead))
145  {
[7035]146
[7039]147  }
148}
[7035]149
[7039]150
[7035]151/**
152 * check the game rules for consistency
153 */
154void MultiplayerTeamDeathmatch::checkGameRules()
[7039]155{
156  //
157  // check for max killing count
158  if( this->teamAKills >= this->maxKills)
159  {
160    // team A winns
161  }
162  else if( this->teamBKills >= this->maxKills)
163  {
164    // team B winns
165  }
166}
[7035]167
168
169
170
171
172
Note: See TracBrowser for help on using the repository browser.