Skip to content

Commit

Permalink
Implementation of a pixellated graphics renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
shnakamura committed Sep 19, 2024
1 parent 6fe1280 commit b6d1f9b
Show file tree
Hide file tree
Showing 17 changed files with 154 additions and 135 deletions.
Binary file added src/Aurora/Assets/Textures/Gores/WoodPeckerNPC0.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 src/Aurora/Assets/Textures/Gores/WoodPeckerNPC1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
106 changes: 106 additions & 0 deletions src/Aurora/Common/Tests/InverseKinematicsSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
namespace Aurora.Common.Tests;

public sealed class InverseKinematicsSystem : ModSystem
{
public sealed class Segment
{
public Vector2 Start;
public Vector2 End;

public float Angle;
public float Length;

public Segment(Vector2 start, float angle, float length)
{
Start = start;
Angle = angle;
Length = length;
CalculateEnd();
}

public void CalculateEnd()
{
var direction = Angle.ToRotationVector2() * Length;
End = Start + direction;
}

public void Follow(Vector2 target)
{
var toTarget = target - Start;
Angle = (float)Math.Atan2(toTarget.Y, toTarget.X); // Calculate angle towards the target
CalculateEnd();
}

public void UpdateStart(Vector2 newStart)
{
Start = newStart;
CalculateEnd();
}

public void Draw()
{
Utils.DrawLine(
Main.spriteBatch,
Start,
End,
Color.White,
Color.White,
4f
);
}
}

private Segment upperArm;
private Segment forearm;

public override void Load()
{
base.Load();
On_Main.DrawInfernoRings += On_MainOnDrawInfernoRings;



}

public override void PostUpdateDusts() {
base.PostUpdateDusts();

Vector2 startPos = new Vector2(0f, 100f);

float upperArmLength = 50f;
float forearmLength = 40f;

upperArm ??= new Segment(Main.LocalPlayer.Center - startPos, 0f, upperArmLength);
forearm ??= new Segment(Main.LocalPlayer.Center - startPos, 0f, forearmLength);
}

private void On_MainOnDrawInfernoRings(On_Main.orig_DrawInfernoRings orig, Main self)
{
orig(self);

if (forearm is null || upperArm is null) {
return;
}

// Get the local player
Player player = Main.LocalPlayer;

// Set the player's center as the starting position of the upper arm
Vector2 playerCenter = player.Center;

// Get the cursor position as the target
Vector2 cursorPosition = Main.MouseWorld;

// Update the arm segments to follow the cursor
upperArm.Follow(cursorPosition);
forearm.Follow(upperArm.Start); // Upper arm should follow forearm's start

// Update the starting position of the forearm based on the upper arm
upperArm.UpdateStart(playerCenter);
forearm.UpdateStart(upperArm.End);

// Draw the arm segments
upperArm.Draw();
forearm.Draw();
}
}
6 changes: 6 additions & 0 deletions src/Aurora/Content/Items/Scarlet/ScarletPlayerDrawLayer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Aurora.Content.Items.Scarlet;

public class ScarletPlayerDrawLayer
{

}
53 changes: 0 additions & 53 deletions src/Aurora/Content/Tiles/TelevisionTileEntity.cs

This file was deleted.

82 changes: 0 additions & 82 deletions src/Aurora/Content/Tiles/TelevisionTileEntityData.cs

This file was deleted.

6 changes: 6 additions & 0 deletions src/Aurora/Core/Graphics/_Renderers/PixellatedRenderer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Aurora.Core.Graphics;

public class PixellatedRenderer
{

}
36 changes: 36 additions & 0 deletions src/Aurora/Core/Physics/_Kinematics/Segment.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
namespace Aurora.Common.Physics;

public sealed class Segment
{
public Vector2 Start;
public Vector2 End;

public float Length;
public float Rotation;

public Segment(Vector2 start, float length, float rotation = 0f) {
Start = start;

Length = length;
Rotation = rotation;

End = Start + Rotation.ToRotationVector2() * Length;
}

public void Follow(Vector2 position) {
End = Start + Rotation.ToRotationVector2() * Length;

Rotation = Start.AngleTo(position);

var direction = position - Start;

direction = direction.SafeNormalize(Vector2.Zero) * Length;
direction *= -1;

Start = position + direction;
}

public void Draw() {
Utils.DrawLine(Main.spriteBatch, Start, End, Color.White, Color.White, 10f);
}
}

0 comments on commit b6d1f9b

Please sign in to comment.