Exemplo n.º 1
0
        private void Create_tower()
        {
            mouse = Mouse.GetState();
            mouse_point = new Point(mouse.X, mouse.Y);

            //Checks when you can pick a tower from the menu
            if (Game1.current_state != Game1.Game_state.title || Game1.current_state != Game1.Game_state.help || Game1.current_state != Game1.Game_state.game_over)
            {

                //Creates tower type 1
                if (menu_tower1.hit_box.Contains(mouse_point) && mouse.LeftButton == ButtonState.Pressed && old_mouse.LeftButton == ButtonState.Released
                    && ui.gold >= 10 && !tower_is_picked_up && !enemy_wave_start)
                {
                    interactive_tower = new Tower(sheet_tex, new Vector2(mouse.X, mouse.Y), new Rectangle(0, 0, 45, 70));
                    interactive_tower.tower_state = Tower.Tower_state.tower1;
                    interactive_towers.Add(interactive_tower);
                    tower_is_picked_up = true;
                    ui.gold -= 10;

                }

                //Creates tower type 2
                else if (menu_tower2.hit_box.Contains(mouse_point) && mouse.LeftButton == ButtonState.Pressed && old_mouse.LeftButton == ButtonState.Released
                    && ui.gold >= 30 && !tower_is_picked_up && !enemy_wave_start)
                {
                    interactive_tower = new Tower(sheet_tex, new Vector2(mouse.X, mouse.Y), new Rectangle(45, 0, 45, 70));
                    interactive_tower.tower_state = Tower.Tower_state.tower2;
                    interactive_towers.Add(interactive_tower);
                    tower_is_picked_up = true;
                    ui.gold -= 30;
                }

                ////Creates tower type 3
                else if (menu_tower3.hit_box.Contains(mouse_point) && mouse.LeftButton == ButtonState.Pressed && old_mouse.LeftButton == ButtonState.Released
                    && ui.gold >= 50 && !tower_is_picked_up && !enemy_wave_start)
                {
                    interactive_tower = new Tower(sheet_tex, new Vector2(mouse.X, mouse.Y), new Rectangle(90, 0, 45, 70));
                    interactive_tower.tower_state = Tower.Tower_state.tower3;
                    interactive_towers.Add(interactive_tower);
                    tower_is_picked_up = true;
                    ui.gold -= 50;
                }

               //Checks where you can place towers

                else if (mouse.LeftButton == ButtonState.Pressed && old_mouse.LeftButton == ButtonState.Released &&
                             mouse.X < 1025 && tower_is_picked_up && Can_place(layer, interactive_tower))
                {
                    if (mouse.X > 0 && mouse.X < 1180 && mouse.Y > 10 && mouse.Y < 650)
                    {

                        interactive_tower.Set_position(new Vector2(mouse.X, mouse.Y));
                        tower_is_picked_up = false;
                        tower_dropped = true;
                        tower_placed_amount++;
                        Draw_rendertarget();

                    }
                }

                //Updates picked up towers to the position of the cursor
                if (tower_is_picked_up)
                {
                    interactive_tower.Set_position(new Vector2(mouse.X, mouse.Y));
                }

            }
            old_mouse = mouse;
        }
Exemplo n.º 2
0
        public bool Can_place(RenderTarget2D layer, Tower t)
        {
            Color[] towerPixels = new Color[t.src_rect.Width * t.src_rect.Height];
                Color[] layerPixels = new Color[t.src_rect.Width * t.src_rect.Height];
                t.sheet_tex.GetData(0, t.src_rect, towerPixels, 0, towerPixels.Length);

                if (mouse.X > 0 && mouse.X < 1220 && mouse.Y > 0 && mouse.Y < 650)
                {
                    layer.GetData(0, t.Get_hit_box(), layerPixels, 0, layerPixels.Length);
                }

                for (int i = 0; i < towerPixels.Length; ++i)
                {
                    if (towerPixels[i].A > 0.0 && layerPixels[i].A > 0.0)
                        return false;
                }
                return true;
        }
Exemplo n.º 3
0
        private void Create_level()
        {
            //Creates lists
            enemies = new List<Enemy>();
            menu_towers = new List<Tower>();
            interactive_towers = new List<Tower>();

            //Sets int and float values
            enemy_amount = 0;
            tower_placed_amount = 0;
            enemy_interval = 100;

            //Creates instances
            menu_tower1 = new Tower(sheet_tex, new Vector2(1080, 50), new Rectangle(0, 0, 45, 70));
            menu_tower2 = new Tower(sheet_tex, new Vector2(1123, 50), new Rectangle(45, 0, 45, 70));
            menu_tower3 = new Tower(sheet_tex, new Vector2(1167, 50), new Rectangle(90, 0, 45, 70));
            path = new SimplePath(graphics);
            layer = new RenderTarget2D(graphics, 1220, 720);
            menu_towers.Add(menu_tower1);
            menu_towers.Add(menu_tower2);
            menu_towers.Add(menu_tower3);

            //Creates steamreader
            sr = new StreamReader("Level1.txt");

            path.Clean();

            //Reads and creates spline points from text file
            while (!sr.EndOfStream)
            {
                string s = sr.ReadLine();
                int x = int.Parse(s.Split(',')[0]);
                int y = int.Parse(s.Split(',')[1]);
                path.AddPoint(new Vector2(x, y));
            }

            Draw_rendertarget();
        }