98 lines
2.5 KiB
GDScript
98 lines
2.5 KiB
GDScript
extends Node
|
|
## Prüft Bewegungs- und Blickrichtung gegen die Kamera-Achsen.
|
|
var main
|
|
var step := 0
|
|
var wait := 0.0
|
|
var ok := 0
|
|
var fail := 0
|
|
var pos0 := Vector3.ZERO
|
|
var fwd0 := Vector3.ZERO
|
|
var right0 := Vector3.ZERO
|
|
|
|
func chk(n: String, c: bool, i := "") -> void:
|
|
if c: ok += 1; print(" OK %s %s" % [n, i])
|
|
else: fail += 1; print(" FAIL %s %s" % [n, i])
|
|
|
|
func _key(c: int, d: bool) -> void:
|
|
var e := InputEventKey.new(); e.physical_keycode = c; e.keycode = c; e.pressed = d
|
|
Input.parse_input_event(e)
|
|
|
|
func _mouse(dx: float, dy: float) -> void:
|
|
var e := InputEventMouseMotion.new()
|
|
e.relative = Vector2(dx, dy)
|
|
e.position = get_viewport().get_visible_rect().size * 0.5
|
|
e.global_position = e.position
|
|
Input.parse_input_event(e)
|
|
|
|
func snap() -> void:
|
|
var c = main.player.camera
|
|
pos0 = main.player.global_position
|
|
fwd0 = -c.global_basis.z # Blickrichtung
|
|
right0 = c.global_basis.x # Bildschirm rechts
|
|
|
|
func moved() -> Vector3:
|
|
return main.player.global_position - pos0
|
|
|
|
func _process(d):
|
|
if main == null:
|
|
main = get_tree().current_scene
|
|
return
|
|
if not main.started:
|
|
main._start_solo()
|
|
return
|
|
if wait > 0.0:
|
|
wait -= d
|
|
return
|
|
var p = main.player
|
|
match step:
|
|
0:
|
|
# Freie Fläche im Personenwagen, quer zur Fahrtrichtung schauen
|
|
var car = main.train.cars[1]
|
|
p.s = car.center_s
|
|
p.x = 0.0
|
|
p.yaw = 0.0
|
|
p.pitch = 0.0
|
|
wait = 0.3
|
|
1:
|
|
snap(); _key(KEY_W, true); wait = 0.5
|
|
2:
|
|
_key(KEY_W, false)
|
|
chk("W läuft nach vorn", moved().dot(fwd0) > 0.2,
|
|
"%.2f" % moved().dot(fwd0))
|
|
wait = 0.3
|
|
3:
|
|
snap(); _key(KEY_S, true); wait = 0.5
|
|
4:
|
|
_key(KEY_S, false)
|
|
chk("S läuft rückwärts", moved().dot(fwd0) < -0.2,
|
|
"%.2f" % moved().dot(fwd0))
|
|
wait = 0.3
|
|
5:
|
|
snap(); _key(KEY_D, true); wait = 0.4
|
|
6:
|
|
_key(KEY_D, false)
|
|
chk("D läuft nach rechts", moved().dot(right0) > 0.15,
|
|
"rechts=%.2f (negativ = falsche Seite)" % moved().dot(right0))
|
|
wait = 0.3
|
|
7:
|
|
snap(); _key(KEY_A, true); wait = 0.4
|
|
8:
|
|
_key(KEY_A, false)
|
|
chk("A läuft nach links", moved().dot(right0) < -0.15,
|
|
"rechts=%.2f" % moved().dot(right0))
|
|
wait = 0.3
|
|
9:
|
|
snap(); _mouse(150.0, 0.0); wait = 0.3
|
|
10:
|
|
var f = -p.camera.global_basis.z
|
|
chk("Maus rechts dreht nach rechts", f.dot(right0) > 0.1,
|
|
"%.2f" % f.dot(right0))
|
|
snap(); _mouse(0.0, 150.0); wait = 0.3
|
|
11:
|
|
var f2 = -p.camera.global_basis.z
|
|
chk("Maus runter schaut runter", f2.y < fwd0.y - 0.05,
|
|
"y %.2f -> %.2f" % [fwd0.y, f2.y])
|
|
print("== %d ok, %d fail ==" % [ok, fail])
|
|
get_tree().quit(1 if fail > 0 else 0)
|
|
step += 1
|