示例#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)));
        }
    }
示例#2
0
    public override void Draw(GameTime gameTime, SpriteBatch spriteBatch)
    {
        //Draw the background
        //DrawRectangleFilled(new Rectangle(new Point(SCREEN_SIZE.X - OVERLAY_SIZE.X, 0), new Point(OVERLAY_SIZE.X, SCREEN_SIZE.Y)), spriteBatch, Color.Black, 0.4f);
        spriteBatch.Draw(SPR_OVERLAY, new Rectangle(new Point(0, SCREEN_SIZE.Y - OVERLAY_SIZE.Y - 24), new Point(SCREEN_SIZE.X, OVERLAY_SIZE.Y + 24)), Color.White);
        //DrawRectangleFilled(new Rectangle(new Point(20, SCREEN_SIZE.Y - OVERLAY_SIZE.Y), new Point(SCREEN_SIZE.X-45, OVERLAY_SIZE.Y-20)), spriteBatch, Color.DarkGray, 1f);
        if (selected != null)
        {
            if (node != null)
            {
                spriteBatch.Draw(SPR_CIRCLE, (node.GlobalPosition + new Vector2(NODE_SIZE.X / 2, 0)) * Camera.scale, null, null, new Vector2(SPR_CIRCLE.Width / 2, SPR_CIRCLE.Height / 2), 0f, Camera.scale * new Vector2(1f, 0.5f) * ((float)selected.range) / ((float)SPR_CIRCLE.Width / 2), new Color(0.2f, 0.2f, 0.2f, 0.05f));                              // draw the range indicator
                spriteBatch.Draw(selected.sprite, (node.GlobalPosition + new Vector2(NODE_SIZE.X / 2, 0)) * Camera.scale, null, null, new Vector2(selected.sprite.Width, selected.sprite.Height) / 2, 0f, Camera.scale, new Color(255, 255 * selectedPossible.ToInt(), 255 * selectedPossible.ToInt(), selectedPossible.ToInt() + 0.5f), SpriteEffects.None, 0); //Draw the selected object at the mouse
            }
        }

        //draw gamestats
        spriteBatch.Draw(ICON_WAVE, new Rectangle(new Point(5, 9), new Point(40, 28)), Color.White);
        DrawText(spriteBatch, FNT_GAMESTATS, "Wave " + Wave.ToString(), new Vector2(55, 7), Color.White);

        spriteBatch.Draw(ICON_KILLS, new Rectangle(new Point(3, 52), new Point(40, 50)), Color.White);
        DrawText(spriteBatch, FNT_GAMESTATS, TotalEnemiesKilled.ToString(), new Vector2(55, 62), Color.White);

        spriteBatch.Draw(ICON_COINS, new Rectangle(new Point(3, 113), new Point(40, 50)), Color.White);
        DrawText(spriteBatch, FNT_GAMESTATS, EcResources.ToString(), new Vector2(55, 114), Color.White);

        spriteBatch.Draw(ICON_LIFE, new Rectangle(new Point(3, 174), new Point(40, 40)), Color.White);
        DrawText(spriteBatch, FNT_GAMESTATS, BaseHealth.ToString() + "/" + MaxBaseHealth.ToString(), new Vector2(55, 170), Color.White);

        //
        //DrawGrid(spriteBatch);

        //Draw the WaveTime
        if (!GameStats.InWave)
        {
            DrawText(spriteBatch, FNT_MENU, "Next wave in: " + (int)(GameStats.WaveTimer / 60), GAME_WINDOW_SIZE.toVector() / 2, Color.White, true);
            DrawText(spriteBatch, FNT_MENU, "Press enter to call wave early", GAME_WINDOW_SIZE.toVector() / 2 + new Vector2(0, 50), Color.White, true);
        }

        base.Draw(gameTime, spriteBatch);
    }
示例#3
0
    public override void HandleInput(InputHelper inputHelper)
    {
        if (inputHelper.MouseLeftButtonDown())
        {
            Vector2 mp = inputHelper.MousePosition;
            {
                if (mp.X > overlayPosition.X && mp.X < overlayPosition.X + minimapSize.X &&
                    mp.Y > overlayPosition.Y && mp.Y < overlayPosition.Y + minimapSize.Y)
                {
                    //Console.WriteLine(new Vector2((mp.X - overlayPosition.X) / minimapSize.X * NODE_SIZE.X * LEVEL_SIZE.X, (mp.Y - overlayPosition.Y) / minimapSize.Y * NODE_SIZE.Y * LEVEL_SIZE.Y));
                    GameWorld.FindByType <Camera>()[0].Position = -new Vector2((mp.X - overlayPosition.X) / minimapSize.X * NODE_SIZE.X * LEVEL_SIZE.X, (mp.Y - overlayPosition.Y) / minimapSize.Y * NODE_SIZE.Y * LEVEL_SIZE.Y / 2) + GAME_WINDOW_SIZE.toVector() / 2 / CameraScale;
                    //Make sure the camera doesn't move out of bounds
                    if (position.X > -NODE_SIZE.X / 2 - GridNode.origin.X / 2)
                    {
                        position.X = -NODE_SIZE.X / 2 - GridNode.origin.X / 2;
                    }
                    if (position.Y > -NODE_SIZE.Y / 2 - GridNode.origin.Y)
                    {
                        position.Y = -NODE_SIZE.Y / 2 - GridNode.origin.Y;
                    }

                    if (position.X < -NODE_SIZE.X * LEVEL_SIZE.X + GAME_WINDOW_SIZE.X / CameraScale.X)
                    {
                        position.X = -NODE_SIZE.X * LEVEL_SIZE.X + GAME_WINDOW_SIZE.X / CameraScale.X;
                    }
                    if (position.Y < -NODE_SIZE.Y / 2 * LEVEL_SIZE.Y + GAME_WINDOW_SIZE.Y / CameraScale.Y)
                    {
                        position.Y = -NODE_SIZE.Y / 2 * LEVEL_SIZE.Y + GAME_WINDOW_SIZE.Y / CameraScale.Y;
                    }
                }
            }
        }
        base.HandleInput(inputHelper);
    }
