예제 #1
0
 public void Broadcast(Message message)
 {
     if (World.Instance.IsSimulating)
         _messages.Enqueue(message);
     else
         Log.Instance.Log("[DEBUG] Ignoring message sent while world is not simulating: " + message.ToString());
 }
 public void MoveRight(Message message)
 {
     shiftingActor.MoveTo(   // Change an Actor's position over an interval
           new Vector2(5.0f, 0.0f),  //the new position
           3.0f,					    //how long it should take to get there
           true,					    //whether or not the interval should use MathUtil::SmoothStep
           "RightMoveDone"		    //the (optional) message to send when the transition is done
     );
     shiftingActor.RotateTo(45.0f, 3.0f, true);
     shiftingActor.ChangeColorTo(new Color(1.0f, 0.0f, 1.0f, 1.0f), 3.0f, true);
     shiftingActor.ChangeSizeTo(1.0f, 3.0f, true);
 }
예제 #3
0
 public void DefferedBroadcast(Message message, float delay)
 {
     _delayedMessages.AddLast(new MessageTimer(message, delay));
 }
예제 #4
0
 public MessageTimer(Message message, float timeRemaining)
 {
     _message = message;
     _timeRemaining = Math.Max(0.0f, timeRemaining);
 }
        private void ReceiveMessage(Message message)
        {
            //Respond to the ScreenStarted message that we sent when the screen started.
            if (message.MessageName == "ScreenStarted")
            {
                p1.InitPhysics(0.8f, 0.5f, 0.7f, PhysicsActor.ShapeType.Box);
            }

            //When the first actor collides, we kick off the physics for the second actor.
            if (message.MessageName == "CollisionWith" + p1.Name)
            {
                // Only init the physics if it isn't already initialized.
                //   *weird* things happen if you initialize it a second time.
                if (p2.Body == null)
                {
                    p2.InitPhysics(0.8f, 0.5f, 0.7f, PhysicsActor.ShapeType.Box);
                }

                //If you need more data about the collision, collision messages always come *from*
                // the actor colliding with the one you care about, and carry a pointer to the
                // relevant Box2D contact point, which contains more information like the normal force,
                // position, tangent, etc.
                //
                //You can get these from GetSender() and the GetValue() function, since the
                // message getting delivered is really a templated TypedMessage<b2ContactPoint*>
                Vector2 vel = p1.Body.LinearVelocity;
                if (Math.Abs(vel.Y) > 5.0f)
                {
                    //We do the check on the actor's speed so that it only makes a sound when dropping
                    // at a certain rate. Otherwise, the bounce noise will play every time it "makes
                    // contact" with the ground as it settles. This leads to the bad kind of cacophany.
                    sound.Play();
                }
            }
            else if (message.MessageName == "CollisionWith" + p2.Name)
            {
                Vector2 vel = p2.Body.LinearVelocity;
                if (Math.Abs(vel.Y) > 5.0f)
                    sound.Play();
            }
        }
 public void ReceiveMessage(Message message)
 {
     if (message.MessageName == "MazeFinderPathPointReached")
     {
         if (_pathIndex < _pathPoints.Count - 1)
         {
             GetToNextPoint();
         }
     }
     else if (message.MessageName == "MouseDown")
     {
         // TODO: Support typed messages
         //TypedMessage<Vec2i> *m = (TypedMessage<Vec2i>*)message;
         //Vec2i screenCoordinates = m->GetValue();
         //Vector2 worldCoordinates = MathUtil::ScreenToWorld(screenCoordinates);
         //GoTo(worldCoordinates);
     }
 }