예제 #1
0
        public bool InLava(IPair pos)
        {
            IPair delta         = pos - Pos;
            int   ground_radius = RADIUS * GameDef.PIXEL_SCALE;

            return(delta.LengthSquare() > ground_radius * ground_radius);
        }
예제 #2
0
 public bool Cast(int id, IPair destination)
 {
     //  return whether success (in cold-down or no ability)
     //  location test
     if (destination.Equal(pos_))
     {
         return(false);
     }
     //  check cd
     if (cd_list_[id] > 0)
     {
         return(false);
     }
     //  not in cd
     if (order_.Casting())
     {
         if ((order_.Param2.X == id && order_.Param1.Equal(destination)) || order_.Param2.X == 1)
         {
             return(true);                                                                                      //  同樣的指令不需要取消
         }
         InterruptCast();
     }
     order_.Cast(id, destination);
     return(true);
 }
예제 #3
0
        public EFMakeFireBall(Unit unit, IPair offset) : base(9, true)
        {
            DrawId = 3;

            unit_   = unit;
            offset_ = offset.Clone();
        }
예제 #4
0
 public void Move(IPair destination)
 {
     if (order_.Casting())
     {
         InterruptCast();
     }
     order_.Move(destination);
 }
예제 #5
0
        public EFExclamation(Player owner, IPair pos) : base(60, false)
        {
            DrawId = 10;

            Owner = owner;
            Pos.Clone(pos);
            Pos.Y -= 60 * GameDef.PIXEL_SCALE;
            GameDef.AdjustCollisionWall(Pos, 60);
        }
예제 #6
0
 public void Dead()
 {
     dead_pos = FocusUnit.Pos.Clone();
     FocusUnit.Stop();   //  中斷施法
     Game.Unit_List.Remove(FocusUnit);
     FocusUnit       = null;
     respawn_effect_ = new EFRespawn(this);
     respawn_effect_.Register();
 }
예제 #7
0
        public const int STRENGTH = 50;  //  as 50 damage spell
        public MIHealBall(Unit caster, IPair destination) : base(80, caster)
        {
            radius_ = RADIUS;
            damage_ = -10;
            speed_  = 350;

            hurt_self_             = true;
            explode_enemy_         = false;
            explode_enemy_missile_ = false;

            Unit target = null;
            bool used = false;
            long min_distance = 0, temp_distance;

            foreach (Unit unit in Game.Unit_List)
            {
                if (unit == caster)
                {
                    continue;
                }
                if (used == false)
                {
                    used         = true;
                    target       = unit;
                    min_distance = (unit.Pos - Pos).LengthSquare();
                }
                else
                {
                    temp_distance = (unit.Pos - Pos).LengthSquare();
                    if (temp_distance < min_distance)
                    {
                        target       = unit;
                        min_distance = temp_distance;
                    }
                }
            }
            if (target != null)
            {
                destination.Clone(target.Pos);
            }

            IPair delta = destination - caster.Pos;

            move_vector_ = delta.Clone();
            move_vector_.ChangeLength(speed_);
            delta.ChangeLength(GameDef.UNIT_RADIUS * GameDef.PIXEL_SCALE);
            Pos.Clone(caster.Pos);
            Pos.Add(delta);
        }
예제 #8
0
 //  constructor
 public Unit(Player owner, IPair pos)
 {
     order_   = new Order();
     cd_list_ = new int[GameDef.SPELL_COUNT];
     for (int i = 0; i < GameDef.SPELL_COUNT; ++i)
     {
         cd_list_[i] = 0;
     }
     speed_       = 350;
     hp_          = GameDef.UNIT_MAX_HP * GameDef.PIXEL_SCALE;
     mp_          = 0;
     pos_         = pos.Clone();
     repusle_     = new IPair();
     last_damage_ = owner;
     Owner        = owner;
     Radius       = GameDef.UNIT_RADIUS;
 }
예제 #9
0
 public static void AdjustCollisionWall(IPair pos, int radius)
 {
     if (pos.X / PIXEL_SCALE + radius >= WIDTH)
     {
         pos.X = (WIDTH - radius - 1) * PIXEL_SCALE;
     }
     if (pos.X / PIXEL_SCALE < radius)
     {
         pos.X = radius * PIXEL_SCALE;
     }
     if (pos.Y / PIXEL_SCALE + radius >= HEIGHT)
     {
         pos.Y = (HEIGHT - radius - 1) * PIXEL_SCALE;
     }
     if (pos.Y / PIXEL_SCALE < radius)
     {
         pos.Y = radius * PIXEL_SCALE;
     }
 }
