Beispiel #1
0
        public override void Update()
        {
            PointF diraction = new PointF(target.WorldPosition.X - WorldPosition.X,
                                          target.WorldPosition.Y - WorldPosition.Y);
            float length = diraction.GetLength();

            if (Math.Abs(length) < 0.01)
            {
                this.Alive = false;
            }
            diraction     = PointExtensions.Scale(diraction, 1 / length);
            WorldPosition = PointExtensions.Sum(WorldPosition, PointExtensions.Scale(diraction, speed));
            if (float.IsNaN(WorldPosition.X) || float.IsNaN(WorldPosition.Y))
            {
                WorldPosition = target.WorldPosition;
                this.Alive    = false;
                return;
            }
            if (PointExtensions.Sub(WorldPosition, target.WorldPosition).GetLength() < speed)
            {
                target.CurrentHealth -= damage;
                if (target.CurrentHealth < 0 && target.Alive)
                {
                    target.Alive  = false;
                    parent.Target = null;
                    GameController.Controller.CurrentPlayer.money += target.Reward;
                    GameController.Controller.CurrentPlayer.score += target.Reward;
                }
                this.Alive = false;
            }

            SetLookTo(target.WorldPosition);
        }
Beispiel #2
0
        public bool isFree(PointF pos)
        {
            PointF roundedPoint = PointExtensions.RoundPointF(pos);
            int    cellInd      = cells.IndexOf(roundedPoint);

            return(cellInd != -1 && openCells[cellInd]);
        }
Beispiel #3
0
        public override void Update()
        {
            if (WorldPosition.Equals(GameField.MyGameField.Finish))
            {
                GameController.Controller.CurrentPlayer.Lives -= this.Punishment;
                this.Alive = false;
            }
            if (path.Count == 0)
            {
                WannaMove(GameField.MyGameField);
                return;
            }
            if (Equals(PointExtensions.Sub(WorldPosition, path[0]).GetLength(), speed) || PointExtensions.Sub(WorldPosition, path[0]).GetLength() < speed)
            {
                WorldPosition = path[0];
                path.RemoveAt(0);
                return;
            }

            PointF target    = path[0];
            PointF diraction = new PointF(target.X - WorldPosition.X,
                                          target.Y - WorldPosition.Y);
            float length = diraction.GetLength();

            diraction     = PointExtensions.Scale(diraction, 1 / length);
            WorldPosition = PointExtensions.Sum(WorldPosition, PointExtensions.Scale(diraction, speed));

            Angle = PointExtensions.GetAngle(new PointF(1, 0), diraction);
        }
Beispiel #4
0
        public override void Spawn(PointF pos)
        {
            GameField field = GameField.MyGameField;

            if (GameField.MyGameField.openCells[field.cells.IndexOf(WorldPosition)] == false)
            {
                return;
            }
            WorldPosition = PointExtensions.RoundPointF(pos);
            GameField.MyGameField.openCells[field.cells.IndexOf(WorldPosition)] = false;
            foreach (var item in Form1.gameObjects.OfType <Boy>())
            {
                item.path = new List <PointF>();
            }
        }
Beispiel #5
0
        public bool CanBuilt(PointF pos)
        {
            if (Mode != ControlMode.Build)
            {
                return(false);
            }

            foreach (var item in Form1.gameObjects.OfType <Enemy>())
            {
                if (pos.Equals(PointExtensions.RoundPointF(item.WorldPosition)) || pos.Equals(GameField.MyGameField.Start) || pos.Equals(GameField.MyGameField.Finish))
                {
                    return(false);
                }
            }
            return(true);
        }
Beispiel #6
0
        public override void Shoot()
        {
            if (!GameController.Controller.UnPaused)
            {
                return;
            }
            if (Target == null || !Target.Alive)
            {
                Target = FindTarget();
                return;
            }

            double distance = PointExtensions.Sub(WorldPosition, Target.WorldPosition).GetLength();

            if (distance > range)
            {
                Target = FindTarget();
                return;
            }
            Form1.gameObjects.Add(new Bullet(Target, damage, "bitBullet.png", WorldPosition, this, 0.3f));
        }
Beispiel #7
0
        private void Form1_MouseClick(object sender, MouseEventArgs e)
        {
            if (!GameController.Controller.GameStarted)
            {
                return;
            }
            Point  screenP  = e.Location;
            PointF worldP   = Camera.ScreenToWorld(screenP);
            PointF nearestP = PointExtensions.RoundPointF(worldP);

            switch (GameController.Controller.CurrentPlayer.Mode)
            {
            case ControlMode.Build:
                GameController.Controller.players[0].BuildTower(nearestP);
                break;

            case ControlMode.Delete:
                GameController.Controller.players[0].RemoveTower(nearestP);
                break;
            }
        }
Beispiel #8
0
        public override void Update()
        {
            if (WorldPosition.Equals(GameField.MyGameField.Finish))
            {
                GameController.Controller.CurrentPlayer.Lives -= this.Punishment;
                this.Alive = false;
            }

            PointF target    = GameField.MyGameField.Finish;
            PointF diraction = new PointF(target.X - WorldPosition.X,
                                          target.Y - WorldPosition.Y);
            float length = diraction.GetLength();

            diraction     = PointExtensions.Scale(diraction, 1 / length);
            WorldPosition = PointExtensions.Sum(WorldPosition, PointExtensions.Scale(diraction, speed));
            Angle         = PointExtensions.GetAngle(new PointF(1, 0), diraction);
            if (PointExtensions.Sub(WorldPosition, target).GetLength() < speed)
            {
                WorldPosition = target;
                return;
            }
        }
Beispiel #9
0
        public override Enemy FindTarget()
        {
            Enemy target = null;

            target = Form1.gameObjects.OfType <FastBoy>().FirstOrDefault(x => x.Alive && x is Enemy && PointExtensions.Distance(x.WorldPosition, WorldPosition) < range);
            if (target == null)
            {
                target = Form1.gameObjects.OfType <Boy>().FirstOrDefault(x => x.Alive && x is Enemy && PointExtensions.Distance(x.WorldPosition, WorldPosition) < range);
            }
            return(target);
        }
Beispiel #10
0
        public void SetLookTo(PointF target)
        {
            PointF diraction = PointExtensions.Sub(WorldPosition, target);

            Angle = PointExtensions.GetAngle(new PointF(-1, 0), diraction);
        }
Beispiel #11
0
 public override void Remove()
 {
     shootT.Stop();
     GameField.MyGameField.openCells[GameField.MyGameField.cells.IndexOf(PointExtensions.RoundPointF(WorldPosition))] = true;
     base.Remove();
 }