Skip to content

Commit

Permalink
Room PB ghosts are gold
Browse files Browse the repository at this point in the history
  • Loading branch information
0x0ade committed Mar 5, 2018
1 parent 6ff63dc commit 4758cae
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 29 deletions.
27 changes: 15 additions & 12 deletions GhostMod/Ghost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
namespace Celeste.Mod.Ghost {
public class Ghost : Actor {

public GhostManager Manager;

public Player Player;

public PlayerSprite Sprite;
Expand All @@ -27,7 +29,7 @@ public class Ghost : Actor {

public GhostName Name;

protected Color color;
public Color Color = Color.White;

protected float alpha;
protected float alphaHair;
Expand Down Expand Up @@ -73,7 +75,12 @@ public void UpdateHair() {
if (!Frame.HasData)
return;

Hair.Color = Frame.HairColor;
Hair.Color = new Color(
(Frame.HairColor.R * Color.R) / 255,
(Frame.HairColor.G * Color.G) / 255,
(Frame.HairColor.B * Color.B) / 255,
(Frame.HairColor.A * Color.A) / 255
);
Hair.Alpha = alphaHair;
Hair.Facing = Frame.Facing;
Hair.SimulateMotion = Frame.HairSimulateMotion;
Expand All @@ -87,7 +94,12 @@ public void UpdateSprite() {
Sprite.Rotation = Frame.Rotation;
Sprite.Scale = Frame.Scale;
Sprite.Scale.X = Sprite.Scale.X * (float) Frame.Facing;
Sprite.Color = Frame.Color * alpha;
Sprite.Color = new Color(
(Frame.Color.R * Color.R) / 255,
(Frame.Color.G * Color.G) / 255,
(Frame.Color.B * Color.B) / 255,
(Frame.Color.A * Color.A) / 255
) * alpha;

Sprite.Rate = Frame.SpriteRate;
Sprite.Justify = Frame.SpriteJustify;
Expand Down Expand Up @@ -137,15 +149,6 @@ public override void Update() {
alphaHair = Calc.LerpClamp(GhostModule.Settings.InnerHairOpacityFactor, GhostModule.Settings.OuterHairOpacityFactor, dist);
}

if (Data != null) {
/* Proposed colors:
* blue - full run PB
* silver - chapter PB
* gold - room PB
*/
// TODO: Ghost colors based on time.
}

UpdateSprite();
UpdateHair();

Expand Down
78 changes: 78 additions & 0 deletions GhostMod/GhostManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
using FMOD.Studio;
using Microsoft.Xna.Framework;
using Monocle;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using YamlDotNet.Serialization;

namespace Celeste.Mod.Ghost {
public class GhostManager : Entity {

public List<Ghost> Ghosts = new List<Ghost>();

public Player Player;

public readonly static Color ColorGold = new Color(1f, 1f, 0f, 1f);
public readonly static Color ColorNeutral = new Color(1f, 1f, 1f, 1f);

public GhostManager(Player player, Level level)
: base(Vector2.Zero) {
Player = player;

Tag = Tags.HUD;

// Read and add all ghosts.
GhostData.ForAllGhosts(level.Session, (i, ghostData) => {
Ghost ghost = new Ghost(player, ghostData);
level.Add(ghost);
Ghosts.Add(ghost);
return true;
});
}

public override void Removed(Scene scene) {
base.Removed(scene);

// Remove any dead ghosts (heh)
for (int i = Ghosts.Count - 1; i > -1; --i) {
Ghost ghost = Ghosts[i];
if (ghost.Player != Player)
ghost.RemoveSelf();
}
Ghosts.Clear();
}

public override void Render() {
/* Proposed colors:
* blue - full run PB (impossible)
* silver - chapter PB (feasible)
* gold - room PB (done)
*/

// Gold is the easiest: Find fastest active ghost.
Ghost fastest = null;
foreach (Ghost ghost in Ghosts) {
// While we're at it, reset all colors.
ghost.Color = ColorNeutral;

if (!ghost.Frame.HasData)
continue;

if (fastest == null || ghost.Data.Frames.Count < fastest.Data.Frames.Count) {
fastest = ghost;
}
}

if (fastest != null) {
fastest.Color = ColorGold;
}

base.Render();
}

}
}
1 change: 1 addition & 0 deletions GhostMod/GhostMod.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="GhostManager.cs" />
<Compile Include="GhostName.cs" />
<Compile Include="GhostInputReplayer.cs" />
<Compile Include="GhostRecorder.cs" />
Expand Down
23 changes: 6 additions & 17 deletions GhostMod/GhostModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class GhostModule : EverestModule {

public static string PathGhosts { get; internal set; }

public List<Ghost> Ghosts = new List<Ghost>();
public GhostManager GhostManager;
public GhostRecorder GhostRecorder;

public Guid Run;
Expand Down Expand Up @@ -49,7 +49,8 @@ public override void Unload() {

public void OnLoadLevel(Level level, Player.IntroTypes playerIntro, bool isFromLoader) {
if (isFromLoader) {
Ghosts.Clear();
GhostManager?.RemoveSelf();
GhostManager = null;
GhostRecorder?.RemoveSelf();
GhostRecorder = null;
Run = Guid.NewGuid();
Expand Down Expand Up @@ -82,21 +83,9 @@ public void Step(Level level) {
GhostRecorder.Data.Write();
}

// Remove any dead ghosts (heh)
for (int i = Ghosts.Count - 1; i > -1; --i) {
Ghost ghost = Ghosts[i];
if (ghost.Player != player)
ghost.RemoveSelf();
}
Ghosts.Clear();

// Read and add all ghosts.
GhostData.ForAllGhosts(level.Session, (i, ghostData) => {
Ghost ghost = new Ghost(player, ghostData);
level.Add(ghost);
Ghosts.Add(ghost);
return true;
});
GhostManager?.RemoveSelf();

level.Add(GhostManager = new GhostManager(player, level));

if (GhostRecorder != null)
GhostRecorder.RemoveSelf();
Expand Down

0 comments on commit 4758cae

Please sign in to comment.