Ejemplo n.º 1
0
        public void Draw(Game1 game, GameTime gameTime, int max_X, int max_Y, Sound1 so, int LevelRefresh, PlayerObject pl)
        {
            string output;
            Vector2 FontOrigin;

            //greyscale_color = (float)Math.Abs(Math.Sin(MathHelper.ToRadians((float)(gameTime.TotalGameTime.TotalSeconds * 10))));

            // TODO: Add your drawing code here
            // Draw the sprite.
            spriteBatch.Begin(SpriteBlendMode.AlphaBlend);

            int xTiles = max_X / sprite4.Width;
            int yTiles = max_Y / sprite4.Height;

            // background image
            for (int i = 0; i <= xTiles; i++)
            {
                for (int j = 0; j <= yTiles; j++)
                {
                    //spriteBatch.Draw(sprite4, Vector2.Zero, null, Color.White, 0.0f, Vector2.Zero, new Vector2(graphics.GraphicsDevice.Viewport.Width / (float)sprite4.Width, graphics.GraphicsDevice.Viewport.Height / (float)sprite4.Height), SpriteEffects.None, 0);
                    //spriteBatch.Draw(sprite4, new Vector2(i * sprite4.Width, j * sprite4.Height), new Color(1.0f, 1.0f, 1.0f, MathHelper.Clamp(greyscale_color,0.2f,1.0f)));
                    spriteBatch.Draw(sprite4, new Vector2(i * sprite4.Width, j * sprite4.Height), new Color(1.0f, 1.0f, 1.0f));
                }
            }

            // tree
            DrawTree(max_Y);

            // flowers
            float half_w = sprite7.Width / 2;
            float half_h = sprite7.Height / 2;
            foreach (MovingObject a in SpriteList2)
            {
                Vector2 center;
            //                float new_scale = (game.CorrectX() + game.CorrectY())/2;
                center = new Vector2(half_w, half_h);
            //                center = new Vector2(sprite7.Width / 2 * game.CorrectX(), sprite7.Height / 2 * game.CorrectY());
                spriteBatch.Draw(sprite7, a.position, null, Color.White, a.rotation, center, 1.0f, SpriteEffects.None, 0.0f);
            //                spriteBatch.Draw(sprite7, new Vector2(a.position.X * game.CorrectX(), a.position.Y * game.CorrectY()), null, Color.White, a.rotation, center, new_scale, SpriteEffects.None, 0.0f);
            }

            // beehive
            spriteBatch.Draw(sprite6, new Vector2(max_X * 4 / 7, 2), Color.White);

            // bees
            if (!game.isGameOver())
            {
                Vector2 center;

                // umbrella
                if (umbrella != null)
                {
                    Rectangle r = new Rectangle(0, 0, sprite11.Width/2, sprite11.Height);
                    center = new Vector2(umb_width, umb_height);
                    spriteBatch.Draw(sprite11, umbrella.position, r, Color.White, 0.0f, center, 1.0f, SpriteEffects.None, 0.0f);
                }

                foreach (MovingObject a in SpriteList)
                {
                    switch (a.tex)
                    {
                        case 0:
                            center = new Vector2(sprite1.Width / 2, sprite1.Height / 2);
                            spriteBatch.Draw(sprite1, a.position, null, Color.White, a.rotation, center, 1.0f, SpriteEffects.None, 0.0f);
                            output = a.position.ToString();
                            FontOrigin = Font1.MeasureString(output) / 2;
                            FontPos = a.position;
                            //spriteBatch.DrawString(Font1, output, FontPos, Color.LightGreen, 0, FontOrigin, 1.0f, SpriteEffects.None, 0.5f);
                            break;
                        case 1:
                            center = new Vector2(sprite2.Width / 2, sprite2.Height / 2);
                            spriteBatch.Draw(sprite2, a.position, null, Color.White, a.rotation, center, 1.0f, SpriteEffects.None, 0.0f);
                            output = a.position.ToString();
                            FontOrigin = Font1.MeasureString(output) / 2;
                            FontPos = a.position;
                            //spriteBatch.DrawString(Font1, output, FontPos, Color.LightGreen, 0, FontOrigin, 1.0f, SpriteEffects.None, 0.5f);
                            break;
                        case 2:
                            center = new Vector2(sprite3.Width / 2, sprite3.Height / 2);
                            spriteBatch.Draw(sprite3, a.position, null, Color.White, a.rotation, center, 1.0f, SpriteEffects.None, 0.0f);
                            output = a.position.ToString();
                            FontOrigin = Font1.MeasureString(output) / 2;
                            FontPos = a.position;
                            //spriteBatch.DrawString(Font1, output, FontPos, Color.LightGreen, 0, FontOrigin, 1.0f, SpriteEffects.None, 0.5f);
                            break;
                        case 3:
                            center = new Vector2(sprite4.Width / 2, sprite4.Height / 2);
                            spriteBatch.Draw(sprite4, a.position, null, Color.White, a.rotation, center, 1.0f, SpriteEffects.None, 0.0f);
                            output = a.position.ToString();
                            FontOrigin = Font1.MeasureString(output) / 2;
                            FontPos = a.position;
                            //spriteBatch.DrawString(Font1, output, FontPos, Color.LightGreen, 0, FontOrigin, 1.0f, SpriteEffects.None, 0.5f);
                            break;
                        case 4:
                            center = new Vector2(sprite5.Width / 2, sprite5.Height / 2);
                            Color draw_color = Color.White;
                            Texture2D current_sprite = sprite5;

                            if (a.first)
                            {
                                current_sprite = sprite10;
                                if (old_position.X > a.position.X )
                                {
                                    SEVal = SpriteEffects.FlipHorizontally;
                                }
                                else
                                if (old_position.X < a.position.X )
                                {
                                    SEVal = SpriteEffects.None;
                                }

                                if (game.GetPlayerHit())
                                    draw_color = Color.Crimson;
                                else
                                    draw_color = Color.White;

                                spriteBatch.Draw(current_sprite, a.position, null, draw_color, a.rotation, center, 1.0f, SEVal, 0.0f);

                                if(pl.umbrella_active>0)
                                {
                                    Rectangle r=new Rectangle(sprite11.Width / 2, 0, sprite11.Width, sprite11.Height);;
                                    center = new Vector2(umb_width, umb_height);
                                    if(SEVal==SpriteEffects.None)
                                        spriteBatch.Draw(sprite11, new Vector2(a.position.X + 30,a.position.Y - 10), r, Color.White, 0.0f, center, 1.0f, SpriteEffects.None, 0.0f);
                                    else
                                        spriteBatch.Draw(sprite11, new Vector2(a.position.X - 30, a.position.Y - 10), r, Color.White, 0.0f, center, 1.0f, SpriteEffects.None, 0.0f);
                                }
                            }
                            else
                            if (a.speed.X < 0)
                                spriteBatch.Draw(current_sprite, a.position, null, draw_color, a.rotation, center, 1.0f, SpriteEffects.FlipHorizontally, 0.0f);
                            else
                                spriteBatch.Draw(current_sprite, a.position, null, draw_color, a.rotation, center, 1.0f, SpriteEffects.None, 0.0f);

                            /*output = a.speed.ToString();
                            FontOrigin = Font1.MeasureString(output) / 2;
                            FontPos = new Vector2(a.position.X,a.position.Y+70);
                            spriteBatch.DrawString(Font1, output, FontPos, Color.Black, 0, FontOrigin, 1.0f, SpriteEffects.None, 0.5f);
                            */
                            break;
                    }

                }
            }
            // Game Over
            else
            {
                float float_effect = 0.75f + MathHelper.Clamp((float)Math.Abs(Math.Sin((gameTime.TotalGameTime.TotalSeconds) * 4 * Math.PI / 180)), 0.0f, 1.0f);
                //float float_effect = 0.75f + (float)Math.Sin((gameTime.TotalGameTime.TotalSeconds)*180 * Math.PI / 180);
                spriteBatch.Draw(sprite9, new Vector2(max_X / 2, max_Y / 2), null, Color.White, 0.0f, new Vector2(sprite9.Width / 2, sprite9.Height / 2), float_effect, SpriteEffects.None, 1.0f);
                so.PlayGameOver(game);
            }

            if (LevelRefresh > 0)
            {
                int Count = LevelRefresh / 60 + 1;
                output = Count.ToString();

                FontOrigin = Font3.MeasureString(output) / 2;
                FontPos = new Vector2(max_X / 2, max_Y / 2);
                spriteBatch.DrawString(Font3, output, FontPos * 1.01f, Color.Black, 0, FontOrigin, 1.5f, SpriteEffects.None, 1.0f);
                spriteBatch.DrawString(Font3, output, FontPos, Color.Wheat, 0, FontOrigin, 1.5f, SpriteEffects.None, 1.0f);
            }

            if (draw_HUD)
            {
                // Draw Hello World
                double val = Math.Sin((gameTime.TotalGameTime.TotalSeconds * 180) * Math.PI / 180);
                double val2 = max_X / (float)sprite4.Height;
                FPS_Count += (double)gameTime.ElapsedGameTime.TotalSeconds;//MovingObject val3 = SpriteList.First();

                framecount++;

                // HUD background
                spriteBatch.Draw(sprite8, Vector2.Zero, Color.White);

                double FPS = framecount/FPS_Count;
                output = "FPS: " + FPS.ToString("F04");
                FontOrigin = Font1.MeasureString(output) / 2;
                FontPos = new Vector2(max_X-100, max_Y-50);
                spriteBatch.DrawString(Font1, output, FontPos * 1.002f, Color.Black, 0, FontOrigin, 1.0f, SpriteEffects.None, 1.0f);
                spriteBatch.DrawString(Font1, output, FontPos, Color.White, 0, FontOrigin, 1.0f, SpriteEffects.None, 1.0f);

                output = "LEVEL: " + game.GetLevel() + "     " + "BEES: " + SpriteList.Count();
                FontOrigin = Font1.MeasureString(output) / 2;
                FontPos = new Vector2(FontOrigin.X + 40, 30);
                spriteBatch.DrawString(Font1, output, new Vector2(FontPos.X * 1.02f, FontPos.Y *1.06f), Color.Black, 0, FontOrigin, 1.0f, SpriteEffects.None, 1.0f);
                spriteBatch.DrawString(Font1, output, FontPos, Color.White, 0, FontOrigin, 1.0f, SpriteEffects.None, 1.0f);

                output = "LIVES: " + game.GetLives();
                FontOrigin = Font1.MeasureString(output) / 2;
                FontPos = new Vector2(FontOrigin.X + 40, 60);
                spriteBatch.DrawString(Font1, output, FontPos * 1.04f, Color.Black, 0, FontOrigin, 1.0f, SpriteEffects.None, 1.0f);
                spriteBatch.DrawString(Font1, output, FontPos, Color.White, 0, FontOrigin, 1.0f, SpriteEffects.None, 1.0f);
                /*
                output = "SINE: " + val.ToString("F04");
                FontOrigin = Font1.MeasureString(output) / 2;
                FontPos = new Vector2(FontOrigin.X + 40, 30);
                spriteBatch.DrawString(Font1, output, FontPos * 1.04f, Color.Black, 0, FontOrigin, 1.0f, SpriteEffects.None, 1.0f);
                spriteBatch.DrawString(Font1, output, FontPos, Color.White, 0, FontOrigin, 1.0f, SpriteEffects.None, 1.0f);
                */
                output = "FLOWERS: " + game.GetFlowerCount();
                FontOrigin = Font1.MeasureString(output) / 2;
                FontPos = new Vector2(FontOrigin.X + 40, 90);
                spriteBatch.DrawString(Font1, output, FontPos * 1.03f, Color.Black, 0, FontOrigin, 1.0f, SpriteEffects.None, 1.0f);
                spriteBatch.DrawString(Font1, output, FontPos, Color.White, 0, FontOrigin, 1.0f, SpriteEffects.None, 1.0f);

                //output = "FPS: " + framecount / FPS_Count;
                output = "UMBRELLAS: " + pl.umbrella; // +" Timeleft: " + pl.umbrella_active;
                FontOrigin = Font1.MeasureString(output) / 2;
                FontPos = new Vector2(FontOrigin.X + 40, 120);
                spriteBatch.DrawString(Font1, output, FontPos * 1.02f, Color.Black, 0, FontOrigin, 1.0f, SpriteEffects.None, 1.0f);
                spriteBatch.DrawString(Font1, output, FontPos, Color.White, 0, FontOrigin, 1.0f, SpriteEffects.None, 1.0f);
            }
            spriteBatch.End();
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Allows the game to perform any initialization it needs to before starting to run.
 /// This is where it can query for any required services and load any non-graphic
 /// related content.  Calling base.Initialize will enumerate through any components
 /// and initialize them as well.
 /// </summary>
 /// 
 protected override void Initialize()
 {
     // TODO: Add your initialization logic here
     base.Initialize();
     pl = new PlayerObject();
     spriteObject.Initialize(this, TargetResolutionX, TargetResolutionY);
 }
Ejemplo n.º 3
0
        public void UpdatePlayerSprite(Game1 game, PlayerObject pl, Sound1 so)
        {
            MouseState current_mouse = Mouse.GetState();

            old_position = SpriteList.First().position;
            if (current_mouse.X > game.GraphicsDevice.Viewport.Width || current_mouse.Y > game.GraphicsDevice.Viewport.Height || current_mouse.X < 0 || current_mouse.Y < 0)
            {
                // out of bounds
            }
            else
                SpriteList.First().position = new Vector2(current_mouse.X * resolution_x_ratio, current_mouse.Y * resolution_y_ratio);

            // check for intersection with umbrella
            if (umbrella != null)
            {
                MovingObject umb_intersect = umbrella;
                umb_intersect.width = umb_width;
                umb_intersect.height = umb_height;
                if (Intersects(SpriteList.First(), umb_intersect))
                {
                    so.PlayUmbrellaPickUp(game);
                    pl.umbrella++;
                    umbrella=null;
                }
            }
        }