示例#1
0
        private void collisionPush(ScreenObject collider)
        {
            float coX = collider.getPosition().X;
            float coY = collider.getPosition().Y;
            float coW = (float)collider.getWidth();
            float coH = (float)collider.getHeight();

            if (coX < _position.X)
            {
                if(_dest.X > coX + coW)
                    _position.X = coX + coW;
            }
            else
            {
                if (_dest.X < coX)
                    _position.X = coX - (float)getWidth();
            }

            if (coY < _position.Y)
            {
                if (_dest.Y > coY + coH)
                    _position.Y = coY + coH;
            }
            else
            {
                if (_dest.Y < coY)
                    _position.Y = coY - (float)getHeight();
            }
        }
示例#2
0
        public override void collide(ScreenObject collider, TimeSpan timeSpan)
        {
            if (collider == _killer || _state == STATE_DEAD || _state == STATE_DYING)
                return;

            if (collider is Shot && collider.getSide() != _side && !(collider is Pavise) && collider.getState() != STATE_DEAD && collider.getState() != Shot.STATE_GROUND)
            {
                if (this is Targeteer)
                {
                    if (collider is ArquebusierShot || (collider is CrossbowShot && collider.getSide() == BattleScreen.SIDE_PLAYER))
                        ((Targeteer)this).shieldBreak();
                    else
                        ((Targeteer)this).shieldBlock();
                }
                else if (this is CrossbowmanPavise)
                {
                    if (_side == BattleScreen.SIDE_PLAYER)
                        ((CrossbowmanPavise)this).shieldBlock();
                    else
                        hit();
                }
                else if (!(this is Leader) && (this._side == BattleScreen.SIDE_ENEMY || _screen.getPlayerFormation().getSoldiers().Contains(this)))
                    hit();

                ((Shot)collider).hit();

                _killer = collider;
            }
            else if ((collider is PikeTip && collider.getSide() != _side) && (_state != STATE_DEAD && _state != STATE_DYING && _state != STATE_ROUTE && _state != STATE_ROUTED))
            {
                if (((PikeTip)collider).getSoldierState() == Pikeman.STATE_LOWERED)
                {
                    if (!(this is Targeteer) && !(this is Wolf))
                    {
                        hit();
                        _killer = collider;
                        ((PikeTip)collider).getPikeman().recoil();
                    }
                    /*else if (this is Colmillos)
                    {
                        if (_state != Colmillos.STATE_ATTACK)
                            this.attack();
                        ((PikeTip)collider).getPikeman().recoil();
                        ((Colmillos)this).myFormation._position.X = collider.getCenter().X + collider.getWidth() / 2 + 100f;
                    }*/
                    else if (this is Targeteer)
                    {
                        if (((Targeteer)this)._hasShield)
                        {
                            ((Targeteer)this).shield();
                            this.setReactionDest(collider.getCenter().X + 50f);//((collider.getSide() == BattleScreen.SIDE_ENEMY? 1 : -1 ) * collider.getWidth() * 0.5f + Soldier.WIDTH * 0.35f
                            if(this is Colmillos)
                                ((Colmillos)this).myFormation._position.X = collider.getCenter().X + collider.getWidth() / 2 + 100f;
                        }
                        else
                        {
                            hit();
                            _killer = collider;
                            ((PikeTip)collider).getPikeman().recoil();
                        }
                    }
                }
            }
            else if ((collider is WeaponSwing && collider.getSide() != _side) && (_state != STATE_DEAD && _state != STATE_DYING && _state != STATE_ROUTE && _state != STATE_ROUTED))
            {
                if (this is Targeteer)
                    ((Targeteer)this).shieldBreak();
                else
                {
                    hit();
                    _killer = collider;
                }

            }
            else if ((collider is LanceTip && collider.getSide() != _side) && (_state != STATE_DEAD && _state != STATE_DYING && _state != STATE_MELEE_WIN && _state != STATE_MELEE_LOSS && _state != STATE_ROUTE && _state != STATE_ROUTED))
            {
                if (this is Targeteer)
                    ((Targeteer)this).shieldBreak();
                else
                    hit();
                ((LanceTip)collider).getCavalry().recoil();
                _killer = collider;
            }
            else if (collider is Soldier)
            {
                bool colliderInFormation = false;
                bool thisInFormation = false;
                if (_screen.getPlayerFormation() != null && _screen.getPlayerFormation().getSoldiers() != null)
                {
                    colliderInFormation = _screen.getPlayerFormation().getSoldiers().Contains(collider);
                    thisInFormation = _screen.getPlayerFormation().getSoldiers().Contains(this);
                }
                if (_state != STATE_DEAD && _state != STATE_DYING && _state != STATE_MELEE_WIN && _state != STATE_MELEE_LOSS && (!(this is Targeteer) || _state != Targeteer.STATE_SHIELDBREAK) && (!(this is DismountedCavalry) || _state != DismountedCavalry.STATE_FALLING))
                {
                    if (this is CrossbowmanPavise && collider is CrossbowmanPavise
                        && (this._state == STATE_CHARGING || this._state == STATE_RELOADING || this._state == STATE_ATTACKING|| this._state == CrossbowmanPavise.STATE_PLACING || this._state == CrossbowmanPavise.STATE_RETRIEVING)
                        && (collider.getState() == STATE_CHARGING || collider.getState() == STATE_RELOADING || collider.getState() == STATE_ATTACKING || collider.getState() == CrossbowmanPavise.STATE_PLACING || collider.getState() == CrossbowmanPavise.STATE_RETRIEVING))
                    {
                        Vector2 changeVector = new Vector2(0f, (float)timeSpan.TotalMilliseconds * _speed);
                        ((CrossbowmanPavise)this).postRetrieveState = _state;
                        ((CrossbowmanPavise)this).paviseRetrieve();
                        if (this._position.Y < collider._position.Y)
                        {

                            this._position -= changeVector;
                            ((CrossbowmanPavise)this)._meleeDestination -= changeVector;
                            ((CrossbowmanPavise)this).chargePosition -= changeVector;
                        }
                        else
                        {
                            this._position += changeVector;
                            ((CrossbowmanPavise)this)._meleeDestination += changeVector;
                            ((CrossbowmanPavise)this).chargePosition += changeVector;
                        }
                    }
                    //push from collisions with other charging enemy soldiers
                    else if (_screen.getLooseSoldiers().Contains(this) && _screen.getLooseSoldiers().Contains(collider)
                        && _side == BattleScreen.SIDE_ENEMY && collider.getSide() == BattleScreen.SIDE_ENEMY
                        && (collider.getState() != STATE_DYING && collider.getState() != STATE_DEAD))
                    {
                        if (this._position.Y < collider._position.Y)
                        {
                            this._position -= new Vector2(0f, (float)timeSpan.TotalMilliseconds * _speed);
                        }
                        else
                        {
                            this._position += new Vector2(0f, (float)timeSpan.TotalMilliseconds * _speed);
                        }
                    }
                    else
                    {
                        if (collider.getSide() == BattleScreen.SIDE_NEUTRAL)
                        {
                            collisionPush(collider);
                        }
                        //fighting
                        else if (_side != collider.getSide() && (thisInFormation || colliderInFormation) && !(this is Leader || collider is Leader) && collider.getState() != STATE_DEAD && collider.getState() != STATE_DYING && collider.getState() != STATE_MELEE_WIN && collider.getState() != STATE_MELEE_LOSS && (!(collider is Targeteer) || collider.getState() != Targeteer.STATE_SHIELDBREAK) && (!(collider is DismountedCavalry) || collider.getState() != DismountedCavalry.STATE_FALLING))
                        {
                            bool rescueFight = (_side == BattleScreen.SIDE_PLAYER && !thisInFormation) ||
                                               (collider.getSide() == BattleScreen.SIDE_PLAYER && !colliderInFormation);
                            if (this is Dopple)
                            {
                                if (_state != STATE_ATTACKING)
                                    attack();
                                ((Soldier)collider).engage(false, _position, this, rescueFight);
                            }
                            else if (collider is Dopple)
                            {
                                if (collider.getState() != STATE_ATTACKING)
                                    ((Dopple)collider).attack();
                                engage(false, collider.getPosition(), (Soldier)collider, rescueFight);
                            }
                            else if (_side == BattleScreen.SIDE_ENEMY || this is Wolf)
                            {
                                engage(true, collider.getPosition(), (Soldier)collider, rescueFight);
                                ((Soldier)collider).engage(false, _position, this, rescueFight);
                            }
                            else
                            {
                                engage(false, collider.getPosition(), (Soldier)collider, rescueFight);
                                ((Soldier)collider).engage(true, _position, this, rescueFight);
                            }
                        }
                        //rescue
                        else if (_side == BattleScreen.SIDE_PLAYER && collider.getSide() == BattleScreen.SIDE_PLAYER && (thisInFormation != colliderInFormation))
                        {
                            if (thisInFormation &&
                                collider.getState() != STATE_CHARGING && collider.getState() != STATE_DYING
                                && collider.getState() != STATE_DEAD
                                && collider.getState() != STATE_MELEE_LOSS && collider.getState() != STATE_MELEE_WIN
                                && collider.getState() != STATE_ATTACKING && collider.getState() != STATE_RELOADING)
                            {
                                ((Soldier)collider)._state = STATE_READY;
                                ((Soldier)collider)._reacting = false;
                                if (((Soldier)collider).myFormation != null && ((Soldier)collider).myFormation != _screen.getPlayerFormation())
                                    ((Soldier)collider).myFormation.removeSoldier(((Soldier)collider));
                                _screen.getPlayerFormation().addSoldier((Soldier)collider);
                                _screen.removeLooseSoldier((Soldier)collider);
                            }
                            else if (colliderInFormation &&
                                this.getState() != STATE_CHARGING && this.getState() != STATE_DYING
                                && this.getState() != STATE_DEAD
                                && this.getState() != STATE_MELEE_LOSS && this.getState() != STATE_MELEE_WIN
                                && this.getState() != STATE_ATTACKING && this.getState() != STATE_RELOADING)
                            {
                                _reacting = false;
                                _state = STATE_READY;
                                if (myFormation != null)
                                    myFormation.removeSoldier(this);
                                _screen.getPlayerFormation().addSoldier(this);
                                _screen.removeLooseSoldier(this);
                            }
                        }
                    }
                }
            }
        }
