public readonly int SpritePositionMod; // Modificateur de position pour le centrage de l'animation public AnimationSprite(Game game, AnimationDefinition definition, int spritePosMod) { Game = game; Definition = definition; CurrentFrame = new Point(); SpritePositionMod = spritePosMod; Speed = 0.07f; }
// Restreint les positions possibles du sprite sur la fenêtre public void SpriteBattlefieldPosition(int destinationX, int destinationY, bool isMoving, GraphicsDeviceManager graphics, AnimationDefinition spriteDefinition) { var topBottomScreen = (graphics.PreferredBackBufferHeight - BattlefieldBackgroundSprite.BlockHeight * 12 - 20) / 2; if (destinationX >= graphics.PreferredBackBufferWidth || destinationX < 0) { return; } if (destinationY < topBottomScreen || destinationY > graphics.PreferredBackBufferHeight - topBottomScreen - 20) { return; } var modPosX = destinationX % BattlefieldBackgroundSprite.BlockWidth; var modPosY = (destinationY - topBottomScreen) % BattlefieldBackgroundSprite.BlockHeight; if ((modPosX < BattlefieldBackgroundSprite.BlockWidth / 2) || (modPosX > BattlefieldBackgroundSprite.BlockWidth / 2)) { destinationX += BattlefieldBackgroundSprite.BlockWidth / 2 - modPosX; } if ((modPosY < BattlefieldBackgroundSprite.BlockHeight / 2) || (modPosY > BattlefieldBackgroundSprite.BlockHeight / 2)) { destinationY += BattlefieldBackgroundSprite.BlockHeight / 2 - modPosY; } if (isMoving) { Direction = new Vector2(destinationX - spriteDefinition.FrameSize.X / 2, destinationY - spriteDefinition.FrameSize.Y + SpritePositionMod); _movingSprite = true; } else { Position = new Vector2(destinationX - spriteDefinition.FrameSize.X / 2, destinationY - spriteDefinition.FrameSize.Y + SpritePositionMod); } }