Beispiel #1
0
        public PlayingState()
        {
            background      = new SpriteGameObject("spr_background");
            player          = new Player();
            player.Position = new Vector2(235, 500);
            snake           = new GameObjectList();
            mushrooms       = new GameObjectList();
            bullets         = new GameObjectList();
            score           = new Score();

            for (int i = 0; i < 10; i++)
            {
                newSnakeSegment = new SnakeSegment(new Vector2(i * 32, 0));
                snake.Add(newSnakeSegment);
            }

            for (int i = 0; i < 20; i++)
            {
                newMushroom = new Mushroom();
                mushrooms.Add(newMushroom);
            }



            this.Add(background);
            this.Add(player);
            this.Add(snake);
            this.Add(mushrooms);
            this.Add(bullets);
            this.Add(score);
        }
Beispiel #2
0
        public void mushroomInit()
        {
            for (int x = 0; x < mushrooms.GetLength(0); x++)
            {
                for (int y = 0; y < mushrooms.GetLength(0); y++)
                {
                    mushrooms[x, y] = new Mushroom(new Rectangle(x * 20, y * 20 + 40, 20, 20), backgroundColor);
                }
            }
            while (checkArray() < id * 10)
            {
                bool check = false;
                int  x     = Globals.rng.Next(30);
                int  y     = Globals.rng.Next(30);
                if (x - 1 >= 0)
                {
                    if (y - 1 >= 0)
                    {
                        if (mushrooms[x - 1, y - 1].visible == true)
                        {
                            check = true;
                        }
                    }
                    if (y + 1 < mushrooms.GetLength(0))
                    {
                        if (mushrooms[x - 1, y + 1].visible == true)
                        {
                            check = true;
                        }
                    }
                }

                if (x + 1 < mushrooms.GetLength(0))
                {
                    if (y - 1 >= 0)
                    {
                        if (mushrooms[x + 1, y - 1].visible == true)
                        {
                            check = true;
                        }
                    }
                    if (y + 1 < mushrooms.GetLength(0))
                    {
                        if (mushrooms[x + 1, y + 1].visible == true)
                        {
                            check = true;
                        }
                    }
                }
                if (check == false)
                {
                    mushrooms[x, y].generate();
                }
            }
        }
Beispiel #3
0
        public MushroomGrid(SpriteBatch spriteBatch, Mushroom mushroom)
        {
            mushrooms = new List <Mushroom>();

            for (int count = 0; count < 50; count++)
            {
                int x, y;
                x = random.Next(30);
                y = random.Next(2, 28);
                Mushroom m = new Mushroom(spriteBatch, mushroom.Texture, mushroom.SpriteWidth, mushroom.SpriteHeight,
                                          new Vector2(x * mushroom.SpriteWidth, y * mushroom.SpriteHeight));
                mushrooms.Add(m);
            }
        }
Beispiel #4
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
            MushField = new Mushroom[30, 30];
            for (int x = 0; x < MushField.Length; x++)
            {
                for (int y = 0; y < MushField.Length; y++)
                {
                    MushField[x, y] = new Mushroom(x * 20, y * 20 + 40);
                }
            }


            base.Initialize();
        }
Beispiel #5
0
        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);

            foreach (SnakeSegment s in snake.Objects)
            {
                foreach (Mushroom m in mushrooms.Objects)
                {
                    if (s.CollidesWith(m) && s.Visible)
                    {
                        s.bounce();
                    }
                }

                foreach (Bullet b in bullets.Objects)
                {
                    if (b.CollidesWith(s) && s.Visible)
                    {
                        bullet.Reset();
                        s.Visible            = false;
                        newMushroom          = new Mushroom();
                        newMushroom.Position = s.Position;
                        mushrooms.Add(newMushroom);
                        score.score += 10;
                    }
                }

                if (s.CollidesWith(player))
                {
                    Centipede.GameStateManager.SwitchTo("GameOverGameState");
                }
            }

            foreach (Bullet b in bullets.Objects)
            {
                foreach (Mushroom m in mushrooms.Objects)
                {
                    if (b.CollidesWith(m) && m.Visible)
                    {
                        bullet.Reset();
                        m.Visible = false;
                    }
                }
            }
        }
Beispiel #6
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // create a new SpriteBatch, which can be used to draw textures
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // load sprites
            pointSprite    = Content.Load <Texture2D>(@"graphics\point");
            bulletSprite   = Content.Load <Texture2D>(@"graphics\bullet");
            playerSprite   = Content.Load <Texture2D>(@"graphics\player");
            mushroomSprite = Content.Load <Texture2D>(@"graphics\mushroom");
            scoreSprite    = Content.Load <Texture2D>(@"graphics\score");
            wurmHead       = Content.Load <Texture2D>(@"graphics\head2");

            // add initial game objects
            player = new Player(spriteBatch, playerSprite, 24, 24,
                                new Vector2(GameConstants.WindowWidth / 2 - 12, GameConstants.WindowHeight - 12));

            wurmheads.Add(new Wurmhead(spriteBatch, wurmHead, 24, 24, new Vector2(random.Next(0, 31) * 24, 24), random.Next(1, 8)));
            mushroom     = new Mushroom(spriteBatch, mushroomSprite, 24, 24, Vector2.Zero);
            mushroomGrid = new MushroomGrid(spriteBatch, mushroom);
            score        = new Score(spriteBatch, scoreSprite, 21, 21, Vector2.Zero);

            Mouse.SetPosition(player.Rectangle.Center.X, player.Rectangle.Center.Y);
        }