public void Draw(SpriteBatch spriteBatch, GunLevelUnit gunLevel, GunExperienceUnit currentExperience, GunExperienceUnit levelExpereince) { levelSprite.Draw(spriteBatch, Units.TileToGame(LevelDrawX), DrawY); number.number = Convert.ToInt32(gunLevel); number.LoadNumber(); number.Draw(spriteBatch, LevelNumberDrawX, DrawY); experienceBarSprite.Draw(spriteBatch, ExperienceBarDrawX, DrawY); if (currentExperience < levelExpereince) { fillSprite.SetPercentageWidth((float)currentExperience / (float)levelExpereince); fillSprite.Draw(spriteBatch, ExperienceBarDrawX, DrawY); } else { maxSprite.Draw(spriteBatch, ExperienceBarDrawX, DrawY); } if (flashTimer.Active && flashTimer.CurrentTime.Ticks / FlashPeriod.Ticks % 2 == 0) { flashSprite.Draw(spriteBatch, ExperienceBarDrawX, DrawY); } }
public bool Update(GameTime gameTime) { if (timer.Expired) { val = 0; } else if (shouldRise) { offsetY = (float)Math.Max(-Units.TileToGame(1), offsetY + Velocity * gameTime.ElapsedGameTime.TotalMilliseconds); } return(!timer.Expired); }
/// <summary> /// /// </summary> /// <param name="side">The side of the tile that is being collided with</param> /// <param name="perpendicularPosition">The position on the tile on the opposite axis of side</param> /// <param name="leadingPosition">Position of the leading edge of the colliding entity</param> /// <param name="shouldTestSlopes">whether slopes should be considered for collision</param> /// <returns> /// isColliding is true if there was a collision /// Returns the position of the collision on the same axis of side /// </returns> public TestCollisionInfo TestCollision(TileInfo.SideType side, GameUnit perpendicularPosition, GameUnit leadingPosition, bool shouldTestSlopes) { TestCollisionInfo info = new TestCollisionInfo(false, leadingPosition); if (tileType[(int)TileInfo.TileFlag.Wall]) { info.isColliding = true; if (side == TileInfo.SideType.TopSide) { info.position = Units.TileToGame(row); } else if (side == TileInfo.SideType.BottomSide) { info.position = Units.TileToGame(row + 1); } else if (side == TileInfo.SideType.LeftSide) { info.position = Units.TileToGame(col); } else { info.position = Units.TileToGame(col + 1); } } else if (shouldTestSlopes && tileType[(int)TileInfo.TileFlag.Slope] && !tileType[(int)TileInfo.SlopeFlagFromSide(side)]) { GameUnit row = Units.TileToGame(this.row); GameUnit col = Units.TileToGame(this.col); float slope = GetSlope(tileType); GameUnit offset = GetOffset(tileType); GameUnit calculatedPosition = TileInfo.Vertical(side) ? slope * (perpendicularPosition - col) + offset + row : (perpendicularPosition - row - offset) / slope + col; bool isColliding = TileInfo.IsMax(side) ? leadingPosition <= calculatedPosition : leadingPosition >= calculatedPosition; info.isColliding = isColliding; info.position = calculatedPosition; } return(info); }
protected override void LoadContent() { spriteBatch = new SpriteBatch(graphics.GraphicsDevice); frontParticleSystem = new ParticleSystem(); entityParticleSystem = new ParticleSystem(); particleTools = new ParticleTools(frontParticleSystem, entityParticleSystem, Content); player = new Player(Content, particleTools, Units.TileToGame(ScreenWidth / 2), Units.TileToGame(ScreenHeight / 2)); damageTexts.AddDamageable(player); bat = new FirstCaveBat(Content, Units.TileToGame(7), Units.TileToGame(ScreenHeight / 2 + 1)); damageTexts.AddDamageable(bat); map = Map.CreateSlopeTestMap(Content); pickups.Add(new PowerDoritoPickup(Content, bat.CenterX, bat.CenterY, PowerDoritoPickup.SizeType.Medium)); pickups.Add(new PowerDoritoPickup(Content, bat.CenterX, bat.CenterY, PowerDoritoPickup.SizeType.Medium)); pickups.Add(new PowerDoritoPickup(Content, bat.CenterX, bat.CenterY, PowerDoritoPickup.SizeType.Medium)); base.LoadContent(); }
public GameUnit GetOffset(BitArray tileType) { BitArray leftTopTall = TileInfo.CreateTileType(); leftTopTall.Set((int)TileInfo.TileFlag.LeftSlope, true); leftTopTall.Set((int)TileInfo.TileFlag.TopSlope, true); leftTopTall.Set((int)TileInfo.TileFlag.TallSlope, true); BitArray rightBottomShort = TileInfo.CreateTileType(); rightBottomShort.Set((int)TileInfo.TileFlag.RightSlope, true); rightBottomShort.Set((int)TileInfo.TileFlag.BottomSlope, true); rightBottomShort.Set((int)TileInfo.TileFlag.ShortSlope, true); if ((leftTopTall.And(tileType).IsEqual(leftTopTall)) || (rightBottomShort.And(tileType).IsEqual(rightBottomShort))) { return(Units.TileToGame(1)); } BitArray leftBottomTall = TileInfo.CreateTileType(); leftBottomTall.Set((int)TileInfo.TileFlag.LeftSlope, true); leftBottomTall.Set((int)TileInfo.TileFlag.BottomSlope, true); leftBottomTall.Set((int)TileInfo.TileFlag.TallSlope, true); BitArray rightTopShort = TileInfo.CreateTileType(); rightTopShort.Set((int)TileInfo.TileFlag.RightSlope, true); rightTopShort.Set((int)TileInfo.TileFlag.TopSlope, true); rightTopShort.Set((int)TileInfo.TileFlag.ShortSlope, true); if (leftBottomTall.And(tileType).IsEqual(leftBottomTall) || rightTopShort.And(tileType).IsEqual(rightTopShort)) { return(0.0f); } return(Units.HalfTile); }
public void DrawBackground(SpriteBatch spriteBatch) { backdrop.Draw(spriteBatch); for (TileUnit row = 0; row < backgroundTiles.Count; row++) { for (TileUnit col = 0; col < backgroundTiles[Convert.ToInt32(row)].Count; col++) { if (backgroundTiles[Convert.ToInt32(row)][Convert.ToInt32(col)] != null) { backgroundTiles[Convert.ToInt32(row)][Convert.ToInt32(col)].Draw(spriteBatch, Units.TileToGame(col), Units.TileToGame(row)); } } } }
public void Draw(SpriteBatch spriteBatch) { for (TileUnit row = 0; row < tiles.Count; row++) { for (TileUnit col = 0; col < tiles[Convert.ToInt32(row)].Count; col++) { if (tiles[Convert.ToInt32(row)][Convert.ToInt32(col)].sprite != null) { tiles[Convert.ToInt32(row)][Convert.ToInt32(col)].sprite.Draw(spriteBatch, Units.TileToGame(col), Units.TileToGame(row)); } } } }
public Vector2 ToGameUnit2D() { return(new Vector2(Units.TileToGame((uint)value.X), Units.TileToGame((uint)value.Y))); }