예제 #1
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            KeyboardState kb = Keyboard.GetState();

            level.Update(gameTime, kb, gameState);
            hud.Update(gameTime, kb, gameState);

            if (gameState == 1)
            {
                if (!level.playerAlive)
                {
                    ChangeState(4);
                }
            }

            if (kb.IsKeyDown(Keys.Enter) && !(kbOld.IsKeyDown(Keys.Enter)))
            {
                if (gameState == 0 || gameState == 3 || gameState == 4)
                {
                    ChangeState(hud.GetSelectedState(gameState));
                    menuSelect.Play();
                }
                else if (gameState == 2)
                {
                    ChangeState(0);
                    menuSelect.Play();
                }
            }

            if (kb.IsKeyDown(Keys.Escape) && !(kbOld.IsKeyDown(Keys.Escape)))
            {
                if (gameState == 0)
                {
                    this.Exit();
                }
                else if (gameState == 1)
                {
                    ChangeState(3);
                }
                else if (gameState == 2)
                {
                    ChangeState(0);
                }
                else if (gameState == 3)
                {
                    ChangeState(1);
                }
            }

            if (level.height > 20200000)
            {
                ChangeState(5);
            }

            kbOld = kb;

            base.Update(gameTime);
        }
예제 #2
0
        public void Update(GameTime gt, KeyboardState kb, int gs)
        {
            //Title menu infinite scrolling
            if (gs == 0 || gs == 2)
            {
                height += 1f;

                if (oldHeight % 100 > height % 100)
                {
                    AddRandomBg("sky");
                }

                oldHeight = height;
            }

            //Actual gameplay
            if (gs == 1)
            {
                if (playerAlive)
                {
                    height += player.speed * gameSpeed;

                    if (oldHeight % 100 > height % 100 && height < 12000)
                    {
                        AddRandomBg("sky");
                    }
                    else if (oldHeight % 100 > height % 100 && height >= 12000 && height < 15000 && transitionNum < 8)
                    {
                        TransitionBg("evening");
                    }
                    else if (oldHeight % 500 > height % 500 && height >= 12800 && height < 100000)
                    {
                        if (height > 16000)
                        {
                            transitionNum = 0;
                        }
                        //The new transition stuff is REALLY hack, thanks LD48 with 4 hours left!
                        AddRandomBg("evening");
                    }
                    else if (oldHeight % 100000 > height % 100000 && height >= 100000 && height < 800000 && transitionNum < 8)
                    {
                        TransitionBg("space");
                    }
                    else if (oldHeight % 100000 > height % 100000 && height >= 100800)
                    {
                        transitionNum = 0;
                        AddRandomBg("space");
                    }

                    if (height < 17000000)
                    {
                        if (oldHeight % (gameSpeed * player.speed * 80) > height % (gameSpeed * player.speed * 80))
                        {
                            Random r    = new Random();
                            int    rNum = r.Next(2);
                            if (rNum % 2 == 1)
                            {
                                collidablesList.Add(CreateRandomCollidable());
                            }
                        }
                        if (oldHeight % (gameSpeed * player.speed * 800) > height % (gameSpeed * player.speed * 800))
                        {
                            Random r    = new Random();
                            int    rNum = r.Next(100);
                            if (rNum > 75)
                            {
                                collectiblesList.Add(resources.ReturnCollectibleFromType(0, r.Next(20, 440)));
                            }
                            else
                            {
                                collectiblesList.Add(resources.ReturnCollectibleFromType(1, r.Next(20, 440)));
                            }
                        }
                    }

                    player.Update(gt, kb);

                    for (int i = 0; i < collidablesList.Count; i++)
                    {
                        try {
                            if (height < 12000)
                            {
                                collidablesList[i].Update(gt, 8 * gameSpeed);
                            }
                            else if (height < 100000)
                            {
                                collidablesList[i].UpdateVertical(gt, 8 * gameSpeed);
                            }
                            else
                            {
                                collidablesList[i].UpdateOscillate(gt, 6 * gameSpeed);
                            }

                            if (collidablesList[i].position.X > 1800 || collidablesList[i].position.X < -1300)
                            {
                                collidablesList.Remove(collidablesList[i]);
                            }

                            if (player.boundingBox.Intersects(collidablesList[i].boundingBox))
                            {
                                if (Utility.CheckPerPixel(player.spriteMask, collidablesList[i].spriteMask,
                                                          player.position, collidablesList[i].position))
                                {
                                    if (player.playerState == 0)
                                    {
                                        player.Damage();
                                    }
                                }
                            }
                        }
                        catch (ArgumentOutOfRangeException) {
                            //Sometimes it tries to access a plane that's been destroyed.
                            //A hacky fix, but that's what LD48 is about.
                        }
                    }

                    for (int i = 0; i < collectiblesList.Count; i++)
                    {
                        try { //Same as above, crappy fixes
                            collectiblesList[i].Update(gt, 8 * gameSpeed);

                            if (collectiblesList[i].position.Y > 900)
                            {
                                collectiblesList.Remove(collectiblesList[i]);
                            }

                            if (player.boundingBox.Intersects(collectiblesList[i].boundingBox))
                            {
                                player.PickupCollectible(collectiblesList[i].type);
                                collectiblesList[i].pickupSound.Play();
                                collectiblesList.Remove(collectiblesList[i]);
                            }
                        }
                        catch (ArgumentOutOfRangeException) {
                        }
                    }

                    if (player.health < 1)
                    {
                        KillPlayer();
                    }

                    oldHeight = height;
                }
                else
                {
                    hud.Update(gt, kb, gs);
                }
            }

            base.Update(gt);
        }