Beispiel #1
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Sets the mouse position in our window.
            Mouse.WindowHandle = this.Window.Handle;

            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            ContentHolder.Load(Content);

            // Button event function triggers
            // Menu button events
            foreach (Button actionbtn in actionButtons)
            {
                actionbtn.clicked += new Button.EventHandler(ButtonClicked);
            }

            // Menu button events
            foreach (Button menubtn in menuButtons)
            {
                menubtn.clicked += new Button.EventHandler(ButtonClicked);
            }

            foreach (Button mpbtn in multiplayerButtons)
            {
                mpbtn.clicked += new Button.EventHandler(MPButtonClicked);
            }

            upgradeTowerButton.clicked += new Button.EventHandler(ButtonClicked);

            // Event handler triggered by the Network.Receive function
            // Triggers when a message is sent from the server
            network.received += new Network.EventHandler(ReceivedNetwork);

            // Event trigger for unit death
            Unit.onDeath    += new EventHandler(UnitDeath);
            Unit.onLastTile += new EventHandler(UnitReachEnd);

            // BUTTON TEXTURES
            // 0 - unit1 (placeholder button)
            // 1 - tower1
            // 2 - tower1upgrade1
            // 3 - tower2
            // 4 - tower2upgrade1
            // 5 - delete tower
            // 6 - new wave
            // 7 - new game menu
            // 8 - multiplayer menu
            // 9 - controls menu
            // 10 - exit menu
            // 11 - blackbox
            // 12 - resume
            // 13 - Save game
            // 14 - Join Lobby
            // 15 - Tumor button

            pathview.Texture = ContentHolder.TowerTextures[4];

            toast.InitVars(ContentHolder.Buttons[1], ContentHolder.Fonts[2]);
            networkMessages.InitVars(ContentHolder.Buttons[1], ContentHolder.Fonts[1]);
            network.Init(ref networkMessages);

            userName.InitVars(ContentHolder.Buttons[1], ContentHolder.Fonts);
            lobbyName.InitVars(ContentHolder.Buttons[1], ContentHolder.Fonts);
            chatBox.InitVars(ContentHolder.Buttons[1], ContentHolder.Fonts);
            Button.Buttons = ContentHolder.Buttons;
            Gui.Font       = ContentHolder.Fonts[1];
            Gui.Sprites    = ContentHolder.GuiSprites;

            Unit.SetSprites(ContentHolder.UnitSprites, ContentHolder.Fonts[0]);
            Ammunition.SetSprites(ContentHolder.AmmunitionSprites);
            map.SetTextures(ContentHolder.TowerTextures);
            Tower.Turret = ContentHolder.TowerTextures[9];
            Button.Fonts = ContentHolder.Fonts;

            // Set the username textbox active from the start
            userName.Active = true;

            //Thread thread = new Thread(new ThreadStart(PlaySong));
            //thread.IsBackground = true;
            //thread.Start();

            // TODO: use this.Content to load your game content here
        }
Beispiel #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

            gameState       = GameState.Menu;
            gameStateNumber = true;

            input           = new Input();
            toast           = new MessageHandler(width, height);
            networkMessages = new MessageHandler(width, height);
            userName        = new TextInput(new Rectangle((width / 2) - 100, (height / 2) - 10, 200, 20));
            lobbyName       = new TextInput(new Rectangle(100, 200, 200, 20));
            chatBox         = new TextInput(new Rectangle(100, height - 40, 600, 20));
            network         = new Network();
            chatlog         = new List <string>();
            lobbyList       = new List <Gui>();

            // Action bar objects
            actionButtons = new List <Button>();
            actionButtons.Add(new Button(new Rectangle(5, height - ACTIONBUTTONOFFSET_X, 60, 60), "10", "Basic ranged tower, medium damage, medium firing speed, medium ammunition speed, single target. 100 gold - 50% return", Keys.D1, 1));
            actionButtons.Add(new Button(new Rectangle(5 + ACTIONBUTTONOFFSET_X, height - ACTIONBUTTONOFFSET_X, 60, 60), "20", "Fast ranged tower, low damage, high firing speed, fast ammunition speed, single target. 200 gold - 50% return", Keys.D2, 3));
            actionButtons.Add(new Button(new Rectangle(width - (ACTIONBUTTONOFFSET_X * 2), height - ACTIONBUTTONOFFSET_X, 60, 60), "3", "Deletes a tower, 50% gold return for normal towers, 100% for walls.", Keys.D, 5));
            actionButtons.Add(new Button(new Rectangle(width - ACTIONBUTTONOFFSET_X, height - ACTIONBUTTONOFFSET_X, 60, 60), "0", "Starts a new wave.", Keys.N, 6));
            actionButtons.Add(new Button(new Rectangle(width - (ACTIONBUTTONOFFSET_X * 3), height - ACTIONBUTTONOFFSET_X, 60, 60), "1", "Place a blocking tower. 5 gold - 100% return.", Keys.D3, 15));

            // Upgrade tower button
            upgradeTowerButton = new Button(new Rectangle(0, 0, 60, 60), "upgradetower", "Upgrade the tower?", Keys.D9, 15);

            Gui.SetScreenSize(width, height);
            topbar            = new Gui(new Rectangle(0, 0, width, 24));
            actionbar         = new Gui(new Rectangle(0, (height - 70), width, 70));
            Button.GameHeight = height;
            Button.GameWidth  = width;

            // Menu objects
            menuButtons = new List <Button>();
            menuButtons.Add(new Button(new Rectangle(width / 2 - MENUBUTTONOFFSET_X, MENUBUTTONOFFSET_X, 400, 70), "13", "Start a new game.", Keys.D1, 7));
            menuButtons.Add(new Button(new Rectangle(width / 2 - MENUBUTTONOFFSET_X, MENUBUTTONOFFSET_X + 75, 400, 70), "14", "Multiplayer.", Keys.D2, 8));
            menuButtons.Add(new Button(new Rectangle(width / 2 - MENUBUTTONOFFSET_X, MENUBUTTONOFFSET_X + (75 * 2), 400, 70), "15", "Check the game controls.", Keys.D3, 9));
            menuButtons.Add(new Button(new Rectangle(width / 2 - MENUBUTTONOFFSET_X, MENUBUTTONOFFSET_X + (75 * 3), 400, 70), "17", "Save the game.", Keys.D4, 13));
            menuButtons.Add(new Button(new Rectangle(width / 2 - MENUBUTTONOFFSET_X, MENUBUTTONOFFSET_X + (75 * 4), 400, 70), "16", "Exit the game.", Keys.D5, 10));

            // Multiplayer buttons
            multiplayerButtons = new List <Button>();
            multiplayerButtons.Add(new Button(new Rectangle(300, 200, 20, 20), "createlobby;", "Create lobby.", Keys.D1, 14));

            // join lobby buttons
            joinLobbyButtons = new List <Button>();

            // Map object
            map        = new Map();
            pathfinder = new Pathfinder(map);
            pathview   = new PathView();

            // Enemy objects
            Unit.SetPathfinder(pathfinder, map);
            Unit.LoadPath();
            waveHandler   = new WaveHandler(enemies);
            pathview.Path = Unit.Path;

            ContentHolder.Initialize();

            // Player object
            player      = new Player(5, 1000, ref map, ref toast, ref waveHandler);
            player.Wave = waveHandler.WaveNumber;

            storageHandler = new StorageHandler();

            base.Initialize();
        }