示例#3
0
        public void checkNonFatalCollision(ScreenObject so, TimeSpan timeSpan)
        {
            float soX, soY, soWidth, soHeight;
            float coX, coY, coWidth, coHeight;

            bool collision = true;

            _screenColliders.Clear();

            // pour all of the screen objects into the list of objects to check for collisions against to start with
            foreach (ScreenObject sObj in _screenObjects)
            {
                if (!(sObj is Soldier) && so.getState() != ScreenObject.STATE_DEAD && so.getState() != ScreenObject.STATE_DYING)
                    _screenColliders.Add(sObj);
            }

            if (so.getState() != ScreenObject.STATE_DEAD || so.getState() != ScreenObject.STATE_DYING)
            {
                // get the values here so we aren't calling functions like crazy
                // pavise HACK
                if (so is Pavise)
                {
                    soX = so.getPosition().X;
                    soY = so.getPosition().Y - 10;
                    soWidth = so.getWidth();
                    soHeight = so.getHeight() + 10;
                }
                else
                {
                    soX = so.getPosition().X;
                    soY = so.getPosition().Y;
                    soWidth = so.getWidth();
                    soHeight = so.getHeight();
                }
                foreach (ScreenObject co in _screenColliders)
                {
                    if (so != co)
                    {
                        // pavise HACK
                        if (so is Pavise)
                        {
                            coX = co.getPosition().X;
                            coY = co.getPosition().Y - 10;
                            coWidth = co.getWidth();
                            coHeight = co.getHeight() + 10;
                        }
                        else
                        {
                            coX = co.getPosition().X;
                            coY = co.getPosition().Y;
                            coWidth = co.getWidth();
                            coHeight = co.getHeight();
                        }

                        collision = true;

                        // see if we didn't collide
                        if (soX > coX + coWidth)
                            collision = false;
                        else if (soX + soWidth < coX)
                            collision = false;
                        else if (soY > coY + coHeight)
                            collision = false;
                        else if (soY + soHeight < coY)
                            collision = false;

                        if (collision)
                        {
                            so.collide(co, timeSpan);
                            co.collide(so, timeSpan);
                        }
                    }
                }
            }
        }
