public bool intersect(XAMLEntity other) { // Do AABB box intersection return(pX < (other.pX + other.size) && (pX + size) > other.pX && pY < (other.pY + other.size) && (pY + size) > other.pY); }
public void spawnEnemy(XAMLEntity player, float gameWidth, float gameHeight) { Random r = new Random(); foreach (var e in enemies) { if (!enemySpawnMap[e]) { float nx, ny; do { nx = (float)(r.NextDouble() * (gameWidth - 30)); ny = (float)(r.NextDouble() * (gameHeight - 30)); } while (dist(nx, ny, player.pX, player.pY) < 50); e.pX = nx; e.pY = ny; enemySpawnMap[e] = true; break; } } }
public MainPage() { InitializeComponent(); // Calculate Canvas Width and Height // Setup Enemy Spawners player = new XAMLEntity(PlayerBox, 30, 50, 50); spawner = new EnemySpawner(new View[] { EnemyBox1, EnemyBox2, EnemyBox3, EnemyBox4, EnemyBox5 }); // Mount Spawning Thread Task.Factory.StartNew(async() => { while (true) { await Task.Delay(3000); MainThread.BeginInvokeOnMainThread(() => { spawner.spawnEnemy(player, gameWidth, gameHeight); }); } }); }
public void despawn(XAMLEntity enemy) { enemy.pX = -100; enemy.pY = -100; enemySpawnMap[enemy] = false; }