Example #1
0
        private void Collision_check()
        {
            //Collision: Enemy with base
            foreach (Enemy e in enemies)
            {
                if (e.curve_pos >= (5000))
                {
                    e.curve_pos = path.beginT;
                    p_manager = new Particle_Manager(Game1.p_textures, e.pos);
                    p_manager_life_length = 25;
                    ui.base_hp -= 1;
                }

            }

            //Collision: Bullet with enemy
            for (int i = 0; i < interactive_towers.Count; i++)
            {
                go_bullets = interactive_towers[i].Get_bullets();

                for (int j = 0; j < go_bullets.Count; j++)
                {
                    for (int k = 0; k < enemies.Count; k++)
                    {
                        if (go_bullets[j].hit_box.Intersects(enemies[k].hit_box))
                        {
                            enemies[k].enemy_health--;
                            go_bullets.RemoveAt(j);
                            break;
                        }

                    }
                }

            }
        }
Example #2
0
        public void Update(RenderTarget2D layer)
        {
            enemy_interval--;

            p_manager_life_length--;

            //Calls methods
            if (!enemy_wave_start)
            {
                Create_tower();
            }
            Collision_check();

            //Makes enemies begin to walk along the path when enter button is hit and towers placed are >= 1:
            if (Keyboard.GetState().IsKeyDown(Keys.Enter) && tower_placed_amount >= 1 && !enemy_wave_start)
            {
                enemy_wave_start = true;
            }

            //Checks if towers are dropped/placed, if enemies are >= 1 and if bullet timer <= 0. If so create bullets:
            if (!tower_is_picked_up && tower_dropped && enemy_wave_start && enemy_amount >= 1)
            {
                foreach (Tower i in interactive_towers)
                {
                    i.Create_bullet();
                    i.Update();
                }
            }

            //Creates an enemy if enter was hit and enemy amount is less than 10
            if (enemy_interval <= 0 && enemy_wave_start && !enemy_wave_full)
            {
                Create_enemy();
            }
            if (enemy_amount == 10)
            {
                enemy_wave_full = true;
            }

            //Calls Enemy class's get_path, which makes it move along the curve
            foreach (Enemy e in enemies)
            {
                e.get_path(path);

            }

            //Checks if enemy health is <= 0 and remove it from the list if so
            for (int i = 0; i < enemies.Count; i++)
            {
                if (enemies[i].enemy_health <= 0)
                {
                    p_manager = new Particle_Manager(Game1.p_textures, enemies[i].pos);
                    p_manager_life_length = 25;
                    Game1.explosion.Play();
                    enemies.RemoveAt(i);
                    ui.enemies_killed++;
                    ui.score += 10;
                    ui.gold += 10;
                    enemy_amount--;
                    break;
                }
            }

            //Checks if 10 enemies are killed. If so, proceed to next level
            if (ui.enemies_killed == 10 && tower_placed_amount > 0 && Game1.current_state == Game1.Game_state.level1)
            {
                enemies.Clear();
                Game1.current_state = Game1.Game_state.level2;
                ui.level++;
                interactive_towers.Clear();
                enemy_wave_start = false;
                enemy_wave_full = false;
                ui.enemies_killed = 0;
                enemy_amount = 0;
                tower_placed_amount = 0;
                graphics.SetRenderTarget(null);
                Draw_rendertarget();

            }

            if (ui.enemies_killed >= 10 && tower_placed_amount > 0 && Game1.current_state == Game1.Game_state.level2)
            {
                enemies.Clear();
                Game1.current_state = Game1.Game_state.level3;
                ui.level++;
                interactive_towers.Clear();
                enemy_wave_start = false;
                enemy_wave_full = false;
                ui.enemies_killed = 0;
                enemy_amount = 0;
                tower_placed_amount = 0;
                graphics.SetRenderTarget(null);
                Draw_rendertarget();

            }

            if (ui.enemies_killed >= 10 && tower_placed_amount > 0 && Game1.current_state == Game1.Game_state.level3)
            {
                enemies.Clear();
                Game1.current_state = Game1.Game_state.winning;
                interactive_towers.Clear();
                enemy_wave_start = false;
                enemy_wave_full = false;
                ui.enemies_killed = 0;
                enemy_amount = 0;
                tower_placed_amount = 0;
            }

            //Change to Game Over state if base HP <= 0
            if (ui.base_hp <= 0)
            {
                Game1.current_state = Game1.Game_state.game_over;
                enemies.Clear();
                interactive_towers.Clear();
            }

            //Update instances
            foreach (Tower i in interactive_towers)
            {
                i.Update();
            }
            foreach (Tower mt in menu_towers)
            {
                mt.Update();
            }
            foreach (Enemy e in enemies)
            {
                e.Update();
            }
            if (p_manager != null)
            {
                p_manager.Update();
            }
            ui.Update();
            old_mouse = mouse;
        }