public void LoadIcons(GraphicsDevice graphics, String bullet_icon, String enemy_icon, ContentManager content, Visualisation vis)
        {
            for (int i = 0; i < m_bullet_count; i++)
            {
                Graphics.Entity.Sprite new_bullet = new Graphics.Entity.Sprite();
                new_bullet.Init(content.Load <Texture2D>(bullet_icon));
                new_bullet.Visible     = false;
                new_bullet.destination = new Rectangle(
                    (int)((((float)graphics.Viewport.Width / 1366.0f) * 175.0f) + (((float)graphics.Viewport.Width / 1366.0f) * 15.0f * i)),
                    (int)(((float)graphics.Viewport.Height / 768.0f) * 714.0f),
                    (int)(((float)graphics.Viewport.Width / 1366.0f) * 15.0f),
                    (int)(((float)graphics.Viewport.Height / 768.0f) * 47.0f));
                m_bullets.Add(new_bullet);
                vis.AddEntity(new_bullet);
            }

            m_enemy_count = Enemy_Container.enemies().Count;
            for (int i = 0; i < m_enemy_count; i++)
            {
                Graphics.Entity.Sprite new_enemy = new Graphics.Entity.Sprite();
                new_enemy.Init(content.Load <Texture2D>(enemy_icon));
                new_enemy.Visible     = false;
                new_enemy.destination = new Rectangle(
                    (int)((((float)graphics.Viewport.Width / 1366.0f) * 171.0f) + (((float)graphics.Viewport.Width / 1366.0f) * 31.0f * i)),
                    (int)(((float)graphics.Viewport.Height / 768.0f) * 664.0f),
                    (int)(((float)graphics.Viewport.Width / 1366.0f) * 31.0f),
                    (int)(((float)graphics.Viewport.Height / 768.0f) * 34.0f));
                m_enemy.Add(new_enemy);
                vis.AddEntity(new_enemy);
            }
        }
 public void reset()
 {
     m_has_won      = false;
     m_lost         = false;
     m_enemy_count  = GamePlay.enemy_count;
     m_bullet_count = 13;
     m_last_shot    = 0.0f;
     Enemy_Container.reset();
 }
        public void show_hud(bool show)
        {
            m_sprite.Visible = show;

            if (GamePlay.difficulty != GameDifficulty.easy)
            {
                m_bullet_count = GamePlay.difficulty == GameDifficulty.hard ? 7 : 10;
            }

            for (int i = 0; i < m_bullet_count; i++)
            {
                m_bullets[i].Visible = show;
            }
            for (int i = 0; i < Enemy_Container.enemies().Count; i++)
            {
                m_enemy[i].Visible = show;
            }
        }
        public override void update(Visualisation vis, GameTime time, GraphicsDevice graphics, GameState gamestate)
        {
            if (!m_lost)
            {
                switch (gamestate)
                {
                case GameState.game:
#if DEBUG
                    if (Input.Down)
                    {
                        Camera.Move(new Vector3(0, 0, -4));
                    }
                    if (Input.Up)
                    {
                        Camera.Move(new Vector3(0, 0, 4));
                    }
                    if (Input.Left)
                    {
                        Camera.Move(new Vector3(-4, 0, 0));
                    }
                    if (Input.Right)
                    {
                        Camera.Move(new Vector3(4, 0, 0));
                    }
#endif
                    float offset = ((float)Math.Sin(time.TotalGameTime.TotalMilliseconds * 0.001f) * (0.0001f * (GamePlay.difficulty.GetHashCode() * 3)));
#if DEBUG
                    offset = 0.0f;
#endif
                    Camera.Turn(new Vector3((Input.Y * 0.01f) + offset, Input.X * 0.01f, 0.0f));

                    if (!m_has_won)
                    {
                        Camera.fov = Camera.fov + (Input.Zoom * -0.017f);
                    }
                    else
                    {
                        Camera.fov = (float)Math.PI / 3.0f;
                    }

                    m_debug_text.text = "Camera Position : " + Camera.position.ToString() +
                                        "\nCamera Rotation : " + Camera.rotation.ToString();

                    bool shot_fired = false;

                    if (Input.Fire && m_bullet_count > 0 &&
                        (float)time.TotalGameTime.TotalMilliseconds - m_last_shot > 2000.0f)
                    {
                        m_bullets[m_bullet_count - 1].Visible = false;
                        m_bullet_count--;
                        shot_fired  = true;
                        m_last_shot = (float)time.TotalGameTime.TotalMilliseconds;
                        m_gun_fire.Play();
                    }

                    List <Entity_Enemy> list = Enemy_Container.enemies();
                    for (int i = 0; i < list.Count; i++)
                    {
                        float?shot_ray = Camera.CastBulletRay(list[i], graphics);
                        if (shot_ray != null)
                        {
                            if (shot_fired && m_bullet_count > 0)
                            {
                                list[i].Kill();
                                m_enemy[m_enemy_count - 1].Visible = false;
                                m_enemy_count--;
                            }

                            m_debug_text.text += "\nEnemy Id : " + i
                                                 + "\nPosition : " + list[i].position
                                                 + "\nRotation : " + list[i].rotation;
                        }
                    }

                    if (m_enemy_count == 0)
                    {
                        m_has_won = true;
                    }

                    break;

                case GameState.menu:
                    offset          = ((float)Math.Sin(time.TotalGameTime.TotalMilliseconds * 0.0005f) * 0.1f);
                    Camera.rotation = new Vector3(-0.49f + offset, 0.34f, 0.0f);
                    break;
                }
            }
        }
