Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Microsoft.Xna.Framework;
- using System;
- using System.Collections.Generic;
- namespace ShootThemAll
- {
- public enum CurveType
- {
- Linear,
- Bezier,
- Sinusoidal,
- Custom,
- }
- public class MovePattern
- {
- public List<Vector2> Waypoints { get; set; }
- public float Speed { get; set; }
- public bool Loop { get; set; }
- public CurveType CurveType { get; set; }
- public Func<float, Vector2> CustomTrajectory { get; set; } // Fonction personnalisée
- public Vector2 CalculatePosition(float progress)
- {
- switch (CurveType)
- {
- case CurveType.Linear:
- return LinearInterpolation(progress);
- case CurveType.Bezier:
- return BezierInterpolation(progress);
- case CurveType.Sinusoidal:
- return SinusoidalMovement(progress);
- default:
- return Waypoints[0]; // Fallback
- }
- }
- private Vector2 LinearInterpolation(float progress)
- {
- int startIndex = (int)(progress * (Waypoints.Count - 1));
- int endIndex = Math.Min(startIndex + 1, Waypoints.Count - 1);
- float segmentProgress = (progress * (Waypoints.Count - 1)) % 1;
- return Vector2.Lerp(Waypoints[startIndex], Waypoints[endIndex], segmentProgress);
- }
- private Vector2 BezierInterpolation(float progress)
- {
- if (Waypoints.Count < 2)
- return Vector2.Zero; // Pas assez de points pour une courbe
- // Normaliser le progrès entre 0 et 1
- float t = Math.Clamp(progress, 0f, 1f);
- int n = Waypoints.Count - 1; // Ordre de la courbe
- Vector2 result = Vector2.Zero;
- for (int i = 0; i <= n; i++)
- {
- // Calculer le coefficient binomial et le terme de la formule de Bézier
- float coefficient = BinomialCoefficient(n, i) * (float)Math.Pow(1 - t, n - i) * (float)Math.Pow(t, i);
- result += coefficient * Waypoints[i];
- }
- return result;
- }
- private static float BinomialCoefficient(int n, int k)
- {
- if (k < 0 || k > n) return 0;
- if (k == 0 || k == n) return 1;
- // Optimisation : utiliser la symétrie pour réduire les calculs
- k = Math.Min(k, n - k);
- float result = 1;
- for (int i = 1; i <= k; i++)
- {
- result *= (n - (k - i)) / (float)i;
- }
- return result;
- }
- private Vector2 SinusoidalMovement(float progress)
- {
- // Exemple : mouvement sinusoïdal autour d'un axe
- Vector2 basePos = LinearInterpolation(progress);
- float amplitude = 50f; // Paramétrable
- float frequency = 2f; // Paramétrable
- basePos.Y += (float)Math.Sin(progress * frequency * Math.PI) * amplitude;
- return basePos;
- }
- }
- //public class Wave
- //{
- // private List<(float spawnTime, Enemy enemy)> _enemies = new();
- // private float _timer;
- // public void AddEnemy(float spawnTime, Enemy enemy)
- // {
- // _enemies.Add((spawnTime, enemy));
- // }
- // public void Update(GameTime gameTime, List<Enemy> activeEnemies)
- // {
- // _timer += (float)gameTime.ElapsedGameTime.TotalSeconds;
- // foreach (var (spawnTime, enemy) in _enemies)
- // {
- // if (_timer >= spawnTime && !activeEnemies.Contains(enemy))
- // {
- // activeEnemies.Add(enemy);
- // }
- // }
- // foreach (var enemy in activeEnemies)
- // {
- // enemy.Update(gameTime);
- // }
- // }
- //}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement