monster spawner and moving to the camera direction

This commit is contained in:
Luca 2024-09-16 19:58:43 +02:00
parent 8c29b8bffd
commit b20f3b5124
821 changed files with 1611 additions and 1409 deletions

View file

@ -1,17 +1,35 @@
extends Panel
@onready var talk_a_texture = preload("res://resources/textures/Xbox Series/Vector/xbox_button_a.svg")
@onready var drag_texture = preload("res://resources/textures/Generic/Vector/generic_button_circle.svg")
var thumbstick_size_factor = 0.5
@onready var talk_a_texture = preload("res://assets/textures/Xbox Series/Vector/xbox_button_a.svg")
@onready var drag_texture = preload("res://assets/textures/Generic/Vector/generic_button_circle.svg")
@onready var thumbstick = $Thumbstick
var thumbstick_size_factor = 0.5
var middle: Vector2 = Vector2(100, 100)
var touch_start: Vector2 = Vector2(0, 0)
var jump_threshold: float = 10.0
var previous: Vector2 = Vector2(0, 0)
var delta: float = 0.0
var pressed: bool = false
# debug rotation
var rotation_delta: Vector2 = Vector2(0, 0)
func _ready() -> void:
thumbstick.custom_minimum_size = Vector2(size.x, size.x) * thumbstick_size_factor
thumbstick.position = middle - thumbstick.size / 2.0
print(thumbstick)
func _unhandled_input(event: InputEvent) -> void:
if event is not InputEventScreenDrag:
return
if event is InputEventScreenDrag:
var touch_position = event.position
rotation_delta = get_viewport_rect().size / 2 - touch_position
simulate_joystick_motion(JOY_AXIS_RIGHT_X, -rotation_delta.x * 0.4, 0)
print(rotation_delta)
func _on_gui_input(event: InputEvent) -> void:
if event is not InputEventScreenTouch and event is not InputEventScreenDrag:
return
@ -38,17 +56,10 @@ func _on_gui_input(event: InputEvent) -> void:
var touch_position = event.position
thumbstick.position = touch_position - thumbstick.size / 2.0
var delta = middle - touch_position
var direction = delta.normalized()
simulate_joystick_motion(0, -direction.x)
simulate_joystick_motion(1, -direction.y)
#if previous.y > thumbstick.position.y + jump_threshold:
# print("jump")
# Input.action_press("ui_accept")
#print(previous)
#previous = thumbstick.position
var _delta = middle - touch_position
var direction = _delta.normalized()
simulate_joystick_motion(JOY_AXIS_LEFT_X, -direction.x)
simulate_joystick_motion(JOY_AXIS_LEFT_Y, -direction.y)
func simulate_joystick_motion(axis: int, value: float, device_id: int = 0) -> void:
var joystick_event = InputEventJoypadMotion.new()
@ -61,6 +72,8 @@ func simulate_joystick_motion(axis: int, value: float, device_id: int = 0) -> vo
func _on_resized() -> void:
print("Size changed to %s" % size)
middle = size / 2.0
custom_minimum_size = Vector2(size.x, size.x)
thumbstick = get_node("Thumbstick")
#if thumbstick:
thumbstick.custom_minimum_size = Vector2(size.x, size.x) * thumbstick_size_factor
thumbstick.position = middle - thumbstick.size / 2.0