random_racer/src/CollectableCoin.cpp

Go to the documentation of this file.
00001 #include "CollectableCoin.h"
00002 
00003 #include "ItemDistributor.h"
00004 
00005 #include <vrsode/SphereShape.h>
00006 
00007 #include <vrs/autodetail.h>
00008 #include <vrs/bounds.h>
00009 #include <vrs/box.h>
00010 #include <vrs/sphere.h>
00011 #include <vrs/torus.h>
00012 
00013 #include <iostream>
00014 
00015 
00016 namespace random_racer
00017 {
00018 
00019 CollectableCoin::CollectableCoin(VRS::SO<VRS::SceneThing> p_thing, 
00020         VRS::Vector p_position, unsigned int p_points, 
00021         VRS::SO<ItemDistributor> p_itemDistributor)
00022         : vrsode::CollisionBody(p_thing, 
00023                 new vrsode::SphereShape(VRS::Bounds(
00024                         VRS::Vector(-3.0, -3.0, -3.0), 
00025                         VRS::Vector(3.0, 3.0, 3.0))), true)
00026 {
00027     m_thing             = p_thing;
00028     m_points            = p_points;
00029     m_itemDistributor   = p_itemDistributor;
00030 
00031     m_rotation                          = new VRS::Rotation(VRS::Vector(1,0,0));
00032     VRS::SO<VRS::SceneThing> subThing   = new VRS::SceneThing(m_thing);
00033 
00034     subThing->append(new VRS::Rotation(
00035             VRS::Vector(0,0,1), VRS::Vector(0,0,0), 90));
00036     subThing->append(m_rotation);
00037     subThing->append(new VRS::AutoDetail(192.0, 192));
00038     subThing->append(new VRS::Torus(0.9, 0.3));
00039 
00040     // subThing->append(new VRS::Box(VRS::Vector(-1,-1,-1),VRS::Vector(1,1,1)));
00041     // subThing->append(new VRS::Sphere(0.7));
00042 
00043     setPosition(p_position);
00044     surface()->setGhostMode(true);
00045     m_rotation->setAngle(random() % 360);
00046 
00047     setCollisionCategory(32);
00048 
00049     m_collisionCookie = false;
00050     m_gotTheCookie    = false;
00051 
00052     // setDebugNode(true);
00053 }
00054 
00055 CollectableCoin::~CollectableCoin()
00056 {
00057 }
00058 
00059 unsigned int
00060 CollectableCoin::points()
00061 {
00062     return m_points;
00063 }
00064 
00065 void
00066 CollectableCoin::rotateOn(double p_angle)
00067 {
00068     m_rotation->setAngle(m_rotation->getAngle() + p_angle);
00069 }
00070 
00071 VRS::SO<VRS::SceneThing>
00072 CollectableCoin::sceneThing()
00073 {
00074     return m_thing;
00075 }
00076 
00077 void 
00078 CollectableCoin::handleCollision(VRS::SO<CollisionBody> p_partner)
00079 {
00080     lock();
00081 
00082     if(m_gotTheCookie == false)
00083         m_collisionCookie = true;
00084 
00085     else
00086         m_gotTheCookie = false;
00087 
00088     unlock();
00089 }
00090 
00091 bool
00092 CollectableCoin::didRecentlyCollide()
00093 {
00094     bool remember = false;
00095 
00096     lock();
00097 
00098     if(m_collisionCookie)
00099     {
00100         m_collisionCookie = false;
00101 
00102         if(m_gotTheCookie == false)
00103         {
00104             remember = true;
00105             m_gotTheCookie = true;
00106         }
00107     }
00108 
00109     unlock();
00110 
00111     return remember;
00112 }
00113 
00114 }

Generated on Fri May 11 21:01:57 2007 for Random Racer by  doxygen 1.5.1