Esempio n. 1
0
        private Critter shoot(Tower tower, Critter critter)
        {
            if (Sprite.GetIsInRange(tower.Position, critter.Position, tower.Range))
            {
                if (tower.AttackState == AttackState.Shooting)
                {
                    float bulletSpeed = 5.0f + (float)RandomHandler.GetRandom(0.0, 2.0);
                    bool hitCritter = false;
                    if (tower.Accuracy + RandomHandler.GetRandom() >= critter.Dexterity + RandomHandler.GetRandom())
                    {
                        hitCritter = true;
                    }

                    tower.AttackState = AttackState.Reloading;
                    tower.LastAttack = getCurrentMilliseconds();
                    createBullet(bulletSpeed, tower, critter, hitCritter);
                }
                else
                {
                    if (getCurrentMilliseconds() - tower.LastAttack > (long)(tower.ReloadSpeed * 1000))
                    {
                        Console.WriteLine(tower.ToString() + " finished reloading");
                        tower.AttackState = AttackState.Shooting;
                    }
                }
            }
            return critter;
        }
Esempio n. 2
0
        private Bullet createBullet(float speed, Tower tower, Critter critter, Boolean hit)
        {
            Bullet bullet = new Bullet();
            bullet.Speed = speed;

            bullet.Position = new Vector2(tower.Position.X + (tower.Width / 2),
                                          tower.Position.Y + (tower.Height / 2));

            bullet.Direction = critter.Position - tower.Position;
            bullet.Direction.Normalize();

            Texture2D texture = null;
            switch (tower.Type)
            {
                case TowerType.RangedTower: texture = Presentation.PresentationController.BulletTexture2D;
                                            bullet.BulletColor = Color.DarkGray;
                                            break;
                case TowerType.MeleeTower: texture = Presentation.PresentationController.BulletTexture2D;
                                           bullet.BulletColor = Color.DarkRed;
                                           break;
                case TowerType.SlowTower: texture = Presentation.PresentationController.BulletTexture2D;
                                          bullet.Slow = true;
                                          bullet.BulletColor = Color.Cyan;
                                          break;
            }
            bullet.Texture = texture;

            bullet.Target = critter;
            bullet.Damage = tower.Damage;
            bullet.Hit = hit;

            bullet.Done = false;
            bullets.Add(bullet);
            return bullet;
        }
Esempio n. 3
0
 // returns true when tower was built successfully
 public static bool BuildTower(Tower tower, Vector2 position)
 {
     return BuildTower(tower, (int)position.X, (int)position.Y);
 }
Esempio n. 4
0
        // returns true when tower was built successfully
        public static bool BuildTower(Tower tower, int x, int y)
        {
            bool succesBuild = false;
            if (!Presentation.Background.IsOnCity(tower))
            {
                if (!Presentation.Background.IsOnWalkPath(tower))
                {
                    if (!IsAnyTowerInRange(x, y))
                    {
                        int cost = tower.Cost,
                            gold = Player.Gold;
                        if (gold >= cost)
                        {
                            tower.Move(x, y);
                            tower.TowerState = TowerState.Bought;
                            tower.AttackState = AttackState.Shooting;
                            Player.Gold -= cost;
                            Tower.PlacingTower = false;
                            succesBuild = true;

                            Console.WriteLine("Building tower");
                        }
                        else
                        {
                            Console.WriteLine("Error: Player does not have enough gold");
                        }
                    }
                    else
                    {
                        Console.WriteLine("Error: Cannot place tower, another tower in range");
                    }
                }
                else
                {
                    Console.WriteLine("Error: Cannot place towers on path");
                }
            }
            else
            {
                Console.WriteLine("Error: Tower cannot be placed on city");
            }

            return succesBuild;
        }
Esempio n. 5
0
        private void init()
        {
            mouse = new Logic.Mouse();
            keyboard = new KeyboardHandler();

            player = new Player(this);
            critter = new Critter(this);
            tower = new Tower(this);

            RandomHandler.Init();
        }