fix menu restart time on keypress
This commit is contained in:
parent
0b86031505
commit
786189057e
2 changed files with 12 additions and 6 deletions
|
@ -9,11 +9,16 @@ var userinput_prefix="inputP"
|
||||||
var time_elapsed=0
|
var time_elapsed=0
|
||||||
|
|
||||||
func addPlayer(key:int):
|
func addPlayer(key:int):
|
||||||
|
#return -1 if player already exists with this key. else return id of player added
|
||||||
if not getPlayerkeys().has(key):
|
if not getPlayerkeys().has(key):
|
||||||
#playerkeys.append(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("Added Key"+str(key))
|
||||||
#print("List:"+str(getPlayerkeys()))
|
#print("List:"+str(getPlayerkeys()))
|
||||||
|
return addID
|
||||||
|
else:
|
||||||
|
return -1
|
||||||
|
|
||||||
func removeAllPlayers():
|
func removeAllPlayers():
|
||||||
players=[]
|
players=[]
|
||||||
|
|
|
@ -26,10 +26,11 @@ func _unhandled_key_input(event: InputEvent) -> void:
|
||||||
if event is InputEventKey:
|
if event is InputEventKey:
|
||||||
if event.pressed:
|
if event.pressed:
|
||||||
#print("Key keycode:"+str(event.keycode))
|
#print("Key keycode:"+str(event.keycode))
|
||||||
Gamestate.addPlayer(event.keycode)
|
var addedID=Gamestate.addPlayer(event.keycode)
|
||||||
|
|
||||||
$MenuDisplay.update_playerlist(Gamestate.players)
|
$MenuDisplay.update_playerlist(Gamestate.players)
|
||||||
|
|
||||||
|
if addedID!=-1:
|
||||||
if len(Gamestate.getPlayerkeys())>=1:
|
if len(Gamestate.getPlayerkeys())>=1:
|
||||||
$Timer.start()
|
$Timer.start()
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in a new issue