teststrecke-game/scripts/gamestate.gd

57 lines
1.1 KiB
GDScript3
Raw Normal View History

2024-11-03 18:16:30 +00:00
extends Node
#var playerkeys: Array[int] = []
var players: Array[Player] = []
var userinput_prefix="inputP"
var time_elapsed=0
2024-11-03 18:16:30 +00:00
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=[]
2024-11-04 18:55:13 +00:00
2024-11-03 18:16:30 +00:00
func getPlayerkeys() -> Array[int]:
var playerkeys: Array[int] = []
for player in players:
playerkeys.append(player.inputkey)
return playerkeys
2024-11-04 18:55:13 +00:00
func getPlayers() -> Array[Player]:
return players
2024-11-03 18:16:30 +00:00
class Player:
var inputkey:int
var color:Color
func _init(key:int, i:int=-1):
inputkey=key
2024-11-04 20:56:07 +00:00
var sat = 1.0
var val = 0.7
2024-11-03 18:16:30 +00:00
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