예제 #10
0
        //  override
        public override void Update()
        {
            hp_ += GameDef.UNIT_RECOVER;
            hp_  = Math.Min(hp_, GameDef.UNIT_MAX_HP * GameDef.PIXEL_SCALE);
            //  cd count
            for (int i = 0; i < GameDef.SPELL_COUNT; ++i)
            {
                if (cd_list_[i] > 0)
                {
                    --cd_list_[i];
                }
            }
            //  move
            IPair delta = repusle_.Clone();

            if (order_.Type == 1)
            {
                IPair move_vector = order_.Param1 - Pos;
                if (move_vector.LengthSquare() > speed_ * speed_)
                {
                    move_vector.ChangeLength(speed_);
                }
                else
                {
                    order_.Stop();
                }
                delta.Add(move_vector);
            }
            //  repusle decrease
            long repusle_length_square = repusle_.LengthSquare();
            long repusle_decrease      = speed_ >> GameDef.REPULSE_DECREASE_FACTOR;

            if (repusle_length_square < repusle_decrease * repusle_decrease)
            {
                repusle_.X = repusle_.Y = 0;
            }
            else
            {
                repusle_.ChangeLength((long)Math.Sqrt((double)repusle_length_square) - repusle_decrease);
            }
            Pos.Add(delta);
            GameDef.AdjustCollisionWall(Pos, Radius);
        }
예제 #11
0
        //  operator
        public void Damage(Player player, IPair pos, int damage)
        {
            hp_ -= damage;
            mp_ += damage;  //  補血就賺囉
            if (mp_ < 0)
            {
                mp_ = 0;
            }
            if (damage <= 0)
            {
                return;                 //  heal
            }
            last_damage_ = player;

            IPair delta = pos_ - pos;

            if (delta.Zero() == false)
            {
                delta.ChangeLength((damage * 3 * (mp_ / GameDef.PIXEL_SCALE + 100) / 100) >> 1);
                repusle_.Add(delta);
            }
        }
예제 #12
0
 public void Clone(IPair pair)
 {
     X = pair.X;
     Y = pair.Y;
 }
예제 #13
0
 public static bool CollisionWall(IPair pos, int radius)
 {
     //  判斷是否碰撞牆壁
     return(pos.X / PIXEL_SCALE + radius >= WIDTH || pos.X / PIXEL_SCALE < radius || pos.Y / PIXEL_SCALE + radius >= HEIGHT || pos.Y / PIXEL_SCALE < radius);
 }
예제 #14
0
        public void PushCast(Keys key, IPair pos)
        {
            if (FocusUnit == null && key != Keys.R)
            {
                return;
            }
            //  parse key
            switch (key)
            {
            case Keys.Q:
                FocusUnit.Cast(0, pos);
                break;

            case Keys.W:
                FocusUnit.Cast(1, pos);
                break;

            case Keys.E:
                FocusUnit.Cast(2, pos);
                break;

            case Keys.S:
                FocusUnit.Cast(3, pos);
                break;

            case Keys.D:
                FocusUnit.Cast(4, pos);
                break;

            case Keys.F:
                FocusUnit.Cast(5, pos);
                break;

            case Keys.R:
                //  驚嘆號
                if (exclamation != null)
                {
                    //  remove first
                    if (Game.Effect_List.Contains(exclamation))
                    {
                        exclamation.Unregister();
                        exclamation = null;
                    }
                }
                if (FocusUnit != null)
                {
                    exclamation = new EFExclamation(this, FocusUnit.Pos);
                }
                else if (dead_pos != null)
                {
                    exclamation = new EFExclamation(this, dead_pos);
                }
                if (exclamation != null)
                {
                    exclamation.Register();
                }
                break;

            default:
                break;
            }
        }
예제 #15
0
 // constructor
 public Effect(int period, bool loop) : base(period)
 {
     pos_  = new IPair();
     loop_ = loop;
     Dead  = false;
 }
예제 #16
0
 public void Sub(IPair pair)
 {
     X -= pair.X;
     Y -= pair.Y;
 }
예제 #17
0
 public void Add(IPair pair)
 {
     X += pair.X;
     Y += pair.Y;
 }
예제 #18
0
 public bool Equal(IPair pair)
 {
     return(X == pair.X && Y == pair.Y);
 }
예제 #19
0
 public IPair(IPair pair) : this(pair.X, pair.Y)
 {
     ;
 }
예제 #20
0
 public void AddRepulse(IPair delta)
 {
     repusle_.Add(delta);
 }
예제 #21
0
 public Ground(int width, int height)
 {
     pos_ = new IPair((width >> 1) * GameDef.PIXEL_SCALE, (height >> 1) * GameDef.PIXEL_SCALE);
 }