Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

PlayerShip.cpp

Go to the documentation of this file.
00001 
00002 /*
00003     TSGL - Teddy Space Game Library
00004     Copyright (C) 2002 Timo Suoranta
00005     tksuoran@cc.helsinki.fi
00006 
00007     This library is free software; you can redistribute it and/or
00008     modify it under the terms of the GNU Lesser General Public
00009     License as published by the Free Software Foundation; either
00010     version 2.1 of the License, or (at your option) any later version.
00011 
00012     This library is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015     Lesser General Public License for more details.
00016 
00017     You should have received a copy of the GNU Lesser General Public
00018     License along with this library; if not, write to the Free Software
00019     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020 
00021     $Id: PlayerShip.cpp,v 1.1 2002/01/08 20:47:05 tksuoran Exp $
00022 */
00023 
00024 
00025 #include "Teddy/SpaceGame/PlayerShip.h"
00026 #include "Teddy/SpaceGame/Root.h"
00027 #include "Teddy/SpaceGame/UserInterface.h"
00028 #include "Teddy/Graphics/View.h"
00029 #include "Teddy/Materials/Material.h"
00030 #include "Teddy/Materials/Light.h"
00031 #include "Teddy/Models/Tube.h"
00032 #include "Teddy/Models/Box.h"
00033 #include "Teddy/Scenes/Scene.h"
00034 #include "Teddy/SysSupport/Messages.h"
00035 #include "Teddy/SysSupport/Clock.h"
00036 #include "Teddy/SysSupport/Timer.h"
00037 using namespace Teddy::Graphics;
00038 using namespace Teddy::Materials;
00039 using namespace Teddy::Maths;
00040 using namespace Teddy::Models;
00041 using namespace Teddy::Scenes;
00042 
00043 
00044 namespace Teddy     {
00045 namespace SpaceGame {
00046 
00047 
00048 #define BULLET_RATE  ( 150.0000f)
00049 #define BULLET_SPEED (  50.0000f)
00050 #define FM_ELITE     0
00051 #define FM_FREE      1
00052 
00053 
00059 PlayerShip::PlayerShip( ShipType *ship_type, Root *root )
00060 :
00061 Ship( "Player", ship_type, root )
00062 {
00063     init();
00064 
00065     ply_light        = NULL;
00066     bullet           = new Tube( "BulletMesh", 5.0, 3.0, 6, 7 );
00067     prev_bullet_time = 0;
00068     clock            = root->getUserInterface()->getView()->getClock();
00069 }
00070 
00071 
00073 void PlayerShip::init(){
00074     wait_up = false;
00075     touch   = false;
00076 }
00077 
00078 
00080 /*virtual*/ void PlayerShip::applyControls( float age ){
00081     /*if( control_fire_weapon ){
00082         trackTarget();
00083     }*/
00084 
00085     Ship::applyControls( age );
00086 
00087 
00088     if( ply_light != NULL ){
00089         ply_light->setPosition( getPosition() /*- getViewAxis() * 200.0f*/ );
00090         ply_light->setSpotDirection( getViewAxis() );
00091     }
00092 
00093     if( control_fire_weapon ){
00094 
00095         float sys_time = root->getUserInterface()->getView()->getClock()->getTime();
00096 
00097         if( sys_time - prev_bullet_time > BULLET_RATE ){
00098             prev_bullet_time = sys_time;
00099 
00100             root->getAudioManager ()->playPulse();
00101             root->getObjectManager()->rayCollision( this );
00102 /*          ModelInstance *mi_bullet = new ModelInstance( "Bullet", bullet );
00103             mi_bullet->copyOrientation( *mi );
00104             mi_bullet->setPosition( getPosition() + getViewAxis() * 5 - GetUpAxis() * 5 );
00105             mi_bullet->tick_translation = 
00106                 getViewAxis() * speed +
00107                 getViewAxis() * BULLET_SPEED;
00108             mi_bullet->setMaterial( &Material::GRAY_75 );
00109             ui->getScene()->addInstance( mi_bullet );
00110             mi_bullet->setCollisionGroup( sb );*/
00111 
00112 
00113             /*
00114 
00115 #define SIDE 4
00116 #define MASS 0.1f
00117             dMass     *mass    = new dMass;
00118             RigidBody *new_box = NULL;
00119             Box       *box     = NULL;
00120             dGeom     *geom    = NULL;
00121 
00122             mass->setBox( 1, SIDE, SIDE, SIDE );
00123             mass->adjust( MASS );
00124 
00125             box   = new Box( "Box", SIDE, SIDE, SIDE );
00126             geom  = new dGeom;
00127             geom->createBox( *space, SIDE, SIDE, SIDE );
00128 
00129             new_box = new RigidBody( "Box", box, geom );
00130             new_box->setMaterial( &Material::WHITE );
00131             ui->getScene()->addInstance( new_box );
00132 
00133             new_box->setPosition ( mi->getPosition() );
00134             new_box->setMass     ( mass );
00135             new_box->setData     ( NULL );
00136             new_box->setLinearVel( mi->getViewAxis() * BULLET_SPEED );
00137 #undef SIDE   */
00138         }
00139     }
00140 }
00141 
00142 
00143 };  //  namespace SpaceGame
00144 };  //  namespace Teddy
00145 
00146