Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 6525 was 6512, checked in by bensch, 19 years ago

orxonox/trunk: loadParams is now virtual.
ALL THE CLASSES HAVE TO CALL

SuperClass::loadParams(root);

isntead of:
static_cast<SuperClass*>(this)→loadParams(root);

which was quite stupid anyways

File size: 2.9 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
23using namespace std;
24
25PowerUp::PowerUp(float r, float g, float b)
26{
27  this->setClassID(CL_POWER_UP, "PowerUp");
28
29  this->respawnType = RESPAWN_NONE;
30/*  if(!PowerUp::sphereModel) {*/
31
32  Model* sphereModel = new PrimitiveModel(PRIM_SPHERE, 7, 5);
33
34  this->setModel(sphereModel);
35  this->buildObbTree( 4);
36  this->sphereMaterial = new Material;
37  this->sphereMaterial->setTransparency(.1);
38  this->sphereMaterial->setDiffuse(r, g, b);
39  this->toList(OM_COMMON);
40}
41
42PowerUp::~PowerUp ()
43{
44  delete this->sphereMaterial;
45}
46
47
48void PowerUp::loadParams(const TiXmlElement* root)
49{
50  WorldEntity::loadParams(root);
51}
52
53
54void PowerUp::collidesWith (WorldEntity* entity, const Vector& location)
55{
56  if(entity->isA(CL_EXTENDABLE))
57  {
58    if(dynamic_cast<Extendable*>(entity)->pickup(this))
59    {
60      this->toList(OM_DEAD_TICK);
61    }
62  }
63}
64
65void PowerUp::draw() const
66{
67  glMatrixMode(GL_MODELVIEW);
68  glPushMatrix();
69
70  /* translate */
71  glTranslatef (this->getAbsCoor ().x,
72                this->getAbsCoor ().y,
73                this->getAbsCoor ().z);
74  Vector tmpRot = this->getAbsDir().getSpacialAxis();
75  glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
76
77   this->sphereMaterial->select();
78   this->getModel(0)->draw();
79
80   glPopMatrix();
81}
82
83const char* PowerUp::respawnTypes[] = {
84  "none",
85  "time"
86};
87
88void PowerUp::setRespawnType(const char* type)
89{
90  for(int i = 0; i < RESPAWN_size; ++i) {
91    if(!strcmp(type, respawnTypes[i])) {
92      this->respawnType = (PowerUpRespawn)i;
93      break;
94    }
95  }
96}
97
98
99
100/********************************************************************************************
101 NETWORK STUFF
102 ********************************************************************************************/
103
104
105/**
106 * data copied in data will bee sent to another host
107 * @param data pointer to data
108 * @param maxLength max length of data
109 * @return the number of bytes writen
110 */
111int PowerUp::readState( byte * data, int maxLength )
112{
113  SYNCHELP_WRITE_BEGIN();
114  SYNCHELP_WRITE_FKT( WorldEntity::readState );
115  return SYNCHELP_WRITE_N;
116}
117
118
119/**
120 * Writes data from network containing information about the state
121 * @param data pointer to data
122 * @param length length of data
123 * @param sender hostID of sender
124 */
125int PowerUp::writeState( const byte * data, int length, int sender )
126{
127  SYNCHELP_READ_BEGIN();
128  SYNCHELP_READ_FKT( WorldEntity::writeState );
129  return SYNCHELP_READ_N;
130}
131
Note: See TracBrowser for help on using the repository browser.