keep playercolors for next round
This commit is contained in:
parent
786189057e
commit
c1992fcfc1
2 changed files with 32 additions and 14 deletions
|
@ -134,9 +134,11 @@ func _process(delta: float) -> void:
|
||||||
|
|
||||||
if game_ended:
|
if game_ended:
|
||||||
var anyplayerkeypressed=false
|
var anyplayerkeypressed=false
|
||||||
|
var id=0
|
||||||
for p in Gamestate.getPlayers():
|
for p in Gamestate.getPlayers():
|
||||||
if Input.is_action_pressed(Gamestate.userinput_prefix+str(p.id)):
|
if Input.is_action_pressed(Gamestate.userinput_prefix+str(id)):
|
||||||
anyplayerkeypressed=true
|
anyplayerkeypressed=true
|
||||||
|
id+=1
|
||||||
if anyplayerkeypressed and timer_close.time_left<time_close_keypressed:
|
if anyplayerkeypressed and timer_close.time_left<time_close_keypressed:
|
||||||
timer_close.wait_time=time_close_keypressed #set time back
|
timer_close.wait_time=time_close_keypressed #set time back
|
||||||
timer_close.stop() #prepare for restarting at this time
|
timer_close.stop() #prepare for restarting at this time
|
||||||
|
|
|
@ -3,24 +3,40 @@ extends Node
|
||||||
|
|
||||||
#var playerkeys: Array[int] = []
|
#var playerkeys: Array[int] = []
|
||||||
var players: Array[Player] = []
|
var players: Array[Player] = []
|
||||||
|
var last_players: Array[Player] = []
|
||||||
|
|
||||||
var userinput_prefix="inputP"
|
var userinput_prefix="inputP"
|
||||||
|
|
||||||
var time_elapsed=0
|
var time_elapsed=0
|
||||||
|
|
||||||
|
func checkColoriFree(i):
|
||||||
|
var free=true
|
||||||
|
for p in players:
|
||||||
|
if p.colori==i: #already taken
|
||||||
|
free=false
|
||||||
|
return free
|
||||||
|
|
||||||
|
|
||||||
func addPlayer(key:int):
|
func addPlayer(key:int):
|
||||||
#return -1 if player already exists with this key. else return id of player added
|
#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): #key is not yet registered
|
||||||
#playerkeys.append(key)
|
var prefered_colori=0
|
||||||
var addID=len(players)
|
for p in last_players:
|
||||||
players.append(Player.new(key,addID))
|
if p.inputkey==key: #key was used in last round
|
||||||
#print("Added Key"+str(key))
|
prefered_colori=p.colori
|
||||||
#print("List:"+str(getPlayerkeys()))
|
|
||||||
return addID
|
#check if color is free, else assign next free
|
||||||
|
while not checkColoriFree(prefered_colori):
|
||||||
|
prefered_colori+=1
|
||||||
|
|
||||||
|
players.append(Player.new(key,prefered_colori))
|
||||||
|
|
||||||
|
return prefered_colori
|
||||||
else:
|
else:
|
||||||
return -1
|
return -1
|
||||||
|
|
||||||
func removeAllPlayers():
|
func removeAllPlayers():
|
||||||
|
last_players=players
|
||||||
players=[]
|
players=[]
|
||||||
|
|
||||||
|
|
||||||
|
@ -37,19 +53,19 @@ func getPlayers() -> Array[Player]:
|
||||||
class Player:
|
class Player:
|
||||||
var inputkey:int
|
var inputkey:int
|
||||||
var color:Color
|
var color:Color
|
||||||
var id:int
|
var colori
|
||||||
|
|
||||||
func _init(key:int, i:int=-1):
|
func _init(key:int, pcolori:int=-1):
|
||||||
inputkey=key
|
inputkey=key
|
||||||
id=i
|
colori=pcolori
|
||||||
var sat = 1.0
|
var sat = 1.0
|
||||||
var val = 0.7
|
var val = 0.7
|
||||||
|
|
||||||
if i<0:
|
if colori<0:
|
||||||
color=Color.from_hsv(randf_range(0.0,1.0), sat,val,1.0)
|
color=Color.from_hsv(randf_range(0.0,1.0), sat,val,1.0)
|
||||||
else:
|
else:
|
||||||
color=Color.from_hsv(fmod(0.3*i,1.0), sat,val,1.0)
|
color=Color.from_hsv(fmod(0.3*colori,1.0), sat,val,1.0)
|
||||||
print("i is "+str(i)+" h="+str(fmod(0.3*i,1.0))+" assigned color "+str(color))
|
print("i is "+str(colori)+" h="+str(fmod(0.3*colori,1.0))+" assigned color "+str(color))
|
||||||
|
|
||||||
|
|
||||||
func startGame():
|
func startGame():
|
||||||
|
|
Loading…
Reference in a new issue