Exemple #1
0
 public override void Draw(SpriteBatch spriteBatch, Camera c)
 {
     if (player_fired)
         spriteBatch.Draw(bullet_tex, (getCenter() - c.getOffset()) / c.getzoomout(), null, Color.White, rotation, new Vector2(bullet_tex.Width / 2, bullet_tex.Height / 2), 1.0F / c.getzoomout(), SpriteEffects.None, 0);
     else
         spriteBatch.Draw(police_tex, (getCenter() - c.getOffset()) / c.getzoomout(), null, Color.White, rotation, new Vector2(bullet_tex.Width / 2, bullet_tex.Height / 2), 1.0F / c.getzoomout(), SpriteEffects.None, 0);
 }
Exemple #2
0
 public override void Draw(SpriteBatch spriteBatch, Camera c)
 {
     if (player_fired)
     {
         spriteBatch.Draw(bullet_tex, (getCenter() - c.getOffset()) / c.getzoomout(), null, Color.White, rotation, new Vector2(bullet_tex.Width / 2, bullet_tex.Height / 2), 1.0F / c.getzoomout(), SpriteEffects.None, 0);
     }
     else
     {
         spriteBatch.Draw(police_tex, (getCenter() - c.getOffset()) / c.getzoomout(), null, Color.White, rotation, new Vector2(bullet_tex.Width / 2, bullet_tex.Height / 2), 1.0F / c.getzoomout(), SpriteEffects.None, 0);
     }
 }
Exemple #3
0
 public virtual void Draw(SpriteBatch spriteBatch, Camera c)
 {
     spriteBatch.Draw(tex, (getCenter() - c.getOffset()) / c.getzoomout(), null, Color.White, rotation, new Vector2(tex.Width / 2, tex.Height / 2), 1.0F / c.getzoomout(), SpriteEffects.None, 0);
 }
