Exemple #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();
            }
        }
Exemple #2
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);
                        }
                    }
                }
            }
        }
Exemple #3
0
        public override void collide(ScreenObject collider, TimeSpan timeSpan)
        {
            float shimmy = (float)timeSpan.TotalMilliseconds * _speed;

            if (collider == _killer || _state == STATE_DEAD || _state == STATE_DYING)
                return;
            if (collider is Terrain)
            {
                terrainCollider = (Terrain)collider;
            }
            else 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() == this.myFormation))
                    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) && _side != BattleScreen.SIDE_NEUTRAL)
                    {
                        hit();
                        _killer = collider;
                        ((PikeTip)collider).getPikeman().recoil();
                    }
                    else if (this is Targeteer)
                    {
                        if ( (!(this is Colmillos) && ((Targeteer)this)._hasShield) || (this is Colmillos && !((ColmillosFormation)((Colmillos)this).myFormation).attacked))
                        {
                            ((Targeteer)this).shield();
                            this.setReactionDest(collider.getCenter().X + 50f);//((collider.getSide() == BattleScreen.SIDE_ENEMY? 1 : -1 ) * collider.getWidth() * 0.5f + Soldier.WIDTH * 0.35f
                        }
                        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 (((WeaponSwing)collider).getSoldier() is Colmillos)
                {
                    if (!((WeaponSwing)collider).hit)
                    {
                        if (this is Targeteer)
                            ((Targeteer)this).shieldBreak();
                        else
                        {
                            hit();
                            _killer = collider;
                        }
                        ((WeaponSwing)collider).hit = true;
                        _screen.removeScreenObject(collider);
                    }

                }
                else 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 = ((Soldier)collider).myFormation == _screen.getPlayerFormation();
                    thisInFormation = myFormation == _screen.getPlayerFormation();
                }
                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 (myFormation == null && ((Soldier)collider).myFormation == null
                        && _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 && _side == BattleScreen.SIDE_PLAYER) || (collider.getSide() == BattleScreen.SIDE_PLAYER && _side == BattleScreen.SIDE_NEUTRAL)))
                        {
                            //fighting
                            if (_side != collider.getSide() && !(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) && (!(collider is Wolf) || collider.getState() != Wolf.STATE_KILL) && (!(this is Wolf) || this._state != Wolf.STATE_KILL))
                            {
                                bool rescueFight = (_side == BattleScreen.SIDE_PLAYER && !thisInFormation) ||
                                                    (collider.getSide() == BattleScreen.SIDE_PLAYER && !colliderInFormation);

                                if (this is Colmillos)
                                {
                                    if (_state != Colmillos.STATE_ATTACK)
                                        attack();
                                    _destination = _position;
                                }
                                else if (collider is Colmillos)
                                {
                                    if (collider.getState() != Colmillos.STATE_ATTACK)
                                        ((Colmillos)collider).attack();

                                    ((Colmillos)collider)._destination = ((Colmillos)collider)._position;
                                }
                                else 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);
                                }
                            }
                        }
                    }
                }
            }
        }
Exemple #4
0
        private Soldier checkGuard(Soldier guard, Soldier shot, ScreenObject enemy)
        {
            if (guard == null)
            {
                if (shot.getState() != Soldier.STATE_MELEE_WIN && shot.getState() != Soldier.STATE_MELEE_LOSS)
                    return shot;
                else
                    return null;
            }
            else
            {
                bool ySmaller = Math.Abs(enemy.getPosition().Y - shot.getDestination().Y) < Math.Abs(enemy.getPosition().Y - guard.getDestination().Y);
                if (ySmaller && shot.guardTarget == null && shot.getState() != Soldier.STATE_MELEE_WIN && shot.getState() != Soldier.STATE_MELEE_LOSS)
                    return shot;
            }

            return guard;
        }