31 lines
807 B
GDScript3
31 lines
807 B
GDScript3
|
|
extends Node2D
|
||
|
|
|
||
|
|
@export var ball: CharacterBody2D
|
||
|
|
@export var score_label: Label
|
||
|
|
|
||
|
|
var score_links : int = 0
|
||
|
|
var score_rechts : int = 0
|
||
|
|
|
||
|
|
func _ready() -> void:
|
||
|
|
# Automatischer Fallback, falls im Inspektor die Zuweisung vergessen wurde
|
||
|
|
if not ball: ball = $Ball
|
||
|
|
if not score_label: score_label = $ScoreLabel
|
||
|
|
update_score_display()
|
||
|
|
|
||
|
|
func _process(_delta: float) -> void:
|
||
|
|
# Prüfen, ob der Ball links aus dem Bildschirm fliegt
|
||
|
|
if ball.global_position.x < 0:
|
||
|
|
score_rechts += 1
|
||
|
|
update_score_display()
|
||
|
|
ball.reset_ball()
|
||
|
|
|
||
|
|
# Prüfen, ob der Ball rechts aus dem Bildschirm fliegt
|
||
|
|
elif ball.global_position.x > 1152:
|
||
|
|
score_links += 1
|
||
|
|
update_score_display()
|
||
|
|
ball.reset_ball()
|
||
|
|
|
||
|
|
func update_score_display() -> void:
|
||
|
|
if score_label:
|
||
|
|
score_label.text = str(score_links) + " : " + str(score_rechts)
|