Skip to content

Commit

Permalink
Add more levels, track deaths and time
Browse files Browse the repository at this point in the history
Implement goals
Add a non-arial font for UI
Add all direction spikes
Add a victory screen
Add a jump sound effect
Add a README
  • Loading branch information
nfaltermeier committed Mar 13, 2021
1 parent c34b772 commit ef8f15c
Show file tree
Hide file tree
Showing 34 changed files with 647 additions and 92 deletions.
2 changes: 1 addition & 1 deletion ASSETS.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Arial font from Windows

Content/Bangers/Bangers-Regular.ttf - Bangers font created by Vernon Adams, released on Google Fonts (https://fonts.google.com/specimen/Bangers) under the Open Font License
Content/Russo One/RussoOne-Regular - Russo One font created by Jovanny Lemonad, released on Google Fonts (https://fonts.google.com/specimen/Russo+One) under the Open Font License

Engine/FrameCounter.cs - FrameCounter code by craftworkgames from https://stackoverflow.com/a/20679895/5863057. Modified to have its own draw method. Licensed under CC BY-SA 3.0 https://creativecommons.org/licenses/by-sa/3.0/legalcode.

Expand Down
53 changes: 53 additions & 0 deletions Actors/Goal.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using Microsoft.Xna.Framework;
using Swing.Engine;
using Swing.Screens;
using System;
using System.Collections.Generic;
using System.Text;
using tainicom.Aether.Physics2D.Dynamics;
using tainicom.Aether.Physics2D.Dynamics.Contacts;

namespace Swing.Actors
{
class Goal : BodiedActor
{
public Goal(Vector2 position, int sideLength) : base(position)
{
Body = MainGame.Instance.World.CreateRectangle(sideLength / (MainGame.PhysicsScale * 2),
sideLength / (MainGame.PhysicsScale * 2), 20, Position / sideLength / MainGame.PhysicsScale);
Body.OnCollision += Body_OnCollision;
foreach (Fixture f in Body.FixtureList)
{
f.IsSensor = true;
}
}

private bool Body_OnCollision(Fixture sender, Fixture other, Contact contact)
{
if (other.Tag is ColliderTags tag)
{
if (tag == ColliderTags.Player)
{
if (Screen is MainGameScreen mgs)
{
if (MainGameScreen.LevelExists(mgs.Level + 1))
{
Screen.ScreenManager.QueueAddScreen(new MainGameScreen(mgs.Level + 1));
mgs.ExitScreen();
}
else
{
Screen.ScreenManager.QueueAddScreen(new VictoryScreen());
}
}
else
{
Debug.LogError($"Goal expected to be on a MainGameScreen, was on a {Screen.GetType()}");
}
}
}

return true;
}
}
}
30 changes: 27 additions & 3 deletions Actors/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,57 @@
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Swing.Engine;
using Swing.Engine.Components;
using Swing.Components;
using Swing.Engine.StateManagement;
using System;
using System.Collections.Generic;
using System.Text;
using tainicom.Aether.Physics2D.Dynamics;
using tainicom.Aether.Physics2D.Dynamics.Contacts;
using Swing.Screens;

namespace Swing.Actors
{
public class Player : BodiedActor
{
private Texture2D sprite;

private PlayerController controller;

public Player(Vector2 position) : base(position)
public Player(Vector2 position, int tileSize) : base(position)
{
Body = MainGame.Instance.World.CreateRectangle(64f / MainGame.PhysicsScale, 64f / MainGame.PhysicsScale, 50f, Position / MainGame.PhysicsScale, bodyType: BodyType.Dynamic);
Body = MainGame.Instance.World.CreateRectangle(tileSize / MainGame.PhysicsScale, tileSize / MainGame.PhysicsScale, 50f, Position / MainGame.PhysicsScale, bodyType: BodyType.Dynamic);
Body.FixedRotation = true;
Body.OnCollision += Body_OnCollision;
Body.OnSeparation += Body_OnSeparation;
Body.LinearDamping = .5f;
foreach (Fixture f in Body.FixtureList)
{
f.Tag = ColliderTags.Player;
}
}

private bool Body_OnCollision(Fixture sender, Fixture other, Contact contact)
{
if (IsDestroyed)
return true;

if (other.Tag is ColliderTags tag)
{
if (tag == ColliderTags.Spike)
{
MainGame.Instance.Deaths++;
if (Screen is MainGameScreen mgs)
{
Screen.ScreenManager.QueueAddScreen(new MainGameScreen(mgs.Level));
Screen.ExitScreen();
}
else
{
Debug.LogError($"Player expected to be on a MainGameScreen, was on a {Screen.GetType()}");
}
Destroy();
}
else if (tag == ColliderTags.Wall)
{
if (controller != null && !controller.IsDestroyed)
Expand All @@ -45,6 +66,9 @@ private bool Body_OnCollision(Fixture sender, Fixture other, Contact contact)

private void Body_OnSeparation(Fixture sender, Fixture other, Contact contact)
{
if (IsDestroyed)
return;

if (other.Tag is ColliderTags tag)
{
if (tag == ColliderTags.Wall)
Expand Down
23 changes: 23 additions & 0 deletions Actors/RunTimeDisplay.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Microsoft.Xna.Framework;
using Swing.Engine.Actors.UI;
using System;
using System.Collections.Generic;
using System.Text;

namespace Swing.Actors
{
public class RunTimeDisplay : TextRenderer
{
public static readonly string format = "hh\\:mm\\:ss\\.ff";
public RunTimeDisplay(Vector2 position) : base(position, "")
{

}

protected override void Update()
{
base.Update();
text = MainGame.Instance.RunTime.ToString(format);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
using System.Text;
using tainicom.Aether.Physics2D.Dynamics;
using tainicom.Aether.Physics2D.Dynamics.Contacts;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Audio;

namespace Swing.Engine.Components
namespace Swing.Components
{
class PlayerController : Component
{
Expand All @@ -19,6 +21,8 @@ class PlayerController : Component
private Dictionary<Fixture, bool> ground;
private float timeSinceJump;

private SoundEffect jumpSound;

public PlayerController(BodiedActor attached) : base(attached)
{
bAttached = attached;
Expand All @@ -32,6 +36,12 @@ internal override void Start()
swingPoint = null;
}

internal override void LoadContent(ContentManager content)
{
base.LoadContent(content);
jumpSound = content.Load<SoundEffect>("Jump");
}

internal override void Update()
{
base.Update();
Expand Down Expand Up @@ -69,6 +79,7 @@ internal override void Update()
{
timeSinceJump = 0;
bAttached.Body.ApplyForce(Vector2.UnitY * 80 * bAttached.Body.Mass * MainGame.PhysicsScale);
jumpSound.Play(0.7f, 0, 0);
}
else if (timeSinceJump <= JumpHangTime)
{
Expand Down Expand Up @@ -113,8 +124,6 @@ public void OnTouchWall(Fixture sender, Fixture wall, Contact contact)
if (contact.FixtureA.Body.BodyType != BodyType.Dynamic)
normal *= -1;

Debug.LogClean($"{normal.ToString()} {contact.FixtureA.Body.BodyType}");

if (Vector2.Dot(normal, -Vector2.UnitY) > 0.5f)
{
ground[wall] = true;
Expand Down
52 changes: 30 additions & 22 deletions Content/Content.mgcb
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,6 @@
/processorParam:TextureFormat=Color
/build:Engine/UI/ValueSliderBackground.png

#begin Engine/UI/ValueSliderBackground.png
/importer:TextureImporter
/processor:TextureProcessor
/processorParam:ColorKeyColor=255,0,255,255
/processorParam:ColorKeyEnabled=True
/processorParam:GenerateMipmaps=False
/processorParam:PremultiplyAlpha=True
/processorParam:ResizeToPowerOfTwo=False
/processorParam:MakeSquare=False
/processorParam:TextureFormat=Color
/build:Engine/UI/ValueSliderBackground.png

#begin Engine/UI/ValueSliderHandle.png
/importer:TextureImporter
/processor:TextureProcessor
Expand All @@ -87,21 +75,41 @@
/processorParam:TextureFormat=Color
/build:Engine/UI/ValueSliderHandle.png

#begin Engine/UI/ValueSliderHandle.png
/importer:TextureImporter
/processor:TextureProcessor
/processorParam:ColorKeyColor=255,0,255,255
/processorParam:ColorKeyEnabled=True
/processorParam:GenerateMipmaps=False
#begin Jump.wav
/importer:WavImporter
/processor:SoundEffectProcessor
/processorParam:Quality=Best
/build:Jump.wav

#begin LargeFont.spritefont
/importer:FontDescriptionImporter
/processor:FontDescriptionProcessor
/processorParam:PremultiplyAlpha=True
/processorParam:ResizeToPowerOfTwo=False
/processorParam:MakeSquare=False
/processorParam:TextureFormat=Color
/build:Engine/UI/ValueSliderHandle.png
/processorParam:TextureFormat=Compressed
/build:LargeFont.spritefont

#begin Levels/1.tmx
/copy:Levels/1.tmx

#begin Levels/2.tmx
/copy:Levels/2.tmx

#begin Levels/3.tmx
/copy:Levels/3.tmx

#begin Levels/4.tmx
/copy:Levels/4.tmx

#begin Levels/5.tmx
/copy:Levels/5.tmx

#begin MediumFont.spritefont
/importer:FontDescriptionImporter
/processor:FontDescriptionProcessor
/processorParam:PremultiplyAlpha=True
/processorParam:TextureFormat=Compressed
/build:MediumFont.spritefont

#begin Player.png
/importer:TextureImporter
/processor:TextureProcessor
Expand Down
Binary file modified Content/Engine/UI/ButtonBase.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Content/Jump.wav
Binary file not shown.
60 changes: 60 additions & 0 deletions Content/LargeFont.spritefont
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
This file contains an xml description of a font, and will be read by the XNA
Framework Content Pipeline. Follow the comments to customize the appearance
of the font in your game, and to change the characters which are available to draw
with.
-->
<XnaContent xmlns:Graphics="Microsoft.Xna.Framework.Content.Pipeline.Graphics">
<Asset Type="Graphics:FontDescription">

<!--
Modify this string to change the font that will be imported.
-->
<FontName>Russo One</FontName>

<!--
Size is a float value, measured in points. Modify this value to change
the size of the font.
-->
<Size>48</Size>

<!--
Spacing is a float value, measured in pixels. Modify this value to change
the amount of spacing in between characters.
-->
<Spacing>0</Spacing>

<!--
UseKerning controls the layout of the font. If this value is true, kerning information
will be used when placing characters.
-->
<UseKerning>true</UseKerning>

<!--
Style controls the style of the font. Valid entries are "Regular", "Bold", "Italic",
and "Bold, Italic", and are case sensitive.
-->
<Style>Regular</Style>

<!--
If you uncomment this line, the default character will be substituted if you draw
or measure text that contains characters which were not included in the font.
-->
<!-- <DefaultCharacter>*</DefaultCharacter> -->

<!--
CharacterRegions control what letters are available in the font. Every
character from Start to End will be built and made available for drawing. The
default range is from 32, (ASCII space), to 126, ('~'), covering the basic Latin
character set. The characters are ordered according to the Unicode standard.
See the documentation for more information.
-->
<CharacterRegions>
<CharacterRegion>
<Start>&#32;</Start>
<End>&#126;</End>
</CharacterRegion>
</CharacterRegions>
</Asset>
</XnaContent>
25 changes: 25 additions & 0 deletions Content/Levels/2.tmx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.4" tiledversion="1.4.3" orientation="orthogonal" renderorder="right-down" width="30" height="17" tilewidth="64" tileheight="64" infinite="0" nextlayerid="2" nextobjectid="1">
<tileset firstgid="1" source="../Tileset.tsx"/>
<layer id="1" name="Tile Layer 1" width="30" height="17">
<data encoding="csv">
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,1,1,1,1,1,1,0,0,0,1,1,1,1,1,1,0,0,0,0,0,0,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,0,0,0,1,1,1,1,1,1,0,0,0,0,0,0,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,0,0,0,1,1,1,1,1,1,0,0,0,0,0,0,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,2,2,2,1,1,1,1,1,1,2,2,2,2,2,2,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
</data>
</layer>
</map>
25 changes: 25 additions & 0 deletions Content/Levels/3.tmx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.4" tiledversion="1.4.3" orientation="orthogonal" renderorder="right-down" width="30" height="17" tilewidth="64" tileheight="64" infinite="0" nextlayerid="2" nextobjectid="1">
<tileset firstgid="1" source="../Tileset.tsx"/>
<layer id="1" name="Tile Layer 1" width="30" height="17">
<data encoding="csv">
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,1,1,1,1,1,0,0,0,1,1,1,1,1,0,0,0,1,1,1,1,0,0,0,1,1,1,1,1,1,
1,1,1,1,1,1,2,2,2,1,1,1,1,1,2,2,2,1,1,1,1,2,2,2,1,1,1,1,1,1
</data>
</layer>
</map>
Loading

0 comments on commit ef8f15c

Please sign in to comment.