Beispiel #1
0
 public virtual void Update(World world, double curTime)
 {
 }
Beispiel #2
0
 private void Die(World world)
 {
     world.ParticleMan.CreateExplosion(ViewX, ViewY,world,this);
     world.Player.Score += this.ScoreValue;
     world.Player.Gold += (int)(this.ScoreValue * 0.7);
     this.DeleteMe = true;
 }
Beispiel #3
0
        public override void Update(World world, double curTime)
        {
            if (DeleteMe)
                return;
            if (this._hits <= 0f)
            {
                this.Die(world);
            }

            if (path.Count > 0 && curTime > _lastMove)
            {
                Move(_velocity);
                _lastMove = curTime + (MoveDelay / Helper.GameSpeed);
                if (_slowEffect != 0)
                    _lastMove += (MoveDelay / Helper.GameSpeed);
            }
            else if(path.Count == 0)
            {
                world.Player.Lives--;
                this.DeleteMe = true;
            }
            if (_slowEffect < curTime && _slowEffect != 0)
            {
                this._velModifier = 0;
                this._slowEffect = 0;
            }
            if (curTime > nextanim)
            {
                framenum++;
                if (framenum >= (Direction + 1) * 19)
                    framenum = (byte)(Direction * 19);
                nextanim = curTime + 52;
                //Currently playing at 19FPS for animations.
            }

            base.Update(world,curTime);
        }
Beispiel #4
0
        private void Update()
        {
            Stopwatch s = new Stopwatch();
            s.Start();
            Stopwatch TotalTimer = new Stopwatch();
            TotalTimer.Start();
            while (true)
            {
                if (GameState == Tower_Defense.GameState.InGame)
                {
                    World.Update(TotalTimer.Elapsed.TotalMilliseconds);

                    if (World.Player.Lives <= 0)
                    {
                        ScoreMenu.InitScoreMenu(this.World.Player,this.World.Map.Name.GetHashCode());
                        GameState = Tower_Defense.GameState.EndGame;
                        World = null;
                    }
                }
                if (GameState == Tower_Defense.GameState.Exit)
                    break;

                HandleUserInput();
                if (_curKey != null)
                {
                    var x = _curKey.KeyCode;
                    HandleIngameKey(x);
                }

                UpdateTime = (int)(s.Elapsed.Milliseconds);
                //if (UpdateTime > UpdateInterval)
                 //   Gameform.Debugger.Debug("GameLoop took " + UpdateTime + "ms");
                if (s.Elapsed.TotalMilliseconds < UpdateInterval)
                    Thread.Sleep((int)(UpdateInterval - s.Elapsed.Milliseconds));
                s.Restart();
            }
        }
Beispiel #5
0
        private void handleMenuInput(System.Windows.Forms.MouseEventArgs click)
        {
            for (int i = 0; i < Menu.Buttons.Count(); i++)
            {
                if (Helper.Contains(Menu.Buttons[i].button, click.Location))
                {
                    if (GameState == GameState.MainMenu)
                    {
                        switch (i)
                        {
                            case 0:
                                this.GameState = Tower_Defense.GameState.LevelSelect;
                            //this.Menu = new LevelSelectMenu();
                            return;
                            case 1:
                                 this.GameState = Tower_Defense.GameState.About;
                            //this.Menu = new AboutMenu();
                            return;
                            case 2:
                                 this.GameState = Tower_Defense.GameState.Exit;
                            return;
                        }
                    }
                    if (GameState == GameState.LevelSelect)
                    {
                        this.World = new World(Gameform, Menu.Buttons[i].Text);
                        this.GameState = Tower_Defense.GameState.InGame;
                        return;
                    }
                    if (GameState == GameState.About)
                    {
                        this.GameState = Tower_Defense.GameState.MainMenu;
                        //this.Menu = new MainMenu();
                        return;
                    }
                    if (GameState == GameState.EndGame)
                    {
                        this.GameState = Tower_Defense.GameState.MainMenu;
                        //this.Menu = new MainMenu();
                        return;
                    }
                    if (GameState == GameState.InGamePause)
                    {
                        if (i == 0)
                        {
                            this.GameState = Tower_Defense.GameState.InGame;
                        }
                        else if (i == 1)
                        {
                            GameState = Tower_Defense.GameState.MainMenu;
                            //this.Menu = new MainMenu();
                            World = null;
                            return;
                        }
                        return;
                    }

                }
            }
        }
Beispiel #6
0
        private void handleInGameInput(System.Windows.Forms.MouseEventArgs click)
        {
            foreach (var z in this.World.UIElements)
            {
                if (Helper.Contains(z.button, click.Location))
                {
                    if (z.Text == "Pause Game")
                    {
                        this.GameState = Tower_Defense.GameState.InGamePause;
                        //this.Menu = new PauseMenu();
                        return;
                    }
                    if (z.Text == "Next Wave")
                    {
                        this.World.NextWave();
                        return;
                    }
                    if (z.Text == "Exit")
                    {
                        GameState = Tower_Defense.GameState.MainMenu;
                        //this.Menu = new MainMenu();
                        World = null;
                        return;
                    }
                    if (z.Text == "Speed")
                    {
                        if (Helper.GameSpeed == 1)
                            Helper.GameSpeed = 2;
                        else
                            Helper.GameSpeed = 1;
                        return;
                    }
                }
            }
            if (this.World != null)
            {
                if (this.World.ShowUpgradeMenu)
                {
                    if (Helper.Contains(UpgradeMenu.Buttons[0].button, click.Location))
                    {
                        if (World.Player.Gold > UpgradeMenu.Tower.UpgradeCost)
                        {
                            World.Player.Gold -= UpgradeMenu.Tower.UpgradeCost;
                            UpgradeMenu.Tower.LevelUP();
                        }
                        this.World.ShowUpgradeMenu = false;
                        return;
                    }
                    else
                    {
                        this.World.ShowUpgradeMenu = false;
                        return;
                    }
                }
                foreach (TowerBuildButton o in World.BuildMenu.Buttons)
                {
                    if (Helper.Contains(o.button, click.Location))
                    {
                        TowerToBuild = (Tower)Assembly.GetAssembly(o.towerType).CreateInstance(o.towerType.FullName);
                        return;
                    }
                }
            if (!Helper.Contains(GameForm.ViewPort, click.Location))
                return;
            foreach (var o in this.World.DrawableObjects)
                if (Helper.Contains(o.ScreenSprite, click.Location))
                {
                    if (o.Type == ObjectType.Tower)
                    {
                        UpgradeMenu.Update((Tower)o);
                        this.World.ShowUpgradeMenu = true;
                    }
                }

            foreach (var m in this.World.Map.Map)
                if (Helper.Contains(m.ScreenSprite, click.Location))
                {
                    if (TowerToBuild != null)
                        BuildTower(m);
                }
            return;
            }
        }