feuerkraft-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Feuerkraft-CVS] rev 299 - trunk/src/vehicles


From: Ingo Ruhnke
Subject: [Feuerkraft-CVS] rev 299 - trunk/src/vehicles
Date: Fri, 05 Dec 2003 22:57:39 +0100

Author: grumbel
Date: 2003-12-05 22:57:38 +0100 (Fri, 05 Dec 2003)
New Revision: 299

Modified:
   trunk/src/vehicles/helicopter.cxx
   trunk/src/vehicles/helicopter.hxx
   trunk/src/vehicles/rotor.cxx
   trunk/src/vehicles/rotor.hxx
Log:
- fixed rotation of the rotor

Modified: trunk/src/vehicles/helicopter.cxx
===================================================================
--- trunk/src/vehicles/helicopter.cxx   2003-12-01 23:38:25 UTC (rev 298)
+++ trunk/src/vehicles/helicopter.cxx   2003-12-05 21:57:38 UTC (rev 299)
@@ -32,8 +32,6 @@
   //      "feuerkraft/huey_rotor2"),
   //heli (resources->get_sprite ("feuerkraft/chuey")),
   //heli_shadow (resources->get_sprite ("feuerkraft/huey_shadow")),
-  rotor("feuerkraft/chinook_rotor", 
-        "feuerkraft/chinook_rotor2"),
   heli (resources->get_sprite ("feuerkraft/chinook")),
   heli_shadow (resources->get_sprite ("feuerkraft/chinook_shadow")),
   helidestroyed (resources->get_sprite ("feuerkraft/helidestroyed")),
@@ -44,6 +42,20 @@
   destroyed (false),
   ai(0)
 {
+  RotorDescription rotor1;
+  rotor1.offset = FloatVector2d(40.0f, 0);
+  rotor1.slow_sprite = "feuerkraft/chinook_rotor";
+  rotor1.fast_sprite = "feuerkraft/chinook_rotor2";
+  rotor1.direction = RotorDescription::LEFT;
+  rotors.push_back(Rotor(rotor1));
+  
+  RotorDescription rotor2;
+  rotor2.offset = FloatVector2d(-40.0f, 0);
+  rotor2.slow_sprite = "feuerkraft/chinook_rotor";
+  rotor2.fast_sprite = "feuerkraft/chinook_rotor2";
+  rotor2.direction = RotorDescription::RIGHT;
+  rotors.push_back(Rotor(rotor2));
+
   pos.x = lst.get_float("x-pos");
   pos.y = lst.get_float("y-pos");
 
@@ -68,8 +80,8 @@
 
       view.draw(heli, pos, orientation);
 
-      rotor.draw(view, pos + FloatVector2d(-40.0f, 0).rotate(orientation), 
orientation);
-      rotor.draw(view, pos + FloatVector2d(+40.0f, 0).rotate(orientation), 
orientation);
+      for (Rotors::iterator i = rotors.begin(); i != rotors.end(); ++i)
+        (*i).draw(view, pos, orientation);
 
       energie.draw (view, int(pos.x), int(pos.y - 40));
     }
