Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

trunk: game rules definitions added

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