2020-06-01 14:45:20 +02:00
|
|
|
using System;
|
2020-06-01 23:02:47 +02:00
|
|
|
using System.Collections.Generic;
|
2020-05-30 19:41:49 +02:00
|
|
|
using System.Numerics;
|
2020-06-02 23:23:43 +02:00
|
|
|
using Coroutine;
|
2020-05-30 19:41:49 +02:00
|
|
|
using Microsoft.Xna.Framework;
|
|
|
|
using Microsoft.Xna.Framework.Graphics;
|
2020-05-31 17:24:10 +02:00
|
|
|
using MLEM.Cameras;
|
2020-05-30 19:41:49 +02:00
|
|
|
using MLEM.Startup;
|
|
|
|
|
2020-06-01 17:39:57 +02:00
|
|
|
namespace TouchyTickets {
|
2020-05-30 19:41:49 +02:00
|
|
|
public class GameImpl : MlemGame {
|
|
|
|
|
|
|
|
public static GameImpl Instance { get; private set; }
|
2020-06-01 23:02:47 +02:00
|
|
|
public readonly ISet<Upgrade> AppliedUpgrades = new HashSet<Upgrade>();
|
2020-06-14 01:18:12 +02:00
|
|
|
public readonly Platform Platform;
|
2020-06-01 16:18:07 +02:00
|
|
|
public BigInteger Tickets;
|
2020-06-01 23:02:47 +02:00
|
|
|
public int TimesRestarted;
|
|
|
|
public int Stars;
|
2020-06-01 14:45:20 +02:00
|
|
|
public ParkMap Map;
|
2020-06-14 01:18:12 +02:00
|
|
|
public Tutorial Tutorial { get; private set; }
|
2020-05-31 17:24:10 +02:00
|
|
|
public Camera Camera { get; private set; }
|
2020-05-30 19:41:49 +02:00
|
|
|
public Ui Ui { get; private set; }
|
2020-05-31 21:16:50 +02:00
|
|
|
public bool DrawMap;
|
2020-06-01 14:45:20 +02:00
|
|
|
public DateTime LastUpdate;
|
2020-06-30 19:06:35 +02:00
|
|
|
public TimeSpan PlayTime;
|
2020-06-01 14:45:20 +02:00
|
|
|
private double saveCounter;
|
2020-06-01 01:21:54 +02:00
|
|
|
|
2020-06-14 01:18:12 +02:00
|
|
|
public GameImpl(Platform platform) {
|
|
|
|
this.Platform = platform;
|
2020-05-30 19:41:49 +02:00
|
|
|
Instance = this;
|
2020-06-14 01:18:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override void LoadContent() {
|
|
|
|
base.LoadContent();
|
2020-06-29 00:41:49 +02:00
|
|
|
Assets.Load();
|
2020-06-16 23:17:18 +02:00
|
|
|
Options.Load();
|
2020-06-25 14:02:41 +02:00
|
|
|
|
2020-06-14 01:18:12 +02:00
|
|
|
// start the load sequence
|
|
|
|
Ui.SetupUiSystem(this.UiSystem);
|
|
|
|
CoroutineHandler.Start(Ui.DisplaySplash(this.LoadGame));
|
|
|
|
}
|
2020-06-09 19:03:55 +02:00
|
|
|
|
2020-06-14 01:18:12 +02:00
|
|
|
private void LoadGame() {
|
2020-06-09 19:03:55 +02:00
|
|
|
// set up analytics
|
|
|
|
var settings = new Dictionary<string, object>();
|
|
|
|
settings["InfoLog"] = true;
|
|
|
|
settings["VerboseLog"] = true;
|
|
|
|
settings["ResourceCurrencies"] = new[] {"Tickets", "Stars"};
|
2020-06-10 00:31:28 +02:00
|
|
|
settings["ResourceItemTypes"] = new[] {"Attraction", "Restart", "Upgrade", "Modifier"};
|
2020-06-09 19:03:55 +02:00
|
|
|
// ios comes first, then android. For now they're the same
|
|
|
|
settings["GameKey"] = new[] {"cc18de06eebbc5d5e987c384fcd28000", "cc18de06eebbc5d5e987c384fcd28000"};
|
|
|
|
settings["SecretKey"] = new[] {"82ca1a930ee38e2383ffb02db7631e16033b511d", "82ca1a930ee38e2383ffb02db7631e16033b511d"};
|
2020-06-14 01:18:12 +02:00
|
|
|
this.Platform.SetupAnalytics(settings);
|
|
|
|
this.Platform.SetupAds();
|
2020-05-30 19:41:49 +02:00
|
|
|
|
2020-06-14 01:18:12 +02:00
|
|
|
this.Tutorial = new Tutorial();
|
2020-06-01 17:19:05 +02:00
|
|
|
|
2020-06-01 16:18:07 +02:00
|
|
|
if (!SaveHandler.Load(this))
|
2020-06-05 23:00:03 +02:00
|
|
|
this.Map = new ParkMap(20, 20);
|
2020-06-01 17:19:05 +02:00
|
|
|
|
2020-06-14 01:18:12 +02:00
|
|
|
// load other stuff
|
2020-05-30 19:41:49 +02:00
|
|
|
this.Ui = new Ui(this.UiSystem);
|
2020-05-31 17:24:10 +02:00
|
|
|
this.Camera = new Camera(this.GraphicsDevice) {
|
2020-06-03 14:19:51 +02:00
|
|
|
Scale = 4,
|
2020-05-31 21:16:50 +02:00
|
|
|
AutoScaleWithScreen = true,
|
|
|
|
AutoScaleReferenceSize = new Point(720, 1280),
|
|
|
|
MaxScale = 24,
|
2020-06-01 23:02:47 +02:00
|
|
|
MinScale = 2
|
2020-05-31 17:24:10 +02:00
|
|
|
};
|
2020-07-08 16:04:44 +02:00
|
|
|
|
|
|
|
// update the map once to make sure that catching up happens during loading
|
|
|
|
this.UpdateMapOnce();
|
2020-05-30 19:41:49 +02:00
|
|
|
}
|
|
|
|
|
2020-05-31 00:44:15 +02:00
|
|
|
protected override void DoUpdate(GameTime gameTime) {
|
|
|
|
base.DoUpdate(gameTime);
|
2020-06-01 14:45:20 +02:00
|
|
|
|
2020-06-14 01:18:12 +02:00
|
|
|
if (this.Map != null) {
|
2020-07-08 16:04:44 +02:00
|
|
|
// update the map
|
|
|
|
this.UpdateMapOnce();
|
2020-06-14 01:18:12 +02:00
|
|
|
// save every 3 seconds
|
|
|
|
this.saveCounter += gameTime.ElapsedGameTime.TotalSeconds;
|
|
|
|
if (this.saveCounter >= 3) {
|
|
|
|
this.saveCounter = 0;
|
|
|
|
SaveHandler.Save(this);
|
|
|
|
}
|
2020-06-01 14:45:20 +02:00
|
|
|
}
|
2020-06-01 01:21:54 +02:00
|
|
|
|
2020-06-30 19:06:35 +02:00
|
|
|
// play time stuff
|
|
|
|
var lastTime = this.PlayTime;
|
|
|
|
this.PlayTime += gameTime.ElapsedGameTime;
|
|
|
|
if (lastTime.TotalHours >= 1 != this.PlayTime.TotalHours >= 1)
|
|
|
|
Ui.DisplayRatePlease();
|
|
|
|
|
2020-06-14 01:18:12 +02:00
|
|
|
this.Ui?.Update(gameTime);
|
|
|
|
this.Tutorial?.Update(this);
|
2020-05-31 00:44:15 +02:00
|
|
|
}
|
|
|
|
|
2020-05-30 19:41:49 +02:00
|
|
|
protected override void DoDraw(GameTime gameTime) {
|
2020-05-31 21:16:50 +02:00
|
|
|
this.GraphicsDevice.Clear(Color.Black);
|
|
|
|
if (this.DrawMap) {
|
|
|
|
this.SpriteBatch.Begin(SpriteSortMode.Deferred, null, SamplerState.PointClamp, transformMatrix: this.Camera.ViewMatrix);
|
2020-06-01 17:19:05 +02:00
|
|
|
this.Map.Draw(gameTime, this.SpriteBatch, Vector2.Zero, 1, 1, true, this.Camera.GetVisibleRectangle());
|
2020-05-31 21:16:50 +02:00
|
|
|
this.SpriteBatch.End();
|
|
|
|
}
|
2020-05-30 19:41:49 +02:00
|
|
|
base.DoDraw(gameTime);
|
|
|
|
}
|
|
|
|
|
2020-06-01 23:02:47 +02:00
|
|
|
public BigInteger GetStarPrice() {
|
2020-07-08 16:16:40 +02:00
|
|
|
return 1000000000 * BigInteger.Pow(100, this.TimesRestarted);
|
2020-06-05 23:51:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public int GetBuyableStars() {
|
2020-06-25 14:02:41 +02:00
|
|
|
#if DEBUG
|
|
|
|
return 3;
|
|
|
|
#endif
|
2020-07-03 16:04:52 +02:00
|
|
|
return (int) BigInteger.Min(3, this.Tickets / this.GetStarPrice());
|
2020-06-01 14:45:20 +02:00
|
|
|
}
|
|
|
|
|
2020-07-08 16:04:44 +02:00
|
|
|
private void UpdateMapOnce() {
|
|
|
|
var now = DateTime.Now;
|
|
|
|
if (this.LastUpdate != default) {
|
|
|
|
var lastTickets = this.Tickets;
|
2020-07-08 18:53:48 +02:00
|
|
|
var lastTps = this.Map.TicketsPerSecond;
|
|
|
|
|
2020-07-08 16:04:44 +02:00
|
|
|
var passed = now - this.LastUpdate;
|
|
|
|
this.Map.Update(passed, passed.TotalSeconds >= 1);
|
|
|
|
|
|
|
|
// if 10 or more seconds passed, we display a message
|
2020-07-08 18:53:48 +02:00
|
|
|
if (Options.Instance.WhileYouWereAwayMessage && passed.TotalSeconds >= 10)
|
|
|
|
Ui.DisplayWhileYouWereAway(passed, this.Tickets - lastTickets, this.Map.TicketsPerSecond - lastTps);
|
2020-07-08 16:04:44 +02:00
|
|
|
}
|
|
|
|
this.LastUpdate = now;
|
|
|
|
}
|
|
|
|
|
2020-05-30 19:41:49 +02:00
|
|
|
}
|
|
|
|
}
|