private void enemyFire(DestructibleObject enemy) { enemy.Fire(); Vector2 bulletSpeed = new Vector2(0, 0); Bullets.Enqueue(new BulletObject(otherBulletTexture, otherBulletTexture, new Vector2(enemy.Position.X, enemy.Position.Y + 80), bulletSpeed, -bulletVelocity, r)); }
private void UpdateDestructibles() { //destructibleObjects.UpdateAll(gameSpeed); int destSize = Destructibles.Count; for (int i = 0; i < destSize; i++) { DestructibleObject curDest = Destructibles.Dequeue(); curDest.Update(gameSpeed); if (curDest.canFire()) { enemyFire(curDest); } bool myShipIsHit = curDest.Intersects(Ship.Bounds); // Should this be here?? if (myShipIsHit) { Ship.Health -= 10; // Customize depending on stuff? (type of ship?) if (Ship.Health <= 0) { gameOver = true; } } bool onScreen = !(curDest.Position.Y > MaxY) && !myShipIsHit; if (onScreen) // If the Enemy is not past the bottom of the screen { Destructibles.Enqueue(curDest); } } }
private void createRandomEnemies() { // Create Enemies [RANDOMLY] int chanceToSpawn = r.Next(25); // Inverse chance to spawn (ie. 25 is 1/25 chance, 100, is 1/100 chance) if (chanceToSpawn == 0 && Destructibles.Count < 20) // Limit destructibles to 20 { int health = 50; // Initial Health of Enemy int fireDamage = r.Next(50); // Firing Damage of Enemy int fireSpeed = r.Next(50); // Firing Speed of Enemy Vector2 moveSpeed = new Vector2(0, (r.Next(0) + 5)); // Movement Speed of Enemy int xPos = r.Next(graphics.PreferredBackBufferWidth); // Initial X Position of the enemy at the top of the screen Vector2 position = new Vector2(xPos, 0); DestructibleObject enemy = new DestructibleObject(position, health, fireDamage, fireSpeed, moveSpeed); enemy.Initialize(new EnemyParticleEngine(enemyEmitTextures, new Vector2(xPos, 0))); //destructibleObjects.Add(enemy); Destructibles.Enqueue(enemy); // Put it in the queue } } // Randomly generate enemies at the top of the screen TEMPORARY SOLUTION
/* * public delegate somethingSomethingSomething?? * * public void PrototypicalRedundanyReducer(theDelegate method, queueToProces objects) * { * int size = objects.Count; * for (int i = 0; i < size; i++) * { * theDelegate(objects); * } * } * * public methodForDelegateStuff1(queueToProcess????) * { * * } * * public methodForDelegateStuff2(queueToProcess????) * { * * } */ private bool TryHit(BulletObject curBullet) { bullet1.Center = (new Vector3(curBullet.Position, 0f)); if (bullet1.Intersects(Ship.Bounds)) { Ship.Health -= 10; // DO STUFF return(true); } else { int destSize = Destructibles.Count; // Go through destructables, check if each one is hit for (int i = 0; i < destSize; i++) { DestructibleObject curDest = Destructibles.Dequeue(); if (curDest.Intersects(bullet1)) { // Maybe spawn some debris here, because somethings been hit? curDest.Damage(curBullet); if (!curDest.IsDead()) { Destructibles.Enqueue(curDest); } else { score += 100; // something's been killed, do stuff! trySpawnRewards(curDest.Position); } return(true); } else { Destructibles.Enqueue(curDest); } } } return(false); }
private void createRandomEnemies() { // Create Enemies [RANDOMLY] int chanceToSpawn = r.Next(25); // Inverse chance to spawn (ie. 25 is 1/25 chance, 100, is 1/100 chance) if (chanceToSpawn == 0 && Destructibles.Count < 20) // Limit destructibles to 20 { int health = 50; // Initial Health of Enemy int fireDamage = r.Next(50); // Firing Damage of Enemy int fireSpeed = r.Next(50); // Firing Speed of Enemy Vector2 moveSpeed = new Vector2(0, (r.Next(0) + 5)); // Movement Speed of Enemy int xPos = r.Next(graphics.PreferredBackBufferWidth); // Initial X Position of the enemy at the top of the screen Vector2 position = new Vector2(xPos, 0); DestructibleObject enemy = new DestructibleObject(position, health, fireDamage, fireSpeed, moveSpeed); enemy.Initialize(new EnemyParticleEngine(enemyEmitTextures, new Vector2(xPos, 0))); //destructibleObjects.Add(enemy); Destructibles.Enqueue(enemy); // Put it in the queue } }
protected override void Draw(GameTime gameTime) { graphics.GraphicsDevice.Clear(Color.Black); spriteBatch.Begin(); //myBackground.Draw(spriteBatch); proceduralStarBackground.Draw(spriteBatch); spriteBatch.End(); spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend); if (!gameOver) { Ship.Draw(spriteBatch); // Go through bullets, drawing each one int size = Bullets.Count; for (int i = 0; i < size; i++) { BulletObject curBullet = Bullets.Dequeue(); if (!TryHit(curBullet)) { curBullet.Draw(spriteBatch); Bullets.Enqueue(curBullet); } else { if (Ship.Health <= 0) { gameOver = true; } } } //destructibleObjects.DrawAll(spriteBatch); // Go through destructables, drawing each one int destSize = Destructibles.Count; for (int i = 0; i < destSize; i++) { DestructibleObject curDest = Destructibles.Dequeue(); curDest.Draw(spriteBatch, enemy1); Destructibles.Enqueue(curDest); } // Go through boons, drawing each one int boonSize = Boons.Count; for (int i = 0; i < boonSize; i++) { BoonObject curBoon = Boons.Dequeue(); curBoon.Draw(spriteBatch, boonTextures); Boons.Enqueue(curBoon); } DrawGUI(); } else { DrawText(new Vector2(MaxX / 2 - 50, MaxY / 2 - 10), "GAME OVER"); DrawText(new Vector2(MaxX / 2 - 85 - score.ToString().Length, MaxY / 2 + 10), "Final Score: " + score); } // FPS COUNTER -- DEBUG/OPTIMIZATION PURPOSES numOfFrames++; spriteBatch.DrawString(font, "FPS: " + FPS.ToString(), new Vector2(0, 40), Color.White); spriteBatch.End(); base.Draw(gameTime); }