41 lines
855 B
GDScript3
41 lines
855 B
GDScript3
|
extends Node
|
||
|
|
||
|
|
||
|
#var playerkeys: Array[int] = []
|
||
|
var players: Array[Player] = []
|
||
|
|
||
|
var userinput_prefix="inputP"
|
||
|
|
||
|
func addPlayer(key:int):
|
||
|
if not getPlayerkeys().has(key):
|
||
|
#playerkeys.append(key)
|
||
|
players.append(Player.new(key,len(players)))
|
||
|
#print("Added Key"+str(key))
|
||
|
#print("List:"+str(getPlayerkeys()))
|
||
|
|
||
|
func removeAllPlayers():
|
||
|
players=[]
|
||
|
|
||
|
func getPlayerkeys() -> Array[int]:
|
||
|
var playerkeys: Array[int] = []
|
||
|
for player in players:
|
||
|
playerkeys.append(player.inputkey)
|
||
|
return playerkeys
|
||
|
|
||
|
class Player:
|
||
|
var inputkey:int
|
||
|
var color:Color
|
||
|
|
||
|
func _init(key:int, i:int=-1):
|
||
|
inputkey=key
|
||
|
var sat = 0.8
|
||
|
var val = 0.5
|
||
|
|
||
|
if i<0:
|
||
|
color=Color.from_hsv(randf_range(0.0,1.0), sat,val,1.0)
|
||
|
else:
|
||
|
color=Color.from_hsv(fmod(0.3*i,1.0), sat,val,1.0)
|
||
|
print("i is "+str(i)+" h="+str(fmod(0.3*i,1.0))+" assigned color "+str(color))
|
||
|
|
||
|
|