public void Read(out TextureDirection dir) { ReadTypeCheck(DataType.TextureDirection); int val; Read(out val); dir = (TextureDirection)val; }
public void Move(float move, bool isMovingObject) { //only control the player if grounded or airControl is turned on if (m_Grounded || m_AirControl) { // Move the character by finding the target velocity Vector3 targetVelocity = new Vector2(move * 10f, m_Rigidbody2D.velocity.y); // And then smoothing it out and applying it to the character m_Rigidbody2D.velocity = Vector3.SmoothDamp(m_Rigidbody2D.velocity, targetVelocity, ref m_Velocity, m_MovementSmoothing); /* * // If the input is moving the player right and the player is facing left... * if (move > 0 && !m_FacingRight && !isMovingObject) * { * // ... flip the player. * m_FacingRight = !m_FacingRight; * } * // Otherwise if the input is moving the player left and the player is facing right... * else if (move < 0 && m_FacingRight && !isMovingObject) * { * // ... flip the player. * m_FacingRight = !m_FacingRight; * } */ if (move > 0) { if (isMovingObject) { // Going right direction = TextureDirection.RIGHT; } // If the input is moving the player right and the player is facing left... if (!m_FacingRight && !isMovingObject) { // ... flip the player. CmdUpdateServerSyncedVariable(!m_FacingRight); } } else if (move < 0) { if (isMovingObject) { // Going left direction = TextureDirection.LEFT; } // Otherwise if the input is moving the player left and the player is facing right... if (m_FacingRight && !isMovingObject) { // ... flip the player. CmdUpdateServerSyncedVariable(!m_FacingRight); } } } }
// Updates the entity public virtual void Update(ref GameTime gameTime) { CollidingWithBoundries = false; Sprite.Update(ref gameTime); // Checks direction of movement to change direction of texture if (Velocity.X < 0) { TextureDirection = TextureDirection.Left; } if (Velocity.X > 0) { TextureDirection = TextureDirection.Right; } // Updates the hitbox HitBox = new Rectangle( (int)Position.X - Sprite.Width / 2 * Sprite.Scale, (int)Position.Y - Sprite.Height / 2 * Sprite.Scale, Sprite.Width * Sprite.Scale, Sprite.Height * Sprite.Scale); // Updates movment, TO BE CHANGED FOR ACCURACY Acceleration = Game1.WindowManager.GetGameplayWindow().CurrentLevel.Gravity; Velocity += Acceleration * Game1.WindowManager.GetGameplayWindow().CurrentLevel.Gravity *(ObeysGravity ? 1 : 0); Position += Acceleration * (float)Math.Pow(gameTime.ElapsedGameTime.TotalSeconds, 2.0) / 2 + Velocity * (float)gameTime.ElapsedGameTime.TotalSeconds; // CHECKS COLLISION WITH BOUNDRIES if (Position.X - HitBox.Width / 2 < Game1.WindowManager.GetGameplayWindow().CurrentLevel.Boundries.Left) { Position = new Vector2(Game1.WindowManager.GetGameplayWindow().CurrentLevel.Boundries.Left + HitBox.Width / 2, Position.Y); Velocity *= new Vector2(0, 1); CollidingWithBoundries = true; } if (Position.X + HitBox.Width / 2 > Game1.WindowManager.GetGameplayWindow().CurrentLevel.Boundries.Right) { Position = new Vector2(Game1.WindowManager.GetGameplayWindow().CurrentLevel.Boundries.Right - HitBox.Width / 2, Position.Y); Velocity *= new Vector2(0, 1); CollidingWithBoundries = true; } if (Position.Y - HitBox.Height / 2 < Game1.WindowManager.GetGameplayWindow().CurrentLevel.Boundries.Top) { Position = new Vector2(Position.X, Game1.WindowManager.GetGameplayWindow().CurrentLevel.Boundries.Top + HitBox.Height / 2); Velocity *= new Vector2(1, 0); CollidingWithBoundries = true; } if (Position.Y + HitBox.Height / 2 > Game1.WindowManager.GetGameplayWindow().CurrentLevel.Boundries.Bottom) { Position = new Vector2(Position.X, Game1.WindowManager.GetGameplayWindow().CurrentLevel.Boundries.Bottom - HitBox.Height / 2); Velocity *= new Vector2(1, 0); CollidingWithBoundries = true; } }
public void Write(TextureDirection dir) { Write(DataType.TextureDirection); Write((int)dir); }