private void Handle(CheckEndOfLineEvent e)
 {
     //
     // Check to see if Ego entity "car" or "opps_x" has crossed the finish line
     //
     constraint.ForEachGameObject(
         (egoComp, endofline) =>
     {
         //
         // If any car crosses the finish line, then game ends
         //
         if (e.car.transform.position.y > endofline.transform.position.y)
         {
             //
             // Following is a play line to see how to add a component to an entity
             // Issue the pause component to the car the just crossed the finish line
             //
             Ego.AddComponent <PauseComponent>(egoComp);
             //
             // Invoke the event that causes the EndOfGameSystem to turn on "Game Over" text
             //
             EgoEvents <EndOfGameEvent> .AddEvent(new EndOfGameEvent(true));
         }
     }
         );
 }
Ejemplo n.º 2
0
    public override void Update()
    {
        constraint.ForEachGameObject(
            (ego, player) =>
        {
            float moveVertical = Input.GetAxis("Vertical");
            if (gameIsOver)
            {
                // do nothing is game is over
            }
            else
            {
                if (Input.GetKey(KeyCode.UpArrow))
                {
                    Vector3 now = player.transform.position;
                    player.transform.position = new Vector3(now.x, now.y + player.speed, now.z);
                    //
                    // invoke an event to check if the player car has crossed the line
                    //
                    if (ego.gameObject.name == "Player")
                    {
                        var eve = new CheckEndOfLineEvent(ego);
                        EgoEvents <CheckEndOfLineEvent> .AddEvent(eve);
                    }
                }
            }
        }

            );
    }
 public override void Update()
 {
     constraint.ForEachGameObject(
         (ego, opponentcar, speed) =>
     {
         if (gameIsOver)
         {
             // do nothing is game is over
         }
         else
         {
             Vector3 now = opponentcar.transform.position;
             opponentcar.transform.position = new Vector3(now.x, now.y + speed.speed, now.z);
             //
             // invoke an event to check if the car has crossed the line
             //     ego is the current GameObject / EgoComponent (happens to be Opps_x car)
             //
             var eve = new CheckEndOfLineEvent(ego);
             EgoEvents <CheckEndOfLineEvent> .AddEvent(eve);
         }
     }
         );
 }