コード例 #1
0
ファイル: World.cs プロジェクト: jewinemiller/Leap
 public void reset(Powerup p)
 {
     player.reset(p);
     sizeFactor = 3.0;
     distTraveled = 0;
     Texture2D tempTex = platforms[0].Texture;
     Texture2D[] textures = platforms[0].Textures;
     Random rand = platforms[0].rand;
     platforms.Clear();
     addPlatform(new Rectangle(100, 200, 150, 25), tempTex, textures, rand);
     addPlatform(new Rectangle(300, 200, 150, 25), tempTex, textures, rand);
     addPlatform(new Rectangle(550, 150, 150, 25), tempTex, textures, rand);
     addPlatform(new Rectangle(800, 175, 150, 25), tempTex, textures, rand);
     score = 0;
 }
コード例 #2
0
ファイル: GameOver.cs プロジェクト: jewinemiller/Leap
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="c">Content Manager</param>
        /// <param name="b">Bounding Rectangle - Displays the menu of set size</param>
        public GameOver(ContentManager c, Rectangle b, World w, Powerup power)
            : base(c, b)
        {
            //Initialize Everything
            items = new List<MenuItem>();
            world = w;
            pUp = power;
            MenuTex = c.Load<Texture2D>("gameover");
            restart = new Button(new Vector2(300.0f, 200.0f), c.Load<Texture2D>("restart"));
            quit = new Button(new Vector2(300.0f, 300.0f), c.Load<Texture2D>("quit"));
            score = new Label(new Vector2(100.0f, 100.0f), c.Load<Texture2D>("quit"), "Your Score: " + w.score/10 + " meters");
            try
            {
                StreamReader reader = new StreamReader("highScore.txt");
                high = Double.Parse(reader.ReadLine());
                reader.Close();
                if (high < w.score)
                {
                    high = w.score;
                    StreamWriter writer = new StreamWriter("highScore.txt", false);
                    writer.Write(Math.Round(high, 2));
                    writer.Close();
                }
            }
            catch (Exception e)
            {
                high = w.score;
                StreamWriter writer = new StreamWriter("highScore.txt", false);
                writer.Write(Math.Round(high, 2));
                writer.Close();
            }
            highScore = new Label(new Vector2(100.0f, 150.0f), c.Load<Texture2D>("quit"), "High Score: " + Math.Round(high, 2) / 10 + " meters");
            buttonClick = c.Load<SoundEffect>("Audio/WAVs/Buttons/button2");

            //Add everything to the array of items.
            isActive = true;
            items.Add(restart);
            items.Add(quit);
            items.Add(score);
            items.Add(highScore);
            //Finish some initialization
            content = c;
        }
コード例 #3
0
ファイル: PauseMenu.cs プロジェクト: jewinemiller/Leap
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="c">Content Manager</param>
        /// <param name="p">The Player</param>
        /// <param name="b">Bounding Rectangle - Displays the menu of set size</param>
        /// <param name="w">The World that the Game takes place in</param>
        public PauseMenu(ContentManager c, Rectangle b, World w, Powerup power)
            : base(c, b)
        {
            //Initialize Everything
            items = new List<MenuItem>();
            world = w;
            pUp = power;

            resume = new Button(new Vector2(300.0f, 150.0f), c.Load<Texture2D>("continue"));
            restart = new Button(new Vector2(300.0f, 250.0f), c.Load<Texture2D>("restart"));
            quit = new Button(new Vector2(300.0f, 350.0f), c.Load<Texture2D>("quit"));
            buttonClick = c.Load<SoundEffect>("Audio/WAVs/Buttons/button2");

            //Add everything to the array of items.
            isActive = true;
            items.Add(resume);
            items.Add(restart);
            items.Add(quit);

            //Finish some initialization
            content = c;
        }
コード例 #4
0
ファイル: Platform.cs プロジェクト: jewinemiller/Leap
        public void display(SpriteBatch s, Powerup torch, Rectangle drawBounds)
        {
            int xDist = 26;

            //Draw left cap
            Rectangle leftBound = new Rectangle(bounds.X, bounds.Y, 26, 25);

            if (drawBounds.Intersects(leftBound))
            {
                Rectangle drawnLeft = Rectangle.Intersect(drawBounds, leftBound);
                s.Draw(textures[0], drawnLeft, new Rectangle(0, 0, textures[0].Width, drawnLeft.Height), Color.White);
            }

            //Draw middle textures
            for (int i = 0; i < piecesToDraw.Length - 1; i++)
            {
                Rectangle temp = new Rectangle(bounds.X + xDist, bounds.Y, 15, 25);

                if (drawBounds.Intersects(temp))
                {
                    Rectangle drawnMid = Rectangle.Intersect(drawBounds, temp);
                    s.Draw(piecesToDraw[i], drawnMid, new Rectangle(0, 0, piecesToDraw[i].Width, drawnMid.Height), Color.White);

                }
                xDist += 15;
            }

            //Draw end cap
            Rectangle endRect = new Rectangle(bounds.X + xDist, bounds.Y, 26, 25);
            if (drawBounds.Intersects(endRect))
            {
                Rectangle drawnEnd = Rectangle.Intersect(drawBounds, endRect);
                // Rectangle temp = Rectangle.Intersect(drawBounds, endRect));
                //s.Draw(textures[1], drawnEnd, new Rectangle(0,0,textures[1].Width, drawnEnd.Height), Color.White);
            }
            xDist -= 15;

            //s.Draw(texture, bounds, Color.Black);

            if (hasTorch == true)
            {
                torch.relocate(this);
                if (drawBounds.Intersects(torch.Bounds))
                {
                    torch.display(s);
                }
            }
        }
