[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: |
---|
[5434] | 12 | main-programmer: Benjamin Grauer |
---|
[2077] | 13 | co-programmer: ... |
---|
| 14 | */ |
---|
| 15 | |
---|
[5439] | 16 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY |
---|
[2077] | 17 | |
---|
[5458] | 18 | #include "laser_power_up.h" |
---|
[5434] | 19 | #include "factory.h" |
---|
[5435] | 20 | #include "state.h" |
---|
[6424] | 21 | #include "network_game_manager.h" |
---|
[2077] | 22 | |
---|
[5437] | 23 | #include "primitive_model.h" |
---|
| 24 | |
---|
[2077] | 25 | using namespace std; |
---|
| 26 | |
---|
[5750] | 27 | CREATE_FACTORY(LaserPowerUp, CL_LASER_POWER_UP); |
---|
[2077] | 28 | |
---|
[6113] | 29 | LaserPowerUp::LaserPowerUp () : PowerUp(0.0, 1.0, 0.0) |
---|
[4597] | 30 | { |
---|
[5434] | 31 | this->init(); |
---|
[4597] | 32 | } |
---|
[2077] | 33 | |
---|
[6113] | 34 | LaserPowerUp::LaserPowerUp(const TiXmlElement* root) : PowerUp(0.0, 1.0, 0.0) |
---|
[5434] | 35 | { |
---|
| 36 | this->init(); |
---|
[2077] | 37 | |
---|
[5434] | 38 | this->loadParams(root); |
---|
| 39 | } |
---|
[2077] | 40 | |
---|
| 41 | |
---|
[5458] | 42 | LaserPowerUp::~LaserPowerUp () |
---|
[5437] | 43 | { |
---|
| 44 | delete this->sphereModel; |
---|
| 45 | delete this->sphereMaterial; |
---|
[5435] | 46 | } |
---|
[5434] | 47 | |
---|
[5435] | 48 | |
---|
[5458] | 49 | void LaserPowerUp::init() |
---|
[5434] | 50 | { |
---|
[5458] | 51 | this->setClassID(CL_LASER_POWER_UP, "LaserPowerUp"); |
---|
[5499] | 52 | this->loadModel("models/guns/test_gun.obj", 2.0); |
---|
[5435] | 53 | |
---|
[5437] | 54 | this->sphereModel = new PrimitiveModel(PRIM_SPHERE, 7, 5); |
---|
| 55 | this->sphereMaterial = new Material; |
---|
[5439] | 56 | this->sphereMaterial->setTransparency(.1); |
---|
[5458] | 57 | this->sphereMaterial->setDiffuse(.7, .7, .1); |
---|
[5437] | 58 | |
---|
[5435] | 59 | this->rotation = Vector(0,1,0); |
---|
[5437] | 60 | this->cycle = (float)rand()/RAND_MAX*M_2_PI; |
---|
| 61 | this->shiftDir(Quaternion((float)rand()/RAND_MAX*M_2_PI, this->rotation)); |
---|
[5434] | 62 | } |
---|
| 63 | |
---|
| 64 | |
---|
[5458] | 65 | void LaserPowerUp::loadParams(const TiXmlElement* root) |
---|
[5434] | 66 | { |
---|
[6512] | 67 | PowerUp::loadParams(root); |
---|
[5434] | 68 | |
---|
| 69 | } |
---|
[5435] | 70 | |
---|
| 71 | |
---|
| 72 | /** |
---|
| 73 | * this function is called, when two entities collide |
---|
| 74 | * @param entity: the world entity with whom it collides |
---|
| 75 | * |
---|
| 76 | * Implement behaviour like damage application or other miscellaneous collision stuff in this function |
---|
| 77 | */ |
---|
[5458] | 78 | void LaserPowerUp::collidesWith(WorldEntity* entity, const Vector& location) |
---|
[5435] | 79 | { |
---|
| 80 | // PRINTF(3)("collision %s vs %s @ (%f,%f,%f)\n", this->getClassName(), entity->getClassName(), location.x, location.y, location.z); |
---|
[5915] | 81 | if (entity->isA(CL_PLAYABLE)) |
---|
[6142] | 82 | this->toList(OM_DEAD); |
---|
[5435] | 83 | } |
---|
| 84 | |
---|
| 85 | /** |
---|
| 86 | * this method is called every frame |
---|
| 87 | * @param time: the time in seconds that has passed since the last tick |
---|
| 88 | * |
---|
| 89 | * Handle all stuff that should update with time inside this method (movement, animation, etc.) |
---|
| 90 | */ |
---|
[5458] | 91 | void LaserPowerUp::tick(float dt) |
---|
[5435] | 92 | { |
---|
| 93 | this->shiftDir(Quaternion(dt, this->rotation)); |
---|
| 94 | this->cycle+=dt; |
---|
| 95 | |
---|
| 96 | } |
---|
| 97 | |
---|
| 98 | /** |
---|
| 99 | * the entity is drawn onto the screen with this function |
---|
| 100 | * |
---|
| 101 | * This is a central function of an entity: call it to let the entity painted to the screen. |
---|
| 102 | * Just override this function with whatever you want to be drawn. |
---|
| 103 | */ |
---|
[5500] | 104 | void LaserPowerUp::draw() const |
---|
[6780] | 105 | { |
---|
| 106 | glMatrixMode(GL_MODELVIEW); |
---|
[5435] | 107 | glPushMatrix(); |
---|
| 108 | /* translate */ |
---|
| 109 | glTranslatef (this->getAbsCoor ().x, |
---|
| 110 | this->getAbsCoor ().y + cos(this->cycle*3.0)*2.0, |
---|
| 111 | this->getAbsCoor ().z); |
---|
| 112 | /* rotate */ |
---|
| 113 | Vector tmpRot = this->getAbsDir().getSpacialAxis(); |
---|
| 114 | glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z ); |
---|
[5994] | 115 | this->getModel()->draw(); |
---|
[5437] | 116 | |
---|
| 117 | this->sphereMaterial->select(); |
---|
| 118 | this->sphereModel->draw(); |
---|
[5435] | 119 | glPopMatrix(); |
---|
| 120 | } |
---|
| 121 | |
---|
[6424] | 122 | int LaserPowerUp::writeBytes( const byte * data, int length, int sender ) |
---|
| 123 | { |
---|
| 124 | setRequestedSync( false ); |
---|
| 125 | setIsOutOfSync( false ); |
---|
| 126 | |
---|
| 127 | SYNCHELP_READ_BEGIN(); |
---|
| 128 | |
---|
| 129 | SYNCHELP_READ_FKT( PowerUp::writeState ); |
---|
| 130 | |
---|
| 131 | return SYNCHELP_READ_N; |
---|
| 132 | } |
---|
| 133 | |
---|
| 134 | |
---|
| 135 | |
---|
| 136 | int LaserPowerUp::readBytes( byte * data, int maxLength, int * reciever ) |
---|
| 137 | { |
---|
| 138 | if ( isOutOfSync() && !requestedSync() && this->getHostID()!=this->getOwner() ) |
---|
| 139 | { |
---|
| 140 | (NetworkGameManager::getInstance())->sync( this->getUniqueID(), this->getOwner() ); |
---|
| 141 | setRequestedSync( true ); |
---|
| 142 | } |
---|
| 143 | |
---|
| 144 | int rec = this->getRequestSync(); |
---|
| 145 | if ( rec > 0 ) |
---|
| 146 | { |
---|
| 147 | *reciever = rec; |
---|
| 148 | |
---|
| 149 | SYNCHELP_WRITE_BEGIN(); |
---|
| 150 | |
---|
| 151 | SYNCHELP_WRITE_FKT( PowerUp::readState ); |
---|
| 152 | |
---|
| 153 | return SYNCHELP_WRITE_N; |
---|
| 154 | } |
---|
| 155 | |
---|
| 156 | *reciever = 0; |
---|
| 157 | return 0; |
---|
| 158 | } |
---|
| 159 | |
---|