@@ -82,7 +94,8 @@
 void 
 Helicopter::update (float delta)
 {
-  rotor.update(delta);
+  for (Rotors::iterator i = rotors.begin(); i != rotors.end(); ++i)
+    (*i).update(delta);
 
   if (state == LANDING)
     {
@@ -91,12 +104,19 @@
         {
           height = 0;
           state = LANDED;
-          rotor.stop();
+
+          for (Rotors::iterator i = rotors.begin(); i != rotors.end(); ++i)
+            (*i).stop();
         }
     }
   else if (state == STARTING)
     {
-      if (rotor.is_running())
+      bool running = true;
+      for (Rotors::iterator i = rotors.begin(); i != rotors.end(); ++i)
+        if (!(*i).is_running())
+          running = false;          
+
+      if (running)
         {
           height += 20.0f * delta;
           if (height > 50.0f)
@@ -161,7 +181,8 @@
   else if (state == LANDED || state == LANDING)
     {
       state = STARTING;
-      rotor.start();
+      for (Rotors::iterator i = rotors.begin(); i != rotors.end(); ++i)
+        (*i).start();
     }
 }
 

Modified: trunk/src/vehicles/helicopter.hxx
===================================================================
--- trunk/src/vehicles/helicopter.hxx   2003-12-01 23:38:25 UTC (rev 298)
+++ trunk/src/vehicles/helicopter.hxx   2003-12-05 21:57:38 UTC (rev 299)
@@ -35,7 +35,8 @@
   enum { FLYING, STARTING, LANDING, LANDED } state;
   float height;
 
-  Rotor rotor;
+  typedef std::vector<Rotor> Rotors;
+  Rotors rotors;
 
   CL_Sprite heli;
   CL_Sprite heli_shadow;

Modified: trunk/src/vehicles/rotor.cxx
===================================================================
--- trunk/src/vehicles/rotor.cxx        2003-12-01 23:38:25 UTC (rev 298)
+++ trunk/src/vehicles/rotor.cxx        2003-12-05 21:57:38 UTC (rev 299)
@@ -21,11 +21,13 @@
 #include "../resource_manager.hxx"
 #include "rotor.hxx"
 
-Rotor::Rotor(const std::string& slow_name,
-             const std::string& fast_name)
+Rotor::Rotor(const RotorDescription& desc)
 {
-  slow = CL_Sprite(resources->get_sprite(slow_name));
-  fast = CL_Sprite(resources->get_sprite(fast_name));
+  // Rotor::Description
+  direction = desc.direction;
+  slow = CL_Sprite(resources->get_sprite(desc.slow_sprite));
+  fast = CL_Sprite(resources->get_sprite(desc.fast_sprite));
+  offset = desc.offset;
 
   running      = false;
   orientation  = 0;
@@ -35,15 +37,23 @@
 }
 
 void
-Rotor::draw(View& view, const FloatVector2d& pos, float ori)
+Rotor::draw(View& view, const FloatVector2d& pos, float parent_orientation)
 {
+  FloatVector2d off = offset;
+
   if (velocity > 8.0f)
     {
-      view.draw(fast, pos, orientation);
+      if (direction == RotorDescription::LEFT)
+        view.draw(fast, pos + off.rotate(parent_orientation), orientation);
+      else
+        view.draw(fast, pos + off.rotate(parent_orientation), -orientation);
     }
   else
     {
-      view.draw(slow, pos, orientation + ori);
+      if (direction == RotorDescription::LEFT)
+        view.draw(slow, pos + off.rotate(parent_orientation), orientation);
+      else
+        view.draw(slow, pos + off.rotate(parent_orientation), -orientation);
     }
 }
 

Modified: trunk/src/vehicles/rotor.hxx
===================================================================
--- trunk/src/vehicles/rotor.hxx        2003-12-01 23:38:25 UTC (rev 298)
+++ trunk/src/vehicles/rotor.hxx        2003-12-05 21:57:38 UTC (rev 299)
@@ -24,10 +24,23 @@
 
 class View;
 
+class RotorDescription
+{
+public:
+  enum Direction { LEFT, RIGHT }; 
+
+  std::string   slow_sprite;
+  std::string   fast_sprite;
+  FloatVector2d offset;
+  RotorDescription::Direction direction;
+};
+
 /** */
 class Rotor
 {
 private:
+  RotorDescription::Direction direction;
+  FloatVector2d offset;
   bool running;
 
   float orientation;
@@ -39,8 +52,7 @@
   CL_Sprite slow;
   CL_Sprite fast;
 public:
-  Rotor(const std::string& slow_name,
-        const std::string& fast_name);
+  Rotor(const RotorDescription& desc);
 
   void draw(View& view, const FloatVector2d& pos, float orientation);
   void update(float delta);





reply via email to

[Prev in Thread] Current Thread [Next in Thread]