Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Threading;
- namespace TrajectorySimulation
- {
- class Program
- {
- public static void Main(string[] args)
- {
- // Initialization
- var countOfMoveableObjects = 3;
- var moveableObjects = new MoveableObject[countOfMoveableObjects];
- // Spawn
- for (var i = 0; i < moveableObjects.Length; i++)
- {
- var index = i + 1;
- moveableObjects[i] = new MoveableObject(index.ToString(), new Vector2Int(index * 5, index * 5));
- }
- while (true)
- {
- // Get alive objects
- var aliveObjects = moveableObjects.Where(m => m.IsAlive).ToArray();
- // Compare collisions
- for (var i = 0; i < aliveObjects.Length; i++)
- {
- for (var j = 0; j < aliveObjects.Length; j++)
- {
- if (j == i) continue;
- // If collided - destroy
- if (aliveObjects[i].Position == aliveObjects[j].Position)
- {
- aliveObjects[i].Destroy();
- aliveObjects[j].Destroy();
- }
- }
- }
- // Move objects
- foreach (var aliveObj in aliveObjects)
- {
- aliveObj.RandomMove();
- }
- // Render
- foreach (var aliveObj in aliveObjects)
- {
- aliveObj.Render();
- }
- Thread.Sleep(100);
- Console.Clear();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement