Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/power_ups/power_up.cc @ 6903

Last change on this file since 6903 was 6815, checked in by bensch, 19 years ago

orxonox/trunk: merged branches/network back to the trunk.
merged with command:
svn merge https://svn.orxonox.net/orxonox/branches/network . -r6774:HEAD

no conflicts…
thats what i call orthogonal work

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: 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 "assert.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_NONE;
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(.1);
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}
56
57
58void PowerUp::collidesWith (WorldEntity* entity, const Vector& location)
59{
60  if(entity->isA(CL_EXTENDABLE))
61  {
62    if(dynamic_cast<Extendable*>(entity)->pickup(this))
63    {
64      this->respawnTime = this->respawnStart;
65      this->toList(OM_DEAD_TICK);
66    }
67  }
68}
69
70void PowerUp::tick(float dt) {
71  if(this->getOMListNumber() != OM_COMMON) {
72    this->respawnTime -= dt;
73    if(this->respawnTime <= 0) {
74      this->respawn();
75      this->toList(OM_COMMON);
76    }
77  }
78}
79
80void PowerUp::draw() const
81{
82  if(this->model != NULL) {
83    glMatrixMode(GL_MODELVIEW);
84    glPushMatrix();
85    glTranslatef (this->getAbsCoor ().x,
86                  this->getAbsCoor ().y,
87                  this->getAbsCoor ().z);
88    Vector tmpRot = this->getAbsDir().getSpacialAxis();
89    glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
90    this->model->draw();
91    glPopMatrix();
92  }
93  this->sphereMaterial->select();
94  WorldEntity::draw();
95}
96
97const char* PowerUp::respawnTypes[] = {
98  "none",
99  "time"
100};
101
102void PowerUp::setRespawnType(const char* type)
103{
104  for(int i = 0; i < RESPAWN_size; ++i) {
105    if(!strcmp(type, respawnTypes[i])) {
106      this->respawnType = (PowerUpRespawn)i;
107      break;
108    }
109  }
110}
111
112
113
114/********************************************************************************************
115 NETWORK STUFF
116 ********************************************************************************************/
117
118
119/**
120 * data copied in data will bee sent to another host
121 * @param data pointer to data
122 * @param maxLength max length of data
123 * @return the number of bytes writen
124 */
125int PowerUp::readState( byte * data, int maxLength )
126{
127  SYNCHELP_WRITE_BEGIN();
128  SYNCHELP_WRITE_FKT( WorldEntity::readState, NWT_PU_WE_STATE );
129  return SYNCHELP_WRITE_N;
130}
131
132
133/**
134 * Writes data from network containing information about the state
135 * @param data pointer to data
136 * @param length length of data
137 * @param sender hostID of sender
138 */
139int PowerUp::writeState( const byte * data, int length, int sender )
140{
141  SYNCHELP_READ_BEGIN();
142  SYNCHELP_READ_FKT( WorldEntity::writeState, NWT_PU_WE_STATE );
143  return SYNCHELP_READ_N;
144}
145
Note: See TracBrowser for help on using the repository browser.