Ejemplo n.º 5
0
        protected override void LoadContent()
        {
            m_song = Content.Load <Song>("FightForFreedoms");

            DebugHelp.Draw_BoundingBox.Init(Content.Load <Effect>("lines"), GraphicsDevice);

            m_vis.Init(GraphicsDevice);

            Enemy_Container.Init(m_world, Content);

            Graphics.Entity.Text debug_text = new Graphics.Entity.Text();
            debug_text.Init(Content.Load <SpriteFont>("default_font"));

            Graphics.Entity.Sprite hud = new Graphics.Entity.Sprite();
            hud.Init(Content.Load <Texture2D>("scope-hd"), GraphicsDevice.Viewport.Bounds);
            hud.Visible = false;
            m_player    = new Player(hud, debug_text, Content.Load <SoundEffect>("Fire"));
            m_world.AddEntity(m_player);
            m_player.LoadIcons(GraphicsDevice, "Bullet-Icon", "Enemy-Icon", Content, m_vis);

            List <Entity_Explosion> explosions_list = new List <Entity_Explosion>();

            for (int i = 0; i < 4; i++)
            {
                Graphics.Entity.Billboard explosion_model = new Graphics.Entity.Billboard();
                explosion_model.Init(Content.Load <Model>("Explosion"),
                                     Content.Load <Effect>("EffectBillboard"),
                                     Content.Load <Texture2D>("explosion_texture"));
                Entity_Explosion explosion = new Entity_Explosion(explosion_model);
                m_world.AddEntity(explosion);
                explosions_list.Add(explosion);
            }

            List <SoundEffect> explosion_sound = new List <SoundEffect>();

            for (int i = 0; i < 3; i++)
            {
                SoundEffect new_explosion_sound = Content.Load <SoundEffect>("explode_" + (i + 1));
                explosion_sound.Add(new_explosion_sound);
            }

            BasicEffect city_effect = new BasicEffect(GraphicsDevice);

            city_effect.FogEnabled    = true;
            city_effect.FogColor      = new Vector3(0.6f, 0.6f, 0.6f);
            city_effect.FogStart      = 0.0f;
            city_effect.FogEnd        = 2000.0f;
            city_effect.SpecularPower = 10000000.0f;

            Graphics.Entity.Model city = new Graphics.Entity.Model();
            city.Init(Content.Load <Model>("city/city"));
            city.basiceffect = city_effect;
            m_city           = new Entity_City(city, explosions_list, explosion_sound);
            m_world.AddEntity(m_city);

            Graphics.Entity.SkyBox skybox = new Graphics.Entity.SkyBox();
            skybox.Init(Content.Load <Model>("skybox/skysphere"),
                        Content.Load <Effect>("skybox/skybox_fx"),
                        Content.Load <TextureCube>("skybox/skytexture"));
            m_skybox = new Entity_SkyBox(skybox);
            m_world.AddEntity(m_skybox);

            //Menu

            m_menu.Init(Content, m_vis, m_world, GraphicsDevice);

            //Fonts

            m_ingame_text = new Graphics.Entity.Text();
            m_ingame_text.Init(Content.Load <SpriteFont>("InGameFont"));
            m_ingame_text.text     = "Shoot All The Terrorists Before They Set The Bombs Off...";
            m_ingame_text.Visible  = false;
            m_ingame_text.position = new Vector2((GraphicsDevice.Viewport.Width * 0.5f) -
                                                 m_ingame_text.font.MeasureString(m_ingame_text.text).X * 0.5f,
                                                 0.0f);
            m_vis.AddEntity(m_ingame_text);

            m_clock_text = new Graphics.Entity.Text();
            m_clock_text.Init(Content.Load <SpriteFont>("InGameFont"), "00:00:60");
            m_clock_text.Visible  = false;
            m_clock_text.position = new Vector2(
                (((float)GraphicsDevice.Viewport.Width / 1366.0f) * 1024.0f),
                (((float)GraphicsDevice.Viewport.Height / 768.0f) * 690.0f));
            m_vis.AddEntity(m_clock_text);

            m_clock_tick = Content.Load <SoundEffect>("clockTick");

            m_black_screen = new Graphics.Entity.Sprite();
            m_black_screen.Init(Content.Load <Texture2D>("blackPixel"),
                                new Rectangle(0, 0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height));
            m_black_screen.Visible = false;
            m_vis.AddEntity(m_black_screen);

            //play audio
            MediaPlayer.Volume = 0.5f;
            MediaPlayer.Play(m_song);
            MediaPlayer.IsRepeating = true;

#if DEBUG
            m_vis.AddEntity(debug_text);
#endif
        }