Compare commits

..

No commits in common. "d1822e98b18a55a1cfa3e1fa5457f9ce5678e5bc" and "7f3c910414fb719c0e5597993983e028d5b6f56d" have entirely different histories.

5 changed files with 11 additions and 44 deletions

View file

@ -15,10 +15,6 @@ run/main_scene="uid://d3c6aioatcy20"
config/features=PackedStringArray("4.5", "GL Compatibility") config/features=PackedStringArray("4.5", "GL Compatibility")
config/icon="res://icon.svg" config/icon="res://icon.svg"
[autoload]
EventBus="*res://scenes/autoload/event_bus.tscn"
[display] [display]
window/size/viewport_width=320 window/size/viewport_width=320

View file

@ -1,6 +0,0 @@
extends Node
signal ball_hit(player: int, velocity: Vector2)
func _ready():
process_mode = Node.PROCESS_MODE_ALWAYS

View file

@ -1 +0,0 @@
uid://qk8k7twgaqtm

View file

@ -1,6 +0,0 @@
[gd_scene load_steps=2 format=3 uid="uid://bmpm30vauuo6u"]
[ext_resource type="Script" uid="uid://qk8k7twgaqtm" path="res://scenes/autoload/event_bus.gd" id="1_quhyk"]
[node name="EventBus" type="Node"]
script = ExtResource("1_quhyk")

View file

@ -24,9 +24,17 @@ func _physics_process(_delta: float) -> void:
var is_moving: bool = velocity.length() > 10 var is_moving: bool = velocity.length() > 10
if Input.is_action_pressed("hit_left") and not is_hitting: if Input.is_action_pressed("hit_left") and not is_hitting:
hit("left") if not is_hitting:
elif Input.is_action_pressed("hit_right") and not is_hitting: sprite.play('up')
hit("right") sprite.frame = 1
sprite.pause()
var hit: Area2D = preload("res://scenes/hit/hit.tscn").instantiate()
add_child(hit)
hit.timer.connect("timeout", _on_hit_end)
is_hitting = true
if is_moving: if is_moving:
if abs(velocity.x) > abs(velocity.y): if abs(velocity.x) > abs(velocity.y):
@ -48,29 +56,5 @@ func get_movement_vector() -> Vector2:
var y_mov: float = Input.get_action_strength('move_down') - Input.get_action_strength('move_up') var y_mov: float = Input.get_action_strength('move_down') - Input.get_action_strength('move_up')
return Vector2(x_mov, y_mov) return Vector2(x_mov, y_mov)
func hit(dir: String) -> void:
if not is_hitting:
sprite.play('up')
sprite.frame = 1
sprite.pause()
var sprite_texture: Texture2D = sprite.sprite_frames.get_frame_texture('up', 1)
var hit_node: Area2D = preload("res://scenes/hit/hit.tscn").instantiate()
# set position according to frame width and height
@warning_ignore("integer_division")
hit_node.global_position = global_position + Vector2(
(sprite_texture.get_width()/2)*(-1 if dir == "left" else 1),
sprite_texture.get_height()*-1
)
# flip entire node horizontally if spawning left
hit_node.scale = Vector2(-1 if dir == "left" else 1, 1)
get_parent().add_child(hit_node)
hit_node.timer.connect("timeout", _on_hit_end)
is_hitting = true
func _on_hit_end() -> void: func _on_hit_end() -> void:
is_hitting = false is_hitting = false