public Player(ContentManager Content, ParticleTools particleTools, GameUnit x, GameUnit y) : base(CollisionType.StickyCollision) { sprites = new Dictionary<SpriteState, Sprite>(); InitializeSprites(Content); this.particleTools = particleTools; kinematicsX = new Kinematics(x, 0); kinematicsY = new Kinematics(y, 0); accelerationX = 0; horizontalFacing = SpriteState.HorizontalFacing.Left; intendedVerticalFacing = SpriteState.VerticalFacing.Horizontal; walkingAnimation = new WalkingAnimation(); maybeGroundTile = null; jumpActive = false; playerHealth = new PlayerHealth(Content); interacting = false; invincibleTimer = new Timer(InvincibleTime); damageText = new FloatingNumber(Content, FloatingNumber.NumberType.Damage); experienceText = new FloatingNumber(Content, FloatingNumber.NumberType.Experience); gunExperienceHud = new GunExperienceHud(Content); polarStar = new PolarStar(Content); collisionRectangle = new CompositeCollisionRectangle(new Rectangle((int)Math.Round(CollisionTopLeft), (int)Math.Round(CollisionYTop), (int)Math.Round(CollisionTopWidth), (int)Math.Round(CollisionYHeight / 2)), new Rectangle((int)Math.Round(CollisionBottomLeft), (int)Math.Round(CollisionYTop + CollisionYHeight / 2), (int)Math.Round(CollisionBottomWidth), (int)Math.Round(CollisionYHeight / 2)), new Rectangle(6, 10, 10, 12), new Rectangle(16, 10, 10, 12)); }
public Rectangle LeftCollision(GameUnit x, GameUnit y, GameUnit delta) { return new Rectangle((int)Math.Round(x + left.Left + delta), (int)Math.Round(y + left.Top), (int)Math.Round(left.Width - delta), left.Height); }
public Rectangle RightCollision(GameUnit x, GameUnit y, GameUnit delta) { return new Rectangle((int)Math.Round(x + rectangle.Left), (int)Math.Round(y + rectangle.Top), (int)Math.Round(rectangle.Width + delta), rectangle.Height); }
public Rectangle BottomCollision(GameUnit x, GameUnit y, GameUnit delta) { return new Rectangle((int)Math.Round(x + bottom.Left), (int)Math.Round(y + bottom.Top), bottom.Width, (int)Math.Round(bottom.Height + delta)); }
public static ProjectileStarParticle Create(ContentManager Content, GameUnit x, GameUnit y) { return new ProjectileStarParticle(Content, SpriteName, Units.TileToPixel(SourceX), Units.TileToPixel(SourceY), Units.TileToPixel(SourceWidth), Units.TileToPixel(SourceHeight), Fps, NumFrames, x, y); }
public ProjectileStarParticle(ContentManager Content, string spriteName, PixelUnit sourceX, PixelUnit sourceY, PixelUnit sourceWidth, PixelUnit sourceHeight, int fps, FrameUnit numFrames, GameUnit x, GameUnit y) : base(Content, spriteName, sourceX, sourceY, sourceWidth, sourceHeight, fps, numFrames, x, y) { }
public static void CreateRandomDeathCloud(ParticleTools particleTools, GameUnit centerX, GameUnit centerY, int numParticles) { for (int i = 0; i < numParticles; i++) { particleTools.EntitySystem.AddNewParticle(new DeathCloudParticle(particleTools.Content, centerX, centerY, Game1.Random.Next(0, 3) * BaseVelocity, Game1.Random.Next(0, 360))); } }
public FloatingNumber(ContentManager Content, NumberType type) { this.Content = Content; shouldRise = true; timer = new Timer(DamageTime); this.type = type; offsetY = 0; val = 0; centerX = 0; centerY = 0; }
public PowerDoritoPickup(ContentManager Content, GameUnit centerX, GameUnit centerY, SizeType size) : base(CollisionType.BouncingCollision) { kinematicsX = new Kinematics(centerX - Units.HalfTile, (Game1.Random.Next(0, 11) - 5) * 0.025f); kinematicsY = new Kinematics(centerY - Units.HalfTile, (Game1.Random.Next(0, 11) - 5) * 0.025f); sprite = new AnimatedSprite(Content, SpriteName, Units.TileToPixel(SourceX), Units.TileToPixel(SourceYs[(int)size]), Units.TileToPixel(SourceWidth), Units.TileToPixel(SourceHeight), Fps, NumFrames); this.size = size; timer = new Timer(LifeTime, true); }
public FirstCaveBat(ContentManager Content, GameUnit x, GameUnit y) { sprites = new Dictionary<BatSpriteState, Sprite>(); this.x = x; this.y = y; flightCenterY = y; alive = true; flightAngle = 0.0f; facing = CaveStory.SpriteState.HorizontalFacing.Right; damageText = new FloatingNumber(Content, FloatingNumber.NumberType.Damage); InitializeSprites(Content); }
public ImmobileSingleLoopParticle(ContentManager Content, string spriteName, PixelUnit sourceX, PixelUnit sourceY, PixelUnit sourceWidth, PixelUnit sourceHeight, int fps, FrameUnit numFrames, GameUnit x, GameUnit y) { this.x = x; this.y = y; sprite = new AnimatedSprite(Content, spriteName, sourceX, sourceY, sourceWidth, sourceHeight, fps, numFrames); }
public DeathCloudParticle(ContentManager Content, GameUnit centerX, GameUnit centerY, VelocityUnit speed, DegreesUnit angle) { this.centerX = centerX - Units.HalfTile; this.centerY = centerY - Units.HalfTile; this.speed = speed; offset = new PolarVector(0, angle); sprite = new AnimatedSprite(Content, SpriteName, Units.TileToPixel(SourceX), Units.TileToPixel(SourceY), Units.TileToPixel(SourceWidth), Units.TileToPixel(SourceHeight), Fps, NumFrames); }
public HeadBumpParticle(ContentManager Content, GameUnit centerX, GameUnit centerY) { this.centerX = centerX; this.centerY = centerY; sprite = new Sprite(Content, "Caret", Units.GameToPixel(SourceX), Units.GameToPixel(SourceY), Units.GameToPixel(Width), Units.GameToPixel(Height)); timer = new Timer(LifeTime, true); particleA = new PolarVector(0, Game1.Random.Next(0, 360)); maxOffsetA = 4 + Game1.Random.Next(0, 16); particleB = new PolarVector(0, Game1.Random.Next(0, 360)); maxOffsetB = 4 + Game1.Random.Next(0, 16); }
public Rectangle Collision(TileInfo.SideType side, GameUnit x, GameUnit y, GameUnit delta) { if (side == TileInfo.SideType.LeftSide) { return LeftCollision(x, y, delta); } if (side == TileInfo.SideType.RightSide) { return RightCollision(x, y, delta); } if (side == TileInfo.SideType.TopSide) { return TopCollision(x, y, delta); } return BottomCollision(x, y, delta); }
private FlashingPickup(ContentManager Content, GameUnit centerX, GameUnit centerY, TileUnit sourceX, TileUnit sourceY, Rectangle rectangle, int value, Pickup.PickupType type) { sprite = new Sprite(Content, SpriteName, Units.TileToPixel(sourceX), Units.TileToPixel(sourceY), Units.TileToPixel(1), Units.TileToPixel(1)); flashSprite = new Sprite(Content, SpriteName, Units.TileToPixel(sourceX + 1), Units.TileToPixel(sourceY), Units.TileToPixel(1), Units.TileToPixel(1)); dissipatingSprite = new Sprite(Content, SpriteName, Units.TileToPixel(DissipatingSourceX), Units.TileToPixel(DissipatingSourceY), Units.TileToPixel(1), Units.TileToPixel(1)); x = centerX - Units.HalfTile; y = centerY - Units.HalfTile; timer = new Timer(LifeTime, true); flashPeriod = StartPeriod; this.rectangle = rectangle; this.value = value; this.type = type; }
public TestCollisionInfo(bool isColliding, GameUnit position) { this.isColliding = isColliding; this.position = position; }
/// <summary> /// Returns true if projectile is still alive /// </summary> /// <param name="gameTime"></param> /// <returns>True if projectile is still alive</returns> public bool Update(GameTime gameTime, Map map, ParticleTools particleTools) { offset += (float)gameTime.ElapsedGameTime.TotalMilliseconds * ProjectileSpeed; TileInfo.SideType direction = TileInfo.FromFacing(horizontalDirection, verticalDirection); Rectangle rectangle = CollisionRectangle; List<CollisionTile> collidingTiles = map.GetCollidingTiles(rectangle, direction); for (int i = 0; i < collidingTiles.Count; i++) { TileInfo.SideType side = TileInfo.OppositeSide(direction); GameUnit perpendicularPosition = TileInfo.Vertical(side) ? rectangle.Center.X : rectangle.Center.Y; GameUnit leadingPosition = rectangle.Side(direction); bool shouldTestSlopes = true; TestCollisionInfo testInfo = collidingTiles[i].TestCollision(side, perpendicularPosition, leadingPosition, shouldTestSlopes); if (testInfo.isColliding) { GameUnit collisionX; if (TileInfo.Vertical(side)) { collisionX = perpendicularPosition; } else { collisionX = testInfo.position; } GameUnit collisionY; if (TileInfo.Vertical(side)) { collisionY = testInfo.position; } else { collisionY = perpendicularPosition; } particleTools.FrontSystem.AddNewParticle(ProjectileWallParticle.Create(particleTools.Content, collisionX - Units.HalfTile, collisionY - Units.HalfTile)); return false; } } if (!alive) { return false; } else if (offset >= ProjectileMaxOffsets[gunLevel - 1]) { particleTools.FrontSystem.AddNewParticle(ProjectileStarParticle.Create(particleTools.Content, X, Y)); return false; } else { return true; } }
public Projectile(Sprite sprite, SpriteState.HorizontalFacing horizontalDirection, SpriteState.VerticalFacing verticalDirection, GameUnit x, GameUnit y, GunLevelUnit gunLevel, ParticleTools particleTools) { this.sprite = sprite; this.horizontalDirection = horizontalDirection; this.verticalDirection = verticalDirection; this.x = x; this.y = y; this.gunLevel = gunLevel; offset = 0; alive = true; particleTools.FrontSystem.AddNewParticle(ProjectileStarParticle.Create(particleTools.Content, x, y)); }
private GameUnit GunY(SpriteState.VerticalFacing verticalFacing, bool gunUp, GameUnit playerY) { GameUnit gunY = playerY; if (verticalFacing == SpriteState.VerticalFacing.Up) { gunY -= Units.HalfTile / 2; } else if (verticalFacing == SpriteState.VerticalFacing.Down) { gunY += Units.HalfTile / 2; } if (gunUp) { gunY -= 2; } return gunY; }
private GameUnit GunX(SpriteState.HorizontalFacing horizontalFacing, GameUnit playerX) { if (horizontalFacing == SpriteState.HorizontalFacing.Left) { return playerX - Units.HalfTile; } else { return playerX; } }
public bool Update(GameTime gameTime, GameUnit playerX) { flightAngle += AngularVelocity * (float)gameTime.ElapsedGameTime.TotalMilliseconds; facing = x + Units.HalfTile > playerX ? CaveStory.SpriteState.HorizontalFacing.Left : CaveStory.SpriteState.HorizontalFacing.Right; y = flightCenterY + FlightAmplitude * (float)Math.Sin(MathHelper.ToRadians(flightAngle)); sprites[SpriteState].Update(); return alive; }
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; }
public void Draw(SpriteBatch spriteBatch, GameUnit x, GameUnit y) { Rectangle destinationRect = new Rectangle(Units.GameToPixel(x), Units.GameToPixel(y), sourceRect.Width, sourceRect.Height); spriteBatch.Draw(tex, destinationRect, sourceRect, Color.White); }
public Kinematics(GameUnit position, VelocityUnit velocity) { this.position = position; this.velocity = velocity; }
public static PixelUnit GameToPixel(GameUnit game) { return Config.graphicsQuality == Config.GraphicsQuality.OriginalQuality ? new PixelUnit((int)Math.Round(game / 2.0f)) : new PixelUnit((int)Math.Round(game)); }
public static IPickup MultiHeartPickup(ContentManager Content, GameUnit centerX, GameUnit centerY) { return new FlashingPickup(Content, centerX, centerY, MultiHeartSourceX, MultiHeartSourceY, MultiHeartRectangle, MultiHeartValue, Pickup.PickupType.Health); }
public void SetPosition(GameUnit centerX, GameUnit centerY) { this.centerX = centerX; this.centerY = centerY; }
public void Draw(SpriteBatch spriteBatch, SpriteState.HorizontalFacing horizontalFacing, SpriteState.VerticalFacing verticalFacing, bool gunUp, GameUnit playerX, GameUnit playerY) { GameUnit x = GunX(horizontalFacing, playerX); GameUnit y = GunY(verticalFacing, gunUp, playerY); sprites[new PolarStarSpriteState(new Tuple<SpriteState.HorizontalFacing, SpriteState.VerticalFacing>( horizontalFacing, verticalFacing))].Draw(spriteBatch, x, y); if (projectileA != null) { projectileA.Draw(spriteBatch); } if (projectileB != null) { projectileB.Draw(spriteBatch); } }
public static TileUnit GameToTile(GameUnit game) { return new TileUnit((uint)(game / TileSize)); }
public void StartFire(GameUnit playerX, GameUnit playerY, SpriteState.HorizontalFacing horizontalFacing, SpriteState.VerticalFacing verticalFacing, bool gunUp, ParticleTools particleTools) { if (projectileA != null && projectileB != null) { return; } GameUnit bulletX = GunX(horizontalFacing, playerX) - Units.HalfTile; GameUnit bulletY = GunY(verticalFacing, gunUp, playerY) - Units.HalfTile; switch (verticalFacing) { case SpriteState.VerticalFacing.Horizontal: bulletY += NozzleHorizontalY; if (horizontalFacing == SpriteState.HorizontalFacing.Left) { bulletX += NozzleHorizontalLeftX; } else { bulletX += NozzleHorizontalRightX; } break; case SpriteState.VerticalFacing.Up: bulletY += NozzleUpY; if (horizontalFacing == SpriteState.HorizontalFacing.Left) { bulletX += NozzleUpLeftX; } else { bulletX += NozzleUpRightX; } break; case SpriteState.VerticalFacing.Down: bulletY += NozzleDownY; if (horizontalFacing == SpriteState.HorizontalFacing.Left) { bulletX += NozzleDownLeftX; } else { bulletX += NozzleDownRightX; } break; default: break; } if (projectileA == null) { projectileA = new Projectile(verticalFacing == SpriteState.VerticalFacing.Horizontal ? horizontalProjectiles[CurrentLevel - 1] : verticalProjectiles[CurrentLevel - 1], horizontalFacing, verticalFacing, bulletX, bulletY, CurrentLevel, particleTools); } else if (projectileB == null) { projectileB = new Projectile(verticalFacing == SpriteState.VerticalFacing.Horizontal ? horizontalProjectiles[CurrentLevel - 1] : verticalProjectiles[CurrentLevel - 1], horizontalFacing, verticalFacing, bulletX, bulletY, CurrentLevel, particleTools); } }
public CollisionInfo(GameUnit position, Tile2D tilePosition, BitArray tileType) { this.position = position; this.tilePosition = tilePosition; this.tileType = tileType; }
public static ProjectileStarParticle Create(ContentManager Content, GameUnit x, GameUnit y) { return(new ProjectileStarParticle(Content, SpriteName, Units.TileToPixel(SourceX), Units.TileToPixel(SourceY), Units.TileToPixel(SourceWidth), Units.TileToPixel(SourceHeight), Fps, NumFrames, x, y)); }