コード例 #1
0
        protected override void LoadContent()
        {
            spriteBatch            = new SpriteBatch(GraphicsDevice);
            titlescreen            = Content.Load <Texture2D>("TitleScreen");
            snowMountainBackground = Content.Load <Texture2D>("SnowyMountainBackground");
            greenForestBackground  = Content.Load <Texture2D>("GreenForestBackground");
            forest4block           = Content.Load <Texture2D>("GreenTile4Long");
            forest8block           = Content.Load <Texture2D>("GreenTile8Long");
            snowy4block            = Content.Load <Texture2D>("SnowyTile4Long");
            snowy8block            = Content.Load <Texture2D>("SnowyTile8Long");
            captainAmericaTexture  = Content.Load <Texture2D>("captainamerica");
            ironManTexture         = Content.Load <Texture2D>("ironman");
            starlordTexture        = Content.Load <Texture2D>("starlord");
            warmachineTexture      = Content.Load <Texture2D>("warmachine");
            healthTexture          = Content.Load <Texture2D>("redpixel");
            chatBackground         = Content.Load <Texture2D>("chatBackground");
            sf           = Content.Load <SpriteFont>("NewSpriteFont");
            muricaShield = Content.Load <Texture2D>("muricashot");
            redLaser     = Content.Load <Texture2D>("redlaser");
            blueLaser    = Content.Load <Texture2D>("bluelaser");
            greenLaser   = Content.Load <Texture2D>("greenlaser");

            GameLobby.LoadContent(Content);
            shotManager      = new ShotManager(muricaShield, redLaser, blueLaser, greenLaser);
            collisionManager = new CollisionManager(new Rectangle(0, 0, this.Window.ClientBounds.Width, this.Window.ClientBounds.Height));
        }
コード例 #2
0
        public static void Update(Game1 game)
        {
            while ((incmsg = Client.ReadMessage()) != null)
            {
                string header = incmsg.ReadString();

                switch (header)
                {
                case "connect":
                {
                    float timer = incmsg.ReadFloat();

                    GameLobby.timer = timer;
                }
                break;

                case "CharacterSelection":
                {
                    string username     = incmsg.ReadString();
                    string selectedChar = incmsg.ReadString();
                    int    x            = incmsg.ReadInt32();
                    int    y            = incmsg.ReadInt32();

                    if (selectedChar == "Ironman")
                    {
                        Player.players.Add(new Player(username,
                                                      new Vector2(x, y),
                                                      Game1.ironManTexture,
                                                      Game1.healthTexture,
                                                      new Rectangle(0, 0, 32, 48)));
                    }
                    else if (selectedChar == "Starlord")
                    {
                        Player.players.Add(new Player(username,
                                                      new Vector2(x, y),
                                                      Game1.starlordTexture,
                                                      Game1.healthTexture,
                                                      new Rectangle(0, 0, 32, 48)));
                    }
                    else if (selectedChar == "America")
                    {
                        Player.players.Add(new Player(username,
                                                      new Vector2(x, y),
                                                      Game1.captainAmericaTexture,
                                                      Game1.healthTexture,
                                                      new Rectangle(0, 0, 32, 48)));
                    }
                    else
                    {
                        Player.players.Add(new Player(username,
                                                      new Vector2(x, y),
                                                      Game1.warmachineTexture,
                                                      Game1.healthTexture,
                                                      new Rectangle(0, 0, 32, 48)));
                    }

                    for (int a = 0; a < Player.players.Count; a++)
                    {
                        for (int b = 0; b < Player.players.Count; b++)
                        {
                            if (a != b && Player.players[a].name.Equals(Player.players[b].name))
                            {
                                Player.players.RemoveAt(a);
                                a--;
                                break;
                            }
                        }
                    }
                }
                break;

                case "move":
                {
                    try {
                        string username  = incmsg.ReadString();
                        float  x         = incmsg.ReadInt32();
                        float  y         = incmsg.ReadInt32();
                        string direction = incmsg.ReadString();

                        for (int i = 0; i < Player.players.Count; i++)
                        {
                            if (Player.players[i].name.Equals(username) && Player.players[i].name != Login.userName)
                            {
                                Player.players[i].playerSprite.Location  = new Vector2(x, y);
                                Player.players[i].playerSprite.direction = direction;
                                break;
                            }
                        }
                    }
                    catch
                    {
                        continue;
                    }
                }
                break;

                case "health":
                {
                    string username = incmsg.ReadString();
                    float  health   = incmsg.ReadFloat();

                    for (int i = 0; i < Player.players.Count; i++)
                    {
                        if (Player.players[i].name == username)
                        {
                            Player.players[i].currentHealth = health;
                        }
                    }
                }
                break;

                case "chat":
                    string chatItem = incmsg.ReadString();
                    ChatManager.chatList.Add(new ChatItem(chatItem));
                    ChatManager.chatStrings.Add(chatItem);
                    break;

                case "newshot":
                {
                    string playername   = incmsg.ReadString();
                    float  posX         = incmsg.ReadFloat();
                    float  posY         = incmsg.ReadFloat();
                    float  velocityX    = incmsg.ReadFloat();
                    float  velocityY    = incmsg.ReadFloat();
                    float  damage       = incmsg.ReadFloat();
                    string selectedChar = incmsg.ReadString();
                    ShotManager.AddBullet(playername, new Vector2(posX, posY), new Vector2(velocityX, velocityY), damage, selectedChar);
                    break;
                }
                }
                Client.Recycle(incmsg);
            }
        }