示例#1
0
        public Peer(string name)
        {
            CanAppend        = true;
            IncomingMessages = new ConcurrentQueue <string>();
            this.Name        = name;

            protocolExample = GemClient.Profile("GemChat")
                              .CreateNetworkProtocolEvent <Package>()
                              .HandleIncoming((sender, package) =>
            {
                QueueMessage(String.Format("Server sent {0} {1}", sender.Statistics.SentBytes, package.Name));
            })
                              .GenerateSendEvent();

            onEvent = GemClient.Profile("GemChat")
                      .CreateNetworkEvent
                      .AndHandleWith(this, x => new Action <string>(x.QueueMessage));

            onCommandExecute = GemClient.Profile("GemChat")
                               .CreateNetworkEvent
                               .AndHandleWith(this, x => new Action <string>(x.ExecuteCommand));

            onEvent.Send(name + " has joined");
            messageAppender = new ParallelTaskStarter(TimeSpan.Zero);
            messageAppender.Start(DequeueIncomingMessages);
        }
示例#2
0
 public void SendCommand(string cmd)
 {
     onCommandExecute.Send(cmd);
 }
示例#3
0
 public void Send(string message)
 {
     onEvent.Send(message);
 }
示例#4
0
文件: Actor.cs 项目: hoangvantu/Gem
        public void HandleInput(GameTime gameTime)
        {
            if (Dead)
            {
                Revive();
            }

            if (InputHandler.IsKeyDown(Keys.W))
            {
                direction = Direction.Up;
                if (onGround)
                {
                    Jump();
                }
            }
            if (InputHandler.IsKeyDown(Keys.S))
            {
                direction = Direction.Down;
            }
            if (InputHandler.IsKeyDown(Keys.D))
            {
                velocity += accelerationAmount;
                direction = Direction.Right;
                if (InputHandler.IsKeyDown(Keys.W))
                {
                    direction |= Direction.Up;
                }
                if (InputHandler.IsKeyDown(Keys.S))
                {
                    direction |= Direction.Down;
                }
            }
            if (InputHandler.IsKeyDown(Keys.A))
            {
                velocity -= accelerationAmount;
                direction = Direction.Left;
                if (InputHandler.IsKeyDown(Keys.W))
                {
                    direction |= Direction.Up;
                }
                if (InputHandler.IsKeyDown(Keys.S))
                {
                    direction |= Direction.Down;
                }
            }
            if (InputHandler.IsKeyReleased(Keys.Space))
            {
                var bulletVelocity = Vector2.Zero;

                if (direction.HasFlag(Direction.Up))
                {
                    bulletVelocity -= Vector2.UnitY;
                }
                if (direction.HasFlag(Direction.Down))
                {
                    bulletVelocity += Vector2.UnitY;
                }
                if (direction.HasFlag(Direction.Left))
                {
                    bulletVelocity -= Vector2.UnitX;
                }
                if (direction.HasFlag(Direction.Right))
                {
                    bulletVelocity += Vector2.UnitX;
                }
                bulletVelocity *= bulletAcceleration;

                var bulletLocation = this.location + new Vector2(this.frameWidth / 2, this.frameHeight / 2);
                onShoot.Send(Name, bulletLocation.X, bulletLocation.Y, bulletVelocity.X, bulletVelocity.Y);

                EffectsManager.AddBulletParticle(Name, bulletLocation, bulletVelocity);
            }

            velocity += fallSpeed;
            HandleVelocity();
            CheckCollision(gameTime);
            onLocationChange.Send(Name, location.X, location.Y);

            Camera.Move((float)gameTime.ElapsedGameTime.TotalSeconds, WorldLocation, velocity, accelerationAmount.X);
        }