Skip to content

Commit 8fed186

Browse files
authored
Merge pull request #26 from Project-Funk-Engine/note-system
Add initial Note system
2 parents 95f25ad + 6c785fa commit 8fed186

10 files changed

Lines changed: 333 additions & 5 deletions

File tree

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,7 @@ Current team members include:
1313

1414

1515

16+
#### Attributions:
17+
Note icon: <a href="https://www.flaticon.com/free-icons/next" title="next icons">Next icons created by Pixel perfect - Flaticon</a>
18+
19+

project.godot

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,34 @@ window/stretch/scale_mode="integer"
2525
[dotnet]
2626

2727
project/assembly_name="Funk Engine"
28+
29+
[input]
30+
31+
arrowUp={
32+
"deadzone": 0.5,
33+
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":87,"key_label":0,"unicode":119,"location":0,"echo":false,"script":null)
34+
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194320,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
35+
]
36+
}
37+
arrowDown={
38+
"deadzone": 0.5,
39+
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":83,"key_label":0,"unicode":115,"location":0,"echo":false,"script":null)
40+
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194322,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
41+
]
42+
}
43+
arrowLeft={
44+
"deadzone": 0.5,
45+
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":65,"key_label":0,"unicode":97,"location":0,"echo":false,"script":null)
46+
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194319,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
47+
]
48+
}
49+
arrowRight={
50+
"deadzone": 0.5,
51+
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194321,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
52+
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":68,"key_label":0,"unicode":100,"location":0,"echo":false,"script":null)
53+
]
54+
}
55+
56+
[rendering]
57+
58+
textures/canvas_textures/default_texture_filter=0

scenes/main.tscn

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,64 @@
1-
[gd_scene format=3 uid="uid://diq2m6va1x52k"]
1+
[gd_scene load_steps=6 format=3 uid="uid://diq2m6va1x52k"]
2+
3+
[ext_resource type="Texture2D" uid="uid://bucvj4fquqpkr" path="res://scripts/noteSystem/assets/right-arrow.png" id="1_7tfja"]
4+
[ext_resource type="Script" path="res://scripts/Main.cs" id="1_it331"]
5+
[ext_resource type="Script" path="res://scripts/noteSystem/NoteChecker.cs" id="3_3bwsh"]
6+
[ext_resource type="Script" path="res://scripts/noteSystem/NoteManager.cs" id="3_hu33e"]
7+
[ext_resource type="Texture2D" uid="uid://b0tvsewgnf2x7" path="res://icon.svg" id="4_j3yyc"]
28

39
[node name="Main" type="Node2D"]
10+
script = ExtResource("1_it331")
11+
12+
[node name="ui" type="Node2D" parent="."]
13+
14+
[node name="dividers" type="Node2D" parent="ui"]
15+
16+
[node name="DivA" type="Sprite2D" parent="ui/dividers"]
17+
modulate = Color(0, 0, 0, 1)
18+
position = Vector2(320, 210)
19+
scale = Vector2(5.10938, 0.041)
20+
texture = ExtResource("4_j3yyc")
21+
22+
[node name="DivB" type="Sprite2D" parent="ui/dividers"]
23+
modulate = Color(0, 0, 0, 1)
24+
position = Vector2(318, 255)
25+
scale = Vector2(5.10938, 0.041)
26+
texture = ExtResource("4_j3yyc")
27+
28+
[node name="DivC" type="Sprite2D" parent="ui/dividers"]
29+
modulate = Color(0, 0, 0, 1)
30+
position = Vector2(317, 314)
31+
scale = Vector2(5.10938, 0.041)
32+
texture = ExtResource("4_j3yyc")
33+
34+
[node name="noteManager" type="Node2D" parent="."]
35+
script = ExtResource("3_hu33e")
36+
37+
[node name="noteCheckers" type="Node2D" parent="noteManager"]
38+
39+
[node name="arrowUp" type="Sprite2D" parent="noteManager/noteCheckers"]
40+
position = Vector2(33, 179)
41+
rotation = -1.5708
42+
scale = Vector2(0.1, 0.1)
43+
texture = ExtResource("1_7tfja")
44+
script = ExtResource("3_3bwsh")
45+
46+
[node name="arrowLeft" type="Sprite2D" parent="noteManager/noteCheckers"]
47+
position = Vector2(33, 233)
48+
rotation = 3.14159
49+
scale = Vector2(0.1, 0.1)
50+
texture = ExtResource("1_7tfja")
51+
script = ExtResource("3_3bwsh")
52+
53+
[node name="arrowDown" type="Sprite2D" parent="noteManager/noteCheckers"]
54+
position = Vector2(33, 285)
55+
rotation = 1.5708
56+
scale = Vector2(0.1, 0.1)
57+
texture = ExtResource("1_7tfja")
58+
script = ExtResource("3_3bwsh")
59+
60+
[node name="arrowRight" type="Sprite2D" parent="noteManager/noteCheckers"]
61+
position = Vector2(33, 336)
62+
scale = Vector2(0.1, 0.1)
63+
texture = ExtResource("1_7tfja")
64+
script = ExtResource("3_3bwsh")

