Exemple #1
0
        ////
        //METHODS
        ////

        private void spawnBullet(Color cColor)
        {
            //reset timer
            bulletspawntimer = 0;
            //direction, distance from center init
            linedirection = (linedirection + 1) % numlindirs;
            float spawnradius = (float)Math.Sqrt(Math.Pow(gamearea.Right - gamearea.Center.X, 2) + Math.Pow(gamearea.Bottom - gamearea.Center.Y, 2));
            //
            double anglevariant = (rand.NextDouble() - 0.5) * Math.PI / 2;
            //Create and init bullets
            GRBullet abullet = new GRBullet();

            abullet.setTex(waveTex);
            abullet.position   = Vector2.Zero;
            abullet.position.X = gamearea.Center.X + spawnradius * (float)Math.Cos(2 * Math.PI / numlindirs * linedirection);
            abullet.position.Y = gamearea.Center.Y + spawnradius * (float)Math.Sin(2 * Math.PI / numlindirs * linedirection);
            abullet.velocity   = Vector2.Zero;
            abullet.velocity.X = -GRWave.BULLETSPEED * (float)Math.Cos(2 * Math.PI / numlindirs * linedirection);
            abullet.velocity.Y = -GRWave.BULLETSPEED * (float)Math.Sin(2 * Math.PI / numlindirs * linedirection);
            abullet.rotation   = (float)rand.NextDouble();
            abullet.rotation   = (abullet.rotation - 0.5f) * maxbulletspin;
            abullet.color      = cColor;
            abullet.fading     = true;

            bullets.Add(abullet);
        }
Exemple #2
0
 //Check for hits and grazes
 private void processCollisions()
 {
     for (int index = 0; index < currentwave.bullets.Count; index++)
     {
         GRBullet cbullet = (GRBullet)currentwave.bullets[index];
         if (player.collidesWithBullet(cbullet))
         {
             player.lives   -= 1;
             grazemultiplier = 0;
             player.setInvincible();
             explosionsfx.Play(0.25f, 0f, 0f);
         }
         if (player.grazesBullet(cbullet) /*&& !inSlowMode*/)
         {
             if (!cbullet.grazeCooldown)
             {
                 if (grazemultiplier < MAX_GRAZE_MULTIPLIER)
                 {
                     grazemultiplier += 1;
                 }
                 //varies pitch from -.5 to 1.5
                 float grazepercent = grazemultiplier / MAX_GRAZE_MULTIPLIER * 1.0f;
                 grazesfx.Play(1.0f, grazepercent - 0.5f, 0);
                 grazelosstimer        = 0;
                 cbullet.grazeCooldown = true;
                 score += GRAZE_SCORE_VALUE * grazemultiplier;
                 pscoreIndicator.addScore(GRAZE_SCORE_VALUE * grazemultiplier, player);
             }
         }
     }
 }
Exemple #3
0
        ////
        //METHODS
        ////

        private void spawnBullet(Color cColor)
        {
            //reset timer
            bulletspawntimer = 0;
            //direction, distance from center init
            linedirection = (linedirection + 1) % numlindirs;
            float spawnradius = (float)Math.Sqrt(Math.Pow(gamearea.Right - gamearea.Center.X, 2) + Math.Pow(gamearea.Bottom - gamearea.Center.Y, 2));
            //
            //Create and init bullets
            GRBullet abullet = new GRBullet();

            abullet.setTex(waveTex);
            abullet.position   = Vector2.Zero;
            abullet.position.X = gamearea.Center.X + spawnradius * (float)Math.Cos(2 * Math.PI / numlindirs * linedirection);
            abullet.position.Y = gamearea.Center.Y + spawnradius * (float)Math.Sin(2 * Math.PI / numlindirs * linedirection);
            abullet.velocity   = Vector2.Zero;
            abullet.velocity.X = -GRWave.BULLETSPEED * (float)Math.Cos(2 * Math.PI / numlindirs * linedirection);
            abullet.velocity.Y = -GRWave.BULLETSPEED * (float)Math.Sin(2 * Math.PI / numlindirs * linedirection);
            abullet.angle      = (float)Math.Atan2(player.position.Y - abullet.position.Y, player.position.X - abullet.position.X);
            //
            abullet.color  = cColor;
            abullet.fading = true;

            bullets.Add(abullet);
        }