コード例 #5
0
ファイル: Platform.cs プロジェクト: jewinemiller/Leap
 public void checkForTorches(Player player, Powerup power)
 {
     foreach (Platform p in platforms)
     {
         p.isPlayerCollecting(power, player);
     }
 }
コード例 #6
0
ファイル: Platform.cs プロジェクト: jewinemiller/Leap
 public void isPlayerCollecting(Powerup powerup, Player player)
 {
     if (this.hasTorch == true)
     {
         torchBounds = new Rectangle(bounds.X + (bounds.Width / 2) - 10, bounds.Y - 50, 20, 20);
         if (player.Body.Intersects(torchBounds))
         {
             this.hasTorch = false;
             powerup.pickup();
         }
     }
 }
コード例 #7
0
ファイル: Player.cs プロジェクト: jewinemiller/Leap
        //Throw torches
        public void throwTorches(KeyboardState currState, KeyboardState prevState, Powerup powerup)
        {
            if (powerup.getUses() > 0)
            {
                if (currState.IsKeyDown(Keys.F) && prevState.IsKeyUp(Keys.F) && currTorch < torches.Length)
                {
                    powerup.use();
                    torches[currTorch].throwTorch();
                    currTorch++;
                    burning2.Play();

                    // here
                }
            }
        }
コード例 #8
0
ファイル: Player.cs プロジェクト: jewinemiller/Leap
        public void reset(Powerup tp)
        {
            position = new Vector2(150, 50);
            body = new Rectangle((int)position.X, (int)position.Y, 50, 50);
            velocity = new Vector2(0, 0);
            hState = HorizontalState.standing;

            //Make an array of three torches
            torches = new Torch[999];
            for (int i = 0; i < torches.Length; i++)
            {
                torches[i] = new Torch(this, flameTexture, world);
            }
            vState = VerticalState.none;
            tp.setUses(3);
        }
