Skip to content

Commit

Permalink
Significantly improve code quality
Browse files Browse the repository at this point in the history
Mainly, this involved specifying fields as private and/or readonly.
I also moved screens and elements to their own namespaces.
  • Loading branch information
AnnoyingRain5 committed Jan 18, 2024
1 parent 2d393b6 commit c0611c0
Show file tree
Hide file tree
Showing 31 changed files with 508 additions and 463 deletions.
73 changes: 33 additions & 40 deletions CrankItUp.Desktop/DiscordRichPresence.cs
Original file line number Diff line number Diff line change
@@ -1,42 +1,35 @@
using DiscordRPC;

namespace CrankItUp.Desktop{

public class Discord{
public DiscordRpcClient client;

//Called when your application first starts.
//For example, just before your main loop, on OnEnable for unity.
public void Initialize()

{

client = new DiscordRpcClient("1039782791602241567");


//Subscribe to events
client.OnReady += (sender, e) =>
{
System.Console.WriteLine("Received Ready from user {0}", e.User.Username);
};

client.OnPresenceUpdate += (sender, e) =>
{
System.Console.WriteLine("Received Update! {0}", e.Presence);
};

//Connect to the RPC
client.Initialize();

//Set the rich presence
client.SetPresence(new RichPresence()
{
Details = "",
Assets = new Assets() {
LargeImageKey = "logo",
}

});
}
}
}
namespace CrankItUp.Desktop
{
public class Discord
{
public DiscordRpcClient Client;

//Called when your application first starts.
//For example, just before your main loop, on OnEnable for unity.
public void Initialize()

{
Client = new DiscordRpcClient("1039782791602241567");

//Subscribe to events
Client.OnReady += (sender, e) => { System.Console.WriteLine("Received Ready from user {0}", e.User.Username); };

Client.OnPresenceUpdate += (sender, e) => { System.Console.WriteLine("Received Update! {0}", e.Presence); };

//Connect to the RPC
Client.Initialize();

//Set the rich presence
Client.SetPresence(new RichPresence
{
Details = "",
Assets = new Assets
{
LargeImageKey = "logo",
}
});
}
}
}
16 changes: 7 additions & 9 deletions CrankItUp.Desktop/Program.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
using osu.Framework.Platform;
using CrankItUp.Game;
using osu.Framework;
using CrankItUp.Game;
using System;
using CrankItUp.Desktop;
using osu.Framework.Platform;

