• Create Account

### #ActualEusKoder

Posted 08 August 2012 - 04:00 AM

Hello, I am developing a 2d platform game with XNA and the starter kit plataformer of msdn.
The fact is that I could use the method of physics that brings the starter kit, (thought they were independent of fps) but to start porting the game to linux by monoGame and lowered fps (windows 63, Ubuntu / Kubuntu 57-59) I then checked that the player did not move properly.

The funny part is that the enemies are moving properly, it have only movement in the x axis.

Now being tested in windows disabling Vertical Sync by:

[source lang="csharp"] graphics.SynchronizeWithVerticalRetrace = false; IsFixedTimeStep = false;[/source]

I leave the pieces of code relevant to them a look.
I believe that these method would be involved:

ApplyPhysics

[source lang="csharp"] public void ApplyPhysics(GameTime gameTime) { float elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds; Vector2 previousPosition = Position; // Base velocity is a combination of horizontal movement control and // acceleration downward due to gravity. velocity.X += movement * MoveAcceleration * elapsed; velocity.Y = MathHelper.Clamp(velocity.Y + GravityAcceleration * elapsed, -MaxFallSpeed, MaxFallSpeed); velocity.Y = DoJump(velocity.Y, gameTime); // Apply pseudo-drag horizontally. if (IsOnGround) velocity.X *= GroundDragFactor; else velocity.X *= GroundDragFactor; //velocity.X *= AirDragFactor; // Prevent the player from running faster than his top speed. velocity.X = MathHelper.Clamp(velocity.X, -MaxMoveSpeed, MaxMoveSpeed); // Apply velocity. Position += velocity *elapsed; Position = new Vector2((float)Math.Round(Position.X), (float)Math.Round(Position.Y)); // If the player is now colliding with the level, separate them. HandleCollisions(gameTime); // If the collision stopped us from moving, reset the velocity to zero. if (Position.X == previousPosition.X) velocity.X = 0; if (Position.Y == previousPosition.Y) { velocity.Y = 0; jumpTime = 0.0f; } }[/source]

I'm trying to simplify character movement putting it as the enemy,

[source lang="csharp"] Vector2 velocity = new Vector2((int)direction * MoveSpeed * elapsed, 0.0f); position = position + velocity;[/source]

but then come the problems of collisions of the character in both axes (X, Y) ...

Attached to the post player and enemy classes of my project.

I would appreciate a little help from someone who is put in the subject, thanks in advance for your time and sorry for my bad English ;).

### #5EusKoder

Posted 08 August 2012 - 03:59 AM

Hello, I am developing a 2d platform game with XNA and the starter kit plataformer of msdn.
The fact is that I could use the method of physics that brings the starter kit, (thought they were independent of fps) but to start porting the game to linux by monoGame and lowered fps (windows 63, Ubuntu / Kubuntu 57-59) I then checked that the player did not move properly.

The funny part is that the enemies are moving properly, it have only movement in the x axis.

Now being tested in windows disabling Vertical Sync by:

[source lang="csharp"] graphics.SynchronizeWithVerticalRetrace = false; IsFixedTimeStep = false;[/source]

I leave the pieces of code relevant to them a look.
I believe that these two methods would be involved:

ApplyPhysics

