public virtual bool Update(IMap map, float seconds) { if (_info.Physics) { this.Movement.Y += Player.gravity * seconds; Move(new Vector2(0,Movement.Y*seconds)); if (map.Collides(this)) { Move(new Vector2(0, -Movement.Y*seconds)); Movement.Y *= -_info.bounceFactor; Movement.X *= _info.bounceFactor; if (_info.CollisionDespawn) return false; } Move(new Vector2(Movement.X*seconds, 0)); if (map.Collides(this)) { Move(new Vector2(-Movement.X*seconds,0)); Movement.X *= -_info.bounceFactor; Movement.Y *= _info.bounceFactor; if (_info.CollisionDespawn) return false; } } else { Move(Movement * seconds); if (_info.CollisionDespawn && map.Collides(this)) return false; } lifeTime -= seconds; _angle = (float)Math.Atan2(Movement.Y, Movement.X); return lifeTime>0; }
public void Update(IMap map, float secs) { if (_info.attractor != null) { Vector2 diff = (_info.attractor.MidPosition - _position); float length = diff.Length(); _acceleration = diff*_info.attraction / (length); if (length < 8) _alive = false; } if (_info.collides) { _position.Y += _speed.Y * secs; if (map.Collides(_position)) { _position.Y -= _speed.Y * secs; _speed.Y = -_speed.Y*dampening; if (_info.sticky) _stuck = true; } _position.X += _speed.X * secs; if (map.Collides(_position)) { _position.X -= _speed.X * secs; _speed.X = -_speed.X*dampening; if (_info.sticky) _stuck = true; } } else { _position += _speed * secs; } _speed += _acceleration * secs; if (_info.maxSpeed > 0) { float len =_speed.Length(); if (_speed.Length() > _info.maxSpeed) _speed /= len / _info.maxSpeed; } if (_stuck) _speed = Vector2.Zero; _lifeTime -= secs; _rotation += _rotSpeed * secs; if (_lifeTime <= 0) _alive = false; }
void TryMove(Vector2 movement, IMap map) { Position += Vector2.UnitX * movement.X; if (map.Collides(this)) { if (movement.X > 0) { _position.X = (float)(16 * Math.Floor(_position.X / 16.0)+_collisionOffset.X); Position = _position; } else { _position.X = (float)(16 * Math.Ceiling(_position.X / 16.0)+_collisionOffset.Y); Position = _position; } wallCollision = true; _speed.X = 0; } _onGround = false; Position += Vector2.UnitY * movement.Y; if (map.Collides(this)) { if (_speed.Y > 0) { _onGround = true; _position.Y = (float)(16 * Math.Floor(_position.Y / 16.0)) + _collisionOffset.Z; Position = _position; } else { _position.Y = (float)(16 * Math.Ceiling(_position.Y / 16.0)) + _collisionOffset.W; Position = _position; } _speed = Vector2.Zero; } if (!jump && !_onGround) flying = true; }
public void Update(IMap map, float ms) { _attacks.AddRange(_addAttack); _addAttack.Clear(); for (int x = 0; x < _attacks.Count; x++) { _attacks[x].Update(ms); if ((!_attacks[x].Penetrates && map.Collides(_attacks[x])) || _attacks[x].lifeTime < 0) { _attacks.RemoveAt(x); x--; } } }