예제 #1
0
        public Tank(string url)
            : base(url, TypeObject.Tank)
        {
            Defense = 40;
            HP = 100;
            BattleField.NumberOfTanks++;
            this.Index = BattleField.NumberOfTanks;

            this.SpeedMove = 1;

            AllowToFire = true;
            Instructions = new List<Instruction>();
            Alive = true;
            bullet = new Bullet(TankResources.Bullet1, this.Index);
            //StatsText default
            StatsText = new TextBlock();
            StatsText.FontSize = 12;
            StatsText.Foreground = new SolidColorBrush(Colors.Black);
            StatsText.Text = HP.ToString();
            StatsText.FontWeight = FontWeights.Bold;
            StatsText.Visibility = System.Windows.Visibility.Visible;
            StatsText.Text = HP.ToString() + "/" + Defense.ToString();
            //Stats default
            Stats = new ProgressBar();
            Stats.Background = new SolidColorBrush(Colors.Transparent);
            //Stats.Width = this.getSize().Width;
            //Stats.Height = this.getSize().Height;
            //Stats.MaxHeight = this.getSize().Height;
            //Stats.MaxWidth = this.getSize().Width;
            //Stats.
            Stats.Padding = new Thickness(0, 0, 0, 0);
            Stats.Visibility = System.Windows.Visibility.Visible;
            Stats.Minimum = 0;
            Stats.Maximum = 100;
            Stats.Value = HP;
            //Stats.
            Stats.Foreground = new SolidColorBrush(Colors.Cyan);
            Stats.Margin = new Thickness(this.getPosition().X, this.getPosition().Y + this.getSize().Height, 0, 0);
            //Stat
        }
예제 #2
0
        public void Fire()
        {
            bullet = new Bullet(TankResources.Bullet1,this.Index);
            bullet.setSize(new Size(5, 5));
            bullet.Direction = this.Direction;
            bullet.Damage = 20;
            bullet.Speed = 10;
            //calculate the position of bullet
            double angle = Math.PI * this.Direction / 180;

            float x = this.getPosition().X;
            float y = this.getPosition().Y;

            x+=(float)this.getSize().Width/2;
            y+=(float)this.getSize().Height/2;

            x += (float)Math.Sin(angle) * (((float)this.getSize().Width+(float)bullet.getSize().Width)/2);
            y -= (float)Math.Cos(angle) * (((float)this.getSize().Height+(float)bullet.getSize().Height)/2);

            x-= ((float)bullet.getSize().Width)/2;
            y-= ((float)bullet.getSize().Width)/2;

            //end bullet-position calculation
            bullet.setPosition(new Position(x, y));
            AllowToFire = false;
            return;
        }
예제 #3
0
 public void beAttacked(Bullet bullet)
 {
     Defense -= bullet.Damage;
     if (Defense < 0) {
         HP -= Math.Abs(Defense);
         Defense = 0;
     }
     if (HP <= 0) {
         Alive = false;
     }
     StatsText.Text = HP.ToString() + "/" + Defense.ToString();
 }
예제 #4
0
        private void ProcessBullet(Bullet bullet)
        {
            bullet.MoveForward(bullet.Speed);

            for (int i = 0; i < Tanks.Count; i++){
                    if (bullet.IsCollided(Tanks[i])) {
                            (Tanks[i]).beAttacked(bullet);
                            Tanks[bullet.TankIndex].FireDone();
                            if (!Tanks[i].Alive) {
                                Bullets.Remove(Tanks[i].bullet);
                                Tanks.RemoveAt(i);
                                updateObjects();
                            }
                        Bullets.Remove(bullet);
                        NeedToUpdate = true;
                    }

                //}

            }
            if(bullet.outOfRange()){
                Tanks[bullet.TankIndex].AllowToFire = true;
                Bullets.Remove(bullet);
            }
        }