Exemple #1
0
    public Camera() : base()
    {
        position = -LEVEL_CENTER + GAME_WINDOW_SIZE.toVector() / 2;
        scale    = new Vector2(1f);
        planes   = new List <GridPlane>();
        for (int i = 0; i < 1; ++i)
        {
            GridPlane p = new GridPlane((Plane)i);
            p.active = false;
            Add(p);
            switch ((Plane)i)
            {
            case Plane.Land:
                Land = p;
                planes.Add(Land);
                //Add items to the land plane (p.Add)
                p.Add(new Base {
                    Position = LEVEL_CENTER
                });
                //p.Add(new ParticleController());
                break;
            }
        }
        currentPlane = planes[(int)Plane.Land]; //Reference the current plane to one of the three
        Console.WriteLine("Current Plane: " + currentPlane.planeType.ToString());
        LevelGenerator levelGenerator = new LevelGenerator();
        List <int[, ]> list           = new List <int[, ]>();

        list = levelGenerator.GenerateNewLevel();
        for (int x = 0; x < LEVEL_SIZE.X; ++x)
        {
            for (int y = 0; y < LEVEL_SIZE.Y; ++y)
            {
                int tex = list[0][x, y];
                if (tex == 2) //Mountain
                {
                    tex = Functions.choose(new List <int> {
                        2, 7, 8
                    });
                }
                if (tex == 5)
                {
                    tex = Functions.choose(new List <int> {
                        5, 9
                    });
                }
                Land.grid[x, y].texture = tex;
            }
        }
        currentPlane.Add(new EnemySpawner(currentPlane)); // The grid must be finished

        for (int i = 1; i <= 5; i += 2)
        {
            currentPlane.Add(new Clouds(new Vector2(-1500 / i, SCREEN_SIZE.Y + 1800 / i)));
        }
    }
Exemple #2
0
    public override void HandleInput(InputHelper inputHelper)
    {
        base.HandleInput(inputHelper);
        mousePos = inputHelper.MousePosition;

        plane = GameWorld.FindByType <Camera>()[0].currentPlane;
        node  = plane.NodeAt(mousePos / Camera.scale, false);
        if (previousNode != node)
        {
            if (previousNode != null)
            {
                previousNode.selected = false;
            }
            previousNode = node;
        }

        if (node == null)
        {
            return;
        }
        else
        {
            node.selected = true;
        }

        selectedPossible = !node.solid && node.available && inputHelper.MouseInGameWindow;

        if (inputHelper.MouseLeftButtonPressed() &&
            inputHelper.MouseInGameWindow &&
            selected != null &&
            selectedPossible)
        {
            Type       t    = Type.GetType(selected.itemType);              //Get the type of the object
            object     temp = Activator.CreateInstance(t);                  //Create an instance of that object
            GameObject obj  = temp as GameObject;                           //Cast it as a GameObject
            obj.Position = node.Position + new Vector2(NODE_SIZE.X / 2, 0); //Adjust the position to the middle of the GridNode
            if (selected.itemType.Equals("ResourceTower") && GameWorld.FindByType <ResourceTower>().Count > 2)
            {
                selected = null;
                return;
            }
            plane.Add(obj);                                        //Add it to the hierarchy
            obj.MyParticleControl.AddTowerBuildGlow(obj.Position); //Add particle effect
            EcResources -= selected.cost;                          //Subtract its cost from the resources
            PlaySound(SND_TOWERPLACE);

            if (!inputHelper.IsKeyDown(Keys.LeftShift) || selected.cost > EcResources) //allow shift-clicking multiple towers
            {
                selected = null;                                                       //Reset the selected object reference
            }
        }

        //Cancel the current selection with X or right click
        if (inputHelper.KeyPressed(Keys.X) && selected != null || inputHelper.MouseRightButtonPressed() && selected != null)
        {
            selected = null;
        }
    }
Exemple #3
0
    public override void Update(object gameTime)
    {
        base.Update(gameTime);
        if (GameStats.InWave)
        {
            if (RANDOM.Next(50) == 0 && resources > 0)
            {
                double   type_a = Math.Sqrt(Math.Min(LIST_ENEMIES.Count, (int)(GameStats.Wave / 3)));
                double   type_b = Math.Sqrt(Math.Min(LIST_ENEMIES.Count, (int)(GameStats.Wave / 3)));
                string   eType  = LIST_ENEMIES[RANDOM.Next((int)(type_a * type_b))];
                Type     t      = Type.GetType(eType);         //Get the type of the object
                object   temp   = Activator.CreateInstance(t); //Create an instance of that object
                Enemy    obj    = temp as Enemy;               //Cast it as an Enemy
                GridNode node   = available[RANDOM.Next(available.Count)];

                obj.startNode = node;
                obj.Position  = node.Position;
                plane.Add(obj);
                resources -= obj.cost;
            }

            bool         AllDeath = true;
            List <Enemy> list     = plane.FindByType <Enemy>();
            foreach (Enemy e in list)
            {
                if (!e.kill)
                {
                    AllDeath = false;
                    break;
                }
            }
            if (AllDeath && GameStats.InWave && resources <= 0)
            {
                GameStats.InWave    = false;
                GameStats.WaveTimer = 10 * 60;
            }
        }

        if (!GameStats.InWave && GameStats.WaveTimer > 0)
        {
            GameStats.WaveTimer--;
            if (GameStats.WaveTimer <= 0)
            {
                GameStats.InWave = true;
                int x = GameStats.Wave++;

                resources = (int)(500 + 2 * Math.Pow(x, (Math.Sqrt(x / 100) + 1)) + 400 * (float)Math.Sqrt(x));
            }
        }
    }