Пример #1
0
        private void UpdateBullets()
        {
            int bulletsSize = Bullets.Count;

            for (int i = 0; i < bulletsSize; i++)
            {
                BulletObject curBullet = Bullets.Dequeue();

                curBullet.Update();

                // If the bullet is past the top of the screen (value needs tweaking)
                if (!(curBullet.Position.Y < -30))
                {
                    Bullets.Enqueue(curBullet);
                }
            }
        }
Пример #2
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);
        }
Пример #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 (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;
        }
 internal void Damage(BulletObject curBullet)
 {
     hit = true;
     Health -= curBullet.GetDamage();
 }
Пример #5
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);
        }
Пример #6
0
 internal void Damage(BulletObject curBullet)
 {
     hit     = true;
     Health -= curBullet.GetDamage();
 }