first version of EU AI Act game
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
extends Control
|
||||
|
||||
var battery_positions = [Vector3(0.0, 0.0, 3.0),
|
||||
Vector3(-3.0, 0.0, -3.0),
|
||||
Vector3(0.0, 0.0, -3.0),
|
||||
Vector3(3.0, 0.0, -3.0)]
|
||||
@onready var player: CharacterBody3D = $".."
|
||||
@onready var batteries = [$Panel/SubViewportContainer/SubViewport/batteries/Battery,
|
||||
$Panel/SubViewportContainer/SubViewport/batteries/Battery2,
|
||||
$Panel/SubViewportContainer/SubViewport/batteries/Battery3,
|
||||
$Panel/SubViewportContainer/SubViewport/batteries/Battery4]
|
||||
var max_pos = 4
|
||||
var index_shown_battery = 0
|
||||
|
||||
func _ready():
|
||||
update_label()
|
||||
|
||||
func _on_arrow_left_pressed() -> void:
|
||||
index_shown_battery -= 1
|
||||
index_shown_battery = posmod(index_shown_battery, max_pos)
|
||||
for index in range(0, len(batteries)):
|
||||
var battery = batteries[index]
|
||||
var new_pos_index = posmod(index - index_shown_battery, max_pos)
|
||||
battery.position = battery_positions[new_pos_index]
|
||||
update_label()
|
||||
|
||||
|
||||
func _on_arrow_right_pressed() -> void:
|
||||
index_shown_battery += 1
|
||||
index_shown_battery = index_shown_battery % max_pos
|
||||
for index in range(0, len(batteries)):
|
||||
var battery = batteries[index]
|
||||
var new_pos_index = (index - index_shown_battery) % max_pos
|
||||
battery.position = battery_positions[new_pos_index]
|
||||
update_label()
|
||||
|
||||
func update_label() -> void:
|
||||
print(index_shown_battery)
|
||||
$Panel/BatteryLabel.text = batteries[index_shown_battery].battery_label
|
||||
|
||||
|
||||
func _on_button_pressed() -> void:
|
||||
if not player.grabbed_item:
|
||||
var child = batteries[index_shown_battery]
|
||||
remove_child(child)
|
||||
max_pos -= 1
|
||||
batteries.remove_at(index_shown_battery)
|
||||
battery_positions.remove_at(-1)
|
||||
index_shown_battery = 0
|
||||
get_tree().current_scene.add_child(child) # zurück zur Welt
|
||||
if child is RigidBody3D:
|
||||
child.freeze = false
|
||||
child.gravity_scale = 1.0
|
||||
player.interact_ray.grab(child)
|
||||
if len(batteries) > 0:
|
||||
reset_batteries()
|
||||
player.toggle_inventory()
|
||||
|
||||
func reset_batteries() -> void:
|
||||
for index in range(0, len(batteries)):
|
||||
var battery = batteries[index]
|
||||
battery.position = battery_positions[index]
|
||||
update_label()
|
||||
|
||||
|
||||
|
||||
func _unhandled_input(event: InputEvent) -> void:
|
||||
if self.visible:
|
||||
if event is InputEventKey and event.pressed:
|
||||
print(event.keycode)
|
||||
if event.keycode == KEY_ENTER:
|
||||
_on_button_pressed()
|
||||
accept_event()
|
||||
if Input.is_action_just_pressed("ui_left"):
|
||||
_on_arrow_left_pressed()
|
||||
elif Input.is_action_just_pressed("ui_right"):
|
||||
_on_arrow_right_pressed()
|
||||
Reference in New Issue
Block a user