示例#4
0
 public override void collide(ScreenObject collider, TimeSpan timeSpan)
 {
     if (collider is PikeTip)
     {
         Pikeman pikeman = ((PikeTip)collider).getPikeman();
         if (pikeman.getState() != Pikeman.STATE_RECOILING &&
             pikeman.getState() != STATE_DYING &&
             pikeman.getState() != STATE_DEAD &&
             pikeman.getState() != Soldier.STATE_MELEE_LOSS &&
             pikeman.getState() != Soldier.STATE_MELEE_WIN &&
             pikeman.getState() != Pikeman.STATE_RAISING &&
             pikeman.guardTarget == this._pikeman)
         {
             pikeman.recoil();
             if (_pikeman is Colmillos)
             {
                 _pikeman._destination.X = collider.getCenter().X + (collider.getSide() == BattleScreen.SIDE_ENEMY ? 1 : -1) * collider.getWidth() * 0.5f + Soldier.WIDTH * 0.35f;
             }
             ((Targeteer)_pikeman).setReactionDest(collider.getCenter().X + (collider.getSide() == BattleScreen.SIDE_ENEMY ? 1 : -1) * collider.getWidth() * 0.5f + Soldier.WIDTH * 0.35f);
             ((Targeteer)_pikeman).resetDefendTimer();
         }
     }
 }