Exemple #4
0
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back ==
                ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                this.Exit();
            }

            if (gamestate == 0)
            {
                if ((GamePad.GetState(PlayerIndex.One).Buttons.A == ButtonState.Pressed || Mouse.GetState().LeftButton == ButtonState.Pressed) && !prevA)
                {
                    gamestate = 1;
                }

                prevA = GamePad.GetState(PlayerIndex.One).Buttons.A == ButtonState.Pressed || Mouse.GetState().LeftButton == ButtonState.Pressed;
                return;
            }
            if (gamestate == 1)
            {
                if ((GamePad.GetState(PlayerIndex.One).Buttons.A == ButtonState.Pressed || Mouse.GetState().LeftButton == ButtonState.Pressed) && !prevA)
                {
                    gamestate = 2;
                    loadLevel();
                    startTime = (float)gameTime.TotalGameTime.TotalSeconds;
                }

                prevA = GamePad.GetState(PlayerIndex.One).Buttons.A == ButtonState.Pressed || Mouse.GetState().LeftButton == ButtonState.Pressed;
                return;
            }

            String alph = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

            if (gamestate == 3)
            {
                if ((GamePad.GetState(PlayerIndex.One).ThumbSticks.Left.Y > .75 || Keyboard.GetState().IsKeyDown(Keys.Down)) && cooldown > 0.1)
                {
                    //dec 1
                    int k = (alph.IndexOf(currchar) - 1) % 26;
                    if (k == -1)
                    {
                        k = 25;
                    }
                    currchar = alph.ToCharArray()[k];
                    cooldown = 0;
                }
                else if ((GamePad.GetState(PlayerIndex.One).ThumbSticks.Left.Y < -.75 || Keyboard.GetState().IsKeyDown(Keys.Up)) && cooldown > 0.1)
                {
                    //inc 1
                    currchar = alph.ToCharArray()[(alph.IndexOf(currchar) + 1) % 26];
                    cooldown = 0;
                }
                if ((GamePad.GetState(PlayerIndex.One).Buttons.A == ButtonState.Pressed || Mouse.GetState().LeftButton == ButtonState.Pressed) && !prevA && name.Length < 8)
                {
                    name     = name + currchar;
                    currchar = 'A';
                }
                if ((GamePad.GetState(PlayerIndex.One).Buttons.B == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.X)) && !prevB && name.Length > 0)
                {
                    currchar = name.ToCharArray().Last();
                    name     = name.Substring(0, name.Length - 1);
                }
                if ((GamePad.GetState(PlayerIndex.One).Buttons.Start == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Space)) && prevStart == false)
                {
                    objs.Clear();

                    StreamReader SR;
                    SR = File.OpenText("score.txt");
                    for (int i = 0; i < 5; i++)
                    {
                        names.Add(SR.ReadLine());
                    }
                    for (int i = 0; i < 5; i++)
                    {
                        scores.Add(Int32.Parse(SR.ReadLine()));
                    }
                    SR.Close();
                    int a = 0;

                    while (Score.score < scores[a])
                    {
                        a++;
                        if (a == scores.Count)
                        {
                            break;
                        }
                    }
                    scores.Insert(a, Score.score);
                    names.Insert(a, name);

                    StreamWriter SW = new StreamWriter("score.txt");
                    for (int i = 0; i < 5; i++)
                    {
                        SW.WriteLine(names[i]);
                    }
                    for (int i = 0; i < 5; i++)
                    {
                        SW.WriteLine(scores[i]);
                    }
                    SW.Close();
                    gamestate = 4;
                    prevStart = GamePad.GetState(PlayerIndex.One).Buttons.Start == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Space);
                    name      = "";
                    Score.reset();
                    return;
                }

                //fixed chars
                //if ((int)currchar == 41) currchar = (char) 42;
                //else if ((int)currchar == 68) currchar = (char) 67;

                cooldown += (float)gameTime.ElapsedGameTime.TotalSeconds;
                prevA     = GamePad.GetState(PlayerIndex.One).Buttons.A == ButtonState.Pressed || Mouse.GetState().LeftButton == ButtonState.Pressed;
                prevB     = GamePad.GetState(PlayerIndex.One).Buttons.B == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.X);
                prevStart = GamePad.GetState(PlayerIndex.One).Buttons.Start == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Space);

                return;
            }
            else if (gamestate == 4)
            {
                if ((GamePad.GetState(PlayerIndex.One).Buttons.Start == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Space)) && !prevStart)
                {
                    objs.Clear();
                    gamestate = 0;
                    prevA     = GamePad.GetState(PlayerIndex.One).Buttons.A == ButtonState.Pressed || Mouse.GetState().LeftButton == ButtonState.Pressed;
                }
                prevStart = GamePad.GetState(PlayerIndex.One).Buttons.Start == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Space);
                return;
            }

            prevStart = GamePad.GetState(PlayerIndex.One).Buttons.Start == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Space);


            if ((GamePad.GetState(PlayerIndex.One).Buttons.Start == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Space)))
            {
                gamestate = 0;
                prevA     = GamePad.GetState(PlayerIndex.One).Buttons.A == ButtonState.Pressed || Mouse.GetState().LeftButton == ButtonState.Pressed;
                return;
            }

            if ((GamePad.GetState(PlayerIndex.One).Buttons.A == ButtonState.Pressed || Mouse.GetState().RightButton == ButtonState.Pressed) && !prevA && player.isAlive())
            {
                loadLevel();
                startTime = (float)gameTime.TotalGameTime.TotalSeconds;
            }

            if ((GamePad.GetState(PlayerIndex.One).Buttons.A == ButtonState.Pressed || Mouse.GetState().LeftButton == ButtonState.Pressed) && !prevA && !player.isAlive())
            {
                gamestate = 3;
            }

            prevA = GamePad.GetState(PlayerIndex.One).Buttons.A == ButtonState.Pressed || Mouse.GetState().LeftButton == ButtonState.Pressed;

            if (GamePad.GetState(PlayerIndex.One).Buttons.Y == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.C))
            {
                Camera.zoomout = Math.Min(Camera.zoomout * 1.01F, 1.2F);
            }
            if (GamePad.GetState(PlayerIndex.One).Buttons.X == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.V))
            {
                Camera.zoomout = Math.Max(0.5F, Camera.zoomout / 1.01F);
            }

            if (Camera.zoomout > 1)
            {
                Camera.zoomout *= 0.999F;
            }

            player.vel = gameTime.ElapsedGameTime.Ticks * GamePad.GetState(PlayerIndex.One).ThumbSticks.Left;
            if (true) //!GamePad.GetState(PlayerIndex.One).IsConnected)
            {
                int y_val = (Keyboard.GetState().IsKeyDown(Keys.Up) ? 1 : 0) - (Keyboard.GetState().IsKeyDown(Keys.Down) ? 1 : 0);
                int x_val = (Keyboard.GetState().IsKeyDown(Keys.Right) ? 1 : 0) - (Keyboard.GetState().IsKeyDown(Keys.Left) ? 1 : 0);
                player.vel = gameTime.ElapsedGameTime.Ticks * new Vector2(x_val, y_val);
            }

            Vector2 stick = GamePad.GetState(PlayerIndex.One).ThumbSticks.Right;

            if (stick != new Vector2(0, 0))
            {
                player.rotation = -(float)(Math.Atan2(GamePad.GetState(PlayerIndex.One).ThumbSticks.Right.Y, GamePad.GetState(PlayerIndex.One).ThumbSticks.Right.X) - Math.PI / 2);
            }
            else
            {
                Vector2 p_center = (player.getCenter() - c.getOffset()) / c.getzoomout();

                float y_val = Mouse.GetState().Y - p_center.Y;
                float x_val = Mouse.GetState().X - p_center.X;
                player.rotation = (float)(Math.Atan2(y_val, x_val) + Math.PI / 2);
            }

            if (GamePad.GetState(PlayerIndex.One).Triggers.Right > 0.1 || Mouse.GetState().LeftButton == ButtonState.Pressed)
            {
                player.fire();
            }
            else
            {
                player.release();
            }

            // Move the sprite around.
            UpdateSprites(gameTime);

            base.Update(gameTime);
        }
