public static AnimationSpec Create(string spriteSheetTextureName, int spriteSheetTextureWidth, int spriteSheetTextureHeight, int frameWidth, int frameHeight, int duration, bool isRepeating) { var spec = new AnimationSpec { SpriteSheet = spriteSheetTextureName, Duration = duration, Repeating = isRepeating }; int cols = spriteSheetTextureWidth / frameWidth; int rows = spriteSheetTextureHeight / frameHeight; spec.NumberOfFrames = cols * rows; spec.Frames = new RectangleF[spec.NumberOfFrames]; int x = 0; int y = 0; for (int i = 0; i < spec.NumberOfFrames; i++) { spec.Frames[i] = new RectangleF(x, y, frameWidth, frameHeight); x += frameWidth; if (x >= spriteSheetTextureWidth) { x = 0; y += frameHeight; } } return(spec); }
public Explosion(Texture2D texture, AnimationSpec animationSpec, Vector2 position, Vector2 size) { Texture = texture; Sprite = new AnimatedSprite(animationSpec); Scale = new Vector2(size.X / Sprite.FrameWidth, size.Y / Sprite.FrameHeight) * 4.0f; SourceOrigin = new Vector2(Sprite.FrameWidth * 0.5f, Sprite.FrameHeight * 0.5f); DestinationOrigin = new Vector2(Sprite.FrameWidth * 0.5f * Scale.X, Sprite.FrameHeight * 0.5f * Scale.Y); Position = position; Body.Velocity = Vector2.Zero; SetupBoundingBox(Sprite.FrameWidth, Sprite.FrameHeight); }
protected Enemy(Texture2D texture, Vector2 position, Vector2 velocity) { Texture = texture; AnimationSpec animationSpec = AssetsManager.Instance.GetAnimations(texture.Name); Sprite = new AnimatedSprite(animationSpec); Scale = new Vector2(RandomGenerator.Instance.GetRandomFloat(1.0f, 3.0f)); SourceOrigin = new Vector2(Sprite.FrameWidth * 0.5f, Sprite.FrameHeight * 0.5f); DestinationOrigin = new Vector2(Sprite.FrameWidth * 0.5f * Scale.X, Sprite.FrameHeight * 0.5f * Scale.Y); Position = position; Body.Velocity = velocity; SetupBoundingBox(Sprite.FrameWidth, Sprite.FrameHeight); }
public AnimationData(AnimationSpec spec) { Spec = spec; CurrentFrame = 0; if (spec == null) { FrameCooldownTime = 0.0f; } else { FrameCooldownTime = spec.Duration; } }
public Player(Texture2D texture, Vector2 position) { Texture = texture; AnimationSpec animationSpec = AssetsManager.Instance.GetAnimations(texture.Name); _sprite = new AnimatedSprite(animationSpec); Scale = new Vector2(1.5f, 1.5f); SourceOrigin = new Vector2(_sprite.FrameWidth * 0.5f, _sprite.FrameHeight * 0.5f); DestinationOrigin = new Vector2(_sprite.FrameWidth * 0.5f * Scale.X, _sprite.FrameHeight * 0.5f * Scale.Y); Position = position; Body.Velocity = Vector2.Zero; SetupBoundingBox(_sprite.FrameWidth, _sprite.FrameHeight); _timeElapsedSinceLastPlayerShot = PLAYER_LASER_COOLDOWN; }
public void KillPlayer() { int i = RandomGenerator.Instance.GetRandomInt(0, 1); SoundEffect sndExplode = AssetsManager.Instance.GetSound($"sndExplode{i}"); sndExplode.Play(); Texture2D texture = AssetsManager.Instance.GetTexture("Fireball02"); AnimationSpec animationSpec = AssetsManager.Instance.GetAnimations(texture.Name); var explosionPosition = new Vector2(Position.X, Position.Y); var playerSize = new Vector2(Body.BoundingBox.Width, Body.BoundingBox.Height); var explosion = new Explosion(texture, animationSpec, explosionPosition, playerSize); GameEntitiesManager.Instance.Explosions.Add(explosion); IsDead = true; }
private void KillEnemy(Enemy enemy) { int idx = RandomGenerator.Instance.GetRandomInt(0, 1); var sndExplode = AssetsManager.Instance.GetSound($"sndExplode{idx}"); sndExplode.Play(); Texture2D texture = AssetsManager.Instance.GetTexture("Explosion10"); AnimationSpec animationSpec = AssetsManager.Instance.GetAnimations("Explosion10"); var explosionPosition = new Vector2(enemy.Position.X, enemy.Position.Y); var enemySize = new Vector2(enemy.Body.BoundingBox.Width, enemy.Body.BoundingBox.Height); var explosion = new Explosion(texture, animationSpec, explosionPosition, enemySize); // { Scale = enemy.Scale }; GameEntitiesManager.Instance.Explosions.Add(explosion); GameEntitiesManager.Instance.Score += enemy.Score; _enemies.Remove(enemy); }
public void AddAnimation(string key, AnimationSpec spec) { _animations.Add(key, spec); }