final is here

This commit is contained in:
2025-09-08 21:58:22 +02:00
parent 2781204d6d
commit f91ae53533
20 changed files with 269 additions and 74 deletions

View File

@@ -7,6 +7,7 @@ class_name Ship
@export var TIME_INVUL := 1.0
@export var animation : AnimationPlayer
@export var target : Node2D
@export var player_2 := false
const SPEED = 25.0
const JUMP_VELOCITY = -400.0
@@ -20,13 +21,12 @@ var is_in = true
var delay_inv := 0.0
var is_currently_hit := false
func _input(event):
pass
func _ready() -> void:
delay_inv = TIME_INVUL +1
GameController.connect("player_hit", start_inv)
func _physics_process(delta: float) -> void:
delay += delta
if is_inv():
@@ -34,29 +34,32 @@ func _physics_process(delta: float) -> void:
animation.play("blink")
else:
animation.play("RESET")
horizontal = Input.get_axis("ui_up", "ui_down")
vertical = Input.get_axis("ui_left", "ui_right")
if vertical != 0:
velocity.x = move_toward(velocity.x, MAX_SPEED * vertical, SPEED)
if ! player_2:
horizontal = Input.get_axis("ui_up", "ui_down")
vertical = Input.get_axis("ui_left", "ui_right")
else:
horizontal = Input.get_axis("up_player_2", "down_player_2")
vertical = Input.get_axis("left_player_2", "right_player_2")
direction = Vector2(vertical, horizontal).normalized()
if direction.x != 0:
velocity.x = move_toward(velocity.x, MAX_SPEED * direction.x, SPEED)
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
if horizontal != 0:
velocity.y = move_toward(velocity.y, MAX_SPEED * horizontal, SPEED)
if direction.y != 0:
velocity.y = move_toward(velocity.y, MAX_SPEED * direction.y, SPEED)
else:
velocity.y = move_toward(velocity.y, 0, SPEED)
if horizontal != 0 or vertical != 0:
direction = Vector2(vertical, horizontal)
rotation = rotate_toward(rotation ,atan2(horizontal, vertical), 0.5)
rotation = rotate_toward(rotation ,atan2(horizontal, vertical), 0.4)
if Input.is_action_pressed("ui_accept") and delay >= 0.5:
if (( not player_2 and Input.is_action_pressed("ui_accept")) or ( player_2 and Input.is_action_pressed("accept_player_2"))) and delay >= 0.5:
shoot()
delay = 0
if !is_inv() and is_currently_hit:
GameController.emit_signal("player_hit")
GameController.emit_signal("player_hit", player_2)
move_and_slide()
@@ -71,5 +74,6 @@ func shoot()->void:
func is_inv() -> bool:
return delay_inv <= TIME_INVUL
func start_inv()->void:
delay_inv = 0.0
func start_inv(type : bool)->void:
if type == player_2 :
delay_inv = 0.0