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 | using namespace std; |
---|
24 | |
---|
25 | PowerUp::PowerUp(float r, float g, float b) |
---|
26 | { |
---|
27 | this->setClassID(CL_POWER_UP, "PowerUp"); |
---|
28 | |
---|
29 | this->respawnType = RESPAWN_NONE; |
---|
30 | this->respawnStart = 10; |
---|
31 | this->model = NULL; |
---|
32 | /* if(!PowerUp::sphereModel) {*/ |
---|
33 | |
---|
34 | Model* sphereModel = new PrimitiveModel(PRIM_SPHERE, 7, 5); |
---|
35 | |
---|
36 | this->setModel(sphereModel); |
---|
37 | this->buildObbTree( 4); |
---|
38 | this->sphereMaterial = new Material; |
---|
39 | this->sphereMaterial->setTransparency(.1); |
---|
40 | this->sphereMaterial->setDiffuse(r, g, b); |
---|
41 | this->toList(OM_COMMON); |
---|
42 | } |
---|
43 | |
---|
44 | PowerUp::~PowerUp () |
---|
45 | { |
---|
46 | delete this->sphereMaterial; |
---|
47 | } |
---|
48 | |
---|
49 | |
---|
50 | void PowerUp::loadParams(const TiXmlElement* root) |
---|
51 | { |
---|
52 | WorldEntity::loadParams(root); |
---|
53 | } |
---|
54 | |
---|
55 | |
---|
56 | void PowerUp::collidesWith (WorldEntity* entity, const Vector& location) |
---|
57 | { |
---|
58 | if(entity->isA(CL_EXTENDABLE)) |
---|
59 | { |
---|
60 | if(dynamic_cast<Extendable*>(entity)->pickup(this)) |
---|
61 | { |
---|
62 | this->respawnTime = this->respawnStart; |
---|
63 | this->toList(OM_DEAD_TICK); |
---|
64 | } |
---|
65 | } |
---|
66 | } |
---|
67 | |
---|
68 | void PowerUp::tick(float dt) { |
---|
69 | if(this->getOMListNumber() != OM_COMMON) { |
---|
70 | this->respawnTime -= dt; |
---|
71 | if(this->respawnTime <= 0) { |
---|
72 | this->toList(OM_COMMON); |
---|
73 | this->respawn(); |
---|
74 | } |
---|
75 | } |
---|
76 | } |
---|
77 | |
---|
78 | void PowerUp::draw() const |
---|
79 | { |
---|
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 | } |
---|
91 | this->sphereMaterial->select(); |
---|
92 | WorldEntity::draw(); |
---|
93 | } |
---|
94 | |
---|
95 | const char* PowerUp::respawnTypes[] = { |
---|
96 | "none", |
---|
97 | "time" |
---|
98 | }; |
---|
99 | |
---|
100 | void PowerUp::setRespawnType(const char* type) |
---|
101 | { |
---|
102 | for(int i = 0; i < RESPAWN_size; ++i) { |
---|
103 | if(!strcmp(type, respawnTypes[i])) { |
---|
104 | this->respawnType = (PowerUpRespawn)i; |
---|
105 | break; |
---|
106 | } |
---|
107 | } |
---|
108 | } |
---|
109 | |
---|
110 | |
---|
111 | |
---|
112 | /******************************************************************************************** |
---|
113 | NETWORK STUFF |
---|
114 | ********************************************************************************************/ |
---|
115 | |
---|
116 | |
---|
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 | */ |
---|
123 | int PowerUp::readState( byte * data, int maxLength ) |
---|
124 | { |
---|
125 | SYNCHELP_WRITE_BEGIN(); |
---|
126 | SYNCHELP_WRITE_FKT( WorldEntity::readState ); |
---|
127 | return SYNCHELP_WRITE_N; |
---|
128 | } |
---|
129 | |
---|
130 | |
---|
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 | */ |
---|
137 | int PowerUp::writeState( const byte * data, int length, int sender ) |
---|
138 | { |
---|
139 | SYNCHELP_READ_BEGIN(); |
---|
140 | SYNCHELP_READ_FKT( WorldEntity::writeState ); |
---|
141 | return SYNCHELP_READ_N; |
---|
142 | } |
---|
143 | |
---|