teststrecke-game/scripts/gamestate.gd

66 lines
1.3 KiB
GDScript

extends Node
#var playerkeys: Array[int] = []
var players: Array[Player] = []
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)
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=[]
func getPlayerkeys() -> Array[int]:
var playerkeys: Array[int] = []
for player in players:
playerkeys.append(player.inputkey)
return playerkeys
func getPlayers() -> Array[Player]:
return players
class Player:
var inputkey:int
var color:Color
var id:int
func _init(key:int, i:int=-1):
inputkey=key
id=i
var sat = 1.0
var val = 0.7
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))
func startGame():
for player in players:
player.setRunning(true)
func addTimeElapsed(delta):
time_elapsed+=delta
func getTimeElapsed():
return time_elapsed
func resetTimeElapsed():
time_elapsed=0