Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/powerups/src/world_entities/power_ups/power_up.cc @ 6945

Last change on this file since 6945 was 6945, checked in by manuel, 18 years ago

powerups work but bugs in weaponmanager

File size: 3.6 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: Manuel Leuenberger
13   co-programmer: ...
14*/
15
16#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY
17
18
19#include "power_up.h"
20#include "extendable.h"
21#include "primitive_model.h"
22
23#include "load_param.h"
24
25using namespace std;
26
27PowerUp::PowerUp(float r, float g, float b)
28{
29  this->setClassID(CL_POWER_UP, "PowerUp");
30
31  this->respawnType = RESPAWN_TIME;
32  this->respawnStart = 10;
33  this->model = NULL;
34/*  if(!PowerUp::sphereModel) {*/
35
36  Model* sphereModel = new PrimitiveModel(PRIM_SPHERE, 7, 5);
37
38  this->setModel(sphereModel);
39  this->buildObbTree( 4);
40  this->sphereMaterial = new Material;
41  this->sphereMaterial->setTransparency(.8);
42  this->sphereMaterial->setDiffuse(r, g, b);
43  this->toList(OM_COMMON);
44}
45
46PowerUp::~PowerUp ()
47{
48  delete this->sphereMaterial;
49}
50
51
52void PowerUp::loadParams(const TiXmlElement* root)
53{
54  WorldEntity::loadParams(root);
55  LoadParam(root, "respawnType", this, PowerUp, setRespawnType);
56  LoadParam(root, "respawnTime", this, PowerUp, setRespawnTime);
57}
58
59
60void PowerUp::collidesWith (WorldEntity* entity, const Vector& location)
61{
62  if(entity->isA(CL_EXTENDABLE))
63  {
64    if(dynamic_cast<Extendable*>(entity)->pickup(this))
65    {
66      switch(respawnType) {
67        case RESPAWN_NONE:
68          this->toList(OM_DEAD);
69          break;
70        case RESPAWN_TIME:
71          this->toList(OM_DEAD_TICK);
72          this->respawnTime = this->respawnStart;
73          break;
74      }
75    }
76  }
77}
78
79void PowerUp::tick(float dt) {
80  if(this->getOMListNumber() != OM_COMMON) {
81    this->respawnTime -= dt;
82    if(this->respawnTime <= 0) {
83      this->toList(OM_COMMON);
84    }
85  }
86}
87
88void PowerUp::draw() const
89{
90  if(this->model != NULL) {
91    glMatrixMode(GL_MODELVIEW);
92    glPushMatrix();
93    glTranslatef (this->getAbsCoor ().x,
94                  this->getAbsCoor ().y,
95                  this->getAbsCoor ().z);
96    Vector tmpRot = this->getAbsDir().getSpacialAxis();
97    glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
98    this->model->draw();
99    glPopMatrix();
100  }
101  this->sphereMaterial->select();
102  WorldEntity::draw();
103}
104
105const char* PowerUp::respawnTypes[] = {
106  "none",
107  "time"
108};
109
110void PowerUp::setRespawnType(const char* type)
111{
112  for(int i = 0; i < RESPAWN_size; ++i) {
113    if(!strcmp(type, respawnTypes[i])) {
114      this->respawnType = (PowerUpRespawn)i;
115      break;
116    }
117  }
118}
119
120void PowerUp::setRespawnTime(const float respawnTime)
121{
122  this->respawnStart = respawnTime;
123}
124
125
126/********************************************************************************************
127 NETWORK STUFF
128 ********************************************************************************************/
129
130
131/**
132 * data copied in data will bee sent to another host
133 * @param data pointer to data
134 * @param maxLength max length of data
135 * @return the number of bytes writen
136 */
137int PowerUp::readState( byte * data, int maxLength )
138{
139  SYNCHELP_WRITE_BEGIN();
140  SYNCHELP_WRITE_FKT( WorldEntity::readState, NWT_PU_WE_STATE );
141  return SYNCHELP_WRITE_N;
142}
143
144
145/**
146 * Writes data from network containing information about the state
147 * @param data pointer to data
148 * @param length length of data
149 * @param sender hostID of sender
150 */
151int PowerUp::writeState( const byte * data, int length, int sender )
152{
153  SYNCHELP_READ_BEGIN();
154  SYNCHELP_READ_FKT( WorldEntity::writeState, NWT_PU_WE_STATE );
155  return SYNCHELP_READ_N;
156}
157
Note: See TracBrowser for help on using the repository browser.