Пример #1
0
 private void Shooting(Hero batman, Texture2D fireText)
 {
     Fire newLazerFire = new Fire(fireText);
     if (batman.right)
     {
         newLazerFire.Velocity = new Vector2(10f, 0);
     }
     else
         newLazerFire.Velocity = new Vector2(-10f, 0);
     newLazerFire.LazerPosition = batman.position;
     newLazerFire.isVisible = true;
     if (batman.batRangs > 0)
     {
         laserFires.Add(newLazerFire);
         batman.batRangs--;
     }
 }
Пример #2
0
        public void Update_level(Hero batman, GameTime gameTime, GraphicsDeviceManager graphics1, int clp, Texture2D fireText1, SoundEffect jump, SoundEffect knife, SoundEffect fight,SoundEffect run,SoundEffect enemy, SoundEffect livePlus, SoundEffect coin, int points1)
        {
            timer += gameTime.ElapsedGameTime;

             if (((batman.position.X <= (float)(scrolls[0].BackRect.X + (graphics1.PreferredBackBufferWidth * 2 / 6))) && (Keyboard.GetState().IsKeyDown(Keys.Left))) || (((batman.position.X >= (float)(scrolls[scrolls.Count - 1].BackRect.X + scrolls[scrolls.Count - 1].BackRect.X - (graphics1.PreferredBackBufferWidth * 2 / 6))) && (Keyboard.GetState().IsKeyDown(Keys.Right)))))
            {
                batman.velocity.X = 0f;
                batman.Update(gameTime, false, plats, graphics1.PreferredBackBufferHeight, graphics1.PreferredBackBufferWidth, jump, fight, run);
                foreach (Enemy evil in enemies)
                {
                    evil.Update(gameTime, 0, plats, graphics1.PreferredBackBufferHeight);
                }
            }
            else if ((batman.position.X >= ((float)(clp + (graphics1.PreferredBackBufferWidth * 4 / 6)))) && (Keyboard.GetState().IsKeyDown(Keys.Right)))
            {
                foreach (MainScroll back in scrolls)
                {
                    back.update(true, clp);
                }

                foreach (Platform plat in plats)
                {

                    plat.Update(true);
                }

                foreach (StaticObject  bonus in BonusLives)
                {
                    bonus.Update(1,graphics1,plats);
                }

                foreach (StaticObject coin1 in Coins)
                {
                    coin1.Update(1, graphics1, plats);
                }

                foreach (Enemy evil in enemies)
                {
                    evil.Update(gameTime, 1, plats, graphics1.PreferredBackBufferHeight);
                }

                batman.velocity.X = 0;
                batman.Update(gameTime, false, plats, graphics1.PreferredBackBufferHeight, graphics1.PreferredBackBufferWidth, jump, fight, run);

            }
            else if ((batman.position.X <= (float)(clp + (graphics1.PreferredBackBufferWidth * 1 / 6))) && (Keyboard.GetState().IsKeyDown(Keys.Left)))
            {
                foreach (MainScroll back in scrolls)
                {
                    back.update(false, clp);
                }
                foreach (Platform plat in plats)
                {
                    plat.Update(false);
                }
                foreach (StaticObject bonus in BonusLives)
                {
                    bonus.Update(2, graphics1, plats);
                }
                foreach (StaticObject coin1 in Coins)
                {
                    coin1.Update(2, graphics1, plats);
                }

                batman.velocity.X = 0;
                batman.Update(gameTime, false, plats, graphics1.PreferredBackBufferHeight, graphics1.PreferredBackBufferWidth, jump, fight, run);
                foreach (Enemy evil in enemies)
                {
                    evil.Update(gameTime, -1, plats, graphics1.PreferredBackBufferHeight);
                }
            }
            else
            {
                batman.Update(gameTime, true, plats, graphics1.PreferredBackBufferHeight, graphics1.PreferredBackBufferWidth, jump, fight, run);
                foreach (Enemy evil in enemies)
                {
                    evil.Update(gameTime, 0, plats, graphics1.PreferredBackBufferHeight);
                }

                foreach (StaticObject bonus in BonusLives)
                {
                    bonus.Update(0, graphics1, plats);
                }
                foreach (StaticObject coin1 in Coins)
                {
                    coin1.Update(0, graphics1, plats);
                }

            }
             if (Keyboard.GetState().IsKeyDown(Keys.Space) && State.IsKeyUp(Keys.Space))
            {
                Shooting(batman, fireText1);
                knife.Play();
            }
             State = Keyboard.GetState();

            UpdateLaser(batman);
            Fight(gameTime, batman);
            for (int k = 0; k < enemies.Count; k++)
            {
                if (enemies[k].live < 0)
                {
                    enemies.RemoveAt(k);
                    batman.batRangs += 5;
                    enemy.Play();
                }
            }

            for (int k = 0; k < BonusLives.Count; k++)
            {
                if (batman.heroRec.Intersects(BonusLives[k].BackRect))
                {
                    livePlus.Play();
                    BonusLives.RemoveAt(k);
                    batman.live += 10;
                }
            }

            for (int k = 0; k < Coins.Count; k++)
            {
                if (batman.heroRec.Intersects(Coins[k].BackRect))
                {
                    coin.Play();
                    Coins.RemoveAt(k);
                    batman.money++;
                }
            }
        }
