Ejemplo n.º 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();
            }
        }
Ejemplo n.º 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);
                        }
                    }
                }
            }
        }