Skip to content

Commit

Permalink
Part 9
Browse files Browse the repository at this point in the history
Ranged enemy
  • Loading branch information
MateuSai committed Aug 18, 2021
1 parent 7297e3b commit 7ff73a6
Show file tree
Hide file tree
Showing 19 changed files with 458 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
source_md5="8c97e935786b994c3cff4008212381b9"
dest_md5="95f9f4dfdc6535bb78f265d86373e65e"
dest_md5="2ae8fab63415433bb13b0ee2b9c689cb"

Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
source_md5="ee2cf371bf7f1107007e67b62680a86b"
dest_md5="501ca82ac953257960b45b55f8a3b4ae"
dest_md5="23f4c0e52d0d2dd5cfcce1b99d33fc36"

Binary file modified .import/goblin_knife.png-4461242fc35ba4832657ab1a22ed648e.stex
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
source_md5="565c2f9a0bb01a9c56975664f8cd375c"
dest_md5="b1dabbd61e5fab5ecb683741906255c8"
dest_md5="1396d62ebda6149cad7dd800805a6f69"

Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/filter=false
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
Expand All @@ -30,5 +30,5 @@ process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=true
detect_3d=false
svg/scale=1.0
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/filter=false
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
Expand All @@ -30,5 +30,5 @@ process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=true
detect_3d=false
svg/scale=1.0
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/filter=false
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
Expand All @@ -30,5 +30,5 @@ process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=true
detect_3d=false
svg/scale=1.0
8 changes: 6 additions & 2 deletions Characters/Enemies/Enemy.gd
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func chase() -> void:
if path:
var vector_to_next_point: Vector2 = path[0] - global_position
var distance_to_next_point: float = vector_to_next_point.length()
if distance_to_next_point < 1:
if distance_to_next_point < 3:
path.remove(0)
if not path:
return
Expand All @@ -26,8 +26,12 @@ func chase() -> void:

func _on_PathTimer_timeout() -> void:
if is_instance_valid(player):
path = navigation.get_simple_path(global_position, player.position)
_get_path_to_player()
else:
path_timer.stop()
path = []
mov_direction = Vector2.ZERO


func _get_path_to_player() -> void:
path = navigation.get_simple_path(global_position, player.position)
48 changes: 48 additions & 0 deletions Characters/Enemies/Goblin/Goblin.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
extends Enemy

const THROWABLE_KNIFE_SCENE: PackedScene = preload("res://Characters/Enemies/Goblin/ThrowableKnike.tscn")

const MAX_DISTANCE_TO_PLAYER: int = 80
const MIN_DISTANCE_TO_PLAYER: int = 40

export(int) var projectile_speed: int = 150

var can_attack: bool = true

var distance_to_player: float

onready var attack_timer: Timer = get_node("AttackTimer")


func _on_PathTimer_timeout() -> void:
if is_instance_valid(player):
distance_to_player = (player.position - global_position).length()
if distance_to_player > MAX_DISTANCE_TO_PLAYER:
_get_path_to_player()
elif distance_to_player < MIN_DISTANCE_TO_PLAYER:
_get_path_to_move_away_from_player()
else:
if can_attack:
can_attack = false
_throw_knife()
attack_timer.start()
else:
path_timer.stop()
path = []
mov_direction = Vector2.ZERO


func _get_path_to_move_away_from_player() -> void:
var dir: Vector2 = (global_position - player.position).normalized()
path = navigation.get_simple_path(global_position, global_position + dir * 100)


func _throw_knife() -> void:
var projectile: Area2D = THROWABLE_KNIFE_SCENE.instance()
projectile.launch(global_position, (player.position - global_position).normalized(), projectile_speed)
get_tree().current_scene.add_child(projectile)



func _on_AttackTimer_timeout() -> void:
can_attack = true
Loading

0 comments on commit 7ff73a6

Please sign in to comment.