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
Line 
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"
20#include "factory.h"
21
22#include "render2D/billboard.h"
23#include "state.h"
24
25#include "player.h"
26#include "playable.h"
27
28
29using namespace std;
30
31
32CREATE_FACTORY(MultiplayerTeamDeathmatch, CL_MULTIPLAYER_TEAM_DEATHMATCH);
33
34
35/**
36 * constructor
37 */
38MultiplayerTeamDeathmatch::MultiplayerTeamDeathmatch(const TiXmlElement* root)
39  : GameRules(root)
40{
41  this->setClassID(CL_MULTIPLAYER_TEAM_DEATHMATCH, "MultiplayerTeamDeathmatch");
42
43  this->bLocalPlayerDead = false;
44  this->deathTimeout = 10.0f;     // 5 seconds
45
46  this->deathScreen = new Billboard();
47  this->deathScreen->setSize(State::getResX()/4.0, State::getResY()/4.0);
48  this->deathScreen->setAbsCoor2D(State::getResX()/2.0f, State::getResY()/2.0f);
49  this->deathScreen->setVisibility(false);
50
51  this->localPlayer = State::getPlayer();
52
53  if( root != NULL)
54    this->loadParams(root);
55}
56
57/**
58 * decontsructor
59 */
60MultiplayerTeamDeathmatch::~MultiplayerTeamDeathmatch()
61{
62  if( this->deathScreen)
63    delete this->deathScreen;
64}
65
66
67
68void MultiplayerTeamDeathmatch::loadParams(const TiXmlElement* root)
69{
70  GameRules::loadParams(root) ;
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");
77
78  LoadParam(root, "death-screen-image", this, MultiplayerTeamDeathmatch, setDeathScreen)
79      .describe("sets the death screen image");
80
81}
82
83
84
85void MultiplayerTeamDeathmatch::setDeathScreen(const char* imageName)
86{
87  if( this->deathScreen)
88    this->deathScreen->setTexture(imageName);
89}
90
91
92
93/**
94 * called when the player enters the game
95 * @param player the spawned player
96 */
97void MultiplayerTeamDeathmatch::onPlayerSpawn()
98{
99  this->bLocalPlayerDead = false;
100  this->deathScreen->setVisibility(false);
101}
102
103
104/**
105 * when the player is killed
106 * @param player the killed player
107 */
108void MultiplayerTeamDeathmatch::onPlayerDeath()
109{
110  this->bLocalPlayerDead = true;
111  this->deathScreen->setVisibility(true);
112}
113
114
115/**
116 * time tick
117 * @param dt time
118 */
119void MultiplayerTeamDeathmatch::tick(float dt)
120{
121  this->checkGameRules();
122
123  // is the local player dead and inactive
124  if( unlikely(this->bLocalPlayerDead))
125  {
126    this->timeout += dt;
127
128    // long enough dead?
129    if( this->timeout >= this->deathTimeout)
130    {
131      this->timeout = 0.0f;
132      // respawn
133      (State::getPlayer())->getPlayable()->respawn();
134    }
135  }
136}
137
138
139/**
140 * draws the stuff
141 */
142void MultiplayerTeamDeathmatch::draw()
143{
144  if( unlikely( this->bLocalPlayerDead))
145  {
146
147  }
148}
149
150
151/**
152 * check the game rules for consistency
153 */
154void MultiplayerTeamDeathmatch::checkGameRules()
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}
167
168
169
170
171
172
Note: See TracBrowser for help on using the repository browser.