Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/network/src/world_entities/power_ups/power_up.cc @ 6784

Last change on this file since 6784 was 6784, checked in by rennerc, 18 years ago

sync: added debug feature

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