示例#1
0
        private void setupPlayer(PlayerData playerData)
        {
            Texture2D[]   txs    = new Texture2D[5];
            SoundEffect[] sounds = new SoundEffect[5];
            txs[(int)Player.DIRECTION.LEFT]     = Content.Load <Texture2D>(@"Textures\right");
            txs[(int)Player.DIRECTION.RIGHT]    = Content.Load <Texture2D>(@"Textures\right");
            txs[(int)Player.DIRECTION.UP]       = Content.Load <Texture2D>(@"Textures\up");
            txs[(int)Player.DIRECTION.DOWN]     = Content.Load <Texture2D>(@"Textures\down");
            txs[(int)Player.DIRECTION.STANDING] = Content.Load <Texture2D>(@"Textures\stand");


            for (int i = 0; i < sounds.Length; i++)
            {
                sounds[i] = Content.Load <SoundEffect>(@"Audio\PlayerDirection\" + i.ToString());
            }
            player          = new Player(txs, sounds, new Vector2(0, 0), 8, 0, 5);
            player.Position = player.PreviousPosition = new Vector2(GraphicsDevice.Viewport.Width / 2 - player.SpriteWidth / 2,
                                                                    GraphicsDevice.Viewport.Height / 2 - player.SpriteHeight / 2);
            player.TargetPos = new Vector2(worldSize.X / 2, worldSize.Y / 2);
            //PrevPlayerPosition = player.Position;
            player.playerData = playerData;
            // Join the current Game
            LidgrenClient.Join(player.playerData);
            LidgrenClient.SendScore(new ScoreData {
                playerID = playerData.playerID, Tag = playerData.GamerTag, score = player.Score
            });
        }
示例#2
0
 /// <summary>
 /// Allows the game to perform any initialization it needs to before starting to run.
 /// This is where it can query for any required services and load any non-graphic
 /// related content.  Calling base.Initialize will enumerate through any components
 /// and initialize them as well.
 /// </summary>
 protected override void Initialize()
 {
     // TODO: Add your initialization logic here
     //worldRect = new Rectangle(new Point(0, 0), worldSize.ToPoint());
     //followCamera = new FollowCamera(this, Vector2.Zero, worldSize);
     inputEngine = new InputEngine(this);
     LidgrenClient.StartServer();
     base.Initialize();
 }
示例#3
0
        private OtherPlayer createOtherPlayer(PlayerData playerData)
        {
            Texture2D   tx          = Content.Load <Texture2D>(@"PlayerImages\" + playerData.imageName);
            OtherPlayer otherPlayer = new OtherPlayer(tx, new Vector2(playerData.X, playerData.Y), 1, playerData);

            // Create a score for the other player in all clients
            LidgrenClient.SendScore(new ScoreData {
                playerID = playerData.playerID,
                Tag      = playerData.GamerTag,
                score    = 0
            });
            return(otherPlayer);
        }
示例#4
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            if (InputEngine.IsKeyPressed(Keys.F10) && !playerJoined)
            {
                LidgrenClient.RequeustToJoin();
            }

            #region update player
            if (player != null)
            {
                player.Update(gameTime);
                player.Position = Vector2.Clamp(player.Position, Vector2.Zero, (worldSize - new Vector2(player.SpriteWidth, player.SpriteHeight)));
            }
            foreach (OtherPlayer p in OtherPlayers)
            {
                p.Update(gameTime);
            }
            #endregion
            #region Update Collectables
            if (player != null)
            {
                foreach (Collectable c  in Collectables)
                {
                    c.Update(gameTime);
                }
            }

            if (player != null)
            {
                foreach (Collectable item in Collectables)
                {
                    if (item.Alive && player.collisionDetect(item))
                    {
                        collectablesAliveCount--;
                        player.Score += item.Score;
                        item.Alive    = false;
                        collectSound.Play();
                        LidgrenClient.Collected(item.collectableData);
                        LidgrenClient.SendScore(new ScoreData {
                            playerID = player.playerData.playerID, Tag = player.playerData.GamerTag, score = player.Score
                        });
                    }
                    item.Update(gameTime);
                }
            }
            #endregion Collectables
            #region Camera Control
            if (player != null & followCamera != null)
            {
                followCamera.Follow(player);
            }
            #endregion
            catchMessage(LidgrenClient.CheckMessages());

            base.Update(gameTime);
        }