Added rudimentary hit combo counter

This commit is contained in:
Luke Hubmayer-Werner 2021-02-07 22:57:26 +10:30
parent 458bf30b4e
commit 1297a6f342
3 changed files with 75 additions and 7 deletions

View File

@ -1,7 +1,8 @@
[gd_scene load_steps=18 format=2]
[gd_scene load_steps=21 format=2]
[ext_resource path="res://scripts/InputHandler.gd" type="Script" id=1]
[ext_resource path="res://assets/text-4k.png" type="Texture" id=2]
[ext_resource path="res://assets/fonts/Sniglet-Regular.ttf" type="DynamicFontData" id=3]
[ext_resource path="res://scripts/ScreenFilter.gd" type="Script" id=4]
[ext_resource path="res://scripts/NoteViewport.gd" type="Script" id=5]
[ext_resource path="res://scripts/NotePainter.gd" type="Script" id=6]
@ -50,10 +51,32 @@ shader_param/array_postmul = Vector3( 1, 1, 1 )
shader_param/array_sidelen = 16
shader_param/array_size = 256
[sub_resource type="CanvasItemMaterial" id=4]
[sub_resource type="DynamicFont" id=4]
size = 48
outline_size = 2
outline_color = Color( 0, 0, 0, 1 )
font_data = ExtResource( 3 )
[sub_resource type="GDScript" id=7]
script/source = "extends Label
const colors = [Color.gray, Color.lightgray, Color.aqua, Color.gold]
func _on_NoteHandler_combo_changed(value) -> void:
text = str(value)
visible = (value > 0)
add_color_override('font_color', colors[int(min(3, value/50))])
func _on_NoteHandler_finished_song(song_key, score_data) -> void:
visible = false
"
[sub_resource type="CanvasItemMaterial" id=5]
blend_mode = 4
[sub_resource type="Curve" id=5]
[sub_resource type="Curve" id=6]
min_value = -1.0
_data = [ Vector2( -1, -1 ), 0.0, 0.0, 0, 0, Vector2( 0, 0 ), 2.0, 2.0, 1, 1, Vector2( 1, 1 ), 0.0, 0.0, 0, 0 ]
@ -130,8 +153,29 @@ material = SubResource( 2 )
[node name="notelines" type="MeshInstance2D" parent="Square/NoteHandler/Viewport/Center"]
material = SubResource( 3 )
[node name="lbl_combo" type="Label" parent="Square/NoteHandler"]
visible = false
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
margin_left = -20.0
margin_top = -7.0
margin_right = 20.0
margin_bottom = 7.0
grow_horizontal = 2
grow_vertical = 2
custom_fonts/font = SubResource( 4 )
text = "0"
align = 1
valign = 1
script = SubResource( 7 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Painter" type="Control" parent="Square"]
material = SubResource( 4 )
material = SubResource( 5 )
anchor_right = 1.0
anchor_bottom = 1.0
script = ExtResource( 6 )
@ -144,7 +188,7 @@ anchor_right = 1.0
anchor_bottom = 1.0
NoteHandlerPath = NodePath("../NoteHandler")
ReceptorsPath = NodePath("../Receptors")
ease_curve = SubResource( 5 )
ease_curve = SubResource( 6 )
[node name="Bezel" type="Control" parent="Square"]
anchor_right = 1.0
@ -163,5 +207,7 @@ __meta__ = {
}
[connection signal="item_rect_changed" from="Square" to="Square/NoteHandler/Viewport" method="_on_Square_item_rect_changed"]
[connection signal="combo_changed" from="Square/NoteHandler" to="Square/NoteHandler/lbl_combo" method="_on_NoteHandler_combo_changed"]
[connection signal="finished_song" from="Square/NoteHandler" to="Square/NoteHandler/lbl_combo" method="_on_NoteHandler_finished_song"]
[connection signal="column_pressed" from="Square/InputHandler" to="Square/NoteHandler" method="_on_InputHandler_column_pressed"]
[connection signal="column_released" from="Square/InputHandler" to="Square/NoteHandler" method="_on_InputHandler_column_released"]

View File

@ -393,8 +393,9 @@ func _draw_score_screen(center: Vector2) -> Array:
ScoreText.score_sub = '%2.3f%%'%(overall_score*100.0)
ScoreText.update()
draw_string_centered(TitleFont, center+Vector2(0, y3+y_spacing*7), 'Early : Late')
draw_string_centered(TitleFont, center+Vector2(0, y3+y_spacing*8), '%3d%% : %3d%%'%[notecount_early*100/max(notecount_total, 1), notecount_late*100/max(notecount_total, 1)])
draw_string_centered(TitleFont, center+Vector2(-150, y3+y_spacing*7), 'Early : Late')
draw_string_centered(TitleFont, center+Vector2(-150, y3+y_spacing*8), '%3d%% : %3d%%'%[notecount_early*100/max(notecount_total, 1), notecount_late*100/max(notecount_total, 1)])
draw_string_centered(TitleFont, center+Vector2(150, y3+y_spacing*7.5), 'Max Combo: %d'%scorescreen_score_data.get('max_combo', 0)) # Safety for older saves
var txt_offset = Vector2.DOWN*10*f_scale
var rect_songs := Rect2(center+Vector2(-100.0, 300.0)*f_scale, Vector2(400.0, 100.0)*f_scale)

View File

@ -4,6 +4,7 @@ var screen_height := 1080
# This script will draw all note events.
signal finished_song(song_key, score_data)
signal combo_changed(value)
var running := false
var song_key = ''
@ -15,6 +16,7 @@ onready var SlideTrailHandler = $'Viewport/Center/SlideTrailHandler'
onready var JudgeText = $'Viewport/Center/JudgeText'
onready var notelines = $'Viewport/Center/notelines'
onready var meshinstance = $'Viewport/Center/meshinstance'
onready var lbl_combo = $lbl_combo
const SQRT2 := sqrt(2)
const DEG45 := deg2rad(45.0)
@ -71,6 +73,16 @@ const TextJudgementStraight := {
'MISS': TextWord.MISS + TextStyle.STRAIGHT
}
var current_combo := 0
func increment_combo():
current_combo += 1
emit_signal('combo_changed', current_combo) # Make text or something?
func end_combo(no_reset := false):
scores['max_combo'] = max(current_combo, scores.get('max_combo', 0))
if not no_reset: # A bit hacky, but we want the ability to cash in the max combo without resetting the counter for... playlist reasons?
current_combo = 0
emit_signal('combo_changed', 0) # Womp womp effect somewhere?
func initialise_scores():
scores = {}
for type in [Note.NOTE_TAP, Note.NOTE_HOLD, Note.NOTE_STAR]:
@ -82,6 +94,8 @@ func initialise_scores():
scores[Note.RELEASE_SCORE_TYPES[type]] = {}
for key in TextJudgement:
scores[Note.RELEASE_SCORE_TYPES[type]][key] = 0
scores['max_combo'] = 0
current_combo = 0
func make_text_mesh(mesh: ArrayMesh, text_id: int, pos: Vector2, angle: float, alpha:=1.0, scale:=1.0):
var r := GameTheme.judge_text_size2 * scale
@ -219,6 +233,11 @@ func activate_note(note, judgement):
Note.NOTE_HOLD:
note.is_held = true
if abs(judgement) < 3:
increment_combo() # For now, only hits count toward building and maintaining combo. Releases and slides do not.
else:
end_combo()
func activate_note_release(note, judgement):
# Only for Hold, Slide
scores[Note.RELEASE_SCORE_TYPES[note.type]][judgement] += 1
@ -582,6 +601,7 @@ func _process(delta):
elif note.time_activated == INF: # Check if notes have been missed
if ((t-note.time_hit) > miss_time) and not note.missed:
note.missed = true
end_combo()
make_judgement_column('MISS', note.column)
scores[note.type]['MISS'] += 1
if Note.RELEASE_SCORE_TYPES.has(note.type):
@ -624,6 +644,7 @@ func _process(delta):
):
self.running = false
self.timers_set = false
end_combo(true)
emit_signal('finished_song', song_key, scores)
# Redraw