added a main menu

This commit is contained in:
Ell 2021-03-13 20:00:34 +01:00
parent c2acdd9fad
commit eacd653d30
8 changed files with 71 additions and 33 deletions

View file

@ -30,11 +30,11 @@
0,0,0,0,0,84,85,86,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,38,0,0,0,17,18,18,18,18,18,18,18,4,2,2,2,2,3,0,0,0,17,18,18,18,18,18,18,18,18,19,0,0,0,0,0,0,0,0,0,0,0,0,0,0,65,66,67,0,55,54,0, 0,0,0,0,0,84,85,86,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,38,0,0,0,17,18,18,18,18,18,18,18,4,2,2,2,2,3,0,0,0,17,18,18,18,18,18,18,18,18,19,0,0,0,0,0,0,0,0,0,0,0,0,0,0,65,66,67,0,55,54,0,
0,0,0,0,0,100,101,102,103,104,0,0,0,0,0,0,0,0,39,0,0,0,0,0,0,0,0,1,2,2,2,3,0,0,0,17,18,18,18,18,18,18,18,18,18,18,18,18,19,0,0,1,5,4,2,2,2,5,18,18,18,19,39,39,0,0,0,0,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2, 0,0,0,0,0,100,101,102,103,104,0,0,0,0,0,0,0,0,39,0,0,0,0,0,0,0,0,1,2,2,2,3,0,0,0,17,18,18,18,18,18,18,18,18,18,18,18,18,19,0,0,1,5,4,2,2,2,5,18,18,18,19,39,39,0,0,0,0,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
0,0,0,0,0,0,0,0,0,0,0,0,1,2,2,2,2,2,2,3,0,0,0,0,0,0,0,17,18,18,18,19,0,0,0,17,4,2,2,2,2,5,18,18,18,18,18,18,19,0,0,9,10,10,21,18,18,18,18,18,18,4,2,2,3,0,0,0,17,18,18,18,18,18,18,18,18,18,18,18,18,18,18, 0,0,0,0,0,0,0,0,0,0,0,0,1,2,2,2,2,2,2,3,0,0,0,0,0,0,0,17,18,18,18,19,0,0,0,17,4,2,2,2,2,5,18,18,18,18,18,18,19,0,0,9,10,10,21,18,18,18,18,18,18,4,2,2,3,0,0,0,17,18,18,18,18,18,18,18,18,18,18,18,18,18,18,
0,0,0,0,0,0,0,0,0,0,0,0,17,18,18,18,18,18,18,19,0,0,0,0,38,39,0,17,4,2,5,19,0,0,0,17,18,18,18,18,18,18,18,18,4,2,2,5,19,0,0,0,0,0,17,18,18,18,18,18,18,18,18,18,19,0,0,0,17,4,2,2,2,2,2,5,18,18,18,18,18,18,18, 0,0,0,0,0,0,0,0,0,0,0,0,17,18,18,18,18,18,18,19,0,0,0,0,38,39,0,17,4,2,5,19,0,0,0,17,18,18,18,18,18,18,18,18,4,2,2,5,19,38,0,0,0,0,17,18,18,18,18,18,18,18,18,18,19,0,0,0,17,4,2,2,2,2,2,5,18,18,18,18,18,18,18,
2,2,2,2,2,2,2,2,2,2,2,2,5,18,4,2,2,2,5,19,0,0,0,1,2,2,2,5,18,18,18,19,0,0,0,17,18,18,18,18,18,18,18,18,18,18,18,18,19,0,0,0,82,0,17,18,4,2,2,2,2,2,2,5,19,0,0,0,17,18,18,18,18,18,18,18,18,4,2,2,2,5,18, 2,2,2,2,2,2,2,2,2,2,2,2,5,18,4,2,2,2,5,19,0,0,0,1,2,2,2,5,18,18,18,19,0,0,0,17,18,18,18,18,18,18,18,18,18,18,18,18,4,3,0,0,82,0,17,18,4,2,2,2,2,2,2,5,19,0,0,0,17,18,18,18,18,18,18,18,18,4,2,2,2,5,18,
18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,19,0,0,0,17,18,18,18,18,18,18,18,19,0,0,0,17,18,18,4,2,2,2,2,2,2,5,18,18,19,0,37,0,0,0,17,18,18,18,18,18,18,18,18,18,19,0,0,0,17,18,18,18,18,18,18,18,18,18,18,18,18,18,18, 18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,19,0,0,0,17,18,18,18,18,18,18,18,19,0,0,0,17,18,18,4,2,2,2,2,2,2,5,18,18,18,19,0,0,0,0,17,18,18,18,18,18,18,18,18,18,19,0,0,0,17,18,18,18,18,18,18,18,18,18,18,18,18,18,18,
18,18,18,18,18,18,4,2,2,2,2,2,5,18,18,18,18,18,18,19,0,0,0,17,4,2,2,2,2,5,18,19,0,0,0,17,18,18,18,18,18,18,18,18,18,18,18,18,19,0,1,2,2,2,5,18,18,18,18,18,4,2,2,5,19,0,0,0,17,18,18,18,4,2,2,2,2,2,5,18,18,18,18, 18,18,18,18,18,18,4,2,2,2,2,2,5,18,18,18,18,18,18,19,0,0,0,17,4,2,2,2,2,5,18,19,0,0,0,17,18,18,18,18,18,18,18,18,18,18,18,18,20,11,0,1,2,2,5,18,18,18,18,18,4,2,2,5,19,0,0,0,17,18,18,18,4,2,2,2,2,2,5,18,18,18,18,
18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,19,0,0,0,17,18,18,18,18,18,18,18,19,0,0,0,17,18,18,18,18,18,18,18,18,18,18,18,18,19,0,9,21,18,18,18,18,18,18,18,18,18,18,18,18,19,0,0,0,17,18,18,18,18,18,18,18,18,18,18,18,18,18,18, 18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,19,0,0,0,17,18,18,18,18,18,18,18,19,0,0,0,17,18,18,18,18,18,18,18,18,18,18,18,18,19,0,0,17,18,18,18,18,18,18,18,18,18,18,18,18,19,0,0,0,17,18,18,18,18,18,18,18,18,18,18,18,18,18,18,
18,4,2,2,2,5,18,18,18,18,4,2,2,2,2,2,2,5,18,19,0,0,0,17,18,4,2,2,2,2,5,19,0,0,0,17,4,2,2,2,2,5,18,18,18,18,18,18,19,0,0,17,4,2,2,2,2,2,5,18,18,18,18,18,19,0,0,0,17,4,2,2,2,2,2,5,18,18,18,18,18,18,18, 18,4,2,2,2,5,18,18,18,18,4,2,2,2,2,2,2,5,18,19,0,0,0,17,18,4,2,2,2,2,5,19,0,0,0,17,4,2,2,2,2,5,18,18,18,18,18,18,19,0,0,17,4,2,2,2,2,2,5,18,18,18,18,18,19,0,0,0,17,4,2,2,2,2,2,5,18,18,18,18,18,18,18,
18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,19,0,0,0,17,18,18,18,18,18,18,18,19,0,0,0,17,18,18,18,18,18,18,18,18,18,18,18,18,19,0,0,17,18,18,18,18,18,18,18,18,18,18,18,18,19,0,0,0,17,18,18,18,18,18,18,18,18,18,18,18,18,18,18 18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,19,0,0,0,17,18,18,18,18,18,18,18,19,0,0,0,17,18,18,18,18,18,18,18,18,18,18,18,18,19,0,0,17,18,18,18,18,18,18,18,18,18,18,18,18,19,0,0,0,17,18,18,18,18,18,18,18,18,18,18,18,18,18,18
</data> </data>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 866 B