Exemple #4
0
        ////
        //METHODS
        ////

        private void spawnburst(Color cColor)
        {
            bulletspawntimer = 0;
            //
            extrabullettoggle = -extrabullettoggle;
            bulletsperburst  += extrabullettoggle;
            //
            for (int burstind = 0; burstind < numspirals; burstind++)
            {
                ArrayList cspiral = (ArrayList)spirals[burstind];
                for (int index = 0; index < bulletsperburst; index++)
                {
                    GRBullet abullet = new GRBullet();

                    abullet.setTex(waveTex);
                    abullet.position    = new Vector2(spiralcenter[burstind].X - waveTex.Width / 2, spiralcenter[burstind].Y - waveTex.Height / 2);
                    abullet.spiraltheta = 2 * (float)Math.PI / bulletsperburst * index;

                    abullet.rotation = bulletspin;
                    abullet.color    = cColor;
                    abullet.fading   = true;
                    //add bullet both to its spiral(for updates) and the masterlist(for rendering)
                    cspiral.Add(abullet);
                    bullets.Add(abullet);
                }
                //spirals.Add(cBurst);
            }
        }
Exemple #5
0
        private void gameoverDraw()
        {
            //BG DRAW
            if (usecolorlerping)
            {
                spriteBatch.Draw(whitepx, screenarea, cFGcolor);
            }
            else
            {
                spriteBatch.Draw(whitepx, screenarea, Color.White);
            }
            spriteBatch.Draw(whitepx, gamearea, cBGcolor);

            //GAME ELEMENTS
            player.Draw(spriteBatch);
            for (int index = 0; index < currentwave.bullets.Count; index++)
            {
                GRBullet cbullet = (GRBullet)currentwave.bullets[index];
                cbullet.Draw(spriteBatch);
            }
            pscoreIndicator.Draw(spriteBatch, pixelfont24, Color.LawnGreen);

            //GUI elements
            spriteBatch.Draw(gameareaborder, Vector2.Zero, DEFAULT_BORDERCOLOR);
            //text rendering
            string  gameoverstring = "game.over";
            Vector2 gameoversize   = pixelfontlarge.MeasureString(gameoverstring);

            spriteBatch.DrawString(pixelfontlarge, gameoverstring, new Vector2(gamearea.Center.X - gameoversize.X / 2, gamearea.Center.Y - gameoversize.Y / 2 - 50), Color.Black);
            string  pressstart     = "press space / start";
            Vector2 pressstartsize = pixelfont24.MeasureString(pressstart);

            spriteBatch.DrawString(pixelfont24, pressstart, new Vector2(gamearea.Center.X - pressstartsize.X / 2, gamearea.Center.Y - pressstartsize.Y / 2 + 50), Color.Black);

            string  gametitle     = "graze.type";
            Vector2 gametitlesize = pixelfont24.MeasureString(gametitle);
            string  livesgui      = "Lives: " + player.lives;
            Vector2 livessize     = pixelfont24.MeasureString(livesgui);
            string  wavegui       = "Wave: " + wavenum;
            Vector2 wavesize      = pixelfont24.MeasureString(wavegui);
            string  grazegui      = "Graze: " + grazemultiplier;
            Vector2 grazesize     = pixelfont24.MeasureString(grazegui);
            string  scoregui      = "Score: " + score;
            Vector2 scoresize     = pixelfont24.MeasureString(scoregui);

            spriteBatch.DrawString(pixelfont24, gametitle, new Vector2(guiarea.Center.X - gametitlesize.X / 2, guiarea.Top), DEFAULT_GUITEXTCOLOR);
            spriteBatch.DrawString(pixelfont24, livesgui, new Vector2(guiarea.Center.X - livessize.X / 2, guiarea.Center.Y), DEFAULT_GUITEXTCOLOR);
            spriteBatch.DrawString(pixelfont24, wavegui, new Vector2(guiarea.Center.X - wavesize.X / 2, guiarea.Center.Y + 50), DEFAULT_GUITEXTCOLOR);
            spriteBatch.DrawString(pixelfont24, grazegui, new Vector2(guiarea.Center.X - grazesize.X / 2, guiarea.Center.Y - 50), DEFAULT_GUITEXTCOLOR);
            spriteBatch.DrawString(pixelfont24, scoregui, new Vector2(guiarea.Center.X - scoresize.X / 2, guiarea.Center.Y - 100), DEFAULT_GUITEXTCOLOR);
        }