コード例 #9
0
ファイル: Player.cs プロジェクト: jewinemiller/Leap
        /// <summary>
        /// This method updates the state of the player based on position and keys pressed.
        /// </summary>
        /// <param name="kbState">This is the current KeyBoardState</param>
        /// <param name="prevState">This is the previouse KeyBoardState</param>
        public void move(KeyboardState kbState, KeyboardState prevState, Powerup tPower)
        {
            //Print out debugging info
            //Console.WriteLine("VSTATE: " + vState);
            //Console.WriteLine("HSTATE: " + hState);
            //Console.WriteLine("POSITION: " + " ( " + position.X + ", " + position.Y + " ) ");
            //Console.WriteLine("VELOCITY: " + " ( " + velocity.X + ", " + velocity.Y + " ) ");

            //Set the x velocity to 0 automatically and set the horizontal state to standing by default
            velocity.X = 0;
            hState = HorizontalState.standing;

            //Check key presses to move player
            if ((kbState.IsKeyDown(Keys.Left) && kbState.IsKeyUp(Keys.Right)) || (kbState.IsKeyDown(Keys.A) && kbState.IsKeyUp(Keys.D)))
            {
                //Move left as long as there is room
                if (position.X > 0 + xSpeed)
                {
                    hState = HorizontalState.walkingLeft;

                    //Move the player to the left
                    velocity.X = -1 * xSpeed;
                }
                animCycle.lastFrame();
            }

            if ((kbState.IsKeyDown(Keys.Right) && kbState.IsKeyUp(Keys.Left)) || (kbState.IsKeyDown(Keys.D) && kbState.IsKeyUp(Keys.A)))
            {
                //Move right as long as there is room
                if (position.X < ((float)screenWidth - xSpeed)/2 - texture.Width / 2)
                {
                    hState = HorizontalState.walkingRight;

                    //Move the player to the right
                    velocity.X = xSpeed;
                }
                else
                {
                    world.bg.scroll((int)xSpeed-3);
                    world.movePlatforms((int)xSpeed);
                    for (int i = 0; i < torches.Length; i++)
                    {
                        if (torches[i].Falling == false)
                        {
                            torches[i].Location = new Vector2(torches[i].Location.X - xSpeed, torches[i].Location.Y);
                        }
                    }

                    hState = HorizontalState.walkingRight;
                    world.rocks.scroll((int)xSpeed - 1);
                }
                animCycle.nextFrame();
            }

            // Jumping/Falling
            if (kbState.IsKeyDown(Keys.Up) || kbState.IsKeyDown(Keys.Space) || kbState.IsKeyDown(Keys.W)) // If the player is currently pressing up.
            {
                if (vState == VerticalState.none || vState == VerticalState.fallingPlatform) // If the player's veritcal state is none (not falling or jumping) or the player is on a Falling Platform.
                {
                    currentPlatform = null;
                    vState = VerticalState.jumping;
                    velocity.Y = -2 * ySpeed;
                }
            }
            else if (vState == VerticalState.jumping) // If the player is currently not pressing up and is jumping.
            {
                // Stop the jump.
                vState = VerticalState.falling;
                velocity.Y = -0.5f * velocity.Y;
            }

            //Check for collision detection
            if(vState == VerticalState.falling)
            {
                foreach (Platform p in world.getPlatforms())
                {
                    if (body.Intersects(p.Bounds))
                    {
                        // && (position.X > p.Bounds.Left - 50 *.75) && (position.X < p.Bounds.Right - 50 * .75)
                        if (position.Y + 44 < p.Bounds.Top + 18)
                        {
                            position.Y = p.Bounds.Top - 43;
                            vState = VerticalState.none;
                            velocity.Y = 0;

                            currentPlatform = p;
                        }
                    }
                }
            }
            if (vState == VerticalState.none)
            {
                bool isColliding = false;
                foreach (Platform p in world.getPlatforms())
                {
                    if (body.Intersects(p.Bounds))
                    {
                        isColliding = true;
                    }
                }

                if (!isColliding)
                {
                    vState = VerticalState.falling;
                    currentPlatform = null;
                }
            }
            if (vState == VerticalState.fallingPlatform) // Check to see if the player is still on the platform horizontally.
            {
                if (position.X + 50 < currentPlatform.Bounds.Left || position.X > currentPlatform.Bounds.Right)
                {
                    vState = VerticalState.falling;
                    currentPlatform = null;
                }
            }

            if (position.Y >= screenHeight - 44) // If the player is at the bottom of the screen.
            {
                if (vState == VerticalState.falling || vState == VerticalState.fallingPlatform) // If the player's vertical state is falling or fallingPlatform.
                {
                    world.reset(tPower);
                }
            }

            //Add our velocity to our position vector
            position.X += velocity.X;
            position.Y += velocity.Y;

            body.X = (int)position.X;
            body.Y = (int)position.Y;

            //Check to see if player is throwing torches
            throwTorches(kbState, prevState, tPower);

            //Update all torches, if any
            for (int i = 0; i < torches.Length; i++)
            {
                torches[i].update();
            }
        }
