public Gameworld(ContentHolder contentHolder) { this.contentHolder = contentHolder; risseObject = new Gameobject(contentHolder.texture_risse, new Vector2(100, 0), Vector2.Zero, 100, 192, 192); backgrounds.Add(new Gameobject(contentHolder.texture_background4, Vector2.Zero, new Vector2(-1, 0))); backgrounds.Add(new Gameobject(contentHolder.texture_background3, Vector2.Zero, new Vector2(-3, 0))); backgrounds.Add(new Gameobject(contentHolder.texture_background1, Vector2.Zero, new Vector2(-6, 0))); backgrounds.Add(new Gameobject(contentHolder.texture_background2, new Vector2(0,15), new Vector2(-8, 0))); //platforms.Add(new Gameobject(contentHolder.texture_platform, new Vector2(900, 500), new Vector2(-6,0))); background_fluff.Add(new Gameobject(contentHolder.texture_checkpoint, new Vector2(checkpointInterval, 560), new Vector2(-10, 0), 256, 256)); platforms.Add(makePlatformSection(new Vector2(checkpointInterval, GROUNDHEIGHT), 0, 0)); background_fluff[0].incrementCheckpoint += new Gameobject.EventHandler(increment); generateMap(); generateObstacles(); generatePlatforms(); //ground = makePlatformSection(new Vector2(0, 670)); //int platformWidth = contentHolder.texture_platform.Width; //for (int i = 0; i < NUMBEROFPLATFORMS; i++) //{ // ground.Add(new Gameobject(contentHolder.texture_platform, new Vector2(- contentHolder.texture_platform.Width + platformWidth, 688), new Vector2(-3, 0))); // platformWidth += contentHolder.texture_platform.Width; //} //ground.Add(new Gameobject(contentHolder.texture_platform, new Vector2(1, 688), new Vector2(-3, 0))); }
public bool collisionDetection(Gameobject object1, Gameobject object2) { if (object1.BoundingBox.Intersects(object2.BoundingBox)) { return true; } else { return false; } }
public void updateFluff(Gameobject risse, ContentHolder contentHolder) { position += velocity; if (BoundingBox.Intersects(risse.BoundingBox)) { if (!checkpointActivated) { currentFrame = 1; incrementCheckpoint((int)position.X); contentHolder.sound_checkpoint.Play(); checkpointActivated = true; } } if (Position.X < -SpriteWidth) { Checkpoints = Checkpoints + 1; position.X += 4000; currentFrame = 0; checkpointActivated = false; } sourceRect = new Rectangle(currentFrame * spriteWidth, 0, spriteWidth, spriteHeight); origin = new Vector2(sourceRect.Width / 2, sourceRect.Height / 2); }
protected override void LoadContent() { // Sets the mouse position in our window. Mouse.WindowHandle = this.Window.Handle; // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); startButton = new Button(new Rectangle((width/3)*2,550,400,75), "Start Spill", ref input, new List<Texture2D>() { contentHolder.menuStart, contentHolder.menuStartHover, contentHolder.menuStartClicked }); menuBackground = new Gameobject(contentHolder.menuBackground, Vector2.Zero, new Vector2(0, 0)); grandma = new Gameobject(contentHolder.grandma, Vector2.Zero, new Vector2(0, 0)); outroBackground = new Gameobject(contentHolder.texture_outro, Vector2.Zero, new Vector2(0, 0)); restartButton = new Button(new Rectangle(50, height - 125, 400, 75), "Start paa nytt", ref input, new List<Texture2D>() { contentHolder.menuRestart, contentHolder.menuRestartHover, contentHolder.menuStartClicked }); menuButton = new Button(new Rectangle(width - 450, height - 125, 400, 75), "Meny", ref input, new List<Texture2D>() { contentHolder.menuMenu, contentHolder.menuMenuHover, contentHolder.menuMenuClicked }); startButton.clicked += new Button.EventHandler(buttonClicked); restartButton.clicked += new Button.EventHandler(buttonClicked); menuButton.clicked += new Button.EventHandler(buttonClicked); controller.goToOutro += new Controller.EventHandler(outro); // TODO: use this.Content to load your game content here }
public void update(Gameworld gameWorld, GameTime gameTime) { risse = gameWorld.Risse; Vector2 prePos = risse.Position; parallaxBackground(gameWorld); physicsEngine.gravitation(risse, gameTime); collisionResolution(gameWorld, prePos); risse.update(gameTime); foreach (Gameobject go in gameWorld.Platforms) { go.update(); } //if (!(MediaPlayer.State == MediaState.Playing)) //{ // MediaPlayer.Play(contentHolder.soundtrack); //} //foreach (Gameobject ground in gameWorld.Ground) //{ // ground.update(); //} foreach (List<Gameobject> g in gameWorld.Ground) { foreach (Gameobject obj in g) { obj.update(); } } foreach (Gameobject obj in gameWorld.Collidables) { obj.update(); } //Console.Out.WriteLine(risse.Position); }
// returns true if colliding from side protected bool collisionDetermineType(Gameworld gameworld, Gameobject risse, Gameobject platform, Vector2 prePos) { if (risse.BoundingBox.Right - (risse.BoundingBox.Width/2) > platform.BoundingBox.Left && risse.BoundingBox.Right - (risse.BoundingBox.Width/2) < platform.BoundingBox.Right) { if (risse.Position.Y + risse.BoundingBox.Height < platform.BoundingBox.Y + platform.BoundingBox.Height){ collisionVertical(gameworld, new Vector2(risse.Position.X, platform.Position.Y - (risse.BoundingBox.Height - 1))); risse.OnTheGround = true; if (risse.Animation != (int)state.crash && risse.Animation != (int)state.ducking) { gameworld.Risse.Animation = (int)state.running; Console.Out.WriteLine("running"); } } else if (risse.Position.Y < platform.BoundingBox.Y + platform.BoundingBox.Height) { if (risse.OnTheGround) { gameworld.Risse.Animation = (int)state.ducking; Console.Out.WriteLine("ducking"); } else { collisionVertical(gameworld, new Vector2(risse.Position.X, platform.Position.Y + (platform.BoundingBox.Height + 1))); } } return false; } if (risse.OnTheGround && risse.Position.Y + risse.BoundingBox.Height < platform.BoundingBox.Y + platform.BoundingBox.Height) { collisionVertical(gameworld, new Vector2(risse.Position.X, platform.Position.Y - (risse.BoundingBox.Height - 1))); return false; } collisionHorizontal(gameworld, prePos); return true; }
public void update(Gameworld gameWorld, GameTime gameTime) { risse = gameWorld.Risse; parallaxBackground(gameWorld); physicsEngine.gravitation(risse, gameTime); collisionResolution(gameWorld, prePos); prePos = new Vector2(risse.BoundingBox.X, risse.BoundingBox.Y); risse.update(gameTime); //foreach (Gameobject go in gameWorld.Platforms) //{ // go.update(); //} gameWorld.updateCheckpointsDone(); if (theState == state.ducking) { if (ducking > 1000) { ducking = 0; theState = state.running; risse.Animation = (int)state.running; } ducking += (float)gameTime.ElapsedGameTime.Milliseconds; } if (theState == state.crash) { if (crashing > 1000) { crashing = 0; theState = state.running; risse.Animation = (int)state.running; } crashing += (float)gameTime.ElapsedGameTime.Milliseconds; } foreach (List<Gameobject> p in gameWorld.Platforms) { foreach (Gameobject obj in p) { obj.update(); } } if (!(MediaPlayer.State == MediaState.Playing)) { MediaPlayer.Play(contentHolder.music_soundtrack); } foreach (Gameobject go in gameWorld.BackgroundFluff) { go.updateFluff(risse, contentHolder); } gameWorld.Platforms[0][0].Position = new Vector2(gameWorld.BackgroundFluff[0].Position.X - gameWorld.Platforms[0][0].Texture.Width, gameWorld.Platforms[0][0].Position.Y); gameWorld.Platforms[0][1].Position = new Vector2(gameWorld.BackgroundFluff[0].Position.X + gameWorld.Platforms[0][1].SpriteWidth, gameWorld.Platforms[0][1].Position.Y); //foreach (Gameobject ground in gameWorld.Ground) //{ // ground.update(); //} foreach (List<Gameobject> g in gameWorld.Ground) { foreach (Gameobject obj in g) { obj.update(); } } foreach (Gameobject obj in gameWorld.Collidables) { obj.update(); } }
public void gravitation(Gameobject gameObject, GameTime gameTime) { float elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds;//0.01666667 (or 16.67 ms) @ 60FPS gameObject.Velocity += new Vector2(0, GRAVITYCONSTANT * elapsed * 4); gameObject.Position += gameObject.Velocity * elapsed; }