Exemple #6
0
        //check for graze with a bullet, false if invincible
        public bool grazesBullet(GRBullet bullet)
        {
            if (isInvincible /*|| bullet.fading*/)
            {
                return(false);
            }
            float deltadist = (float)Math.Sqrt(Math.Pow(position.X - bullet.position.X, 2) + Math.Pow(position.Y - bullet.position.Y, 2));

            if (deltadist <= this.grazerad + bullet.hitrad)
            {
                return(true);
            }
            return(false);
        }
Exemple #7
0
        //check for collision with a bullet, false if invincible or bullet is fading in/out
        public bool collidesWithBullet(GRBullet bullet)
        {
            if (isInvincible || bullet.fading)
            {
                return(false);
            }
            float deltadist = (float)Math.Sqrt(Math.Pow(position.X - bullet.position.X, 2) + Math.Pow(position.Y - bullet.position.Y, 2));

            if (deltadist <= this.hitrad + bullet.hitrad)
            {
                return(true);
            }
            return(false);
        }
Exemple #8
0
        public GRWaveBounce(int wavenum, Rectangle gamearea, Texture2D waveTex, Color cColor)
        {
            this.wavetime = 0;
            this.wavenum  = wavenum;
            this.gamearea = gamearea;
            this.waveTex  = waveTex;
            bullets       = new ArrayList();
            Random rand = new Random();

            //Init number of bullets
            int numbullets = wavenum + 2;

            if (numbullets > maxbullets)
            {
                numbullets = maxbullets;
            }

            //Create and init bullets
            for (int index = 0; index < numbullets; index++)
            {
                GRBullet abullet = new GRBullet();

                abullet.setTex(waveTex);
                abullet.position = new Vector2(
                    rand.Next(gamearea.Left + abullet.sprTx.Width / 2, gamearea.Right - abullet.sprTx.Width / 2),
                    rand.Next(gamearea.Top + abullet.sprTx.Height / 2, gamearea.Bottom - abullet.sprTx.Height / 2));
                abullet.velocity = new Vector2(rand.Next(1, 50), rand.Next(1, 50));
                abullet.velocity.Normalize();
                abullet.velocity *= GRWave.BULLETSPEED;
                abullet.rotation  = (float)rand.NextDouble();
                abullet.rotation  = (abullet.rotation - 0.5f) * maxbulletspin;
                abullet.color     = cColor;
                abullet.fading    = true;
                abullet.opacity   = 0;

                bullets.Add(abullet);
            }
        }
Exemple #9
0
        //Handles input from the user, called in update
        private void processInGameInput()
        {
            // Input Polling Section
            KeyboardState keystate = Keyboard.GetState();
            GamePadState  p1gp     = GamePad.GetState(PlayerIndex.One);
            Vector2       lstick   = p1gp.ThumbSticks.Left;

            //player control

            //movement
            player.velocity = Vector2.Zero;
            if (keystate.IsKeyDown(Keys.Down) || p1gp.DPad.Down == ButtonState.Pressed)
            {
                player.velocity += Vector2.UnitY;
            }
            if (keystate.IsKeyDown(Keys.Up) || p1gp.DPad.Up == ButtonState.Pressed)
            {
                player.velocity -= Vector2.UnitY;
            }
            if (keystate.IsKeyDown(Keys.Left) || p1gp.DPad.Left == ButtonState.Pressed)
            {
                player.velocity -= Vector2.UnitX;
            }
            if (keystate.IsKeyDown(Keys.Right) || p1gp.DPad.Right == ButtonState.Pressed)
            {
                player.velocity += Vector2.UnitX;
            }
            if (player.velocity != Vector2.Zero)
            {
                player.velocity.Normalize();
            }
            //stick
            if (Math.Abs(lstick.X) > 0.1f || Math.Abs(lstick.Y) > 0.1f)
            {
                player.velocity.X = lstick.X;
                player.velocity.Y = -lstick.Y;
                if ((float)Math.Sqrt(player.velocity.X * player.velocity.X + player.velocity.Y * player.velocity.Y) > 1.0f)
                {
                    player.velocity.Normalize();
                }
            }
            //have slowMo effect player too
            if (inSlowMode)
            {
                player.velocity /= SLOW_MODE_SPEED;
            }
            //focus button
            if (keystate.IsKeyDown(Keys.A) || p1gp.Buttons.A == ButtonState.Pressed)
            {
                player.focusOn = true;
            }
            else
            {
                player.focusOn = false;
            }
            //slow mode
            if (keystate.IsKeyDown(Keys.S) || p1gp.Buttons.X == ButtonState.Pressed)
            {
                if (!inSlowMode)
                {
                    slowmosfx.Play(0.3f, 0f, 0f);
                    inSlowMode = true;
                    gamespeed /= SLOW_MODE_SPEED;
                    for (int index = 0; index < currentwave.bullets.Count; index++)
                    {
                        GRBullet cbullet = (GRBullet)currentwave.bullets[index];
                        cbullet.rotation /= SLOW_MODE_SPEED;
                    }
                }
            }
        }
