From 5083b945aa6e97c5513695cb79b3844809024aec Mon Sep 17 00:00:00 2001 From: Luna Brovchuk Date: Sun, 1 Oct 2023 15:45:32 +0200 Subject: [PATCH] "Fix" Line --- src/models/enemies/bat/Bat.tscn | 1 + src/models/player/player.gd | 29 +++++++++++++++-------------- src/scenes/game/Game.tscn | 10 ++++------ 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/models/enemies/bat/Bat.tscn b/src/models/enemies/bat/Bat.tscn index e60b400..ed748fd 100644 --- a/src/models/enemies/bat/Bat.tscn +++ b/src/models/enemies/bat/Bat.tscn @@ -10,6 +10,7 @@ extents = Vector2( 4, 3 ) extents = Vector2( 6, 4 ) [node name="Bat" type="KinematicBody2D" groups=["bat", "enemy"]] +z_index = 1 collision_layer = 2 collision_mask = 2 script = ExtResource( 2 ) diff --git a/src/models/player/player.gd b/src/models/player/player.gd index 33233f2..c974b62 100644 --- a/src/models/player/player.gd +++ b/src/models/player/player.gd @@ -1,5 +1,6 @@ extends KinematicBody2D +onready var bullet_preload = preload("res://src/models/bullet/Bullet.tscn") var outline_material = load("res://res/shaders/outline_material.tres") var speed_multiplier: float = 1.0 var invincibility_timer = .0 @@ -9,13 +10,13 @@ var target: EnemyClass var slowed = false var speed = 100 -onready var bullet = preload("res://src/models/bullet/Bullet.tscn") -var bullet_instance +var draw_node +var bullet func _process(_delta): if Input.is_action_just_pressed("shoot"): _shoot() - + update() func get_input(): var input_direction = Input.get_vector("left", "right", "up", "down") @@ -40,6 +41,17 @@ func area_entered(area): invincible = true invincibility_timer = .0 +func _shoot(): + bullet = bullet_preload.instance() + get_parent().add_child(bullet) + bullet.global_position.x = self.global_position.x + 12 + bullet.global_position.y = self.global_position.y - 4 + +func _draw(): + if target != null: + var dist2enemy = position.distance_to(target.global_position) + draw_line(Vector2(12, 8), target.global_position - self.global_position + Vector2(8, 7), Color("ffde00")) + func _physics_process(delta): get_input() @@ -63,14 +75,3 @@ func _physics_process(delta): velocity = move_and_slide(velocity * speed_multiplier) choose_target() target.material = outline_material - -func _shoot(): - bullet_instance = bullet.instance() - get_parent().add_child(bullet_instance) - bullet_instance.global_position.x = get_node("../Player").global_position.x + 12 - bullet_instance.global_position.y = get_node("../Player").global_position.y - 4 - -func _draw(): - var distance_2_enemy = position.distance_to(Vector2(100, 100)) - draw_line(Vector2(12, 8), Vector2(distance_2_enemy * cos(self.global_position.x), distance_2_enemy * sin(self.global_position.y)), Color(255, 255, 255)) - #TODO replace self.global_position.x,y to enemy x,y diff --git a/src/scenes/game/Game.tscn b/src/scenes/game/Game.tscn index 340653b..af96e17 100644 --- a/src/scenes/game/Game.tscn +++ b/src/scenes/game/Game.tscn @@ -71,24 +71,22 @@ shape = SubResource( 3 ) position = Vector2( 160, 109.875 ) shape = SubResource( 3 ) +[node name="Player" parent="View" instance=ExtResource( 5 )] +position = Vector2( 46, 42 ) +z_index = 1 + [node name="Enemies" type="Node2D" parent="View"] [node name="TrashCan" parent="View/Enemies" instance=ExtResource( 13 )] [node name="Bat" parent="View/Enemies" instance=ExtResource( 14 )] -z_index = 1 [node name="Bat2" parent="View/Enemies" instance=ExtResource( 14 )] position = Vector2( 142, 54 ) -z_index = 1 [node name="Ghost" parent="View/Enemies" instance=ExtResource( 15 )] position = Vector2( 509, 100 ) -[node name="Player" parent="View" instance=ExtResource( 5 )] -position = Vector2( 46, 42 ) -z_index = 1 - [node name="UIWrapper" type="CanvasLayer" parent="."] layer = 3