Exemple #5
0
 public override void Draw(SpriteBatch spriteBatch, Camera c)
 {
     spriteBatch.Draw(tex, (getCenter() - c.getOffset()) / c.getzoomout(), null, Color.White, rotation, new Vector2(tex.Width / 2, tex.Height / 2), 1.0F / c.getzoomout(), SpriteEffects.None, 0);
 }
Exemple #6
0
        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            graphics.GraphicsDevice.Clear(new Color(20, 100, 0));

            // Draw the sprite.
            spriteBatch.Begin(SpriteBlendMode.AlphaBlend);

            if (gamestate == 0)
            {
                spriteBatch.Draw(tex_dict["title"], new Vector2(0, 0), Color.White);
            }
            else if (gamestate == 1)
            {
                spriteBatch.Draw(tex_dict["instructions"], new Vector2(0, 0), Color.White);
            }
            else if (gamestate == 3)
            {
                graphics.GraphicsDevice.Clear(Color.Black);
                if (((int)gameTime.TotalRealTime.TotalSeconds * 2) % 2 == 0)
                {
                    spriteBatch.DrawString(scoreFont, name + currchar, new Vector2(500, 300), Color.White);
                }
                else
                {
                    spriteBatch.DrawString(scoreFont, name, new Vector2(500, 300), Color.White);
                }
            }
            else if (gamestate == 4)
            {
                graphics.GraphicsDevice.Clear(Color.Black);
                StreamReader SR;

                SR = File.OpenText("Content\\score.txt");
                for (int i = 0; i < 5; i++)
                {
                    names[i] = SR.ReadLine();
                }

                spriteBatch.DrawString(scoreFont, names[0] + "\n" + names[1] + "\n" + names[2] + "\n" + names[3] + "\n" + names[4], new Vector2(300, 200), Color.White);

                string a = SR.ReadLine();
                string b = SR.ReadLine();
                string c = SR.ReadLine();
                string d = SR.ReadLine();
                string e = SR.ReadLine();


                spriteBatch.DrawString(announceFont, "Highscores", new Vector2(1280 / 2 - (announceFont.MeasureString("Highscores").X / 2), 50), Color.White);
                spriteBatch.DrawString(scoreFont, String.Format("{0:0000000000}\n{1:0000000000}\n{2:0000000000}\n{3:0000000000}\n{4:0000000000}", a, b, c, d, e), new Vector2(800, 200), Color.White);
                SR.Close();
            }
            else
            {
                for (int y = 360; y < 3360; y += 720)
                {
                    for (int x = 1280 / 2; x < 3640; x += 1280)
                    {
                        spriteBatch.Draw(tex_dict["grass"], (new Vector2(x, y) - c.getOffset()) / c.getzoomout(), null, Color.White, 0,
                                         new Vector2(tex_dict["grass"].Width / 2, tex_dict["grass"].Height / 2), 1.0F / c.getzoomout(), SpriteEffects.None, 0);
                    }
                }
                for (int i = 0; i < objs.Count; i++)
                {
                    objs[i].Draw(spriteBatch, c);
                }

                spriteBatch.Draw(tex_dict["health_bg"], new Vector2(198, 678), null, Color.White, 0, new Vector2(0, 0), new Vector2(804, 14), SpriteEffects.None, 0);
                spriteBatch.Draw(tex_dict["health"], new Vector2(200, 680), null, Color.White, 0, new Vector2(0, 0), new Vector2(player.health * 80, 10), SpriteEffects.None, 0);

                spriteBatch.Draw(tex_dict["health_bg"], new Vector2(98, 38), null, Color.White, 0, new Vector2(0, 0), new Vector2(1004, 24), SpriteEffects.None, 0);
                spriteBatch.Draw(tex_dict["energy"], new Vector2(100, 40), null, Color.White, 0, new Vector2(0, 0), new Vector2(player.energy * 1000, 20), SpriteEffects.None, 0);

                spriteBatch.DrawString(scoreFont, "Score: " + Score.score, new Vector2(0, 60), Color.White);
                spriteBatch.DrawString(scoreFont, "Combo: " + Score.miss_combo, new Vector2(1000, 60), Color.White);
                //spriteBatch.DrawString(scoreFont, "Objects: " + (objs.Count - objectCount) + "\nTime: " + (int)(gameTime.TotalGameTime.TotalMinutes - startTime / 60) + ":" + String.Format("{0:00}", ((int)gameTime.TotalGameTime.TotalSeconds - startTime) % 60), new Vector2(0, 60), Color.White);

                if (player == null || !player.isAlive())
                {
                    spriteBatch.DrawString(announceFont, "YOU ARE DEAD", new Vector2(400, 250), Color.White);
                    spriteBatch.DrawString(announceFont, "Score: " + Score.score, new Vector2(400, 310), Color.White);
                }
            }

            spriteBatch.End();

            base.Draw(gameTime);
        }