Skip to content

Commit e0b2063

Browse files
committed
added note queue system
two notes will be displayed to the player, the one in the circle will be the next note that will be placed. currently supports "single" and "double" notes, where double notes are supposed to eventually give double points.
1 parent 2db3f63 commit e0b2063

8 files changed

Lines changed: 214 additions & 0 deletions

File tree

scenes/CustomNotes/NoteQueue.cs

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using Godot;
4+
5+
public partial class NoteQueue : Node
6+
{
7+
[Export]
8+
private Sprite2D _currentNote;
9+
10+
[Export]
11+
private Sprite2D _nextNote;
12+
13+
private Queue<string> _noteQueue = new Queue<string>();
14+
private Dictionary<string, Texture2D> _noteSprites = new Dictionary<string, Texture2D>();
15+
16+
public override void _Ready()
17+
{
18+
_noteSprites["single"] = GD.Load<Texture2D>(
19+
"res://scenes/CustomNotes/assets/single_note.png"
20+
);
21+
_noteSprites["double"] = GD.Load<Texture2D>(
22+
"res://scenes/CustomNotes/assets/double_note.png"
23+
);
24+
25+
UpdateQueue();
26+
}
27+
28+
public void AddNoteToQueue(string noteType)
29+
{
30+
_noteQueue.Enqueue(noteType);
31+
UpdateQueue();
32+
}
33+
34+
//returns current note, and removes it from the queue
35+
public string GetCurrentNote()
36+
{
37+
if (_noteQueue.Count > 0)
38+
{
39+
string currentNoteName = _noteQueue.Dequeue();
40+
UpdateQueue();
41+
return currentNoteName;
42+
}
43+
return null;
44+
}
45+
46+
private void UpdateQueue()
47+
{
48+
if (_noteQueue.Count > 0 && _noteSprites.ContainsKey(_noteQueue.Peek()))
49+
_currentNote.Texture = _noteSprites[_noteQueue.Peek()];
50+
else
51+
_currentNote.Texture = null;
52+
53+
if (_noteQueue.Count > 1)
54+
{
55+
string[] notes = _noteQueue.ToArray();
56+
if (_noteSprites.ContainsKey(notes[1]))
57+
_nextNote.Texture = _noteSprites[notes[1]];
58+
else
59+
_nextNote.Texture = null;
60+
}
61+
else
62+
{
63+
_nextNote.Texture = null;
64+
}
65+
}
66+
67+
//Fisher-Yates shuffle from: https://stackoverflow.com/a/1262619
68+
public void ScrambleQueue()
69+
{
70+
List<string> tempList = new List<string>(_noteQueue);
71+
Random rng = new Random();
72+
73+
int n = tempList.Count;
74+
while (n > 1)
75+
{
76+
n--;
77+
int k = rng.Next(n + 1);
78+
(tempList[k], tempList[n]) = (tempList[n], tempList[k]);
79+
}
80+
81+
_noteQueue = new Queue<string>(tempList);
82+
}
83+
84+
//TODO: should work, in order to run in game use
85+
// noteQueueInstance.AddNoteToQueue("single");
86+
}

scenes/CustomNotes/NoteQueue.tscn

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
[gd_scene load_steps=5 format=3 uid="uid://bvhpon5liybd1"]
2+
3+
[ext_resource type="Script" path="res://scenes/CustomNotes/NoteQueue.cs" id="1_jeqam"]
4+
[ext_resource type="Texture2D" uid="uid://cnyr5usjdv0ni" path="res://scenes/CustomNotes/assets/temp_note_queue.png" id="2_0p21a"]
5+
[ext_resource type="Texture2D" uid="uid://c3chrsxrulapd" path="res://scenes/CustomNotes/assets/single_note.png" id="3_ewo1s"]
6+
[ext_resource type="Texture2D" uid="uid://caw70lr5e1yiq" path="res://scenes/CustomNotes/assets/double_note.png" id="4_7sgy6"]
7+
8+
[node name="NoteQueue" type="Control"]
9+
layout_mode = 3
10+
anchors_preset = 15
11+
anchor_right = 1.0
12+
anchor_bottom = 1.0
13+
grow_horizontal = 2
14+
grow_vertical = 2
15+
script = ExtResource("1_jeqam")
16+
17+
[node name="NoteQueueSprite" type="Sprite2D" parent="."]
18+
texture = ExtResource("2_0p21a")
19+
20+
[node name="CurrentNote" type="Sprite2D" parent="."]
21+
position = Vector2(-14, -1)
22+
texture = ExtResource("3_ewo1s")
23+
24+
[node name="NextNote" type="Sprite2D" parent="."]
25+
position = Vector2(16, -2)
26+
texture = ExtResource("4_7sgy6")
637 Bytes
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://caw70lr5e1yiq"
6+
path="res://.godot/imported/double_note.png-b077a9744f626fbc60d331cfc2e231a0.ctex"
7+
metadata={
8+
"vram_texture": false
9+
}
10+
11+
[deps]
12+
13+
source_file="res://scenes/CustomNotes/assets/double_note.png"
14+
dest_files=["res://.godot/imported/double_note.png-b077a9744f626fbc60d331cfc2e231a0.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
612 Bytes
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://c3chrsxrulapd"
6+
path="res://.godot/imported/single_note.png-7542bb1712899b622105d29cce049bce.ctex"
7+
metadata={
8+
"vram_texture": false
9+
}
10+
11+
[deps]
12+
13+
source_file="res://scenes/CustomNotes/assets/single_note.png"
14+
dest_files=["res://.godot/imported/single_note.png-7542bb1712899b622105d29cce049bce.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
4.32 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://cnyr5usjdv0ni"
6+
path="res://.godot/imported/temp_note_queue.png-e563d517d16e6739ec71ecb1d9b4ade7.ctex"
7+
metadata={
8+
"vram_texture": false
9+
}
10+
11+
[deps]
12+
13+
source_file="res://scenes/CustomNotes/assets/temp_note_queue.png"
14+
dest_files=["res://.godot/imported/temp_note_queue.png-e563d517d16e6739ec71ecb1d9b4ade7.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

0 commit comments

Comments
 (0)