From c7f24462823fec2ddd460f8c486d0eff5eb988c9 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Mon, 1 Jun 2020 16:18:07 +0200 Subject: [PATCH] fences and trees --- ThemeParkClicker/Content/Content.mgcb | 5 ++ .../Content/Textures/Tiles.aseprite | Bin 0 -> 1073 bytes ThemeParkClicker/Content/Textures/Tiles.png | Bin 0 -> 1163 bytes ThemeParkClicker/GameImpl.cs | 30 ++-------- ThemeParkClicker/ParkMap.cs | 52 +++++++++++++++++- ThemeParkClicker/Ui.cs | 6 +- 6 files changed, 62 insertions(+), 31 deletions(-) create mode 100644 ThemeParkClicker/Content/Textures/Tiles.aseprite create mode 100644 ThemeParkClicker/Content/Textures/Tiles.png diff --git a/ThemeParkClicker/Content/Content.mgcb b/ThemeParkClicker/Content/Content.mgcb index d6d7b88..774eb6a 100644 --- a/ThemeParkClicker/Content/Content.mgcb +++ b/ThemeParkClicker/Content/Content.mgcb @@ -35,3 +35,8 @@ /processor:TextureProcessor /build:Textures/Attractions.png +#begin Textures/Tiles.png +/importer:TextureImporter +/processor:TextureProcessor +/build:Textures/Tiles.png + diff --git a/ThemeParkClicker/Content/Textures/Tiles.aseprite b/ThemeParkClicker/Content/Textures/Tiles.aseprite new file mode 100644 index 0000000000000000000000000000000000000000..d998752ab8387aa6f60da5b71c940567eb0a985d GIT binary patch literal 1073 zcmcJL|5wX<9LL|$bdKZO;T&I%=yRNo6F;nPtYqrUPKT9+l~Q3U*{N=2i*7U=N)v~i zTASK%?>VO1xs}3B5(}M7$ef#+;#gZ_-_XPde ztH6+uy`ay|qhNf78B9{qps=kEeE8e}(kMby)%9ThAsLvGnhM573&8BPC%`H{Kd>t% z2{h*30E?7i;E7BhIu#4Jj{iG_21{TA=))c2u!b^xAq!Jz!V!Y7gBrXb1taK;yU;W& zpn!aYBN?&CL?F@-#w}So%nz88 zZL$j^%mE>nz|>pa~G`4Mz? zShCfWw)1w~nP;2IEhbB@`GBi2{)2nfsgYCRe|Yhn+Zz=*6_V@$t#DyWqL#g-gE=U3 zuh}s})tlbI^;BQb?a(KP*?0Y~8N_A>hbdIn%hyH3)=fF~UM;MUM?NYT(&sQmQbDk0 zS4+^|*O$f)X`Sv*n{VCI@$H#vTjJ;LrmSUIc`FB^1M?gWYumX}ezmc9=0|_)pU>hH z&Y+8x_PD{WfX?CuPLknVl31aUnBG=uxigxH7#pA*&kc0w?>Me zT(}x;SN0hNQb%;b+;`&9sG5F57taxCOIsGqj%i+U{mJR>*Ai`cnZVY5Po^m>8r!qD zRF*dHx$;U_b?K0@Pt+2$QfCNSQPLy5Z`E7+&TrHVr}XL**Y`HEqGl8yWSZ2rO3#pV s>GA@((A%~zojxC>>d@6bUSoRoX@IA&rBBCXG^Dk2tli1@M-giN3gHH?T>t<8 literal 0 HcmV?d00001 diff --git a/ThemeParkClicker/Content/Textures/Tiles.png b/ThemeParkClicker/Content/Textures/Tiles.png new file mode 100644 index 0000000000000000000000000000000000000000..1878967018629e6ba03de567f50c15a8c1271384 GIT binary patch literal 1163 zcmeAS@N?(olHy`uVBq!ia0y~yU<5K5893O0R7}x|G!U;i$lZxy-8q?;3=Ax;o-U3d z6?5L+-k&WUF2nF)eb0&YjusP2KG+NJ&ool;_A*L6v1s8;lO-2!2LBWAooAi$;hJLf z%O?)YMVOY#-dVdeL4$XR%-WEfjjvUrH~GK!vy093oPS>J-tT+W?BDC|e4iT?|E6}T z`=N^u71rh6?Rt3J@y?#w*D*iM_pXm#S@Gc2EsfO^r2dG1EJ?Svd}t!eKSygWgVLgc z5Aw2n%j)d!-aIG2=Z+WOx#iZkE2pJ?{*u4&n0XUNLQ zM*cNZIXSQ0b#poL;qihsaSKoG@LOJN6;o$Hv~TaTPI^~`CyaI z?4R@Y?XSM@>&*kVH}BKR?NPaCY_HYtN?7KR!FW zx>eZaW>>73eBrNIA2O%-`!XG<Ll^Gvuq*N4G8e|r6g;%_hBui3o% zvrXjxRh2DT_x9W6+^r}VDHZD5z_%=pQS9s1`#1JP{@=Bnq^0!Q4;F@)*xr3i4B^p>SAU<}{{7SL za zbnO5C(>!wJ8k^J_o-lK}tL-6?cfTnsu^qnHdRzYZ;m|8`JnkRA-PLcseOaCV{nON^ zXUpDS*`8l-bG`ll=KAS(?MxDt7yam|`XsY^%^r`-&tH80_I}aZ^I40tey_ADcp1c> zw*9{Myu|6YSA6F$4u2Vc_gipoNap@Ed~3FxwsSA%WZ z_sLQ5pRxy1j~rf={YUh{ySZnho this.tickets; - set { - var diff = value - this.tickets; - if (diff > 0) - this.ticketsPerSecondCounter += (long) diff; - this.tickets = value; - } - } + public BigInteger Tickets; public ParkMap Map; public Camera Camera { get; private set; } public Ui Ui { get; private set; } public bool DrawMap; public DateTime LastUpdate; - public float TicketsPerSecond { get; private set; } - private long ticketsPerSecondCounter; - private double secondCounter; private double saveCounter; public GameImpl() { @@ -38,6 +26,10 @@ namespace ThemeParkClicker { protected override void LoadContent() { base.LoadContent(); + + if (!SaveHandler.Load(this)) + this.Map = new ParkMap(10, 10); + this.Ui = new Ui(this.UiSystem); this.Camera = new Camera(this.GraphicsDevice) { Scale = 5, @@ -46,9 +38,6 @@ namespace ThemeParkClicker { MaxScale = 24, MinScale = 3 }; - - if (!SaveHandler.Load(this)) - this.Map = new ParkMap(10, 10); } protected override void DoUpdate(GameTime gameTime) { @@ -66,15 +55,6 @@ namespace ThemeParkClicker { this.Ui.Update(gameTime); - // we average tickets per second over 4 seconds - const float avgTime = 4; - this.secondCounter += gameTime.ElapsedGameTime.TotalSeconds; - if (this.secondCounter >= avgTime) { - this.secondCounter -= avgTime; - this.TicketsPerSecond = this.ticketsPerSecondCounter / avgTime; - this.ticketsPerSecondCounter = 0; - } - // save every 3 seconds this.saveCounter += gameTime.ElapsedGameTime.TotalSeconds; if (this.saveCounter >= 3) { diff --git a/ThemeParkClicker/ParkMap.cs b/ThemeParkClicker/ParkMap.cs index 1649417..4d34bf1 100644 --- a/ThemeParkClicker/ParkMap.cs +++ b/ThemeParkClicker/ParkMap.cs @@ -15,13 +15,18 @@ namespace ThemeParkClicker { [DataContract] public class ParkMap { + private static readonly UniformTextureAtlas TilesTexture = new UniformTextureAtlas(MlemGame.LoadContent("Textures/Tiles"), 16, 16); + private const int AdditionalRadius = 10; [DataMember] public readonly int Width; [DataMember] public readonly int Height; [DataMember] private readonly List<(Point, Attraction)> attractions = new List<(Point, Attraction)>(); + private readonly Dictionary treePositions = new Dictionary(); + private readonly Dictionary fencePositions = new Dictionary(); + public float TicketsPerSecond { get; private set; } public Attraction PlacingAttraction; public Point PlacingPosition; private bool draggingAttraction; @@ -29,11 +34,39 @@ namespace ThemeParkClicker { public ParkMap(int width, int height) { this.Width = width; this.Height = height; + + // set up trees + var random = new Random(); + for (var i = 0; i < 100; i++) { + var type = random.Next(3); + var x = random.Next(-AdditionalRadius, this.Width + AdditionalRadius); + var y = random.Next(-AdditionalRadius, this.Height + AdditionalRadius); + if (x < 0 || y < 0 || x >= this.Width || y >= this.Width) + this.treePositions[new Point(x, y)] = type; + } + + // set up fences + this.fencePositions[new Point(-1, -1)] = 2; + this.fencePositions[new Point(this.Width, -1)] = 3; + this.fencePositions[new Point(-1, this.Height)] = 4; + this.fencePositions[new Point(this.Width, this.Height)] = 5; + for (var x = 0; x < this.Width; x++) { + this.fencePositions[new Point(x, -1)] = 0; + this.fencePositions[new Point(x, this.Height)] = 0; + } + for (var y = 0; y < this.Height; y++) { + this.fencePositions[new Point(-1, y)] = 1; + this.fencePositions[new Point(this.Width, y)] = 1; + } } public void Update(GameTime time, TimeSpan passed) { - foreach (var (_, attraction) in this.attractions) + var tickets = 0F; + foreach (var (_, attraction) in this.attractions) { attraction.Update(time, passed); + tickets += attraction.Type.GenerationPerSecond; + } + this.TicketsPerSecond = tickets; // map movement if (GameImpl.Instance.DrawMap) { @@ -68,13 +101,26 @@ namespace ThemeParkClicker { .Any(p => this.PlacingPosition + p == offset); } } + camera.ConstrainWorldBounds(new Vector2(-AdditionalRadius) * Attraction.TileSize, new Vector2(this.Width + AdditionalRadius, this.Height + AdditionalRadius) * Attraction.TileSize); } } - public void Draw(GameTime time, SpriteBatch batch, Vector2 position, float scale, float alpha) { + public void Draw(GameTime time, SpriteBatch batch, Vector2 position, float scale, float alpha, int additionalRadius = AdditionalRadius) { var tileSize = Attraction.TileSize * scale; // draw ground - batch.Draw(batch.GetBlankTexture(), new RectangleF(position, new Vector2(this.Width, this.Height) * tileSize), ColorExtensions.FromHex(0xff53a662) * alpha); + for (var x = -additionalRadius; x < this.Width + additionalRadius; x++) { + for (var y = -additionalRadius; y < this.Height + additionalRadius; y++) { + var pos = new Vector2(x, y); + var drawPos = position + pos * tileSize; + batch.Draw(TilesTexture[0, 0], drawPos, Color.White * alpha, 0, Vector2.Zero, scale, SpriteEffects.None, 0); + + if (this.fencePositions.TryGetValue(pos.ToPoint(), out var fenceType)) { + batch.Draw(TilesTexture[fenceType, 1], drawPos, Color.White * alpha, 0, Vector2.Zero, scale, SpriteEffects.None, 0); + } else if (this.treePositions.TryGetValue(pos.ToPoint(), out var treeType)) { + batch.Draw(TilesTexture[1 + treeType, 0], drawPos, Color.White * alpha, 0, Vector2.Zero, scale, SpriteEffects.None, 0); + } + } + } // draw attractions foreach (var (pos, attraction) in this.attractions) batch.Draw(attraction.Type.TextureRegion, position + pos.ToVector2() * tileSize, Color.White * alpha, 0, Vector2.Zero, scale, SpriteEffects.None, 0); diff --git a/ThemeParkClicker/Ui.cs b/ThemeParkClicker/Ui.cs index c11313d..7afb5a6 100644 --- a/ThemeParkClicker/Ui.cs +++ b/ThemeParkClicker/Ui.cs @@ -45,7 +45,7 @@ namespace ThemeParkClicker { if (rainingTickets[i].Update()) rainingTickets.RemoveAt(i); } - while (rainingTickets.Count < Math.Min(GameImpl.Instance.TicketsPerSecond / 10, 500)) + while (rainingTickets.Count < Math.Min(GameImpl.Instance.Map.TicketsPerSecond / 10, 500)) rainingTickets.Add(new RainingTicket()); }, OnDrawn = (e, time, batch, alpha) => { @@ -58,7 +58,7 @@ namespace ThemeParkClicker { ticketGroup.AddChild(new Paragraph(Anchor.AutoCenter, 1, p => GameImpl.Instance.DisplayTicketCount(), true) { TextScale = 0.3F }); - ticketGroup.AddChild(new Paragraph(Anchor.AutoCenter, 1, p => GameImpl.Instance.TicketsPerSecond.ToString("0.##") + "/s", true) { + ticketGroup.AddChild(new Paragraph(Anchor.AutoCenter, 1, p => GameImpl.Instance.Map.TicketsPerSecond.ToString("0.##") + "/s", true) { PositionOffset = new Vector2(0, -8) }); BigInteger lastTickets = 0; @@ -83,7 +83,7 @@ namespace ThemeParkClicker { var (scaleX, scaleY) = e.DisplayArea.Size / mapSize; var scale = Math.Min(scaleX, scaleY); var pos = e.DisplayArea.Location + (e.DisplayArea.Size - mapSize * scale) / 2; - map.Draw(time, batch, pos, scale, alpha); + map.Draw(time, batch, pos, scale, alpha, 0); }, OnPressed = e => { var map = GameImpl.Instance.Map;