//Constructor public Torch(Player p, Texture2D f, World w) { player = p; position = p.Location; velocity = new Vector2(0, 0); bounds = new Rectangle((int)position.X, (int)position.Y, 20, 50); flame = f; world = w; }
public bool checkPlayerCollision(Player player) { if (player.VState != Player.VerticalState.none) { return false; } if (player.Body.Intersects(Bounds)) { // && (position.X > p.Bounds.Left - 50 *.75) && (position.X < p.Bounds.Right - 50 * .75) if (player.Location.Y + 50 < Bounds.Top + 18) { return true; } } /* if (player.Location.X >= this.Bounds.X + this.Bounds.Width / 2) { return true; }*/ return false; }
public void checkForTorches(Player player, Powerup power) { foreach (Platform p in platforms) { p.isPlayerCollecting(power, player); } }
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(); } } }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { world.addPlatform(new Rectangle(100, 100, 150, 25),Content.Load<Texture2D>("Platform")); world.addPlatform(new Rectangle(300, 100, 150, 25), Content.Load<Texture2D>("Platform")); world.addPlatform(new Rectangle(550, 100, 150, 25), Content.Load<Texture2D>("Platform")); world.addPlatform(new Rectangle(800, 100, 150, 25), Content.Load<Texture2D>("Platform")); playerTexture = Content.Load<Texture2D>("dude"); player = new Player(playerTexture, graphics, world); // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); // TODO: use this.Content to load your game content here }
/// <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; }