示例#4
0
    public override void HandleInput(InputHelper inputHelper)
    {
        if (inputHelper.CurrentPressedKeys().ToList().Contains(Keys.D) && inputHelper.CurrentPressedKeys().ToList().Contains(Keys.LeftShift))
        {
            GameEnvironment.GameStateManager.AddGameState("GameOverState", new GameOverState());
            GameEnvironment.GameStateManager.SwitchTo("GameOverState");
        }
        if (inputHelper.IsKeyDown(Keys.LeftShift) && inputHelper.IsKeyDown(Keys.H))
        {
            if (inputHelper.IsKeyDown(Keys.W))
            {
                GameStats.Wave++;
            }
            if (inputHelper.IsKeyDown(Keys.D))
            {
                GameStats.Wave++;
            }
            if (inputHelper.IsKeyDown(Keys.R))
            {
                GameStats.EcResources += 10;
            }
            if (inputHelper.IsKeyDown(Keys.L))
            {
                GameStats.BaseHealth += 2;
            }
        }

        //zoom
        Vector2 oldScale = scale;

        if (inputHelper.ScrollUp())
        {
            if (scale.X < 1f)
            {
                scale *= new Vector2(1.07f);
            }
        }
        if (inputHelper.ScrollDown())
        {
            if ((LEVEL_SIZE.X * NODE_SIZE.X * scale.X > GAME_WINDOW_SIZE.X + 96))
            {
                scale *= new Vector2(1 / 1.07f);
            }
        }
        if (inputHelper.IsKeyDown(Keys.Q))
        {
            if (scale.X < 1f)
            {
                scale *= new Vector2(1.02f);
            }
        }
        if (inputHelper.IsKeyDown(Keys.A))
        {
            if ((LEVEL_SIZE.X * NODE_SIZE.X * scale.X > GAME_WINDOW_SIZE.X + 96))
            {
                scale *= new Vector2(1 / 1.02f);
            }
        }
        Vector2 dScale = scale - oldScale;

        position -= (position + (SCREEN_SIZE.toVector())) * dScale / oldScale;
        //Focus on base
        if (inputHelper.IsKeyDown(Keys.Space))
        {
            position += (-position - LEVEL_CENTER * scale + scale * GAME_WINDOW_SIZE.toVector() / 2) / 22;
        }
        //Manually handle the input of the active plane
        currentPlane.HandleInput(inputHelper);

        //Camera Movement
        Vector2 mp  = inputHelper.MousePosition;
        float   spd = SLIDE_SPEED / scale.X;

        if (mp.X < SLIDE_BORDER)
        {
            position.X += spd;
        }
        if (mp.X > SCREEN_SIZE.X - SLIDE_BORDER)
        {
            position.X -= spd;
        }
        if (mp.Y < SLIDE_BORDER)
        {
            position.Y += spd;
        }
        if (mp.Y > SCREEN_SIZE.Y - SLIDE_BORDER)
        {
            position.Y -= spd;
        }

        //Make sure the camera doesn't move out of bounds
        if (position.X > -NODE_SIZE.X / 2 - GridNode.origin.X / 2)
        {
            position.X = -NODE_SIZE.X / 2 - GridNode.origin.X / 2;
        }
        if (position.Y > -NODE_SIZE.Y / 2 - GridNode.origin.Y)
        {
            position.Y = -NODE_SIZE.Y / 2 - GridNode.origin.Y;
        }

        if (position.X < -NODE_SIZE.X * LEVEL_SIZE.X + GAME_WINDOW_SIZE.X / scale.X)
        {
            position.X = -NODE_SIZE.X * LEVEL_SIZE.X + GAME_WINDOW_SIZE.X / scale.X;
        }
        if (position.Y < -NODE_SIZE.Y / 2 * LEVEL_SIZE.Y + GAME_WINDOW_SIZE.Y / scale.Y)
        {
            position.Y = -NODE_SIZE.Y / 2 * LEVEL_SIZE.Y + GAME_WINDOW_SIZE.Y / scale.Y;
        }

        base.HandleInput(inputHelper);
    }