コード例 #10
0
ファイル: Game1.cs プロジェクト: jewinemiller/Leap
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            lightmask = Content.Load<Texture2D>("lightmask");
            lightEffect = Content.Load<Effect>("lighting");
            //background = Content.Load<Texture2D>("background");
            //bg2 = Content.Load<Texture2D>("bg2");
            flameTexture = Content.Load<Texture2D>("Torches/torch1");
            cursor = Content.Load<Texture2D>("cursor");

            bgHolder = Content.Load<Texture2D>("wally");
            backgrounds.Add(bgHolder);
            bgHolder = Content.Load<Texture2D>("wally2");
            backgrounds.Add(bgHolder);
            bgHolder = Content.Load<Texture2D>("wally");
            backgrounds.Add(bgHolder);
            bgHolder = Content.Load<Texture2D>("wally2");
            backgrounds.Add(bgHolder);

            bgHolder = Content.Load<Texture2D>("rocky1");
            rocks.Add(bgHolder);
            bgHolder = Content.Load<Texture2D>("rocky2");
            rocks.Add(bgHolder);
            bgHolder = Content.Load<Texture2D>("rocky1");
            rocks.Add(bgHolder);
            bgHolder = Content.Load<Texture2D>("rocky2");
            rocks.Add(bgHolder);

            font = Content.Load<SpriteFont>("Font");
            fontLocation = new Vector2(0.0f, graphics.GraphicsDevice.Viewport.Height-25);
            fontTime = 0;

            bgmusic = Content.Load<Song>("Audio/MP3s/song2");

            platformTextures = new Texture2D[17];
            platformTextures[0] = Content.Load<Texture2D>("Platforms/endcap_left");
            platformTextures[1] = Content.Load<Texture2D>("Platforms/endcap_right");

            for (int i = 0; i < platformTextures.Length - 3; i++)
            {
                platformTextures[i + 2] = Content.Load<Texture2D>("Platforms/segment" + Convert.ToString(i+1));
            }

            pHolder = Content.Load<Texture2D>("running/lofwalking10001");
            playerAnimation.Add(pHolder);
            pHolder = Content.Load<Texture2D>("running/lofwalking10002");
            playerAnimation.Add(pHolder);
            pHolder = Content.Load<Texture2D>("running/lofwalking10003");
            playerAnimation.Add(pHolder);
            pHolder = Content.Load<Texture2D>("running/lofwalking10004");
            playerAnimation.Add(pHolder);
            pHolder = Content.Load<Texture2D>("running/lofwalking10005");
            playerAnimation.Add(pHolder);
            pHolder = Content.Load<Texture2D>("running/lofwalking10006");
            playerAnimation.Add(pHolder);
            pHolder = Content.Load<Texture2D>("running/lofwalking10007");
            playerAnimation.Add(pHolder);
            pHolder = Content.Load<Texture2D>("running/lofwalking10008");
            playerAnimation.Add(pHolder);
            pHolder = Content.Load<Texture2D>("running/lofwalking10009");
            playerAnimation.Add(pHolder);
            pHolder = Content.Load<Texture2D>("running/lofwalking10010");
            playerAnimation.Add(pHolder);
            pHolder = Content.Load<Texture2D>("running/lofwalking10011");
            playerAnimation.Add(pHolder);
            pHolder = Content.Load<Texture2D>("running/lofwalking10012");
            playerAnimation.Add(pHolder);

            playerAnim = new Animation(1, playerAnimation);

            world.addPlatform(new Rectangle(100, 200, 150, 25), Content.Load<Texture2D>("Platform"), platformTextures, randomNumber);
            world.addPlatform(new Rectangle(300, 200, 150, 25), Content.Load<Texture2D>("Platform"), platformTextures, randomNumber);
            world.addPlatform(new Rectangle(550, 150, 150, 25), Content.Load<Texture2D>("Platform"), platformTextures, randomNumber);
            world.addPlatform(new Rectangle(800, 175, 150, 25), Content.Load<Texture2D>("Platform"), platformTextures, randomNumber);

            playerTexture = Content.Load<Texture2D>("dude");
            player = new Player(playerTexture, graphics, world, flameTexture);
            player.animCycle = playerAnim;
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            var param = graphics.GraphicsDevice.PresentationParameters;
            scene = new RenderTarget2D(graphics.GraphicsDevice, param.BackBufferWidth, param.BackBufferHeight);
            mask = new RenderTarget2D(graphics.GraphicsDevice, param.BackBufferWidth, param.BackBufferHeight);

            menu = new MainMenu(Content, new Rectangle(0, 0, graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight));

            MediaPlayer.Play(bgmusic);
            MediaPlayer.IsRepeating = true;

            //Powerups
            torchTexture = Content.Load<Texture2D>("Torches/torch1");
            torchPowerupPos = new Vector2(0,0);
            torchPowerup = new Powerup(torchTexture, torchPowerupPos, 3);

            //bg2 = Content.Load<Texture2D>("bg2");
            //bg3 = Content.Load<Texture2D>("bg3");

            /*bgs[0] = background;
            bgs[1] = background;
            bgs[2] = background;

            rects[0] = new Rectangle(0, 0, background.Width, background.Height);
            rects[1] = new Rectangle(background.Width, 0, background.Width, background.Height);
            rects[2] = new Rectangle(background.Width, 0, background.Width, background.Height);
            */
            rects = new Rectangle[backgrounds.Count];
            rockrects = new Rectangle[rocks.Count];
            rects[0] = new Rectangle(0, 0, backgrounds[0].Width, backgrounds[0].Height);
            rockrects[0] = new Rectangle(0, 0, rocks[0].Width, rocks[0].Height);

            for (int i = 1; i < rects.Length; i++)
            {
                rects[i] = new Rectangle((rects[i - 1].X + rects[i - 1].Width), 0, backgrounds[i].Width, backgrounds[i].Height);
            }

            for (int i = 1; i < rockrects.Length; i++)
            {
                rockrects[i] = new Rectangle((rockrects[i - 1].X + rockrects[i - 1].Width), 0, rocks[i].Width, rocks[i].Height);
            }

            backObj = new Background(rects);
            world.bg = backObj;
            rockObj = new Background(rockrects);
            world.rocks = rockObj;
        }