little wobble animation for placement!

This commit is contained in:
Ellpeck 2020-06-16 17:52:29 +02:00
parent 71930cbebb
commit 87006f0b1c
3 changed files with 22 additions and 2 deletions

View file

@ -25,6 +25,7 @@ namespace TouchyTickets.Attractions {
public readonly AttractionType Type; public readonly AttractionType Type;
[DataMember] [DataMember]
private float ticketPercentage; private float ticketPercentage;
private float animationSizeModifier;
public Attraction(AttractionType type) { public Attraction(AttractionType type) {
this.Type = type; this.Type = type;
@ -39,10 +40,23 @@ namespace TouchyTickets.Attractions {
GameImpl.Instance.Tickets += total; GameImpl.Instance.Tickets += total;
this.ticketPercentage -= total; this.ticketPercentage -= total;
} }
// animation stuff
if (this.animationSizeModifier > 0)
this.animationSizeModifier = Math.Max(this.animationSizeModifier - 0.2F, 0);
// return the generation rate per second // return the generation rate per second
return genRate; return genRate;
} }
public void Draw(SpriteBatch batch, Vector2 position, float alpha, float scale) {
var drawScale = scale;
if (this.animationSizeModifier > 0)
drawScale += (float) Math.Sin(this.animationSizeModifier) * 0.05F;
var center = this.Type.TextureRegion.Size.ToVector2() / 2;
batch.Draw(this.Type.TextureRegion, position + center * scale, Color.White * alpha, 0, center, drawScale, SpriteEffects.None, 0);
}
public float GetGenerationRate(ParkMap map, Point position) { public float GetGenerationRate(ParkMap map, Point position) {
var genRate = this.Type.GetGenerationRate(); var genRate = this.Type.GetGenerationRate();
@ -84,6 +98,10 @@ namespace TouchyTickets.Attractions {
return (long) Math.Ceiling(modifier.InitialPrice * Math.Pow(1 + 0.4F, amount)); return (long) Math.Ceiling(modifier.InitialPrice * Math.Pow(1 + 0.4F, amount));
} }
public void Wobble() {
this.animationSizeModifier = MathHelper.Pi;
}
private IEnumerable<Attraction> GetSurrounding(ParkMap map, Point position, AttractionType type) { private IEnumerable<Attraction> GetSurrounding(ParkMap map, Point position, AttractionType type) {
foreach (var tile in this.Type.GetCoveredTiles()) { foreach (var tile in this.Type.GetCoveredTiles()) {
foreach (var dir in Direction2Helper.Adjacent) { foreach (var dir in Direction2Helper.Adjacent) {

View file

@ -158,7 +158,7 @@ namespace TouchyTickets {
foreach (var offset in attraction.Type.GetCoveredTiles()) foreach (var offset in attraction.Type.GetCoveredTiles())
batch.Draw(batch.GetBlankTexture(), new RectangleF(position + (pos + offset).ToVector2() * tileSize, tileSize), color * 0.25F * alpha); batch.Draw(batch.GetBlankTexture(), new RectangleF(position + (pos + offset).ToVector2() * tileSize, tileSize), color * 0.25F * alpha);
} }
batch.Draw(attraction.Type.TextureRegion, position + pos.ToVector2() * tileSize, Color.White * alpha, 0, Vector2.Zero, scale, SpriteEffects.None, 0); attraction.Draw(batch, position + pos.ToVector2() * tileSize, alpha, scale);
} }
// placing attraction // placing attraction
if (this.PlacingAttraction != null) { if (this.PlacingAttraction != null) {
@ -166,7 +166,7 @@ namespace TouchyTickets {
var color = this.CanPlace(this.PlacingPosition, this.PlacingAttraction) ? Color.Yellow : Color.Red; var color = this.CanPlace(this.PlacingPosition, this.PlacingAttraction) ? Color.Yellow : Color.Red;
foreach (var pos in this.PlacingAttraction.Type.GetCoveredTiles()) foreach (var pos in this.PlacingAttraction.Type.GetCoveredTiles())
batch.Draw(batch.GetBlankTexture(), new RectangleF(placingPos + pos.ToVector2() * tileSize, tileSize), color * 0.25F * alpha); batch.Draw(batch.GetBlankTexture(), new RectangleF(placingPos + pos.ToVector2() * tileSize, tileSize), color * 0.25F * alpha);
batch.Draw(this.PlacingAttraction.Type.TextureRegion, placingPos, Color.White * alpha * 0.5F, 0, Vector2.Zero, scale, SpriteEffects.None, 0); this.PlacingAttraction.Draw(batch, placingPos, alpha * 0.5F, scale);
} }
} }

View file

@ -166,6 +166,7 @@ namespace TouchyTickets {
GameImpl.Instance.Platform.AddResourceEvent(true, "Tickets", price, "Attraction", attraction.Key); GameImpl.Instance.Platform.AddResourceEvent(true, "Tickets", price, "Attraction", attraction.Key);
map.Place(map.PlacingPosition, map.PlacingAttraction); map.Place(map.PlacingPosition, map.PlacingAttraction);
map.PlacingAttraction.Wobble();
this.FadeUi(false, () => this.uiSystem.Remove(e2.Root.Name)); this.FadeUi(false, () => this.uiSystem.Remove(e2.Root.Name));
}, },
OnUpdated = (e2, time) => ((Button) e2).IsDisabled = !map.CanPlace(map.PlacingPosition, map.PlacingAttraction) OnUpdated = (e2, time) => ((Button) e2).IsDisabled = !map.CanPlace(map.PlacingPosition, map.PlacingAttraction)
@ -233,6 +234,7 @@ namespace TouchyTickets {
GameImpl.Instance.Platform.AddResourceEvent(true, "Tickets", price, "Modifier", modifier.Name); GameImpl.Instance.Platform.AddResourceEvent(true, "Tickets", price, "Modifier", modifier.Name);
attraction.ApplyModifier(map.PlacingModifier); attraction.ApplyModifier(map.PlacingModifier);
attraction.Wobble();
}, },
OnUpdated = (e2, time) => { OnUpdated = (e2, time) => {
var disabled = map.SelectedPosition == null; var disabled = map.SelectedPosition == null;