-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'pathfinding' into behavior-tree
- Loading branch information
Showing
9 changed files
with
221 additions
and
34 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,27 @@ | ||
extends BTCondition | ||
|
||
@export var player_key: String = "player" | ||
@export var view_distance: float = 200.0 | ||
var player_dummy | ||
var player_in_sight = false | ||
|
||
func tick(blackboard: Dictionary) -> int: | ||
var actor = blackboard["actor"] | ||
var player = blackboard.get(player_key) | ||
|
||
# Check if the player exists and is within the view distance | ||
if player != null and (player.global_position - actor.global_position).length() <= view_distance: | ||
|
||
if blackboard["eating_player"]: | ||
return SUCCESS | ||
elif player_in_sight: | ||
blackboard["sees_player"] = true | ||
print("sees the player") | ||
blackboard["player"] = player_dummy | ||
return SUCCESS | ||
else: | ||
blackboard["sees_player"] = false | ||
return FAILURE | ||
|
||
func _on_detection_area_body_entered(body: Node2D) -> void: | ||
if body.is_in_group("player"): | ||
player_dummy = body | ||
player_in_sight = true | ||
|
||
func _on_detection_area_body_exited(body: Node2D) -> void: | ||
if body.is_in_group("player"): | ||
player_in_sight = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
extends Area2D | ||
|
||
@onready var animated_sprite_cat: AnimatedSprite2D = %animated_sprite_cat | ||
|
||
func _on_body_entered(body: Node) -> void: | ||
if body.is_flying or not body.has_method("die"): | ||
return | ||
|
||
animated_sprite_cat.play("eating") | ||
body.animated_sprite_2d.visible = false | ||
|
||
body.die() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
extends BTAction | ||
|
||
@export var need: String | ||
@export var rate: String | ||
@export var action: String | ||
@onready var detection_area_polygon: CollisionPolygon2D = %detection_area_polygon | ||
|
||
func tick(blackboard: Dictionary) -> int: | ||
blackboard["eating_player"] = true | ||
blackboard["hunger_for_player"] -= blackboard["delta"] * blackboard[rate] | ||
|
||
# Cat is satisfied with need | ||
if blackboard[need] < 0: | ||
blackboard[need] = 0 | ||
blackboard[action] = false | ||
return SUCCESS | ||
|
||
var animated_sprite = blackboard["actor"].get_node("animated_sprite_cat") | ||
animated_sprite.play("eating_player") | ||
|
||
return RUNNING |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters