コード例 #1
0
ファイル: Menu.cs プロジェクト: wahabjawed/tower-defense-game
        public static void Draw(SpriteBatch spriteBatch)
        {
            spriteBatch.Begin();
            spriteBatch.Draw(menuScreen, new Rectangle(0, 0, Game1.graphicsDev.Viewport.Width, Game1.graphicsDev.Viewport.Height), Color.White);

            spriteBatch.End();

            EffectsManager.Draw(spriteBatch);


            spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend);

            for (int i = 0; i < MenuButton.Length; i++)
            {
                spriteBatch.Draw(MenuButton[i], new Rectangle((int)MenuButtonPos[i].X, (int)MenuButtonPos[i].Y, MenuButton[i].Width, MenuButton[i].Height), Color.White);
            }
            spriteBatch.End();
            spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend);
            shaderEffect1.CurrentTechnique.Passes[0].Apply();

            spriteBatch.Draw(MenuButton[mIndex], new Rectangle((int)MenuButtonPos[mIndex].X, (int)MenuButtonPos[mIndex].Y, MenuButton[mIndex].Width, MenuButton[mIndex].Height), Color.White);
            spriteBatch.End();
            spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend);

            for (int i = 0; i < 6; i++)
            {
                spriteBatch.Draw(MenuBall[i], new Rectangle((int)MenuBallPos[i].X, (int)MenuBallPos[i].Y, MenuBall[i].Width, MenuBall[i].Height), Color.White);
            }
            spriteBatch.End();

            spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend);
            shaderEffect.CurrentTechnique.Passes[0].Apply();

            spriteBatch.Draw(Title, new Rectangle(200, 10, Title.Width, Title.Height), Color.White);
            spriteBatch.End();
        }
コード例 #2
0
 public override void EffectOfAoe(float Aoe, Enemies EnemOfInitialHit, List <Enemies> enemy, Bullet bullet)
 {
     EffectsManager.AddEarthSparksEffects(EnemOfInitialHit.CenterofSprite, EnemOfInitialHit.Direction);
     base.EffectOfAoe(Aoe, EnemOfInitialHit, enemy, bullet);
 }
コード例 #3
0
        //How A Left MouseClick is Handled.
        private void MouseClicked()
        {
            //Code To CheckIf We ClickedOnAnEnemy.
            foreach (Enemies enem in EnemiesInGame)
            {
                if (enem.CheckIfClicked(MouseWorldRect))
                {
                    NullifyEverything();
                    EnemySelected = enem;
                    if (!(EnemySelected.Type.ToString().Equals("Composite")))
                    {
                        GetEnemyElement();
                    }
                    EnemySelected.spriteAnimation.Shader = shader;
                    return;
                }
            }

            //Check if the SpinButtonIsClicked,
            if (spinButton.CheckIfClicked(MouseWorldRect))
            {
                SpinButtonClicked();
            }
            //If We are on the the Tower SelectionScreen.
            if (spinButton.isAnimation1)
            {
                //Check If any of the towers have been Clicked.
                foreach (Tower T in TowersInGame)
                {
                    if (T.CheckIfClicked(MouseWorldRect))
                    {
                        NullifyEverything();
                        CircleEffect = new DrawAble(new SpriteAnimation(CreateCircle((int)T.TowerRange)), T.Location, 0, 0);
                        Vector2 CricleEffectLocation = CircleEffect.Location;
                        CricleEffectLocation.X -= CircleEffect.spriteAnimation.CurrentAnimation.CurrentRect.Width / 2;
                        CricleEffectLocation.Y -= CircleEffect.spriteAnimation.CurrentAnimation.CurrentRect.Height / 2;
                        CricleEffectLocation.X += T.spriteAnimation.CurrentAnimation.CurrentRect.Width / 2;
                        CricleEffectLocation.Y += T.spriteAnimation.CurrentAnimation.CurrentRect.Height / 2;
                        CircleEffect.Location   = CricleEffectLocation;
                        CircleEffect.spriteAnimation.TintColor = Color.Red;
                        CurrentlySelected = T;
                        CurrentlySelected.spriteAnimation.Shader = shader;
                        CurrentlySelected.TurretAnim.Shader      = shader;
                        CreateSellButton();
                        DisplayNewButtons();
                        return;
                    }
                }
                //How To Handle A ButtonClick in TowerSection.
                foreach (Button b in ButtonsToDisplay)
                {
                    ButtonTower BT = b as ButtonTower; //We Know it is of the ButtonTower Kind.

                    if (b.CheckIfClicked(MouseWorldRect))
                    {
                        if (CurrentlySelected != null && CurrentlyClicked == null) //This Statement is True If We Want To update a tower.
                        {
                            Tower t = BT.Value;
                            if (CheckIfElementsRequirementMet(CurrentlySelected, t))
                            {
                                if (Gold >= BT.GoldToCreate)
                                {
                                    Game1.sound.playSound("OnTowerCreation");
                                    //if (r.Next(1, 9) < 4)
                                    //{
                                    //    Game1.sound.playSound("FoolishDecision");
                                    //}
                                    //else if (r.Next(1, 9) > 6)
                                    //{
                                    //    Game1.sound.playSound("SoYouThink");
                                    //}
                                    Gold -= BT.GoldToCreate;
                                    TowersInGame.Add(t.Copy(CurrentlySelected.Location, BT.GoldToCreate / 2));
                                    TowersInGame.Remove(CurrentlySelected);
                                    NullifyEverything();
                                    FlipFlopButtons();
                                }
                                else
                                {
                                    EffectsManager.NoGoldEffect();
                                }
                            }
                            else
                            {
                                EffectsManager.NotEnoughElements();
                            }
                        }
                        else // This Runs When We are making a base Tower
                        {
                            CurrentlyClicked = BT.Value;
                            TowerToDisplay   = CurrentlyClicked.Copy(BT.Location, BT.GoldToCreate / 2);
                        }
                        return;
                    }
                } // End Of Button Looping Code for Tower Panel.

                // This Runs When We have Clicked On a Button to Create a tower and we are not intersecting with the panel. It shows the red and green tower.
                if (CurrentlyClicked != null && !(PanelRec.Intersects(MouseScreenRect)))
                {
                    Vector2 TileAtClick = tilemap.GetCollTileAtPixel(new Vector2(MouseWorldRect.X, MouseWorldRect.Y));
                    if (tilemap.GetCollCellIndex(TileAtClick) == 1)
                    {
                        if (Gold >= DefaultTowerCost)
                        {
                            //This Code will Create A Default Tower if you have selected it.C:\Users\Arsinx\documents\visual studio 2010\Projects\EleTD\EleTD\EleTD\EffectsManager.cs
                            Gold -= DefaultTowerCost;
                            Game1.sound.playSound("OnTowerCreation");
                            //if (r.Next(1, 9) < 4)
                            //{
                            //    Game1.sound.playSound("FoolishDecision");
                            //}
                            //else if (r.Next(1, 9) > 6)
                            //{
                            //    Game1.sound.playSound("SoYouThink");
                            //}
                            TileAtClick *= 64;
                            TowersInGame.Add(CurrentlyClicked.Copy(TileAtClick, DefaultTowerCost));  // We are not Dividing the Tower Cost By 2 Because the basic tower has full Sell price.
                            tilemap.SetCollisionTile((int)TileAtClick.X, (int)TileAtClick.Y, 0);
                            CurrentlyClicked = null;
                            TowerToDisplay   = null;
                            return;
                        }
                        else
                        {
                            EffectsManager.NoGoldEffect();
                        }
                    }
                    else
                    {
                        EffectsManager.CantBuildEffect();
                        Game1.sound.playSound("CannotBuildTower");
                        return;
                    }
                } // End OF Selected Tower Display Code.

                //If We Click the Sell Button.
                if (CurrentlySelected != null)
                {
                    if (sellButton.CheckIfClicked(MouseWorldRect))
                    {
                        TowersInGame.Remove(sellButton.Value);
                        Game1.sound.playSound("OnTowerSell");
                        if (r.Next(1, 9) > 6)
                        {
                            Game1.sound.playSound("FoolishDecision");
                        }

                        EffectsManager.WritingEffect(sellButton.Value.CenterofSprite, sellButton.Value.SellPrice);
                        Gold += sellButton.Value.SellPrice;
                        NullifyEverything();
                        FlipFlopButtons();
                        return;
                    }
                } // End of Sell Code
            }
            else  //If Elements Screen is the main screen.
            {
                //How to handle elements if we are in the screen for Elements.
                foreach (Button b in ButtonsToDisplay)
                {
                    if (b.CheckIfClicked(MouseWorldRect))
                    {
                        ButtonElement BE = b as ButtonElement;
                        if (Materia > 0)
                        {
                            BoughtElementsList.Add(BE.Type);
                            Materia--;
                            return;
                        }
                        else
                        {
                            EffectsManager.NotEnoughMateria();
                        }
                    }
                }

                //TowerClick In Elements Section.
                foreach (Tower T in TowersInGame)
                {
                    if (T.CheckIfClicked(MouseWorldRect))
                    {
                        SpinButtonClicked();
                        CurrentlySelected = T;
                        CurrentlySelected.spriteAnimation.Shader = shader;
                        CurrentlySelected.TurretAnim.Shader      = shader;
                        CreateSellButton();
                        DisplayNewButtons();

                        return;
                    }
                }
            }
            NullifyEverything();
            FlipFlopButtons();
        }
コード例 #4
0
ファイル: Menu.cs プロジェクト: wahabjawed/tower-defense-game
        public static void Update(GameTime gameTime)
        {
            Camera.Position = Vector2.Zero;

            TimeSinceSpawn += (float)gameTime.ElapsedGameTime.TotalMilliseconds;
            if (TimeSinceSpawn >= 500)
            {
                TimeSinceSpawn = 0;
                EffectsManager.MenuSparkEffect(MenuBallCenter[0], Color.OrangeRed, Color.Yellow);
                EffectsManager.MenuSparkEffect(MenuBallCenter[1], Color.YellowGreen, Color.SandyBrown);
                EffectsManager.MenuSparkEffect(MenuBallCenter[2], Color.Aqua, Color.Blue);
                EffectsManager.MenuSparkEffect(MenuBallCenter[3], Color.BurlyWood, Color.Brown);
                EffectsManager.MenuSparkEffect(MenuBallCenter[4], Color.WhiteSmoke, Color.LightGoldenrodYellow);
                EffectsManager.MenuSparkEffect(MenuBallCenter[5], Color.BlueViolet, Color.Blue);
            }


            if (elapsedTime < 2000 && swit)
            {
                elapsedTime += (float)gameTime.ElapsedGameTime.TotalMilliseconds;

                if (elapsedTime > 1900)
                {
                    swit = false;
                }
            }
            else if (elapsedTime > 0)
            {
                elapsedTime -= (float)gameTime.ElapsedGameTime.TotalMilliseconds;
                if (elapsedTime < 100)
                {
                    elapsedTime = 0;
                    swit        = true;
                }
            }
            shaderEffect.Parameters["BlurAmount"].SetValue(elapsedTime / 30000);
            shaderEffect.Parameters["Center"].SetValue(0.5f);
            shaderEffect.Parameters["Brightness"].SetValue(elapsedTime / 30000);

            if (Game1.currentState == Game1.States.menu)
            {
                if (InputHandler.KeyPressed(Keys.Up))
                {
                    mIndex--;
                    Game1.sound.playSound("MenuButtonClick");
                }
                else if (InputHandler.KeyPressed(Keys.Down))
                {
                    mIndex++;
                    Game1.sound.playSound("MenuButtonClick");
                }

                if (mIndex > 2)
                {
                    mIndex = 0;
                }
                else if (mIndex < 0)
                {
                    mIndex = 2;
                }


                if (InputHandler.KeyReleased(Keys.Enter))
                {
                    if (mIndex == 0)
                    {
                        Game1.sound.pauseSound("MainMenu");
                        Game1.currentState = Game1.States.arcade;
                        EffectsManager.ClearEffects();
                    }
                    else if (mIndex == 1)
                    {
                        Game1.sound.pauseSound("MainMenu");

                        Game1.currentState = Game1.States.instructions;
                        Game1.sound.playSound("PauseScreen");
                        //Game1.sound.pauseSound("Instruction");

                        EffectsManager.ClearEffects();
                    }
                    else
                    {
                        Game1.Exited = true;
                    }
                }
            }

            EffectsManager.Update(gameTime);
        }