After

Width:  |  Height:  |  Size: 1.3 KiB

View file

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
@ -13,6 +14,7 @@ using MLEM.Extensions;
using MLEM.Font; using MLEM.Font;
using MLEM.Formatting.Codes; using MLEM.Formatting.Codes;
using MLEM.Startup; using MLEM.Startup;
using MLEM.Textures;
using MLEM.Ui; using MLEM.Ui;
using MLEM.Ui.Elements; using MLEM.Ui.Elements;
using MonoGame.Extended; using MonoGame.Extended;
@ -47,7 +49,11 @@ namespace GreatSpringGameJam {
this.UiSystem.Style.Font = new GenericSpriteFont(LoadContent<SpriteFont>("Fonts/Regular")); this.UiSystem.Style.Font = new GenericSpriteFont(LoadContent<SpriteFont>("Fonts/Regular"));
this.UiSystem.Style.TextScale = 0.075F; this.UiSystem.Style.TextScale = 0.075F;
this.UiSystem.Style.TextColor = ColorHelper.FromHexRgb(0xebd5bd); this.UiSystem.Style.TextColor = ColorHelper.FromHexRgb(0xebd5bd);
this.UiSystem.Style.ButtonTexture = new NinePatch(this.SpriteBatch.GenerateSquareTexture(ColorHelper.FromHexRgb(0x594e6f) * 0.35F), 0);
this.UiSystem.AutoScaleWithScreen = true; this.UiSystem.AutoScaleWithScreen = true;
this.UiSystem.Controls.HandleKeyboard = false;
this.UiSystem.Controls.HandleGamepad = false;
this.UiSystem.Controls.HandleTouch = false;
this.UiSystem.TextFormatter.AddImage("Flower", Entity.StuffTexture[0, 1]); this.UiSystem.TextFormatter.AddImage("Flower", Entity.StuffTexture[0, 1]);
this.UiSystem.TextFormatter.AddImage("Gnome", Entity.StuffTexture[1, 1]); this.UiSystem.TextFormatter.AddImage("Gnome", Entity.StuffTexture[1, 1]);
this.UiSystem.TextFormatter.AddImage("Snow", Entity.StuffTexture[2, 1]); this.UiSystem.TextFormatter.AddImage("Snow", Entity.StuffTexture[2, 1]);
@ -56,27 +62,51 @@ namespace GreatSpringGameJam {
this.mapLoader = new ContentManager(this.Services, this.Content.RootDirectory); this.mapLoader = new ContentManager(this.Services, this.Content.RootDirectory);
var scores = GetScoreFile(); var scores = GetScoreFile();
if (scores.Exists) { if (scores.Exists) {
using (var reader = new JsonTextReader(scores.OpenText())) using var reader = new JsonTextReader(scores.OpenText());
this.Scores = Serializer.Deserialize<Dictionary<string, int>>(reader); this.Scores = Serializer.Deserialize<Dictionary<string, int>>(reader);
} }
this.Camera = new Camera(this.GraphicsDevice) { this.Camera = new Camera(this.GraphicsDevice) {
AutoScaleWithScreen = true, AutoScaleWithScreen = true,
Scale = 4 Scale = 4
}; };
this.StartMap("Overworld");
// open the main menu
var group = new Group(Anchor.TopLeft, Vector2.One, false);
group.AddChild(new Image(Anchor.TopCenter, new Vector2(0.45F, -0.5F), Entity.StuffTexture[0, 2, 4, 2]) {
OnUpdated = (e, time) => e.PositionOffset = new Vector2(0, 50 + MathF.Sin((float) time.TotalGameTime.TotalSeconds * 2) * 5)
});
group.AddChild(new Paragraph(Anchor.BottomCenter, 1, "Created by <l https://ellpeck.de>Ellpeck</l> for the <l https://itch.io/jam/great-spring-game-jam-2021>Great Spring Game Jam: 2021</l>", true) {
TextScale = 0.06F
});
var buttons = group.AddChild(new Group(Anchor.BottomCenter, new Vector2(500)) {PositionOffset = new Vector2(0, 125)});
buttons.AddChild(new Button(Anchor.AutoCenter, new Vector2(1, 60), "<i Gnome> Play <i Flower>") {
OnPressed = e => {
if (!this.IsInCutscene)
this.StartLevel("Overworld", Color.White);
}
});
buttons.AddChild(new VerticalSpace(10));
buttons.AddChild(new Button(Anchor.AutoLeft, new Vector2(245, 50), "View on itch"));
buttons.AddChild(new Button(Anchor.AutoInlineIgnoreOverflow, new Vector2(245, 50), "View source") {
PositionOffset = new Vector2(10, 0),
OnPressed = e => Process.Start(new ProcessStartInfo("https://git.ellpeck.de/Ellpeck/GreatSpringGameJam") {UseShellExecute = true})
});
this.UiSystem.Add("MainMenu", group);
} }
protected override void DoUpdate(GameTime gameTime) { protected override void DoUpdate(GameTime gameTime) {
base.DoUpdate(gameTime); base.DoUpdate(gameTime);
if (this.Map != null) {
this.Map.Update(gameTime); this.Map.Update(gameTime);
if (!this.IsInCutscene) if (this.Player != null && !this.IsInCutscene)
this.FocusCameraOnPlayer(); this.FocusCameraOnPlayer();
} }
}
protected override void DoDraw(GameTime gameTime) { protected override void DoDraw(GameTime gameTime) {
this.GraphicsDevice.Clear(ColorHelper.FromHexRgb(0x729cd4)); this.GraphicsDevice.Clear(ColorHelper.FromHexRgb(0x729cd4));
base.DoDraw(gameTime); base.DoDraw(gameTime);
if (this.Map != null)
this.Map.Draw(gameTime, this.SpriteBatch, this.Camera); this.Map.Draw(gameTime, this.SpriteBatch, this.Camera);
} }
@ -143,7 +173,7 @@ namespace GreatSpringGameJam {
CoroutineHandler.Start(this.FadeAndStartLevel(name, fadeColor)); CoroutineHandler.Start(this.FadeAndStartLevel(name, fadeColor));
} }
private IEnumerable<Wait> FadeAndStartLevel(string map, Color fadeColor) { private IEnumerable<Wait> FadeAndStartLevel(string mapName, Color fadeColor) {
var fadeOverlay = new Group(Anchor.TopLeft, Vector2.One, false) { var fadeOverlay = new Group(Anchor.TopLeft, Vector2.One, false) {
OnDrawn = (e, time, batch, a) => batch.FillRectangle(e.DisplayArea.ToExtended(), fadeColor * a), OnDrawn = (e, time, batch, a) => batch.FillRectangle(e.DisplayArea.ToExtended(), fadeColor * a),
DrawAlpha = 0 DrawAlpha = 0
@ -156,8 +186,20 @@ namespace GreatSpringGameJam {
yield return new Wait(0.25F); yield return new Wait(0.25F);
this.UiSystem.Remove("EndCard"); this.UiSystem.Remove("EndCard");
this.StartMap(map); this.UiSystem.Remove("MainMenu");
// load next map
this.mapLoader.Unload();
var map = new Map(this.mapLoader.Load<TiledMap>($"Maps/{mapName}"), mapName);
var spawnPoint = map.SpawnPoint.ToVector2();
if (mapName == "Overworld" && this.Map != null && this.Map.Name != mapName)
spawnPoint = (map.GetLevelEntrances().First(e => e.Name == this.Map.Name).Position / map.TileSize).FloorCopy();
this.Player = new Player(map, spawnPoint);
this.Map = map;
this.Map.AddEntity(this.Player);
this.FocusCameraOnPlayer(1);
// fade back in
yield return new Wait(0.25F); yield return new Wait(0.25F);
while (fadeOverlay.DrawAlpha > 0) { while (fadeOverlay.DrawAlpha > 0) {
fadeOverlay.DrawAlpha -= 0.04F; fadeOverlay.DrawAlpha -= 0.04F;
@ -173,19 +215,6 @@ namespace GreatSpringGameJam {
this.Camera.ConstrainWorldBounds(Vector2.Zero, this.Map.SizeInPixels.ToVector2()); this.Camera.ConstrainWorldBounds(Vector2.Zero, this.Map.SizeInPixels.ToVector2());
} }
private void StartMap(string name) {
// dispose loaded maps so that edits don't persist
this.mapLoader.Unload();
var map = new Map(this.mapLoader.Load<TiledMap>($"Maps/{name}"), name);
var spawnPoint = map.SpawnPoint.ToVector2();
if (name == "Overworld" && this.Map != null && this.Map.Name != name)
spawnPoint = (map.GetLevelEntrances().First(e => e.Name == this.Map.Name).Position / map.TileSize).FloorCopy();
this.Player = new Player(map, spawnPoint);
this.Map = map;
this.Map.AddEntity(this.Player);
this.FocusCameraOnPlayer(1);
}
private static FileInfo GetScoreFile() { private static FileInfo GetScoreFile() {
var appData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); var appData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
return new FileInfo(Path.Combine(appData, $"{Assembly.GetExecutingAssembly().GetName().Name}.dat")); return new FileInfo(Path.Combine(appData, $"{Assembly.GetExecutingAssembly().GetName().Name}.dat"));

View file

@ -5,13 +5,14 @@
<TargetFramework>net5.0</TargetFramework> <TargetFramework>net5.0</TargetFramework>
<PublishReadyToRun>false</PublishReadyToRun> <PublishReadyToRun>false</PublishReadyToRun>
<TieredCompilation>false</TieredCompilation> <TieredCompilation>false</TieredCompilation>
<AssemblyName>A Breath of Spring Air</AssemblyName>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Contentless" Version="3.0.5" /> <PackageReference Include="Contentless" Version="3.0.5" />
<PackageReference Include="MLEM" Version="5.0.0-73" /> <PackageReference Include="MLEM" Version="5.0.0-77" />
<PackageReference Include="MLEM.Extended" Version="5.0.0-73" /> <PackageReference Include="MLEM.Extended" Version="5.0.0-77" />
<PackageReference Include="MLEM.Startup" Version="5.0.0-73" /> <PackageReference Include="MLEM.Startup" Version="5.0.0-77" />
<PackageReference Include="MonoGame.Content.Builder.Task" Version="3.8.0.1641" /> <PackageReference Include="MonoGame.Content.Builder.Task" Version="3.8.0.1641" />
<PackageReference Include="MonoGame.Extended.Content.Pipeline" Version="3.8.0" /> <PackageReference Include="MonoGame.Extended.Content.Pipeline" Version="3.8.0" />
<PackageReference Include="MonoGame.Extended.Tiled" Version="3.8.0" /> <PackageReference Include="MonoGame.Extended.Tiled" Version="3.8.0" />
@ -29,8 +30,13 @@
<TrimmerRootAssembly Include="MLEM.Ui" Visible="false" /> <TrimmerRootAssembly Include="MLEM.Ui" Visible="false" />
</ItemGroup> </ItemGroup>
<PropertyGroup>
<ApplicationIcon>Icon.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup> <ItemGroup>
<Folder Include="Content\Palettes" /> <Content Include="Icon.ico" />
<Folder Include="Content\Tilesets" /> <EmbeddedResource Include="Icon.bmp">
<LogicalName>Icon.bmp</LogicalName>
</EmbeddedResource>
</ItemGroup> </ItemGroup>
</Project> </Project>

BIN
GreatSpringGameJam/Icon.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 256 KiB

BIN
GreatSpringGameJam/Icon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 200 KiB

View file

@ -1,4 +1,7 @@
<configuration> <configuration>
<packageSources>
<add key="Ellpeck" value="https://nuget.ellpeck.de/v3/index.json" />
</packageSources>
<config> <config>
<add key="globalPackagesFolder" value="./packages" /> <add key="globalPackagesFolder" value="./packages" />
</config> </config>