namespace CrankItUp.Game
namespace CrankItUp.Desktop
{
public static class Program
{
private static osu.Framework.Game game = new CrankItUpGame();
private static GameHost host = Host.GetSuitableDesktopHost(@"CrankItUp");
private static readonly osu.Framework.Game game = new CrankItUpGame();
private static readonly GameHost host = Host.GetSuitableDesktopHost(@"CrankItUp");

public static Discord discordrpc = new Discord();
private static readonly Discord discordrpc = new Discord();

public static void Main()
{
Expand All @@ -21,7 +19,7 @@ public static void Main()
host.Run(game);
}

public static CrankItUpGame getGame()
public static CrankItUpGame GetGame()
{
return (CrankItUpGame)game;
}
Expand Down
1 change: 0 additions & 1 deletion CrankItUp.Game.Tests/Visual/CrankItUpTestScene.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using osu.Framework.Testing;
using osu.Framework.Graphics;

namespace CrankItUp.Game.Tests.Visual
{
Expand Down
1 change: 1 addition & 0 deletions CrankItUp.Game.Tests/Visual/TestSceneCrankItUpGame.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using CrankItUp.Game.Screens;
using osu.Framework.Allocation;
using osu.Framework.Platform;
using NUnit.Framework;
Expand Down
1 change: 1 addition & 0 deletions CrankItUp.Game.Tests/Visual/TestSceneCreditsScreen.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using CrankItUp.Game.Screens;
using osu.Framework.Graphics;
using osu.Framework.Screens;
using NUnit.Framework;
Expand Down
2 changes: 0 additions & 2 deletions CrankItUp.Game.Tests/Visual/TestSceneDifficultySelect.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using osu.Framework.Graphics;
using osu.Framework.Screens;
using NUnit.Framework;

namespace CrankItUp.Game.Tests.Visual
Expand Down
1 change: 1 addition & 0 deletions CrankItUp.Game.Tests/Visual/TestSceneGameScreen.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using CrankItUp.Game.Screens;
using osu.Framework.Graphics;
using osu.Framework.Screens;
using NUnit.Framework;
Expand Down
1 change: 1 addition & 0 deletions CrankItUp.Game.Tests/Visual/TestSceneSettingsScreen.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using CrankItUp.Game.Screens;
using osu.Framework.Graphics;
using osu.Framework.Screens;
using NUnit.Framework;
Expand Down
1 change: 1 addition & 0 deletions CrankItUp.Game.Tests/Visual/TestSceneTitleScreen.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using CrankItUp.Game.Screens;
using osu.Framework.Graphics;
using osu.Framework.Screens;
using NUnit.Framework;
Expand Down
1 change: 1 addition & 0 deletions CrankItUp.Game.Tests/Visual/TestSceneTrackSelect.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using CrankItUp.Game.Screens;
using osu.Framework.Graphics;
using osu.Framework.Screens;
using NUnit.Framework;
Expand Down
8 changes: 6 additions & 2 deletions CrankItUp.Game/src/CrankItUpGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,34 @@
using osu.Framework.Screens;
using System;
using System.IO;
using CrankItUp.Game.Screens;

namespace CrankItUp.Game
{
public partial class CrankItUpGame : CrankItUpGameBase
{
private ScreenStack screenStack;
bool showSetup;
private bool showSetup;

[BackgroundDependencyLoader]
private void load(Storage store)
{
// Add your top-level game components here.
// A screen stack and sample screen has been provided for convenience, but you can replace it if you don't want to use screens.
Child = screenStack = new ScreenStack { RelativeSizeAxes = Axes.Both };

// load settings
try
{
var sr = new StreamReader(store.GetStream("settings.json"));
var settings = JObject.Parse(sr.ReadToEnd());
Settings.inputmode = (Settings.InputMode)settings.GetValue<int>("inputMode");
Settings.Inputmode = (Settings.InputMode)settings.GetValue<int>("inputMode");
}
catch
{
Console.WriteLine("Invalid or non-existant settings! Using default values");
}

showSetup = !store.ExistsDirectory("maps");
}

Expand All @@ -45,6 +48,7 @@ protected override void LoadComplete()
{
screenStack.Push(new TitleScreen());
}

base.LoadComplete();
}
}
Expand Down
61 changes: 31 additions & 30 deletions CrankItUp.Game/src/Elements/BaseNote.cs
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
using System;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Textures;
using osuTK;
using System;

namespace CrankItUp.Game
namespace CrankItUp.Game.Elements
{
public partial class BaseNote : CompositeDrawable
{
/**
so my thoughts on how mapping should be implemented
we have a ring where notes can be placed of all the potential spots for the platter to
be (may be a bit complicated because mapping a circle to a non circlular object, we can probably
be (may be a bit complicated because mapping a circle to a non circular object, we can probably
make a ring of some thickness tho to account for that if my mental math is right)
this also makes it so all we have to do to instantiate any given note is pass in its radial direction and then use a
vector of some static magnitude to be able to project it onto the spawning circle
**/

private double radians;

private long spawnTime;
private long travelTime;
Sprite note;

Vector2 velocity;
Boolean firstCollision;

private static float PROJECTION_VECTOR_MAGNITUDE = 375; //pixels
private static readonly float projection_vector_magnitude = 375; //pixels

public BaseNote(double radians, long spawnTime)
{
Expand Down Expand Up @@ -65,70 +65,71 @@ private void load(TextureStore textures)
protected override void Update()
{
Vector2 centerPosition = new Vector2(
(float)(X + NoteManager.radius),
(float)(Y + NoteManager.radius)
(float)(X + NoteManager.Radius),
(float)(Y + NoteManager.Radius)
);
double leftStartAngle = radians - Math.PI / 2.0;
Vector2 leftTangent = new Vector2(
centerPosition.X - (float)(NoteManager.radius * Math.Cos(leftStartAngle)),
centerPosition.Y - (float)(NoteManager.radius * Math.Sin(leftStartAngle))
centerPosition.X - (float)(NoteManager.Radius * Math.Cos(leftStartAngle)),
centerPosition.Y - (float)(NoteManager.Radius * Math.Sin(leftStartAngle))
);
Vector2 leftWaypoint = new Vector2(
leftTangent.X - (float)(NoteManager.radius * Math.Cos(radians)),
leftTangent.Y - (float)(NoteManager.radius * Math.Sin(radians))
leftTangent.X - (float)(NoteManager.Radius * Math.Cos(radians)),
leftTangent.Y - (float)(NoteManager.Radius * Math.Sin(radians))
);
double rightStartAngle = radians + Math.PI / 2.0;
Vector2 rightTangent = new Vector2(
centerPosition.X - (float)(NoteManager.radius * Math.Cos(rightStartAngle)),
centerPosition.Y - (float)(NoteManager.radius * Math.Sin(rightStartAngle))
centerPosition.X - (float)(NoteManager.Radius * Math.Cos(rightStartAngle)),
centerPosition.Y - (float)(NoteManager.Radius * Math.Sin(rightStartAngle))
);
Vector2 rightWaypoint = new Vector2(
rightTangent.X - (float)(NoteManager.radius * Math.Cos(radians)),
rightTangent.Y - (float)(NoteManager.radius * Math.Sin(radians))
rightTangent.X - (float)(NoteManager.Radius * Math.Cos(radians)),
rightTangent.Y - (float)(NoteManager.Radius * Math.Sin(radians))
);
Line collision = new Line(new Point(rightWaypoint), new Point(leftWaypoint));

if (collision.intersection(Crank.collisionLine) != null)
if (collision.Intersection(Crank.CollisionLine) != null)
{
//collision has happened, we do some math to determine the accuracy
ClearTransforms();

if (firstCollision)
{
Console.WriteLine(Crank.collisionLine.toString());
Console.WriteLine(Crank.collisionLine.getPoint2().toString());
Console.WriteLine(Crank.collisionLine.getPoint1().toString());
Console.WriteLine(Crank.CollisionLine.ToString());
Console.WriteLine(Crank.CollisionLine.GetPoint2().ToString());
Console.WriteLine(Crank.CollisionLine.GetPoint1().ToString());
Console.WriteLine("");
Console.WriteLine(collision.toString());
Console.WriteLine(collision.getPoint2().toString());
Console.WriteLine(collision.getPoint1().toString());
Console.WriteLine(collision.intersection(Crank.collisionLine).toString());
Console.WriteLine(collision.ToString());
Console.WriteLine(collision.GetPoint2().ToString());
Console.WriteLine(collision.GetPoint1().ToString());
Console.WriteLine(collision.Intersection(Crank.CollisionLine).ToString());
firstCollision = false;
}
}
}

public void spawn()
public void Spawn()
{
double finalMagnitude = PROJECTION_VECTOR_MAGNITUDE - NoteManager.radius;
double finalMagnitude = projection_vector_magnitude - NoteManager.Radius;
Vector2 spawnPointCenteredCoordinates = new Vector2(
(float)(finalMagnitude * Math.Cos(-radians)),
(float)(finalMagnitude * Math.Sin(-radians))
);
Position = spawnPointCenteredCoordinates + Constants.NOTE_DESTINATION;
velocity = new Vector2(
(float)(NoteManager.approachRate * Math.Cos(radians)),
(float)(NoteManager.approachRate * Math.Sin(radians))
(float)(NoteManager.ApproachRate * Math.Cos(radians)),
(float)(NoteManager.ApproachRate * Math.Sin(radians))
);
double timeSeconds = finalMagnitude / NoteManager.approachRate;
double timeSeconds = finalMagnitude / NoteManager.ApproachRate;
travelTime = (long)(timeSeconds * 1000);
}

public long getTravelTime()
public long GetTravelTime()
{
return travelTime;
}

public long getSpawnTime()
public long GetSpawnTime()
{
return spawnTime;
}
Expand Down
Loading

0 comments on commit c0611c0

Please sign in to comment.