protected void handleYCollision() { if (vy > 0) { Box.Y = (Box.Y / Globals.TileHeight) * Globals.TileHeight + (Globals.TileHeight - Box.Height); } else { Box.Y = ((Box.Y / Globals.TileHeight) + 1) * Globals.TileHeight; } Box.Y = Globals.WrappedY(Box.Y); vy = 0; }
public List <Tile> Collide(Sprite sprite) { int top = Globals.WrappedY(sprite.Box.Top) / Globals.TileHeight; int bottom = Globals.WrappedY(sprite.Box.Bottom - 1) / Globals.TileHeight; int left = Globals.WrappedX(sprite.Box.Left) / Globals.TileWidth; int right = Globals.WrappedX(sprite.Box.Right - 1) / Globals.TileWidth; List <Tile> tilesToCheck = new List <Tile>(); for (int i = left; i != (right + 1) % Width; i = (i + 1) % Width) { for (int j = top; j != (bottom + 1) % Height; j = (j + 1) % Height) { if (Tiles[i, j] != null && Tiles[i, j].Solid) { tilesToCheck.Add(Tiles[i, j]); } } } return(tilesToCheck); }
protected void handleYCollision() { if (Math.Abs(vy) > 2) { SoundEffectInstance b = bounceSound.CreateInstance(); b.Volume = Math.Abs(vy) / maxV; b.Play(); } if (vy > 0) { Box.Y = (Box.Y / Globals.TileHeight) * Globals.TileHeight + (Globals.TileHeight - Box.Height); } else { Box.Y = ((Box.Y / Globals.TileHeight) + 1) * Globals.TileHeight; } Box.Y = Globals.WrappedY(Box.Y); vy = -vy * restitution; vx = vx * friction; //vx = vx * restitution; }
protected void moveY() { Box.Y = Globals.WrappedY(Box.Y + (int)vy); }
public override void Update(GameTime gameTime) { Box.Y = Globals.WrappedY(Box.Y + (int)vy); vy += gravity; if (vy > maxV) { vy = maxV; } if (Globals.Map.Collide(this).Any()) { if (vy > 0) { Box.Y = (Box.Y / Globals.TileHeight) * Globals.TileHeight + (Globals.TileHeight - Box.Height); jumping = false; } else { Box.Y = ((Box.Y / Globals.TileHeight) + 1) * Globals.TileHeight; } Box.Y = Globals.WrappedY(Box.Y); vy = 0; } foreach (Explosion e in Explosion.ExplosionList) { if (Collides(e)) { Dead = true; } } foreach (Powerup p in Powerup.PowerupList) { if (Collides(p)) { powerupSound.Play(); p.Effect(this); p.Dead = true; } } Globals.HandleTimer(ref bombCooldown, gameTime); KeyboardState kbs = Keyboard.GetState(); if (kbs.IsKeyDown(controls["right"])) { WalkRight(); } if (kbs.IsKeyDown(controls["left"])) { WalkLeft(); } if (kbs.IsKeyDown(controls["jump"])) { Jump(); } /* * if (kbs.IsKeyDown(Keys.Q)) * { * BombType = (BombTypes)(((int)BombType + 1) % Enum.GetValues(typeof(BombTypes)).GetLength(0)); * } */ if (kbs.IsKeyDown(controls["bomb"]) && bombCooldown == 0) { bombHold += gameTime.ElapsedGameTime.Milliseconds; if (bombHold > bombHoldMax) { bombHold = bombHoldMax; } } if (kbs.IsKeyUp(controls["bomb"]) && bombHold > 0) { throwSound.Play(); if (PushBombs() == 0) { Bomb b; float throwPower = ThrowModifier * (float)bombHold / (float)bombHoldMax; if (BombType == BombTypes.Bomb) { b = new Bomb(Box, ExplosionSize); b.Throw(throwPower, Direction); } else if (BombType == BombTypes.FloatingBomb) { b = new FloatingBomb(Box, ExplosionSize); b.Throw(throwPower, Direction); } else if (BombType == BombTypes.StickyBomb) { b = new StickyBomb(Box, ExplosionSize); b.Throw(throwPower, Direction); } } bombCooldown = 200; bombHold = 0; } }