Beispiel #1
0
 public void PeerLeft(StarCollectorDemoPeer peer)
 {
     // schedule peer to be removed from PeerList on the main thread
     executionFiber.Enqueue(() =>
     {
         PeerList.Remove(peer);
     });
 }
Beispiel #2
0
 public void PeerJoined(StarCollectorDemoPeer peer)
 {
     // schedule peer to be added to PeerList on the main thread
     executionFiber.Enqueue(() =>
     {
         PeerList.Add(peer);
     });
 }
Beispiel #3
0
        public void SpawnPlayer(StarCollectorDemoPeer peer)
        {
            Player player = new Player();

            player.Owner   = peer;
            player.ActorID = AllocateActorID();

            Players.Add(player);
        }
Beispiel #4
0
        public void PeerLeft(StarCollectorDemoPeer peer)
        {
            // schedule peer to be removed from PeerList on the main thread
            executionFiber.Enqueue(() =>
            {
                PeerList.Remove(peer);

                // remove player object belonging to this peer
                Players.RemoveAll(player => { return(player.Owner == peer); });
            });
        }
Beispiel #5
0
        public void ProcessMessage(StarCollectorDemoPeer sender, OperationRequest operationRequest, SendParameters sendParameters)
        {
            if (operationRequest.OperationCode == (byte)StarCollectorRequestTypes.MoveCommand)
            {
                // move command from player
                long  actorID = (long)operationRequest.Parameters[0];
                float velX    = (float)operationRequest.Parameters[1];
                float velY    = (float)operationRequest.Parameters[2];

                // find actor
                Player player = (Players.Find(pl => { return(pl.ActorID == actorID); }));

                // apply velocity
                player.VelocityX = velX;
                player.VelocityY = velY;
            }
        }
Beispiel #6
0
        public void SpawnPlayer(StarCollectorDemoPeer peer)
        {
            Player player = new Player();

            player.Owner   = peer;
            player.ActorID = AllocateActorID();

            Players.Add(player);

            EventData evt = new EventData((byte)StarCollectorEventTypes.CreateActor);

            evt.Parameters    = new Dictionary <byte, object>();
            evt.Parameters[0] = player.ActorType;
            evt.Parameters[1] = player.ActorID;
            evt.Parameters[2] = player.PosX;
            evt.Parameters[3] = player.PosY;
            evt.Parameters[4] = peer.PlayerID;

            BroadcastEvent(evt, new SendParameters());
        }
Beispiel #7
0
        public void PeerLeft(StarCollectorDemoPeer peer)
        {
            // schedule peer to be removed from PeerList on the main thread
            executionFiber.Enqueue(() =>
            {
                PeerList.Remove(peer);

                // find the player object belonging to the peer
                Player player = Players.Find(actor => { return(actor.Owner == peer); });

                // broadcast DestroyActor event with player's actor ID
                EventData evt     = new EventData((byte)StarCollectorEventTypes.DestroyActor);
                evt.Parameters    = new Dictionary <byte, object>();
                evt.Parameters[0] = player.ActorID;

                BroadcastEvent(evt, new SendParameters());

                // remove from Players list
                Players.Remove(player);
            });
        }
Beispiel #8
0
        public void PeerJoined(StarCollectorDemoPeer peer)
        {
            // schedule peer to be added to PeerList on the main thread
            executionFiber.Enqueue(() =>
            {
                PeerList.Add(peer);

                // send player CreateActor events for all players and stars

                foreach (Player p in Players)
                {
                    EventData evt     = new EventData((byte)StarCollectorEventTypes.CreateActor);
                    evt.Parameters    = new Dictionary <byte, object>();
                    evt.Parameters[0] = p.ActorType;
                    evt.Parameters[1] = p.ActorID;
                    evt.Parameters[2] = p.PosX;
                    evt.Parameters[3] = p.PosY;
                    evt.Parameters[4] = (p.Owner as StarCollectorDemoPeer).PlayerID;

                    peer.SendEvent(evt, new SendParameters());
                }

                foreach (Star s in Stars)
                {
                    EventData evt     = new EventData((byte)StarCollectorEventTypes.CreateActor);
                    evt.Parameters    = new Dictionary <byte, object>();
                    evt.Parameters[0] = s.ActorType;
                    evt.Parameters[1] = s.ActorID;
                    evt.Parameters[2] = s.PosX;
                    evt.Parameters[3] = s.PosY;

                    peer.SendEvent(evt, new SendParameters());
                }

                SpawnPlayer(peer);
            });
        }
Beispiel #9
0
 public void ProcessMessage(StarCollectorDemoPeer sender, OperationRequest operationRequest, SendParameters sendParameters)
 {
     // process messages here
 }
Beispiel #10
0
 public void OnOperationRequest(StarCollectorDemoPeer sender, OperationRequest operationRequest, SendParameters sendParameters)
 {
     // schedule a message to be processed on the main thread
     executionFiber.Enqueue(() => { this.ProcessMessage(sender, operationRequest, sendParameters); });
 }
Beispiel #11
0
 public void OnOperationRequest(StarCollectorDemoPeer sender, OperationRequest operationRequest, SendParameters sendParameters)
 {
 }
Beispiel #12
0
 public void PeerLeft(StarCollectorDemoPeer peer)
 {
 }
Beispiel #13
0
 public void PeerJoined(StarCollectorDemoPeer peer)
 {
 }