Пример #1
0
        public override void Update(float delta)
        {
            Tower s = Game.PlayArea.CurrentlySelected;

            if (s != null && AKS.WasJustPressed(Mouse.Button.Left))
            {
                // check if upgrade clicked //
                RectangleShape r = new RectangleShape(_upgradeBackground);
                r.Position += _renderSprite.Position;

                if (Utils.PointIsInRect(Game.MousePosition, r))
                {
                    Game.TryUpgradeTower(s);
                }

                // check if sell clicked //
                r           = new RectangleShape(_sellBackground);
                r.Position += _renderSprite.Position;

                if (Utils.PointIsInRect(Game.MousePosition, r))
                {
                    Game.RemoveTower(s);
                    Game.Money += s.Worth;
                    Game.PlayArea.CurrentlySelected = null;
                }
            }
        }
Пример #2
0
 public void Update(float delta)
 {
     if (AKS.WasJustPressed(Mouse.Button.Left) && Utils.PointIsInRect(Game.MousePosition, _startBackground))
     {
         ReadyToStart = true;
     }
 }
        public override void Update(float delta)
        {
            int      i        = 0;
            Vector2f mousePos = Utils.Snap2Grid(Game.MousePosition);

            CurrentlyHovered = null;

            foreach (Tower tower in Allowed)
            {
                float    x        = i % SizeTiles.X * Game.TileSize + Game.TileSize / 2;
                float    y        = (i / SizeTiles.X) * Game.TileSize + Game.TileSize / 2;
                Vector2f towerPos = Position + new Vector2f(x, y);
                if (mousePos == towerPos)
                {
                    CurrentlyHovered = tower;
                    if (AKS.WasJustPressed(Mouse.Button.Left))
                    {
                        var toAdd = tower.CloneLevel0();
                        Game.Towers.Add(toAdd);
                        Game.PlayArea.CurrentlyPlacing = toAdd;
                    }
                    break;
                }
                i++;
            }
        }
Пример #4
0
 public void Update(float delta)
 {
     if (AKS.WasJustPressed(Mouse.Button.Left) && Utils.PointIsInRect(Game.MousePosition, _retryLevelBackground))
     {
         Choice = ChoiceOption.RetryLevel;
     }
     else if (AKS.WasJustPressed(Mouse.Button.Left) && Utils.PointIsInRect(Game.MousePosition, _returnToTitleBackground))
     {
         Choice = ChoiceOption.ReturnToTitle;
     }
 }
Пример #5
0
        protected void Run()
        {
            while (Window.IsOpen)
            {
                AKS.Update();

                float delta = this.clock.Restart().AsSeconds();
                this.counter += delta;
                Window.DispatchEvents();

                if (this.counter >= this.framerate)
                {
                    int times = (int)(this.counter / this.framerate);
                    this.counter %= this.framerate;

                    for (int i = 0; i < times; i++)
                    {
                        this.Update(this.framerate);
                    }
                }

                this.Draw(Window);
            }
        }
Пример #6
0
        public Game(uint width, uint height)
        {
            RenderWindow window = new RenderWindow(new VideoMode(width, height), "TOU8HOU JAM 5 BABEY", Styles.Close);

            window.SetVerticalSyncEnabled(true);
            window.SetActive();
            Window = window;

            _viewSize = new Vector2f(width, height);
            View v = new View(new FloatRect(new Vector2f(0, 0), _viewSize));

            Window.SetView(v);

            //Window.Resized += (sender, eeee) =>
            //{
            //    Window.SetView(this.CalcView());
            //};

            AKS.InitializeWindow(window);

            this.clock = new Clock();

            window.Closed += (sender, e) =>
            {
                window.Close();
            };

            window.KeyPressed += (sender, e) =>
            {
                if (e.Code == Keyboard.Key.Escape)
                {
                    window.Close();
                }
            };

            TitleScreen    = new TitleScreen();
            GameOverScreen = new GameOverScreen();

            _playArea = new PlayArea(new Vector2i(20, 20), new Vector2f(0, 0));
            _playArea.SetLevel(new Level1());

            _hpBackground = new RectangleShape(new Vector2f(TileSize * 20, TileSize));
            _hpForeground = new RectangleShape(new Vector2f(TileSize * 20, TileSize));

            _hpBackground.FillColor = Color.Red;
            _hpForeground.FillColor = Color.Green;

            _hpBackground.OutlineColor     = _hpForeground.OutlineColor = Color.Black;
            _hpBackground.OutlineThickness = _hpForeground.OutlineThickness = 1;

            _hpBackground.Position = _hpForeground.Position = new Vector2f(0, TileSize * 20);

            _moneyBackground = new RectangleShape(new Vector2f(TileSize * 4, TileSize * 2))
            {
                FillColor = new Color(50, 50, 100, 255),
                Position  = new Vector2f(TileSize * 20, TileSize * (21 - 2))
            };
            _moneyText = new Text(Money.ToString(), Font)
            {
                Position      = Utils.RoundV(_moneyBackground.Position + _moneyBackground.Size / 2),
                CharacterSize = 22
            };

            _startBackground = new RectangleShape(new Vector2f(TileSize * 4, TileSize * 2))
            {
                FillColor = new Color(50, 100, 50, 255),
                Position  = new Vector2f(TileSize * 24, TileSize * 19)
            };
            _startText = new Text("Start", Font)
            {
                Position      = Utils.RoundV(_startBackground.Position + _startBackground.Size / 2),
                CharacterSize = 22
            };

            _textBackground = new RectangleShape(new Vector2f(TileSize * 28, TileSize * 4))
            {
                FillColor        = new Color(0, 0, 0, 255),
                OutlineColor     = Color.White,
                OutlineThickness = 2,
                Position         = new Vector2f(0, TileSize * 17)
            };
            _textText = new Text("hi :)", Font)
            {
                Position      = new Vector2f(8, TileSize * 17 + 8),
                CharacterSize = 22
            };

            _dimBackground = new RectangleShape(new Vector2f(TileSize * 28, TileSize * 21))
            {
                FillColor = new Color(0, 0, 0, 200)
            };

            _inventory   = new TowerInventory(new Vector2f(20 * Game.TileSize, 0), new Vector2i(8, 2));
            _infoDisplay = new InfoDisplay(new Vector2f(20 * TileSize, 2 * TileSize), new Vector2u((uint)(8 * TileSize), (uint)(17 * TileSize)));

            PlayArea       = _playArea;
            TowerInventory = _inventory;

            //Money += 500000;

            //AdvanceLevel();

            ReturnToTitle();

            Music        = new Music("Content/bgm.ogg");
            Music.Loop   = true;
            Music.Volume = DefaultMusicVolume;
            Music.Play();

            AKS.WatchKey(Keyboard.Key.M);
            AKS.WatchKey(Keyboard.Key.U);
            AKS.WatchKey(Keyboard.Key.R);
            AKS.WatchKey(Keyboard.Key.P);

            this.Run();
        }
