/[enigma]/enigma/src/stones_simple.cc
ViewVC logotype

Diff of /enigma/src/stones_simple.cc

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.21 by reallysoft, Mon Jun 23 13:25:54 2003 UTC revision 1.22 by reallysoft, Wed Jun 25 13:28:26 2003 UTC
# Line 1407  namespace Line 1407  namespace
1407      };      };
1408  }  }
1409    
1410    // -------------------------
1411    //      ActorImpulseBase
1412    // -------------------------
1413    
 //----------------------------------------  
 // ActorImpulseStone  
 //----------------------------------------  
1414  namespace  namespace
1415  {  {
1416      class ActorImpulseStone : public Stone {      class ActorImpulseBase : public Stone {
         CLONEOBJ(ActorImpulseStone);  
1417      public:      public:
1418          ActorImpulseStone() : Stone("st-actorimpulse"), state(IDLE) {}          ActorImpulseBase(const char *kind) : Stone(kind), state(IDLE) {}
1419      private:      private:
1420          enum State { IDLE, PULSING, BROKEN };          enum State { IDLE, PULSING, BROKEN };
1421          State state;          State state;
1422    
1423          void actor_hit (const StoneContact &sc) {          void actor_hit (const StoneContact &sc) {
1424              if (state == IDLE) {              if (state == IDLE) {
1425                  double forcefac = 200;                  // normal points from stone-center _to_ actor.
1426                  sc.actor->add_force (forcefac * normalize(sc.normal));                  // actor_hit is called before reflect, but the force added below
1427                  play_sound("impulse");                  // is applied to actor after the reflection.
1428    
1429                    V2     normal   = normalize(sc.actor->get_pos() - get_pos().center());
1430                    double forcefac = 800;
1431                    V2     forcevec = normal*forcefac;
1432    
1433                    {
1434                        ActorInfo *ai        = sc.actor->get_actorinfo();
1435                        double     vel_abs   = length(ai->vel);
1436                        double     force_abs = length(forcevec);
1437    //                     warning("actor_hit (vel=%f=[%f/%f], force=%f=[%f/%f] mass=%f)",
1438    //                             vel_abs, ai->vel[0], ai->vel[1],
1439    //                             force_abs, forcevec[0], forcevec[1],
1440    //                             ai->mass);
1441                    }
1442    
1443                    sc.actor->add_force (forcevec);
1444    
1445                    play_sound("impulse");
1446                  set_anim("st-actorimpulse-anim");                  set_anim("st-actorimpulse-anim");
1447                  state = PULSING;                  state = PULSING;
1448              }              }
1449          }          }
1450    
1451          void animcb() {          void animcb() {
1452              if (state == PULSING) {              if (state == PULSING) {
# Line 1442  namespace Line 1459  namespace
1459    
1460    
1461  //----------------------------------------  //----------------------------------------
1462  // ActorImpulseStone Invisible  // ActorImpulseStone
1463  //----------------------------------------  //----------------------------------------
1464  namespace  namespace
1465  {  {
1466      class ActorImpulseStoneInvisible : public Stone {      class ActorImpulseStone : public ActorImpulseBase {
1467          CLONEOBJ(ActorImpulseStoneInvisible);          CLONEOBJ(ActorImpulseStone);
1468      public:      public:
1469          ActorImpulseStoneInvisible() : Stone("st-actorimpulse_invisible"), state(IDLE) {}          ActorImpulseStone() : ActorImpulseBase("st-actorimpulse") {}
1470      private:      };
1471          enum State { IDLE, PULSING, BROKEN };  }
         State state;  
1472    
         void actor_hit (const StoneContact &sc) {  
             if (state == IDLE) {  
                 double forcefac = 200;  
                 sc.actor->add_force (forcefac * normalize(sc.normal));  
                 play_sound("impulse");  
                 set_anim("st-actorimpulse-anim");  
                 state = PULSING;  
             }  
         }  
1473    
1474          void animcb() {  //----------------------------------------
1475              if (state == PULSING) {  // ActorImpulseStone Invisible
1476                  state = IDLE;  //----------------------------------------
1477                  init_model();  namespace
1478              }  {
1479          }      class ActorImpulseStoneInvisible : public ActorImpulseBase {
1480            CLONEOBJ(ActorImpulseStoneInvisible);
1481        public:
1482            ActorImpulseStoneInvisible() : ActorImpulseBase("st-actorimpulse_invisible") {}
1483      };      };
1484  }  }
1485    

Legend:
Removed from v.1.21  
changed lines
  Added in v.1.22

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26