Exemple #1
0
        public override void Update(GameTime gameTime)
        {
            ChickenCrosser chicken       = (ChickenCrosser)Game;
            KeyboardState  keyboardState = Keyboard.GetState();

            position += speed;

            if (position.Y <= 0)
            {
                speed.Y = Math.Abs(speed.Y);
                //chicken.wolfSound.Play();
            }
            if (position.X + tex.Width >= Shared.stage.X)
            {
                speed.X = -Math.Abs(speed.X);
            }
            if (position.X <= 0)
            {
                speed.X = Math.Abs(speed.X);
            }
            if (position.Y + tex.Height >= Shared.stage.Y)
            {
                speed.Y = -Math.Abs(speed.Y);
            }

            base.Update(gameTime);
        }
        public override void Update(GameTime gameTime)
        {
            ChickenCrosser chicken = (ChickenCrosser)Game;

            KeyboardState keyboardState = Keyboard.GetState();

            if (keyboardState.IsKeyDown(Keys.Up))
            {
                position -= speed;
            }
            if (position.Y < 0)
            {
                chicken.winString.Visible = true;
                speed.Y      = 0;
                this.Visible = false;
                position     = new Vector2(0, -300);
                if (keyboardState.IsKeyDown(Keys.Enter))
                {
                    chicken.chickenSound.Play();
                    NewGame();
                }
            }
            else if (keyboardState.IsKeyDown(Keys.Down))
            {
                position += speed;
                if (position.Y + tex.Height >= Shared.stage.Y)
                {
                    position.Y = Shared.stage.Y - tex.Height;
                }
            }
            base.Update(gameTime);
        }
        public HelpScene(Game game) : base(game)
        {
            ChickenCrosser chicken = (ChickenCrosser)game;

            this.spriteBatch = chicken.spriteBatch;
            helpTex          = chicken.Content.Load <Texture2D>("Images/Help");
        }
Exemple #4
0
        public HowToPlayScene(Game game) : base(game)
        {
            ChickenCrosser chicken = (ChickenCrosser)game;

            this.spriteBatch = chicken.spriteBatch;
            howToPlayTex     = chicken.Content.Load <Texture2D>("Images/HowToPlay");
        }
        public AboutScene(Game game) : base(game)
        {
            ChickenCrosser chicken = (ChickenCrosser)game;

            this.spriteBatch = chicken.spriteBatch;
            aboutTex         = chicken.Content.Load <Texture2D>("Images/About");
        }
        public void NewGame()
        {
            ChickenCrosser chicken = (ChickenCrosser)Game;

            position = new Vector2((Shared.stage.X - tex.Width) / 2,
                                   Shared.stage.Y - tex.Height);
            speed = new Vector2(0, 5);
            chicken.winString.Visible = false;
            chicken.attempts          = 1;
            this.Visible = true;
        }
        public ChickenCharacter(Game game,
                                SpriteBatch spriteBatch,
                                Texture2D tex) : base(game)
        {
            ChickenCrosser chicken = (ChickenCrosser)game;

            this.spriteBatch = spriteBatch;
            this.tex         = tex;
            position         = new Vector2((Shared.stage.X - tex.Width) / 2,
                                           Shared.stage.Y - tex.Height);
            speed = new Vector2(0, 5);
        }
        public CollisionDetection(Game game,
                                  ChickenCharacter chicken,
                                  WolfCharacter wolf,
                                  Celebration celebration,
                                  SoundEffect explosion) : base(game)
        {
            ChickenCrosser chickenCrosser = (ChickenCrosser)game;

            this.chicken     = chicken;
            this.wolf        = wolf;
            this.celebration = celebration;
            this.explosion   = explosion;
        }
Exemple #9
0
        public ActionScene(Game game) : base(game)
        {
            ChickenCrosser chicken = (ChickenCrosser)game;

            this.spriteBatch = chicken.spriteBatch;
            chickenTex       = chicken.Content.Load <Texture2D>("Images/Chicken");
            actionTex        = chicken.Content.Load <Texture2D>("Images/Action");

            chickenCharacter = new ChickenCharacter(game, spriteBatch, chickenTex);
            this.Components.Add(chickenCharacter);

            Texture2D celebrationTex = chicken.Content.Load <Texture2D>("Images/Celebration");

            celebration = new Celebration(chicken, spriteBatch, celebrationTex, Vector2.Zero, 5);
            this.Components.Add(celebration);


            Random randomWolfSpeed = new Random();


            int x     = randomWolfSpeed.Next(8, 16);
            int y     = randomWolfSpeed.Next(8, 16);
            int signX = randomWolfSpeed.Next(0, 2);
            int signY = randomWolfSpeed.Next(0, 2);

            if (signX == 1)
            {
                x = -x;
            }
            if (signY == 1)
            {
                y = -y;
            }
            wolfSpeed = new Vector2(x, y);

            Texture2D wolfTex = chicken.Content.Load <Texture2D>("Images/Wolf");

            wolfCharacter = new WolfCharacter(game, spriteBatch, wolfTex, wolfSpeed);

            SoundEffect explosion = chicken.Content.Load <SoundEffect>("Music/Explosion");

            this.Components.Add(wolfCharacter);
            CollisionDetection cd = new CollisionDetection(chicken, chickenCharacter, wolfCharacter, celebration, explosion);

            this.Components.Add(cd);
        }
Exemple #10
0
        public StartScene(Game game) : base(game)
        {
            ChickenCrosser chickenCrosser = (ChickenCrosser)game;

            this.spriteBatch = chickenCrosser.spriteBatch;
            SpriteFont regularFont   = chickenCrosser.Content.Load <SpriteFont>("Fonts/regularFont");
            SpriteFont highlightFont = chickenCrosser.Content.Load <SpriteFont>("Fonts/highlightFont");

            startTex  = chickenCrosser.Content.Load <Texture2D>("Images/Start");
            menuSound = chickenCrosser.Content.Load <SoundEffect>("Music/MenuSelect");

            startSong = chickenCrosser.Content.Load <Song>("Music/StartSong");
            MediaPlayer.IsRepeating = true;
            MediaPlayer.Play(startSong);

            Menu = new MenuComponent(chickenCrosser, spriteBatch, regularFont, highlightFont, menuItems, menuSound);
            this.Components.Add(Menu);
        }
        public override void Update(GameTime gameTime)
        {
            ChickenCrosser chickenCrosser = (ChickenCrosser)Game;

            if (wolf.getBound().Intersects(chicken.getBound()))
            {
                KeyboardState keyboardState = Keyboard.GetState();
                chicken.speed.Y      = 0;
                wolf.speed.Y         = 0;
                wolf.speed.X         = 0;
                celebration.Position = new Vector2(chicken.getBound().X - wolf.getBound().Width / 2,
                                                   chicken.getBound().Y - wolf.getBound().Height / 2);
                celebration.startAnimation();
                chickenCrosser.tryAgain.Visible = true;
                if (keyboardState.IsKeyDown(Keys.Enter))
                {
                    ResetGame();
                    chickenCrosser.wolfSound.Play();
                    chickenCrosser.attempts++;
                }
            }

            base.Update(gameTime);
        }
 static void Main()
 {
     using (var game = new ChickenCrosser())
         game.Run();
 }