add key holddown time to enter game and add explosion effect

This commit is contained in:
interfisch 2024-12-31 17:25:01 +01:00
parent d047c52c31
commit 5194eab229
3 changed files with 79 additions and 22 deletions

View file

@ -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

View file

@ -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:

View file

@ -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<len(players):
var p=players[i]
label.text=str(OS.get_keycode_string(p.inputkey))
if (p.inputkey==flashplayer_keycode): #this player pressed their key again
if (p.inputkey==flashplayer_keycode): #this player should show an animation
if effect=="blink":
var outlinesize=min(max(0,label.get_theme_constant("outline_size")+ADD_STEP_OUTLINESIZE),MAX_OUTLINESIZE) #enlarge outline a bit
label.add_theme_constant_override("outline_size",outlinesize)
if effect=="explode":
var outlinesize=MAX_OUTLINESIZE
label.add_theme_constant_override("outline_size",outlinesize) #make outline max size
var font_size=label.get_theme_font_size("font_size")
var new_playerlist_particles_2d=playerlist_particles_2d.duplicate()
$MarginContainer.add_child(new_playerlist_particles_2d)
new_playerlist_particles_2d.position=label.position+Vector2(font_size/3,font_size*0.75) #try to center on text
new_playerlist_particles_2d.emitting=true
new_playerlist_particles_2d.emission_rect_extents=Vector2(font_size/3,font_size*0.75)*2
new_playerlist_particles_2d.color=p.color
var outlinesize=min(max(0,label.get_theme_constant("outline_size")+30),60)
label.add_theme_constant_override("outline_size",outlinesize)
label.set("theme_override_colors/font_color",p.color)
else:
label.text=""