fix menu restart time on keypress

This commit is contained in:
interfisch 2024-11-09 12:07:59 +01:00
parent 0b86031505
commit 786189057e
2 changed files with 12 additions and 6 deletions

View file

@ -9,11 +9,16 @@ var userinput_prefix="inputP"
var time_elapsed=0
func addPlayer(key:int):
#return -1 if player already exists with this key. else return id of player added
if not getPlayerkeys().has(key):
#playerkeys.append(key)
players.append(Player.new(key,len(players)))
var addID=len(players)
players.append(Player.new(key,addID))
#print("Added Key"+str(key))
#print("List:"+str(getPlayerkeys()))
return addID
else:
return -1
func removeAllPlayers():
players=[]

View file

@ -26,14 +26,15 @@ func _unhandled_key_input(event: InputEvent) -> void:
if event is InputEventKey:
if event.pressed:
#print("Key keycode:"+str(event.keycode))
Gamestate.addPlayer(event.keycode)
var addedID=Gamestate.addPlayer(event.keycode)
$MenuDisplay.update_playerlist(Gamestate.players)
if len(Gamestate.getPlayerkeys())>=1:
$Timer.start()
else:
$Timer.stop()
if addedID!=-1:
if len(Gamestate.getPlayerkeys())>=1:
$Timer.start()
else:
$Timer.stop()