scripts/Main.cs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,24 @@
11
using System;
22
using Godot;
3+
using static NoteManager;
34

45
public partial class Main : Node2D
56
{
6-
// Called when the node enters the scene tree for the first time.
7-
public override void _Ready() { }
7+
private NoteManager _noteManager;
88

9-
// Called every frame. 'delta' is the elapsed time since the previous frame.
10-
public override void _Process(double delta) { }
9+
public override void _Ready()
10+
{
11+
_noteManager = GetNode<NoteManager>("noteManager");
12+
_noteManager.CreateNote(ArrowType.Down);
13+
}
14+
15+
public override void _Process(double delta)
16+
{
17+
//have a tiny chance of spanning a note in a row every frame. For testing purposes.
18+
if (GD.Randf() >= 0.02f)
19+
return;
20+
var randomLane = (ArrowType)
21+
GD.RandRange(0, ArrowType.GetValues(typeof(ArrowType)).Length - 1);
22+
_noteManager.CreateNote(randomLane);
23+
}
1124
}

scripts/noteSystem/Note.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using Godot;
2+
3+
/**
4+
* @class Note
5+
* @brief This class represents a note that scrolls across the screen to be played by the player. WIP
6+
*/
7+
public partial class Note : Sprite2D
8+
{
9+
private float _defaultNoteSpeed = 100;
10+
11+
//TODO: This is for a time based implementation. We need to find a way to make this exact.
12+
private float _expectedHitTime = 0;
13+
14+
public void Init(NoteManager.ArrowData parentArrowData, float speed, float hitTime)
15+
{
16+
_defaultNoteSpeed = speed;
17+
_expectedHitTime = hitTime;
18+
SelfModulate = parentArrowData.color;
19+
SetPosition(new Vector2(700, parentArrowData.node.Position.Y));
20+
RotationDegrees = parentArrowData.node.RotationDegrees;
21+
}
22+
23+
// Called every frame. 'delta' is the elapsed time since the previous frame.
24+
public override void _Process(double delta)
25+
{
26+
SetPosition(new Vector2(Position.X - _defaultNoteSpeed * ((float)delta * 100), Position.Y));
27+
28+
if (Position.X < -100)
29+
QueueFree();
30+
}
31+
}

scripts/noteSystem/NoteChecker.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using System;
2+
using Godot;
3+
4+
public partial class NoteChecker : Sprite2D
5+
{
6+
private bool _isPressed;
7+
private Color _color;
8+
private float _fadeTime = 2.0f;
9+
10+
// Called when the node enters the scene tree for the first time.
11+
public override void _Ready()
12+
{
13+
//TODO: Something
14+
}
15+
16+
// Called every frame. 'delta' is the elapsed time since the previous frame.
17+
public override void _Process(double delta)
18+
{
19+
SelfModulate = _isPressed
20+
? Modulate.Lerp(_color, _fadeTime)
21+
: SelfModulate.Lerp(
22+
new Color(_color.R * 0.5f, _color.G * 0.5f, _color.B * 0.5f, 1),
23+
(float)delta * _fadeTime
24+
);
25+
}
26+
27+
public void SetPressed(bool pressed)
28+
{
29+
_isPressed = pressed;
30+
}
31+
32+
public void SetColor(Color color)
33+
{
34+
_color = color;
35+
36+
SelfModulate = new Color(_color.R * 0.5f, _color.G * 0.5f, _color.B * 0.5f, 1);
37+
}
38+
}