Пример #3
0
 public void Fight(GameTime gameTime, Hero bat)
 {
     foreach (Enemy evil in enemies)
     {
         if (bat.heroRec.Intersects(evil.heroRec))
         {
             bat.live -= 1;
             if (Keyboard.GetState().IsKeyDown(Keys.F))
             {
                 evil.live -= 1;
             }
             bat.healthRec.Width = bat.live / 10;
         }
     }
 }
Пример #4
0
        public void UpdateLaser(Hero bats1)
        {
            foreach (Fire onelas in laserFires)
            {
                onelas.LazerPosition += onelas.Velocity;
                onelas.LazerRec = new Rectangle((int)onelas.LazerPosition.X, (int)onelas.LazerPosition.Y, onelas.LazerTexture.Width, onelas.LazerTexture.Height);
                if (Vector2.Distance(onelas.LazerPosition, bats1.position) > 300)
                    onelas.isVisible = false;
            }

            for (int i = 0; i < laserFires.Count; i++)
            {
                if (!laserFires[i].isVisible)
                {
                    laserFires.RemoveAt(i);
                }
            }

            foreach (Fire bullet in laserFires)
            {
                foreach (Enemy enemy in enemies)
                {
                    if (enemy.heroRec.Intersects(bullet.LazerRec))
                    {
                        enemy.live -= 20;
                        bullet.isVisible = false;
                    }
                }
            }
        }
Пример #5
0
        public void Draw_Level(Hero batman, GameTime gameTime, SpriteBatch spriteBatch,SpriteFont font, GraphicsDeviceManager graphics)
        {
            foreach (MainScroll sc in scrolls)
            {
                sc.Draw(spriteBatch);
            }

            foreach (Platform plat in plats)
            {
                plat.Draw(spriteBatch);
            }

            foreach (Enemy evil in enemies)
            {
                evil.Draw(spriteBatch);
            }

            foreach (Live livePlus in BonusLives)
            {
                livePlus.Draw(spriteBatch);
            }

            foreach (Coin c1 in Coins)
            {
                c1.Draw(spriteBatch);
            }

            batman.Draw(spriteBatch);

            foreach (Fire shot in laserFires)
            {
                shot.Draw(spriteBatch);
            }

            spriteBatch.DrawString(font, "Time: " +timer.Seconds + "." +timer.Milliseconds, new Vector2(graphics.PreferredBackBufferWidth/1.65f, 20), Color.White);
        }