Example #1
0
        /// <summary>
        /// Checks to see if this ball is stuck in/on a wall
        /// </summary>
        private void stuckBall(Ball ball, int tick)
        {   //Exists?
            if (ball == null)
            {
                return;
            }

            short x = ball._state.positionX;
            short y = ball._state.positionY;

            LvlInfo.Tile tile = getTile(x, y);
            if (tile.Vision == 1 || getTerrain(x, y).soccerEnabled == false)
            {
                //Are we being carried or been spawned in?
                if (ball.ballStatus != (int)Ball.BallStatus.Dropped)
                {
                    return;
                }

                if (!ball.deadBall && (tick - ball._state.lastUpdateServer) > 5000) //5 secs
                {
                    ball.deadBall = true;
                    //Update our time
                    int updateTick = ((Environment.TickCount >> 16) << 16) + (ball._state.lastUpdateServer & 0xFFFF);
                    ball._state.lastUpdate       = updateTick;
                    ball._state.lastUpdateServer = tick;

                    setTicker(5, 3, 500, "Ball Respawning: ", delegate()
                    {
                        //Make sure someone didnt use *getball
                        if (!ball.deadBall)
                        {
                            return;
                        }
                        //Respawn it
                        Ball.Spawn_Ball(null, ball);
                    });
                }
            }
        }
Example #2
0
        /// <summary>
        /// Updates the state in accordance with movement instructions
        /// </summary>
        public virtual bool updateState(double delta)
        {       //If we're dead
            if (delta <= 0 || !bEnabled)
            {
                return(false);
            }

            //Are we frozen?
            if (_tickMovementFrozenUntil != 0 && _tickMovementFrozenUntil > Environment.TickCount)
            {
                _isThrustingForward  = false;
                _isThrustingBackward = false;
                _isStrafingLeft      = false;
                _isStrafingRight     = false;
            }
            else
            {
                _tickMovementFrozenUntil = 0;
            }

            //Get our speed values for our current terrain
            SpeedValues stats = _type.TerrainSpeeds[_terrainType];

            //Apply our rotation
            if (_isRotatingLeft)
            {
                _direction -= ((_rollRotate / 10000.0d) * delta);
            }
            else if (_isRotatingRight)
            {
                _direction += ((_rollRotate / 10000.0d) * delta);
            }

            _direction %= 240;

            if (_direction < 0)
            {
                _direction = 240 + _direction;
            }

            //Vectorize our direction, unf.
            Vector2 directionVector = Vector2.createUnitVector(_direction);
            Vector2 accelVector     = Vector2.Zero;

            //Apply our thrusting instructions
            _thrustDirection = 0;

            if (_isThrustingForward)
            {
                accelVector.x   += directionVector.x * _rollThrust;
                accelVector.y   += directionVector.y * _rollThrust;
                _thrustDirection = _direction;
            }
            else if (_isThrustingBackward)
            {
                accelVector.x   += directionVector.x * -_rollThrustBack;
                accelVector.y   += directionVector.y * -_rollThrustBack;
                _thrustDirection = calculateNewDirection(_direction, 120);
            }

            if (_isStrafingLeft)
            {
                double tmpX = directionVector.x;
                accelVector.x += directionVector.y * _rollThrustStrafe;
                accelVector.y += -tmpX * _rollThrustStrafe;
            }
            else if (_isStrafingRight)
            {
                double tmpX = directionVector.x;
                accelVector.x += -directionVector.y * _rollThrustStrafe;
                accelVector.y += tmpX * _rollThrustStrafe;
            }

            //Apply our acceleration
            _velocity.x += accelVector.x * (delta / 1000.0d);
            _velocity.y += accelVector.y * (delta / 1000.0d);

            //Apply friction
            double frictionMod = 1000 - ((((((double)_rollFriction) * 800) / 256) / 10) * (delta / 10.0d));

            _velocity.x = ((_velocity.x * frictionMod) / 1000.0d);
            _velocity.y = ((_velocity.y * frictionMod) / 1000.0d);

            //TODO: Add the effects of projectile explosions on our velocity
            //TODO: Check for physics react accordingly

            //Clamp our resulting velocity
            if (_velocity.Length >= _rollTopSpeed / 1)
            {
                _velocity.Normalize(_rollTopSpeed / 1);
            }

            //Calculate our new position
            double xPerTick = _velocity.x / 10000.0d;
            double yPerTick = _velocity.y / 10000.0d;

            yPerTick *= 0.70f;                                  //Y coordinates are bigger than x by 0.7?

            Vector2 newPosition = new Vector2(_position.x + (xPerTick * delta), _position.y + (yPerTick * delta));

            //Clamp our position
            newPosition.x = Math.Min(newPosition.x, (AssetManager.Manager.Level.Width - 1) * 16);
            newPosition.x = Math.Max(newPosition.x, 0);
            newPosition.y = Math.Min(newPosition.y, (AssetManager.Manager.Level.Height - 1) * 16);
            newPosition.y = Math.Max(newPosition.y, 0);

            //Check for collisions
            int tileX    = (int)Math.Floor(_position.x / 16);
            int tileY    = (int)Math.Floor(_position.y / 16);
            int newTileX = (int)Math.Floor(newPosition.x / 16);
            int newTileY = (int)Math.Floor(newPosition.y / 16);

            LvlInfo.Tile tile = _arena._tiles[(newTileY * _arena._levelWidth) + newTileX];

            if (tile.Blocked)
            {
                bool collision = false;

                if (Math.Abs(tileX - newTileX) > 0)
                {
                    _velocity.x *= -1;
                    collision    = true;
                }

                if (Math.Abs(tileY - newTileY) > 0)
                {
                    _velocity.y *= -1;
                    collision    = true;
                }

                if (collision)
                {
                    _velocity *= _type.BouncePercent / 1000.0d;
                }
            }

            //Finally, we can adjust our position
            _position.x = newPosition.x;
            _position.y = newPosition.y;

            //Update the state, converting our floats into the nearest short values
            _state.positionX  = (short)(uint)_position.x;
            _state.positionY  = (short)(uint)_position.y;
            _state.velocityX  = (short)(uint)_velocity.x;
            _state.velocityY  = (short)(uint)_velocity.y;
            _state.yaw        = (byte)_direction;
            _state.direction  = getDirection();
            _state.lastUpdate = Environment.TickCount;

            //TODO: Apply vector tolerance to decide whether to update
            return(true);
        }