public virtual void Update(GameTime gameTime) { if (alive) { texture.Update(gameTime, this); hitbox.Update(this); } }
public override void Update(GameTime gameTime) { float seconds = (float)gameTime.ElapsedGameTime.TotalSeconds; fuse += seconds; if (fuse > DYNAMITE_FUSE_LENGTH) { setTexture(explodingTexture); exploding = true; } if (velocity.LengthSquared() > 0) { velocity -= velocity * 0.95f * seconds; } float nextX = position.X + (velocity.X * seconds); float nextY = position.Y + (velocity.Y * seconds); if (!canMove(new Vector2(velocity.X * seconds, 0))) { nextX = position.X; } if (!canMove(new Vector2(0, velocity.Y * seconds))) { nextY = position.Y; } position = new Vector2(nextX, nextY); //blast collision foreach (Character c in Game1.characterManager.liveCharacters) { if (texture.getHitbox() != null && texture.getHitbox().intersects(c.hitbox)) { if (!alreadyHit.Contains(c)) { alreadyHit.Add(c); c.hitBy(this); } } } //stunhits cave boss allowing for damage foreach (Enemy e in Game1.levelManager.enemies) { if (e is DynaBoss) { if (texture.getHitbox() != null && texture.getHitbox().intersects(e.hitbox)) { if (!alreadyHit.Contains(e)) { alreadyHit.Add(e); ((DynaBoss)e).stunHit(hitDamage); } } } } fuseTexture.Update(gameTime, this); base.Update(gameTime); }
public void setTexture(AnimatedTexture tex) { if (texture != null) { foreach (Hitbox hitbox in texture.onFrameHitboxes) { if (hitbox != null) { hitbox.active = false; } } } texture = tex; texture.Update(null, this); if (texture.onStart != null) { texture.onStart(); } }
public override void Update(GameTime gameTime) { if (!alive) { return; } float seconds = (float)gameTime.ElapsedGameTime.TotalSeconds; velocity += acceleration * seconds; position += velocity * seconds; if (fallSpeed > FALL_SPEED_MINIMUM) { fallSpeed -= fallSpeed * FALL_SPEED_DECAY_PER_SECOND * seconds; } if (height > 0f) { height -= fallSpeed * seconds; } else { height = 0f; } if (Math.Abs(velocity.X) < 0.001f && Math.Abs(velocity.Y) < 0.001f) { acceleration = Vector2.Zero; velocity = Vector2.Zero; } if (exploding) { explosion.Update(gameTime, this); hitbox.active = true; explosionTime += seconds; float timeRatio = explosionTime / BalloonBomb.EXPLOSION_TIME; radius = BalloonBomb.EXPLOSION_RADIUS * timeRatio; if (explosionTime > BalloonBomb.EXPLOSION_TIME) { hitbox.active = false; alive = false; } else { foreach (Enemy e in Game1.levelManager.enemies) { if (hitbox.intersects(e.hitbox) && !e.hitboxesHitBy.Contains(hitbox)) { e.hitboxesHitBy.Add(hitbox); e.hitBy(parent, damage, position, knockbackStrength, knockbackDuration); } } } } else { fuse += seconds; if (fuse > BalloonBomb.FUSE_SECONDS && height == 0f) { exploding = true; } } hitbox.width = hitbox.height = (int)rad - getTexture().Width / 2; alpha = 1 - (rad - getTexture().Width) / EXPLOSION_RADIUS; scale = (rad / getTexture().Width); base.Update(gameTime); }
public void setTexture(AnimatedTexture tex) { if (texture != null) foreach (Hitbox hitbox in texture.onFrameHitboxes) if (hitbox != null) { hitbox.active = false; } texture = tex; texture.Update(null, this); if (texture.onStart != null) texture.onStart(); }