teststrecke-game/scripts/car_node.gd

47 lines
1.2 KiB
GDScript3
Raw Permalink Normal View History

2024-11-03 18:16:30 +00:00
extends Node2D
2024-11-04 20:56:07 +00:00
@onready var cbcar: CharacterBody2D = $CharacterBody_Car
@onready var carbody: Sprite2D = $CharacterBody_Car/sprite_body
2024-11-03 18:16:30 +00:00
var reference_gamestateplayer
2024-11-03 18:16:30 +00:00
func getSpeed() -> float:
2024-11-04 20:56:07 +00:00
return cbcar.velocity.length()
2024-11-03 18:16:30 +00:00
func getPosition():
2024-11-04 20:56:07 +00:00
return cbcar.position
2024-11-10 00:06:25 +00:00
func getPositionLookahead(t:float):
#return position of car in t seconds
return getPosition()+cbcar.velocity*t
2024-11-03 18:16:30 +00:00
func setPosition(p:Vector2):
2024-11-04 20:56:07 +00:00
cbcar.position=p
2024-11-03 18:16:30 +00:00
func setPlayerinformation(playerid, playercolor,preference_gamestateplayer):
2024-11-04 20:56:07 +00:00
cbcar.playerid=playerid
carbody.modulate = playercolor
reference_gamestateplayer=preference_gamestateplayer
2024-11-05 07:18:14 +00:00
2024-11-11 18:09:24 +00:00
func setCheckpoints(cps,rounds):
2024-11-05 07:18:14 +00:00
cbcar.checkpoints=cps
cbcar.checkpointtimes.resize(cps.size()*rounds)
2024-11-05 07:18:14 +00:00
cbcar.checkpointtimes.fill(0.0)
2024-11-04 20:56:07 +00:00
func move_and_slide():
cbcar.move_and_slide()
func printDebug():
for i in cbcar.get_slide_collision_count():
var collision = cbcar.get_slide_collision(i)
print(""+str(cbcar.playerid)+" Collided with: "+ str( collision.get_collider().name)+" pid="+str(collision.get_collider().playerid)+" pos="+str(collision.get_collider().position))
func setRunning(r:bool):
cbcar.running=r
func getCharacterBody():
return cbcar
func hasFinished():
return cbcar.finalTime!=-1