// Create player and accompanying components.
        private Ball CreatePlayer(SubWorld world, string name = "")
        {
            GameEntity entity   = new GameEntity(name);
            Ball       ball     = new Ball(entity);
            Collider   collider = new Collider(entity, 64, 64, true);

            world.GetSystem <BallSystem>().Add(ball);
            world.GetSystem <ColliderSystem>().Add(collider);
            return(ball);
        }
示例#2
0
        // Create brick and accompanying components.
        private Brick CreateBrick(SubWorld world, string name = "")
        {
            GameEntity entity   = new GameEntity(name);
            Brick      brick    = new Brick(entity, 96, 16);
            Collider   collider = new Collider(entity, 96, 16, false);

            world.GetSystem <ColliderSystem>().Add(collider);
            world.GetSystem <BrickSystem>().Add(brick);

            return(brick);
        }
        /// <summary>
        /// Process the Player Position message.
        /// </summary>
        /// <param name="client">Client the message is from.</param>
        /// <param name="message">Message itself.</param>
        protected override void PlayerPositionChange(Client client, Message message)
        {
            // Get current world.
            SubWorld world = CurrentWorld;

            // Find the TCP Client's world.
            while (world.Client != client)
            {
                if (world.Opponent == null)
                {
                    world = null;
                    break;
                }
                world = world.Opponent;
            }

            // If Client World is found.
            if (world != null)
            {
                // Get the World's Player.
                GameEntity player = world.GetSystem <PlayerSystem>().Get("Player").Parent;

                // Calculate the new Player position.
                byte[] data = message.GetData();
                data = (data.Length == 2) ? data : new byte[] { 0, data[0] };
                data = new byte[] { data[1], data[0] };
                short pos = BitConverter.ToInt16(data, 0);

                // Update Player position.
                player.Position.x = pos;
            }
        }
        /// <summary>
        /// Process the activate PowerUp message.
        /// </summary>
        /// <param name="client">Client the message is from.</param>
        /// <param name="message">Message itself.</param>
        protected override void ActivatePowerUp(Client client, Message message)
        {
            // Get the Client's SubWorld and activate PowerUp.
            SubWorld world = SubWorlds[Clients.IndexOf(client)];

            world.GetSystem <PowerUpSystem>().ActivatePowerUp();
        }