[source lang="csharp"] public void ApplyPhysics(GameTime gameTime) { float elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds; Vector2 previousPosition = Position; // Base velocity is a combination of horizontal movement control and // acceleration downward due to gravity. velocity.X += movement * MoveAcceleration * elapsed; velocity.Y = MathHelper.Clamp(velocity.Y + GravityAcceleration * elapsed, -MaxFallSpeed, MaxFallSpeed); velocity.Y = DoJump(velocity.Y, gameTime); // Apply pseudo-drag horizontally. if (IsOnGround) velocity.X *= GroundDragFactor; else velocity.X *= GroundDragFactor; //velocity.X *= AirDragFactor; // Prevent the player from running faster than his top speed. velocity.X = MathHelper.Clamp(velocity.X, -MaxMoveSpeed, MaxMoveSpeed); // Apply velocity. Position += velocity *elapsed; Position = new Vector2((float)Math.Round(Position.X), (float)Math.Round(Position.Y)); // If the player is now colliding with the level, separate them. HandleCollisions(gameTime); // If the collision stopped us from moving, reset the velocity to zero. if (Position.X == previousPosition.X) velocity.X = 0; if (Position.Y == previousPosition.Y) { velocity.Y = 0; jumpTime = 0.0f; } }[/source]

HandleCollisions

[source lang="csharp"]private void HandleCollisions(GameTime gameTime) { // Get the player's bounding rectangle and find neighboring tiles. Rectangle bounds = BoundingRectangle; int leftTile = (int)Math.Floor((float)bounds.Left / Tile.Width); int rightTile = (int)Math.Ceiling(((float)bounds.Right / Tile.Width)) - 1; int topTile = (int)Math.Floor((float)bounds.Top / Tile.Height); int bottomTile = (int)Math.Ceiling(((float)bounds.Bottom / Tile.Height)) - 1; // Reset flag to search for ground collision. isOnGround = false; // For each potentially colliding tile, for (int y = topTile; y <= bottomTile; ++y) { for (int x = leftTile; x <= rightTile; ++x) { // If this tile is collidable, TileCollision collision = Level.GetCollision(x, y); if (collision != TileCollision.Passable) { // Determine collision depth (with direction) and magnitude. Rectangle tileBounds = Level.GetBounds(x, y); Vector2 depth = RectangleExtensions.GetIntersectionDepth(bounds, tileBounds); if (depth != Vector2.Zero) { float absDepthX = Math.Abs(depth.X); float absDepthY = Math.Abs(depth.Y); // Resolve the collision along the shallow axis. if (absDepthY < absDepthX || collision == TileCollision.Platform) { // If we crossed the top of a tile, we are on the ground. if (previousBottom <= tileBounds.Top) isOnGround = true; // Ignore platforms, unless we are on the ground. if (collision == TileCollision.Impassable || IsOnGround) { // Resolve the collision along the Y axis. Position = new Vector2(Position.X, Position.Y + depth.Y); // Perform further collisions with the new bounds. bounds = BoundingRectangle; } } else if (collision == TileCollision.Impassable) // Ignore platforms. { // Resolve the collision along the X axis. Position = new Vector2(Position.X + depth.X, Position.Y); // Perform further collisions with the new bounds. bounds = BoundingRectangle; } if (collision == TileCollision.Spike) { // Resolve the collision along the shallow axis. if (absDepthY < absDepthX) { // Resolve the collision along the Y axis. Position = new Vector2(Position.X, Position.Y + depth.Y); // Perform further collisions with the new bounds. bounds = BoundingRectangle; isJumping = true; velocity.Y = DoJump(-40000.0f, gameTime); level.PlayerStatus.CurrentHealth -= 10; } else { // Resolve the collision along the X axis. Position = new Vector2(Position.X + depth.X, Position.Y); // Perform further collisions with the new bounds. bounds = BoundingRectangle; } } } } } } // Save the new bounds bottom. previousBottom = bounds.Bottom; }[/source]

I'm trying to simplify character movement putting it as the enemy,

[source lang="csharp"] Vector2 velocity = new Vector2((int)direction * MoveSpeed * elapsed, 0.0f); position = position + velocity;[/source]

but then come the problems of collisions of the character in both axes (X, Y) ...

Attached to the post player and enemy classes of my project.

I would appreciate a little help from someone who is put in the subject, thanks in advance for your time and sorry for my bad English ;).

### #4EusKoder

Posted 08 August 2012 - 03:58 AM

Hello, I am developing a 2d platform game with XNA and the starter kit plataformer of msdn.
The fact is that I could use the method of physics that brings the starter kit, (thought they were independent of fps) but to start porting the game to linux by monoGame and lowered fps (windows 63, Ubuntu / Kubuntu 57-59) I then checked that the player did not move properly.

The funny part is that the enemies are moving properly, it have only movement in the x axis.

Now being tested in windows disabling Vertical Sync by:

[source lang="csharp"] graphics.SynchronizeWithVerticalRetrace = false; IsFixedTimeStep = false;[/source]

I leave the pieces of code relevant to them a look.
I believe that these two methods would be involved:

ApplyPhysics

[source lang="csharp"] public void ApplyPhysics(GameTime gameTime) { float elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds; Vector2 previousPosition = Position; // Base velocity is a combination of horizontal movement control and // acceleration downward due to gravity. velocity.X += movement * MoveAcceleration * elapsed; velocity.Y = MathHelper.Clamp(velocity.Y + GravityAcceleration * elapsed, -MaxFallSpeed, MaxFallSpeed); velocity.Y = DoJump(velocity.Y, gameTime); // Apply pseudo-drag horizontally. if (IsOnGround) velocity.X *= GroundDragFactor; else velocity.X *= GroundDragFactor; //velocity.X *= AirDragFactor; // Prevent the player from running faster than his top speed. velocity.X = MathHelper.Clamp(velocity.X, -MaxMoveSpeed, MaxMoveSpeed); // Apply velocity. Position += velocity *elapsed; Position = new Vector2((float)Math.Round(Position.X), (float)Math.Round(Position.Y)); // If the player is now colliding with the level, separate them. HandleCollisions(gameTime); // If the collision stopped us from moving, reset the velocity to zero. if (Position.X == previousPosition.X) velocity.X = 0; if (Position.Y == previousPosition.Y) { velocity.Y = 0; jumpTime = 0.0f; } }[/source]

HandleCollisions

[source lang="csharp"]private void HandleCollisions(GameTime gameTime) { // Get the player's bounding rectangle and find neighboring tiles. Rectangle bounds = BoundingRectangle; int leftTile = (int)Math.Floor((float)bounds.Left / Tile.Width); int rightTile = (int)Math.Ceiling(((float)bounds.Right / Tile.Width)) - 1; int topTile = (int)Math.Floor((float)bounds.Top / Tile.Height); int bottomTile = (int)Math.Ceiling(((float)bounds.Bottom / Tile.Height)) - 1; // Reset flag to search for ground collision. isOnGround = false;[/source]
[source lang="csharp"] // For each potentially colliding tile, for (int y = topTile; y <= bottomTile; ++y) { for (int x = leftTile; x <= rightTile; ++x) { // If this tile is collidable, TileCollision collision = Level.GetCollision(x, y); if (collision != TileCollision.Passable) { // Determine collision depth (with direction) and magnitude. Rectangle tileBounds = Level.GetBounds(x, y); Vector2 depth = RectangleExtensions.GetIntersectionDepth(bounds, tileBounds); if (depth != Vector2.Zero) { float absDepthX = Math.Abs(depth.X); float absDepthY = Math.Abs(depth.Y); // Resolve the collision along the shallow axis. if (absDepthY < absDepthX || collision == TileCollision.Platform) { // If we crossed the top of a tile, we are on the ground. if (previousBottom <= tileBounds.Top) isOnGround = true; // Ignore platforms, unless we are on the ground. if (collision == TileCollision.Impassable || IsOnGround) { // Resolve the collision along the Y axis. Position = new Vector2(Position.X, Position.Y + depth.Y); // Perform further collisions with the new bounds. bounds = BoundingRectangle; } } else if (collision == TileCollision.Impassable) // Ignore platforms. { // Resolve the collision along the X axis. Position = new Vector2(Position.X + depth.X, Position.Y); // Perform further collisions with the new bounds. bounds = BoundingRectangle; } if (collision == TileCollision.Spike) { // Resolve the collision along the shallow axis. if (absDepthY < absDepthX) { // Resolve the collision along the Y axis. Position = new Vector2(Position.X, Position.Y + depth.Y); // Perform further collisions with the new bounds. bounds = BoundingRectangle; isJumping = true; velocity.Y = DoJump(-40000.0f, gameTime); level.PlayerStatus.CurrentHealth -= 10; } else { // Resolve the collision along the X axis. Position = new Vector2(Position.X + depth.X, Position.Y); // Perform further collisions with the new bounds. bounds = BoundingRectangle; } } } } } } // Save the new bounds bottom. previousBottom = bounds.Bottom; }[/source]

I'm trying to simplify character movement putting it as the enemy,

[source lang="csharp"] Vector2 velocity = new Vector2((int)direction * MoveSpeed * elapsed, 0.0f); position = position + velocity;[/source]

but then come the problems of collisions of the character in both axes (X, Y) ...

Attached to the post player and enemy classes of my project.

I would appreciate a little help from someone who is put in the subject, thanks in advance for your time and sorry for my bad English ;).

### #3EusKoder

Posted 08 August 2012 - 02:49 AM

Hello, I am developing a 2d platform game with XNA and the starter kit plataformer of msdn.
The fact is that I could use the method of physics that brings the starter kit, (thought they were independent of fps) but to start porting the game to linux by monoGame and lowered fps (windows 63, Ubuntu / Kubuntu 57-59) I then checked that the player did not move properly.

The funny part is that the enemies are moving properly, it have only movement in the x axis.

Now being tested in windows disabling Vertical Sync by:

[source lang="csharp"] graphics.SynchronizeWithVerticalRetrace = false; IsFixedTimeStep = false;[/source]

I leave the pieces of code relevant to them a look.
I believe that these two methods would be involved:

ApplyPhysics

[source lang="csharp"] public void ApplyPhysics(GameTime gameTime) { float elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds; Vector2 previousPosition = Position; // Base velocity is a combination of horizontal movement control and // acceleration downward due to gravity. velocity.X += movement * MoveAcceleration * elapsed; velocity.Y = MathHelper.Clamp(velocity.Y + GravityAcceleration * elapsed, -MaxFallSpeed, MaxFallSpeed); velocity.Y = DoJump(velocity.Y, gameTime); // Apply pseudo-drag horizontally. if (IsOnGround) velocity.X *= GroundDragFactor; else velocity.X *= GroundDragFactor; //velocity.X *= AirDragFactor; // Prevent the player from running faster than his top speed. velocity.X = MathHelper.Clamp(velocity.X, -MaxMoveSpeed, MaxMoveSpeed); // Apply velocity. Position += velocity *elapsed; Position = new Vector2((float)Math.Round(Position.X), (float)Math.Round(Position.Y)); // If the player is now colliding with the level, separate them. HandleCollisions(gameTime); // If the collision stopped us from moving, reset the velocity to zero. if (Position.X == previousPosition.X) velocity.X = 0; if (Position.Y == previousPosition.Y) { velocity.Y = 0; jumpTime = 0.0f; } }[/source]

HandleCollisions

[source lang="csharp"]private void HandleCollisions(GameTime gameTime) { // Get the player's bounding rectangle and find neighboring tiles. Rectangle bounds = BoundingRectangle; int leftTile = (int)Math.Floor((float)bounds.Left / Tile.Width); int rightTile = (int)Math.Ceiling(((float)bounds.Right / Tile.Width)) - 1; int topTile = (int)Math.Floor((float)bounds.Top / Tile.Height); int bottomTile = (int)Math.Ceiling(((float)bounds.Bottom / Tile.Height)) - 1; // Reset flag to search for ground collision. isOnGround = false; // For each potentially colliding tile, for (int y = topTile; y <= bottomTile; ++y) { for (int x = leftTile; x <= rightTile; ++x) { // If this tile is collidable, TileCollision collision = Level.GetCollision(x, y); if (collision != TileCollision.Passable) { // Determine collision depth (with direction) and magnitude. Rectangle tileBounds = Level.GetBounds(x, y); Vector2 depth = RectangleExtensions.GetIntersectionDepth(bounds, tileBounds); if (depth != Vector2.Zero) { float absDepthX = Math.Abs(depth.X); float absDepthY = Math.Abs(depth.Y); // Resolve the collision along the shallow axis. if (absDepthY < absDepthX || collision == TileCollision.Platform) { // If we crossed the top of a tile, we are on the ground. if (previousBottom <= tileBounds.Top) isOnGround = true; // Ignore platforms, unless we are on the ground. if (collision == TileCollision.Impassable || IsOnGround) { // Resolve the collision along the Y axis. Position = new Vector2(Position.X, Position.Y + depth.Y); // Perform further collisions with the new bounds. bounds = BoundingRectangle; } } else if (collision == TileCollision.Impassable) // Ignore platforms. { // Resolve the collision along the X axis. Position = new Vector2(Position.X + depth.X, Position.Y); // Perform further collisions with the new bounds. bounds = BoundingRectangle; } if (collision == TileCollision.Spike) { // Resolve the collision along the shallow axis. if (absDepthY < absDepthX) { // Resolve the collision along the Y axis. Position = new Vector2(Position.X, Position.Y + depth.Y); // Perform further collisions with the new bounds. bounds = BoundingRectangle; isJumping = true; velocity.Y = DoJump(-40000.0f, gameTime); level.PlayerStatus.CurrentHealth -= 10; } else { // Resolve the collision along the X axis. Position = new Vector2(Position.X + depth.X, Position.Y); // Perform further collisions with the new bounds. bounds = BoundingRectangle; } } } } } } // Save the new bounds bottom. previousBottom = bounds.Bottom; }[/source]

I'm trying to simplify character movement putting it as the enemy,

[source lang="csharp"] Vector2 velocity = new Vector2((int)direction * MoveSpeed * elapsed, 0.0f); position = position + velocity;[/source]

but then come the problems of collisions of the character in both axes (X, Y) ...

Attached to the post player and enemy classes of my project.

I would appreciate a little help from someone who is put in the subject, thanks in advance for your time and sorry for my bad English ;).

### #2EusKoder

Posted 08 August 2012 - 02:45 AM

Hello, I am developing a 2d platform game with XNA and the starter kit plataformer of msdn.
The fact is that I could use the method of physics that brings the starter kit, (thought they were independent of fps) but to start porting the game to linux by monoGame and lowered fps (windows 63, Ubuntu / Kubuntu 57-59) I then checked that the player did not move properly.

The funny part is that the enemies are moving properly, it have only movement in the x axis.

Now being tested in windows disabling Vertical Sync by:

[source lang="csharp"] graphics.SynchronizeWithVerticalRetrace = false; IsFixedTimeStep = false;[/source]

I leave the pieces of code relevant to them a look.
I believe that these two methods would be involved:

ApplyPhysics

[source lang="csharp"] public void ApplyPhysics(GameTime gameTime) { float elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds; Vector2 previousPosition = Position; // Base velocity is a combination of horizontal movement control and // acceleration downward due to gravity. velocity.X += movement * MoveAcceleration * elapsed; velocity.Y = MathHelper.Clamp(velocity.Y + GravityAcceleration * elapsed, -MaxFallSpeed, MaxFallSpeed); velocity.Y = DoJump(velocity.Y, gameTime); // Apply pseudo-drag horizontally. if (IsOnGround) velocity.X *= GroundDragFactor; else velocity.X *= GroundDragFactor; //velocity.X *= AirDragFactor; // Prevent the player from running faster than his top speed. velocity.X = MathHelper.Clamp(velocity.X, -MaxMoveSpeed, MaxMoveSpeed); // Apply velocity. Position += velocity *elapsed; Position = new Vector2((float)Math.Round(Position.X), (float)Math.Round(Position.Y)); // If the player is now colliding with the level, separate them. HandleCollisions(gameTime); // If the collision stopped us from moving, reset the velocity to zero. if (Position.X == previousPosition.X) velocity.X = 0; if (Position.Y == previousPosition.Y) { velocity.Y = 0; jumpTime = 0.0f; } }[/source]

HandleCollisions

[source lang="csharp"]private void HandleCollisions(GameTime gameTime) { // Get the player's bounding rectangle and find neighboring tiles. Rectangle bounds = BoundingRectangle; int leftTile = (int)Math.Floor((float)bounds.Left / Tile.Width); int rightTile = (int)Math.Ceiling(((float)bounds.Right / Tile.Width)) - 1; int topTile = (int)Math.Floor((float)bounds.Top / Tile.Height); int bottomTile = (int)Math.Ceiling(((float)bounds.Bottom / Tile.Height)) - 1; // Reset flag to search for ground collision. isOnGround = false; // For each potentially colliding tile, for (int y = topTile; y <= bottomTile; ++y) { for (int x = leftTile; x <= rightTile; ++x) { // If this tile is collidable, TileCollision collision = Level.GetCollision(x, y); if (collision != TileCollision.Passable) { // Determine collision depth (with direction) and magnitude. Rectangle tileBounds = Level.GetBounds(x, y); Vector2 depth = RectangleExtensions.GetIntersectionDepth(bounds, tileBounds); if (depth != Vector2.Zero) { float absDepthX = Math.Abs(depth.X); float absDepthY = Math.Abs(depth.Y); // Resolve the collision along the shallow axis. if (absDepthY < absDepthX || collision == TileCollision.Platform) { // If we crossed the top of a tile, we are on the ground. if (previousBottom <= tileBounds.Top) isOnGround = true; // Ignore platforms, unless we are on the ground. if (collision == TileCollision.Impassable || IsOnGround) { // Resolve the collision along the Y axis. Position = new Vector2(Position.X, Position.Y + depth.Y); // Perform further collisions with the new bounds. bounds = BoundingRectangle; } } else if (collision == TileCollision.Impassable) // Ignore platforms. { // Resolve the collision along the X axis. Position = new Vector2(Position.X + depth.X, Position.Y); // Perform further collisions with the new bounds. bounds = BoundingRectangle; } if (collision == TileCollision.Spike) { // Resolve the collision along the shallow axis. if (absDepthY < absDepthX) { // Resolve the collision along the Y axis. Position = new Vector2(Position.X, Position.Y + depth.Y); // Perform further collisions with the new bounds. bounds = BoundingRectangle; isJumping = true; velocity.Y = DoJump(-40000.0f, gameTime); level.PlayerStatus.CurrentHealth -= 10; } else { // Resolve the collision along the X axis. Position = new Vector2(Position.X + depth.X, Position.Y); // Perform further collisions with the new bounds. bounds = BoundingRectangle; } } } } } } // Save the new bounds bottom. previousBottom = bounds.Bottom; }[/source]

I'm trying to simplify character movement putting it as the enemy,

[source lang="csharp"] Vector2 velocity = new Vector2((int)direction * MoveSpeed * elapsed, 0.0f); position = position + velocity;[/source]

but then come the problems of collisions of the character in both axes (X, Y) ...

Attached to the post player and enemy classes of my project.

I would appreciate a little help from someone who is put in the subject, thanks in advance for your time and sorry for my bad English ;).

### #1EusKoder

Posted 08 August 2012 - 02:44 AM

Hello, I am developing a 2d platform game with XNA and the starter kit plataformer of msdn.
The fact is that I could use the method of physics that brings the starter kit, (thought they were independent of fps) but to start porting the game to linux by monoGame and lowered fps (windows 63, Ubuntu / Kubuntu 57-59) I then checked that the player did not move properly.

The funny part is that the enemies are moving properly, it have only movement in the x axis.

Now being tested in windows disabling Vertical Sync by:

[source lang="csharp"] graphics.SynchronizeWithVerticalRetrace = false; IsFixedTimeStep = false;[/source]

I leave the pieces of code relevant to them a look.
I believe that these two methods would be involved:

ApplyPhysics

[source lang="csharp"] public void ApplyPhysics(GameTime gameTime) { float elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds; Vector2 previousPosition = Position; // Base velocity is a combination of horizontal movement control and // acceleration downward due to gravity. velocity.X += movement * MoveAcceleration * elapsed; velocity.Y = MathHelper.Clamp(velocity.Y + GravityAcceleration * elapsed, -MaxFallSpeed, MaxFallSpeed); velocity.Y = DoJump(velocity.Y, gameTime); // Apply pseudo-drag horizontally. if (IsOnGround) velocity.X *= GroundDragFactor; else velocity.X *= GroundDragFactor; //velocity.X *= AirDragFactor; // Prevent the player from running faster than his top speed. velocity.X = MathHelper.Clamp(velocity.X, -MaxMoveSpeed, MaxMoveSpeed); // Apply velocity. Position += velocity *elapsed; Position = new Vector2((float)Math.Round(Position.X), (float)Math.Round(Position.Y)); // If the player is now colliding with the level, separate them. HandleCollisions(gameTime); // If the collision stopped us from moving, reset the velocity to zero. if (Position.X == previousPosition.X) velocity.X = 0; if (Position.Y == previousPosition.Y) { velocity.Y = 0; jumpTime = 0.0f; } }[/source]

HandleCollisions

[source lang="csharp"]private void HandleCollisions(GameTime gameTime) { // Get the player's bounding rectangle and find neighboring tiles. Rectangle bounds = BoundingRectangle; int leftTile = (int)Math.Floor((float)bounds.Left / Tile.Width); int rightTile = (int)Math.Ceiling(((float)bounds.Right / Tile.Width)) - 1; int topTile = (int)Math.Floor((float)bounds.Top / Tile.Height); int bottomTile = (int)Math.Ceiling(((float)bounds.Bottom / Tile.Height)) - 1; // Reset flag to search for ground collision. isOnGround = false; // For each potentially colliding tile, for (int y = topTile; y <= bottomTile; ++y) { for (int x = leftTile; x <= rightTile; ++x) { // If this tile is collidable, TileCollision collision = Level.GetCollision(x, y); if (collision != TileCollision.Passable) { // Determine collision depth (with direction) and magnitude. Rectangle tileBounds = Level.GetBounds(x, y); Vector2 depth = RectangleExtensions.GetIntersectionDepth(bounds, tileBounds); if (depth != Vector2.Zero) { float absDepthX = Math.Abs(depth.X); float absDepthY = Math.Abs(depth.Y); // Resolve the collision along the shallow axis. if (absDepthY < absDepthX || collision == TileCollision.Platform) { // If we crossed the top of a tile, we are on the ground. if (previousBottom <= tileBounds.Top) isOnGround = true; // Ignore platforms, unless we are on the ground. if (collision == TileCollision.Impassable || IsOnGround) { // Resolve the collision along the Y axis. Position = new Vector2(Position.X, Position.Y + depth.Y); // Perform further collisions with the new bounds. bounds = BoundingRectangle; } } else if (collision == TileCollision.Impassable) // Ignore platforms. { // Resolve the collision along the X axis. Position = new Vector2(Position.X + depth.X, Position.Y); // Perform further collisions with the new bounds. bounds = BoundingRectangle; } if (collision == TileCollision.Spike) { // Resolve the collision along the shallow axis. if (absDepthY < absDepthX) { // Resolve the collision along the Y axis. Position = new Vector2(Position.X, Position.Y + depth.Y); // Perform further collisions with the new bounds. bounds = BoundingRectangle; isJumping = true; velocity.Y = DoJump(-40000.0f, gameTime); level.PlayerStatus.CurrentHealth -= 10; } else { // Resolve the collision along the X axis. Position = new Vector2(Position.X + depth.X, Position.Y); // Perform further collisions with the new bounds. bounds = BoundingRectangle; } } } } } } // Save the new bounds bottom. previousBottom = bounds.Bottom; }[/source]

I'm trying to simplify character movement putting it as the enemy,

[source lang="csharp"] Vector2 velocity = new Vector2((int)direction * MoveSpeed * elapsed, 0.0f); position = position + velocity;[/source]

but then come the problems of collisions of the character in both axes (X, Y) ...

Attached to the post player and enemy classes of my project.

I would appreciate a little help from someone who is put in the subject, thanks in advance for your time.

PARTNERS