Exemple #10
0
 //Update loop for when game is in progress
 private void inGameUpdate(GameTime gameTime)
 {
     //input processing
     processInGameInput();
     //collision processing
     processCollisions();
     //object and field updating
     //COLOR
     if (usecolorlerping)
     {
         colorlerptimer += (float)gameTime.ElapsedGameTime.TotalSeconds;
         if (colorlerptimer < COLOR_LERP_DURATION)
         {
             cFGcolor = Color.Lerp(lastFGcolor, targetFGcolor, colorlerptimer / COLOR_LERP_DURATION);
             cBGcolor = Color.Lerp(lastBGcolor, targetBGcolor, colorlerptimer / COLOR_LERP_DURATION);
         }
         else
         {
             colorlerptimer = 0;
             lastFGcolor    = cFGcolor;
             lastBGcolor    = cBGcolor;
             targetFGcolor  = new Color(rand.Next(0, 255), rand.Next(0, 255), rand.Next(0, 255));
             targetBGcolor  = new Color(rand.Next(0, 255), rand.Next(0, 255), rand.Next(0, 255));
         }
     }
     //TIMER BEHAVIOR
     grazelosstimer += (float)gameTime.ElapsedGameTime.TotalSeconds;
     if (grazelosstimer > GRAZE_LOSS_INTERVAL)
     {
         if (grazemultiplier > 0)
         {
             grazemultiplier -= 1;
         }
         grazelosstimer = 0;
     }
     //if in slow mode
     if (inSlowMode && slowmodetimer < SLOW_MODE_DURATION)
     {
         slowmodetimer += (float)gameTime.ElapsedGameTime.TotalSeconds;
     }
     //if exiting slow mode
     if (inSlowMode && slowmodetimer >= SLOW_MODE_DURATION)
     {
         inSlowMode      = false;
         grazemultiplier = 0;
         gamespeed      *= SLOW_MODE_SPEED;
         for (int index = 0; index < currentwave.bullets.Count; index++)
         {
             GRBullet cbullet = (GRBullet)currentwave.bullets[index];
             cbullet.rotation *= SLOW_MODE_SPEED;
         }
         slowmodetimer = 0;
     }
     //PLAYER + WAVE UPDATE
     player.Update(gameTime, gamespeed);
     currentwave.Update(gameTime, gamespeed, inSlowMode, cFGcolor);
     pscoreIndicator.Update(gameTime, player);
     //NEW WAVE
     if (currentwave.isWaveComplete())
     {
         newwavesfx.Play();
         score += WAVE_SCORE_VALUE;
         pscoreIndicator.addScore(WAVE_SCORE_VALUE, player);
         wavenum++;
         if (inSlowMode)
         {
             gamespeed += WAVE_SPEED_INCREASE / SLOW_MODE_SPEED;
         }
         else
         {
             gamespeed += WAVE_SPEED_INCREASE;
         }
         //set random new wave type
         setWave();
     }
     //game over
     if (player.lives <= 0)
     {
         gamestate = GRGameState.gameover;
         player.setInvincibleOff();
     }
 }