public override void Update(GameTime gameTime, Map map) { velocity.Y += gravity; if (velocity.X == 0) { edible = true; } Move(map, owner.movers, velocity.X, velocity.Y); }
protected void Move(Map map, List<Collideable> cols, float x, float y) { List<Collideable> allCols = new List<Collideable>(); if (y != 0) { pos.Y += (y / MainGame.fps); rect.Y = (int)pos.Y; allCols.AddRange(map.ClosestTo(pos)); allCols.AddRange(cols); CheckColl(allCols, 0, y); } if (x != 0) { pos.X += (x / MainGame.fps); rect.X = (int)pos.X; allCols.Clear(); allCols.AddRange(map.ClosestTo(pos)); allCols.AddRange(cols); CheckColl(allCols, x, 0); } }
public virtual void Update(GameTime gameTime, Map map) { }
/*public void Update(GameTime gameTime, Map map) { List<Collideable> remove = new List<Collideable>(); foreach (Collideable c in movers) { c.Update(gameTime, cols); if (!c.Alive) { remove.Add(c); } } foreach (Collideable c in remove) { movers.Remove(c); } }*/ public void Update(GameTime gameTime, Map map) { remove.Clear(); foreach (Collideable c in toAddMovers) { movers.Add(c); } toAddMovers.Clear(); foreach (Collideable c in movers) { c.Update(gameTime, map); if (!c.Alive) { remove.Add(c); } } foreach (Collideable c in remove) { movers.Remove(c); } }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { Map.SetTileMapper(); spriteBatch = new SpriteBatch(GraphicsDevice); font = Content.Load<SpriteFont>("tempFont"); Texture2D dude = Content.Load<Texture2D>("PlayerSheet"); Texture2D wall = Content.Load<Texture2D>("WallSheet"); Texture2D rockWall = Content.Load<Texture2D>("RockWallSheet"); Player.attackImage = Content.Load<Texture2D>("AttackSheet"); heart = Content.Load<Texture2D>("HeartSheet"); bGround = Content.Load<Texture2D>("Background"); strip = Content.Load<Texture2D>("Strip"); string[] data = { "wwwwwwwwwwwwwwwwwwwwwwww", "w w", "w w", "w w", "w w", "w w", "w w", "w w", "w w", "w w", "w w", "w w w", "w w", "wwwwwwwwwwwwwwwwwwwwwwww" }; map = new Map(0, 0, data[0].Length, data.Length); graphics.PreferredBackBufferWidth = data[0].Length * 32; graphics.PreferredBackBufferHeight = data.Length * 32 + 32; graphics.ApplyChanges(); map.player = dude; map.wall = wall; map.rockWall = rockWall; map.SetMap(data, cols); player1 = new Player(dude, new Vector2(32 * 3, 32 * 11), 32, 32); Dictionary<string, Keys> controls = new Dictionary<string, Keys>(); controls.Add("left", Keys.A); controls.Add("right", Keys.D); controls.Add("jump", Keys.W); controls.Add("eat", Keys.F); controls.Add("attack", Keys.E); player1.AddControls(controls); player1.SetColour(new Color(170, 170, 255)); player2 = new Player(dude, new Vector2(32 * 20, 32 * 11), 32, 32); controls = new Dictionary<string, Keys>(); controls.Add("left", Keys.J); controls.Add("right", Keys.L); controls.Add("jump", Keys.I); controls.Add("eat", Keys.H); controls.Add("attack", Keys.U); player2.AddControls(controls); player2.SetColour(new Color(255, 170, 170)); cols.Add(player1, true); cols.Add(player2, true); cols.Add(new MovingPlatform(wall, new Vector2(32 * 10, 32 * 12), 5 * 32, 32), true); //cols.Add(new Player(dude, new Vector2(50, 200), 32, 32), true); //cols.Add(new Wall(wall, new Vector2(50, 250), 32, 32), false); //cols.Add(new RockWall(rockWall, new Vector2(70, 228), 32, 32), false); }
public override void Update(GameTime gameTime, Map map) { velocity.Y += gravity; if (velocity.Y > terminalVelocity) { velocity.Y = terminalVelocity; } if (realEating) { if (spriteSheet.CurrentAnim != "eat") { spriteSheet.SetAnim("eat", 0.7f, flipped); } if (spriteSheet.flipped != flipped) { spriteSheet.SetAnim("eat", 0.7f, flipped); } } else if (velocity.Y > 5*gravity || velocity.Y < 0) { if (spriteSheet.CurrentAnim != "fall") { spriteSheet.SetAnim("fall", 0.3f, flipped); } if (spriteSheet.flipped != flipped) { spriteSheet.SetAnim("fall", 0.3f, flipped); } } else if (velocity.X != 0) { if (spriteSheet.CurrentAnim != "walking") { spriteSheet.SetAnim("walking", 0.9f, flipped); } if (spriteSheet.flipped != flipped) { spriteSheet.SetAnim("walking", 0.9f, flipped); } } else { if (spriteSheet.CurrentAnim != "idle") { spriteSheet.SetAnim("idle", 0.6f, flipped); } if (spriteSheet.flipped != flipped) { spriteSheet.SetAnim("idle", 0.6f, flipped); } } if (shot) { shotTime += (float)gameTime.ElapsedGameTime.TotalSeconds; if (shotTime >= shotCooldown) { shot = false; } } if (attacking) { attacking = false; if (!shot) { if (owner != null && points > 0) { Vector2 attkDirection = new Vector2(200, -200); if (flipped) { attkDirection.X *= -1; } attkDirection.X += velocity.X; owner.Add(new Attack(attackImage, attkDirection, this, tint, new Vector2(rect.Center.X - 8, rect.Center.Y - 8), 16, 16), true); points--; shot = true; shotTime = 0.0f; } } } if (isHit) { lasthit -= (float)gameTime.ElapsedGameTime.TotalSeconds; if (lasthit <= 0) { lasthit = 0; isHit = false; } } if (MainGame.fps != 0) { jumpPossible = false; Move(map, owner.movers ,velocity.X, velocity.Y); } }