Пример #7
0
        protected void Update(float delta)
        {
            if (AKS.WasJustPressed(Keyboard.Key.M))
            {
                Music.Volume = Music.Volume == 0 ? DefaultMusicVolume : 0;
            }

            if (TitleScreen.ReadyToStart)
            {
                if (IsGameOver)
                {
                    GameOverScreen.Update(delta);

                    if (GameOverScreen.Choice == GameOverScreen.ChoiceOption.RetryLevel)
                    {
                        IsGameOver = false;
                        GameOverScreen.IsWinScreen = false;
                        ReloadLevel();
                    }
                    else if (GameOverScreen.Choice == GameOverScreen.ChoiceOption.ReturnToTitle)
                    {
                        IsGameOver = false;
                        GameOverScreen.IsWinScreen = false;
                        ReturnToTitle();
                    }
                }
                else
                {
                    if (TextQueue.Count > 0)
                    {
                        if (AKS.WasJustPressed(Mouse.Button.Left))
                        {
                            TextQueue.RemoveAt(0);
                        }
                    }
                    else
                    {
                        if (AKS.WasJustPressed(Keyboard.Key.R))
                        {
                            Towers.Clear();
                            ReloadLevel();
                        }
                        else
                        {
                            _inventory.Update(delta);
                            _infoDisplay.Update(delta);

                            _playArea.Update(delta);

                            if (IsGameOver)
                            {
                                GameOverScreen.Choice = GameOverScreen.ChoiceOption.None;
                                Towers.Clear();
                                return;
                            }

                            if (_playArea.IsFinished)
                            {
                                AdvanceLevel();
                            }

                            if ((AKS.WasJustPressed(Mouse.Button.Left) && Utils.PointIsInRect(MousePosition, _startBackground)) ||
                                AKS.WasJustPressed(Keyboard.Key.P))
                            {
                                if (_playArea.IsStarted)
                                {
                                    _playArea.IsPaused = !_playArea.IsPaused;
                                }
                                else
                                {
                                    _playArea.Start();
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                TitleScreen.Update(delta);
            }
        }
Пример #8
0
        public override void Update(float delta)
        {
            bool didPlace   = false;
            var  snappedPos = Utils.Snap2Grid(Game.MousePosition);

            if (CurrentlyPlacing != null)
            {
                if (AKS.WasJustReleased(Mouse.Button.Left))
                {
                    if (CanPlaceTowerAt(snappedPos))
                    {
                        CurrentlyPlacing.Position = snappedPos;
                        Game.Money -= CurrentlyPlacing.Cost;
                        CurrentlyPlacing.IsPlaced = true;
                        CurrentlySelected         = CurrentlyPlacing;
                        CurrentlyPlacing          = null;
                        didPlace = true;
                    }
                }
                else if (AKS.WasJustReleased(Mouse.Button.Right))
                {
                    Game.RemoveTower(CurrentlyPlacing);
                    CurrentlyPlacing = null;
                }
            }

            bool newSelected = false;

            CurrentlyHovered = null;

            foreach (var tower in Game.PlacedTowers)
            {
                if (tower.Position == snappedPos)
                {
                    if (AKS.WasJustPressed(Mouse.Button.Left))
                    {
                        CurrentlySelected = tower;
                        newSelected       = true;
                    }
                    else
                    {
                        CurrentlyHovered = tower;
                    }
                }
            }

            if (AKS.WasJustPressed(Mouse.Button.Left) && !newSelected)
            {
                Vector2i gridPos = Utils.Vf2Grid(Game.MousePositionf);
                if (gridPos.X < _widthTiles && gridPos.Y < _heightTiles)
                {
                    CurrentlySelected = null;
                }
            }

            var upgradeCandidate = CurrentlyHovered ?? CurrentlySelected;

            if (upgradeCandidate != null && AKS.WasJustPressed(Keyboard.Key.U))
            {
                Game.TryUpgradeTower(upgradeCandidate);
            }

            if (!IsStarted || IsPaused)
            {
                return;
            }

            for (int frame = 0; frame < (AKS.IsKeyDown(Keyboard.Key.LControl) ? 10 : 1); frame++)
            {
                foreach (var tower in Game.PlacedTowers)
                {
                    tower.Update(delta);
                }

                foreach (var wave in Waves)
                {
                    wave.Update(delta);

                    Hp -= wave.FrameDamage;
                    if (Hp <= 0)
                    {
                        Game.IsGameOver = true;
                        return;
                    }

                    if (wave.IsFinishedSpawning && !_finishedWaves.Contains(wave))
                    {
                        _finishedWaves.Add(wave);

                        if (_finishedWaves.Count == _level.NumWaves)
                        {
                            _softFinished = true;
                        }
                        else
                        {
                            _waveCooldownTimer = 0;
                            _waveCooldownGoal  = wave.Cooldown;
                            _waveToSpawn       = _level.SpawnWave();
                        }
                    }
                }

                if (_waveToSpawn != null)
                {
                    _waveCooldownTimer += delta;

                    if (_waveCooldownTimer >= _waveCooldownGoal)
                    {
                        Waves.Add(_waveToSpawn);
                        _waveToSpawn = null;
                    }
                }

                foreach (var bullet in Bullets)
                {
                    if (bullet.ShouldBeCulled)
                    {
                        _bulletsToRemove.Add(bullet);
                    }
                    else
                    {
                        bullet.Update(delta);

                        if (bullet.ShouldBeCulled)
                        {
                            _bulletsToRemove.Add(bullet);
                        }
                        if (bullet.IsCollidable)
                        {
                            foreach (var wave in Waves)
                            {
                                if (!wave.TryBullet(bullet))
                                {
                                    if (bullet.ShouldBeCulled)
                                    {
                                        _bulletsToRemove.Add(bullet);
                                    }
                                    continue;
                                }
                            }
                        }
                    }
                }

                foreach (var bullet in _bulletsToRemove)
                {
                    Bullets.Remove(bullet);
                }

                _bulletsToRemove.Clear();

                foreach (var wave in Waves)
                {
                    wave.CullDeadCreeps();
                }

                if (_softFinished)
                {
                    if (!_awaitingCooldown)
                    {
                        int totalCreeps = 0;

                        foreach (CreepWave wave in Waves)
                        {
                            totalCreeps += wave.Creeps.Count;
                        }

                        if (totalCreeps == 0)
                        {
                            _awaitingCooldown = true;
                        }
                    }

                    if (_awaitingCooldown)
                    {
                        _cooldownTimer += delta;
                        if (_cooldownTimer >= _cooldownGoal)
                        {
                            IsFinished = true;
                            break;
                        }
                    }
                }
            }
        }