Exemplo n.º 1
0
        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 && EnemyShips.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(2) + 4));           // 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);
                List <WeaponObject> enemyWeapons = new List <WeaponObject>();
                int                 numWeps      = r.Next(2) + 1;
                for (int i = 0; i < numWeps; i++)
                {
                    float FireSpeed = r.Next(100, 500);
                    enemyWeapons.Add(new WeaponObject(false, 1, (int)(0.5 * FireSpeed), -10, 0.3, 1, FireSpeed));
                }
                EnemyShip enemy = new EnemyShip(position, health, enemyWeapons, moveSpeed);

                enemy.Initialize(new EnemyParticleEngine(enemyEmitTextures, new Vector2(xPos, 0)));

                //destructibleObjects.Add(enemy);
                EnemyShips.Enqueue(enemy); // Put it in the queue
            }
        } // Randomly generate enemies at the top of the screen TEMPORARY SOLUTION
Exemplo n.º 2
0
        private void UpdateEnemies()
        {
            //destructibleObjects.UpdateAll(gameSpeed);
            for (int i = 0; i < EnemyShips.Count; i++)
            {
                EnemyShip curEnemy = EnemyShips.Dequeue();
                curEnemy.Update(delta);
                curEnemy.fire(Bullets, bulletTextures, r);

                bool myShipIsHit = curEnemy.Intersects(Ship.Bounds); // Should this be here??
                if (myShipIsHit)
                {
                    Ship.Health -= 10 * ((int)(curEnemy.CurSpeed.Y) / 4); // Customize depending on stuff? (type of ship?)
                    if (Ship.Health <= 0)
                    {
                        gameOver = true;
                    }
                }

                bool onScreen = !(curEnemy.Position.Y > MaxY) && !myShipIsHit;
                if (onScreen) // If the Enemy is not past the bottom of the screen
                {
                    EnemyShips.Enqueue(curEnemy);
                }
            }
        }
Exemplo n.º 3
0
        /*
         * 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 (!curBullet.isFriendly() && bullet1.Intersects(Ship.Bounds))
            {
                Ship.Health -= 10; // DO STUFF
                return(true);
            }
            else if (curBullet.isFriendly())
            {
                int destSize = EnemyShips.Count;
                // Go through destructables, check if each one is hit
                for (int i = 0; i < destSize; i++)
                {
                    EnemyShip curDest = EnemyShips.Dequeue();
                    if (curDest.Intersects(bullet1))
                    {
                        // Maybe spawn some debris here, because somethings been hit?
                        curDest.Damage(curBullet);
                        if (!curDest.IsDead())
                        {
                            EnemyShips.Enqueue(curDest);
                        }
                        else
                        {
                            score += 100;
                            // something's been killed, do stuff!
                            trySpawnRewards(curDest.Position);
                        }
                        return(true);
                    }
                    else
                    {
                        EnemyShips.Enqueue(curDest);
                    }
                }
            }
            return(false);
        }
Exemplo n.º 4
0
        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 = EnemyShips.Count;
                for (int i = 0; i < destSize; i++)
                {
                    EnemyShip curDest = EnemyShips.Dequeue();
                    curDest.Draw(spriteBatch, enemy1);
                    EnemyShips.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++;

            FPS = gameTime.ElapsedGameTime.Ticks;
            spriteBatch.DrawString(font, "FPS: " + FPS.ToString(), new Vector2(0, 40), Color.White);

            spriteBatch.End();

            base.Draw(gameTime);
        }
Exemplo n.º 5
0
        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 && EnemyShips.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(2) + 4)); // 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);
                List<WeaponObject> enemyWeapons = new List<WeaponObject>();
                int numWeps = r.Next(2) + 1;
                for (int i = 0; i < numWeps; i++)
                {
                    float FireSpeed = r.Next(100, 500);
                    enemyWeapons.Add(new WeaponObject(false, 1, (int)(0.5 * FireSpeed), -10, 0.3, 1, FireSpeed));
                }
                EnemyShip enemy = new EnemyShip(position, health, enemyWeapons, moveSpeed);

                enemy.Initialize(new EnemyParticleEngine(enemyEmitTextures, new Vector2(xPos, 0)));

                //destructibleObjects.Add(enemy);
                EnemyShips.Enqueue(enemy); // Put it in the queue
            }
        }