scripts/noteSystem/NoteManager.cs

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
using System.Collections.Generic;
2+
using Godot;
3+
4+
public partial class NoteManager : Node2D
5+
{
6+
public enum ArrowType
7+
{
8+
Up,
9+
Down,
10+
Left,
11+
Right,
12+
}
13+
14+
public struct ArrowData
15+
{
16+
public Color color;
17+
public string key;
18+
public NoteChecker node;
19+
}
20+
21+
private Dictionary<ArrowType, ArrowData> _arrows;
22+
23+
private void InitializeArrowCheckers()
24+
{
25+
_arrows = new()
26+
{
27+
{
28+
ArrowType.Up,
29+
new ArrowData
30+
{
31+
color = Colors.Green,
32+
key = "arrowUp",
33+
node = GetNode<NoteChecker>("noteCheckers/arrowUp"),
34+
}
35+
},
36+
{
37+
ArrowType.Down,
38+
new ArrowData
39+
{
40+
color = Colors.Aqua,
41+
key = "arrowDown",
42+
node = GetNode<NoteChecker>("noteCheckers/arrowDown"),
43+
}
44+
},
45+
{
46+
ArrowType.Left,
47+
new ArrowData
48+
{
49+
color = Colors.HotPink,
50+
key = "arrowLeft",
51+
node = GetNode<NoteChecker>("noteCheckers/arrowLeft"),
52+
}
53+
},
54+
{
55+
ArrowType.Right,
56+
new ArrowData
57+
{
58+
color = Colors.Red,
59+
key = "arrowRight",
60+
node = GetNode<NoteChecker>("noteCheckers/arrowRight"),
61+
}
62+
},
63+
};
64+
65+
//Set the color of the arrows
66+
foreach (var arrow in _arrows)
67+
{
68+
arrow.Value.node.SetColor(arrow.Value.color);
69+
}
70+
}
71+
72+
public override void _Ready()
73+
{
74+
InitializeArrowCheckers();
75+
}
76+
77+
public override void _Process(double delta)
78+
{
79+
foreach (var arrow in _arrows)
80+
{
81+
if (Input.IsActionJustPressed(arrow.Value.key))
82+
{
83+
arrow.Value.node.SetPressed(true);
84+
}
85+
else if (Input.IsActionJustReleased(arrow.Value.key))
86+
{
87+
arrow.Value.node.SetPressed(false);
88+
}
89+
}
90+
}
91+
92+
public Note CreateNote(ArrowType arrow)
93+
{
94+
return CreateNote(_arrows[arrow]);
95+
}
96+
97+
private Note CreateNote(ArrowData arrowData)
98+
{
99+
var noteScene = ResourceLoader.Load<PackedScene>("res://scripts/noteSystem/note.tscn");
100+
var note = noteScene.Instantiate<Note>();
101+
102+
note.Init(arrowData, 1.0f, -1);
103+
104+
AddChild(note);
105+
return note;
106+
}
107+
}
14.3 KB
Loading
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
[remap]
2+
3+
importer="texture"
4+
type="CompressedTexture2D"
5+
uid="uid://bucvj4fquqpkr"
6+
path="res://.godot/imported/right-arrow.png-8f579df18e1ada04d965b123ceaf76a0.ctex"
7+
metadata={
8+
"vram_texture": false
9+
}
10+
11+
[deps]
12+
13+
source_file="res://scripts/noteSystem/assets/right-arrow.png"
14+
dest_files=["res://.godot/imported/right-arrow.png-8f579df18e1ada04d965b123ceaf76a0.ctex"]
15+
16+
[params]
17+
18+
compress/mode=0
19+
compress/high_quality=false
20+
compress/lossy_quality=0.7
21+
compress/hdr_compression=1
22+
compress/normal_map=0
23+
compress/channel_pack=0
24+
mipmaps/generate=false
25+
mipmaps/limit=-1
26+
roughness/mode=0
27+
roughness/src_normal=""
28+
process/fix_alpha_border=true
29+
process/premult_alpha=false
30+
process/normal_map_invert_y=false
31+
process/hdr_as_srgb=false
32+
process/hdr_clamp_exposure=false
33+
process/size_limit=0
34+
detect_3d/compress_to=1

scripts/noteSystem/note.tscn

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[gd_scene load_steps=3 format=3 uid="uid://ck3bfqy30rjbq"]
2+
3+
[ext_resource type="Texture2D" uid="uid://bucvj4fquqpkr" path="res://scripts/noteSystem/assets/right-arrow.png" id="1_kubiy"]
4+
[ext_resource type="Script" path="res://scripts/noteSystem/Note.cs" id="2_gpd2w"]
5+
6+
[node name="Right-arrow" type="Sprite2D"]
7+
scale = Vector2(0.0800024, 0.0800024)
8+
texture = ExtResource("1_kubiy")
9+
script = ExtResource("2_gpd2w")

0 commit comments

Comments
 (0)