diff --git a/scenes/menu.tscn b/scenes/menu.tscn index f75738d..f9056b8 100644 --- a/scenes/menu.tscn +++ b/scenes/menu.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=15 format=3 uid="uid://b1uhymisifcho"] +[gd_scene load_steps=16 format=3 uid="uid://b1uhymisifcho"] [ext_resource type="Script" path="res://scripts/menu.gd" id="1_fushn"] [ext_resource type="Script" path="res://scripts/menudisplay.gd" id="2_jc4pv"] @@ -12,6 +12,10 @@ [ext_resource type="Texture2D" uid="uid://bst8p5s1sgurm" path="res://sprites/menu_bg.png" id="10_equk1"] [ext_resource type="Texture2D" uid="uid://drgqjl330tj2p" path="res://scenes/map_preview/no_preview.png" id="11_3sx36"] +[sub_resource type="Curve" id="Curve_kioen"] +_data = [Vector2(0, 1), 0.0, 0.0, 0, 0, Vector2(1, 0), 0.0, 0.0, 0, 0] +point_count = 2 + [sub_resource type="Animation" id="Animation_7lydi"] length = 0.001 tracks/0/type = "value" @@ -131,6 +135,26 @@ layout_mode = 2 theme_override_font_sizes/font_size = 40 uppercase = true +[node name="PlayerlistParticles2D" type="CPUParticles2D" parent="MenuDisplay/MarginContainer"] +position = Vector2(-317, -51.245) +emitting = false +amount = 200 +lifetime = 3.0 +one_shot = true +preprocess = 0.1 +explosiveness = 1.0 +lifetime_randomness = 0.4 +fract_delta = false +emission_shape = 3 +emission_rect_extents = Vector2(20, 5) +direction = Vector2(0, -1) +spread = 180.0 +initial_velocity_min = 20.0 +initial_velocity_max = 500.0 +scale_amount_min = 2.0 +scale_amount_max = 10.0 +scale_amount_curve = SubResource("Curve_kioen") + [node name="btn_fullscreen" type="CheckButton" parent="MenuDisplay"] offset_left = 845.0 offset_top = 540.0 diff --git a/scripts/menu.gd b/scripts/menu.gd index 38f5d7d..b9ac73c 100644 --- a/scripts/menu.gd +++ b/scripts/menu.gd @@ -1,10 +1,13 @@ extends Node - @onready var countdown: Label = $MenuDisplay/countdown @onready var btn_fullscreen = $MenuDisplay/btn_fullscreen @onready var btn_save_whitelist= $MenuDisplay/btn_save_whitelist var keywhitelist +var keyHolddownQueue = {} + +const KEY_HOLDDOWN_TO_ENTER_TIME=500 #in milliseconds + func _ready(): removeAssignedKeys() Gamestate.removeAllPlayers() @@ -44,22 +47,17 @@ func removeAssignedKeys(): InputMap.erase_action(action) func _unhandled_key_input(event: InputEvent) -> void: + var currentmsecs=Time.get_ticks_msec() + if event is InputEventKey: - if event.pressed: - if keywhitelist.has(event.keycode) or keywhitelist.size()<1: - print("Key keycode:"+str(event.keycode)) - var addedID=Gamestate.addPlayer(event.keycode) + if keywhitelist.has(event.keycode) or keywhitelist.size()<1: #is key whitelisted? + if event.is_pressed() and not keyHolddownQueue.has(event.keycode) and not Gamestate.getPlayerkeys().has(event.keycode): #key just pressed and not already added + keyHolddownQueue[event.keycode]=currentmsecs + if event.is_released() and keyHolddownQueue.has(event.keycode): + keyHolddownQueue.erase(event.keycode) - $MenuDisplay.update_playerlist(Gamestate.players,event.keycode) - - if addedID!=-1: #player was added - if len(Gamestate.getPlayerkeys())>=1: - $Timer.start() - else: - $Timer.stop() - else: - print("keycode "+str(event.keycode)+" is not whitelisted") - + if event.is_pressed() and Gamestate.getPlayerkeys().has(event.keycode): #key pressed and player already added + $MenuDisplay.update_playerlist(Gamestate.players,event.keycode,"blink") func _on_timer_timeout() -> void: #Start Game @@ -70,6 +68,26 @@ func _on_timer_timeout() -> void: #Start Game func _process(delta: float) -> void: + var currentmsecs=Time.get_ticks_msec() + + for queuedKey in keyHolddownQueue: + if currentmsecs-keyHolddownQueue[queuedKey]>KEY_HOLDDOWN_TO_ENTER_TIME: #and pressed long enough + keyHolddownQueue.erase(queuedKey) + + #if keywhitelist.has(event.keycode) or keywhitelist.size()<1: #is key whitelisted? + print("Key added. keycode:"+str(queuedKey)) + var addedID=Gamestate.addPlayer(queuedKey) + + $MenuDisplay.update_playerlist(Gamestate.players,queuedKey,"explode") + + + if addedID!=-1: #player was added + if len(Gamestate.getPlayerkeys())>=1: + $Timer.start() + else: + $Timer.stop() + + if $Timer.is_stopped() or $Timer.time_left>3.5: $MenuDisplay.updateCountdown(-1) #do not display countdown else: diff --git a/scripts/menudisplay.gd b/scripts/menudisplay.gd index 7ee14e5..8e12dda 100644 --- a/scripts/menudisplay.gd +++ b/scripts/menudisplay.gd @@ -1,5 +1,8 @@ extends Node2D +const ADD_STEP_OUTLINESIZE=30 +const MAX_OUTLINESIZE=60 +@onready var playerlist_particles_2d: CPUParticles2D = $MarginContainer/PlayerlistParticles2D # Called when the node enters the scene tree for the first time. func _ready() -> void: @@ -13,20 +16,32 @@ func updateCountdown(t): else: $countdown.visible=true $countdown.text=str(t) - -func update_playerlist(players:Array[Gamestate.Player],flashplayer_keycode=-1): + +func update_playerlist(players:Array[Gamestate.Player],flashplayer_keycode=-1,effect="blink"): var Playerlabels=$MarginContainer/VBoxContainer_Playerlist.get_children() var i=0 for label in Playerlabels: - #print(type_string(typeof(label))) if i