Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 7089 was 7089, checked in by patrick, 18 years ago

trunk: game rules should work now

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