Skip to content

Commit

Permalink
Add State for player so he behaves differently when scripting to norm…
Browse files Browse the repository at this point in the history
…al play.
  • Loading branch information
CartBlanche committed Jan 27, 2025
1 parent 642ee0d commit a3621bb
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public Player Player
public TimeSpan TimeTaken => timeTaken;

private string levelPath;
private bool onMainMenu;
private TimeSpan maximumTimeToCompleteLevel = TimeSpan.FromMinutes(2.0);
public TimeSpan MaximumTimeToCompleteLevel { get => maximumTimeToCompleteLevel; }

Expand Down Expand Up @@ -161,6 +162,9 @@ public Level(ScreenManager screenManager, string levelPath, int levelIndex)
timeTaken = TimeSpan.Zero;
this.levelPath = levelPath;

// If it's the MainMenu/Tutorial level, ignore stats and giving it a score.
onMainMenu = levelPath.Contains("00.txt");

using (Stream fileStream = TitleContainer.OpenStream(levelPath))
{
LoadTiles(fileStream);
Expand Down Expand Up @@ -378,6 +382,7 @@ private Tile LoadStartTile(int x, int y)

start = RectangleExtensions.GetBottomCenter(GetBounds(x, y));
player = new Player(this, start);
player.Mode = PlayerMode.Playing;

return new Tile(null, TileCollision.Passable);
}
Expand Down Expand Up @@ -483,15 +488,15 @@ public void Update(
}

// Pause while the player is dead or we've reached maximum time allowed.
if (!Player.IsAlive || TimeTaken == MaximumTimeToCompleteLevel)
if (!Player.IsAlive
|| TimeTaken == MaximumTimeToCompleteLevel)
{
// Still want to perform physics on the player.
Player.ApplyPhysics(gameTime);
}
else if (ReachedExit)
{
// If it's the MainMenu/Tutorial level, ignore stats and giving it a score.
if (levelPath.Contains("00.txt"))
if (onMainMenu)
return;

if (!saved)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@

namespace ___SafeGameName___.Core;

enum PlayerMode
{
Scripting,
Playing
}

/// <summary>
/// Our fearless adventurer!
/// </summary>
Expand Down Expand Up @@ -140,6 +146,9 @@ public bool IsPoweredUp
{
get { return powerUpTime > 0.0f; }
}

public PlayerMode Mode { get; internal set; }

private readonly Color[] poweredUpColors = {
Color.Red,
Color.Blue,
Expand Down Expand Up @@ -214,7 +223,8 @@ public void Update(
InputState inputState,
DisplayOrientation displayOrientation)
{
HandleInput(inputState, displayOrientation);
if (Mode == PlayerMode.Playing)
HandleInput(inputState, displayOrientation);

Move(gameTime);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Reflection.Emit;
using ___SafeGameName___.Core;
using ___SafeGameName___.Core.Effects;
using ___SafeGameName___.Core.Inputs;
Expand Down Expand Up @@ -96,6 +97,7 @@ public override void LoadContent()
string levelPath = "Content/Levels/00.txt";
level = new Level(ScreenManager, levelPath, 00);
level.ParticleManager = particleManager;
level.Player.Mode = PlayerMode.Scripting;

gradientTexture = content.Load<Texture2D>("Sprites/gradient");
}
Expand Down

0 comments on commit a3621bb

Please sign in to comment.