-
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 pull request #36 from rasmussvala/dev
Hand In
- Loading branch information
Showing
187 changed files
with
12,696 additions
and
293 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -2,4 +2,5 @@ | |
.godot/ | ||
/android/ | ||
*.tmp | ||
*.import | ||
*.import | ||
/.vscode |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
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,31 @@ | ||
```mermaid | ||
graph TD | ||
A((Root)) --> B[Check Mouse] | ||
A --> C[Check Tiredness] | ||
A --> D[Check Hunger] | ||
A --> T[Check Cheese] | ||
A --> E(Wander) | ||
B --> F{See Player?} | ||
B --> G(Chase Player) | ||
B --> H(Eat Player) | ||
C --> I{Tired?} | ||
C --> J{Bed Available?} | ||
C --> K(Walk to Bed) | ||
C --> L(Sleep) | ||
D --> M{Hungry?} | ||
D --> N{Plate Available?} | ||
D --> O{Food on Plate?} | ||
D --> P[Eat Sequence] | ||
P --> Q(Walk to Food) | ||
P --> R(Eat) | ||
P --> S(Remove Food) | ||
T --> U{Cheese in Scene} | ||
T --> V(Walk to Cheese) | ||
T --> W(Watch Cheese) | ||
``` |
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,39 @@ | ||
extends BTCondition | ||
|
||
@onready var detection_ray: RayCast2D = %detection_ray | ||
|
||
@export var player_key: String = "player" | ||
var player: CharacterBody2D = null | ||
|
||
func tick(blackboard: Dictionary) -> int: | ||
|
||
if blackboard["eating_player"]: | ||
return SUCCESS | ||
elif player != null: | ||
blackboard["player"] = player | ||
|
||
# Calc direction from cat to player | ||
var direction = player.global_position - detection_ray.global_position | ||
|
||
# Rotate ray in the same direction as the cat because it isn't at the right angle already??? | ||
var rotated_direction = direction.rotated(-detection_ray.global_rotation) | ||
|
||
# Divide by two because it's two times as big as it should???? | ||
detection_ray.target_position = rotated_direction / 2 | ||
|
||
if not detection_ray.is_colliding(): | ||
return SUCCESS | ||
return FAILURE | ||
else: | ||
blackboard["player"] = null | ||
return FAILURE | ||
|
||
func _on_detection_area_body_entered(body: Node2D) -> void: | ||
# Assign player to the body detected | ||
if body.is_in_group("player"): | ||
player = body | ||
|
||
func _on_detection_area_body_exited(body: Node2D) -> void: | ||
# Remove the player when out of detection | ||
if body.is_in_group("player"): | ||
player = null |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
extends BTAction | ||
|
||
@export var chase_speed: float = 150.0 | ||
@export var stop_distance: float = 10.0 | ||
@onready var cat_mouth: Area2D = %cat_mouth | ||
var eat_range = false | ||
|
||
func tick(blackboard: Dictionary) -> int: | ||
var actor = blackboard["actor"] | ||
var player = blackboard.get("player") | ||
|
||
if blackboard["eating_player"]: | ||
return SUCCESS | ||
|
||
if player == null: | ||
return FAILURE | ||
|
||
var distance_to_player = (player.global_position - actor.global_position).length() | ||
|
||
# Chase player if not close enough | ||
if distance_to_player > stop_distance: | ||
var direction = (player.global_position - actor.global_position).normalized() | ||
|
||
# Set velocity and move the actor | ||
actor.velocity = direction * chase_speed | ||
actor.move_and_slide() | ||
|
||
# Rotate the actor to face the player | ||
actor.rotation = direction.angle() | ||
|
||
# Play the walking animation | ||
actor.get_node("animated_sprite_cat").play("walk") | ||
|
||
if eat_range: | ||
return SUCCESS | ||
|
||
return RUNNING | ||
else: | ||
# Stop the actor and play idle animation | ||
actor.velocity = Vector2.ZERO | ||
actor.get_node("animated_sprite_cat").play("idle") | ||
return FAILURE | ||
|
||
func _on_cat_mouth_body_entered(_body: Node2D) -> void: | ||
eat_range = true |
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,17 @@ | ||
extends BTCondition | ||
|
||
@export var need: String | ||
@export var threshold: String | ||
@export var action: String | ||
|
||
func tick(blackboard: Dictionary) -> int: | ||
# Is needed and want to do action | ||
if blackboard[need] >= blackboard[threshold]: | ||
return SUCCESS | ||
|
||
# Is already doing the action and want to continue until it hits 0 | ||
elif blackboard[action] and blackboard[need] > 0: | ||
return SUCCESS | ||
|
||
# Need is satisfied and we don't want to do the action | ||
return FAILURE |
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,26 @@ | ||
extends BTAction | ||
|
||
@export var need: String | ||
@export var rate: String | ||
@export var action: String | ||
@onready var detection_area_polygon: CollisionPolygon2D = %detection_area_polygon | ||
@onready var cat_mouth_area_polygon: CollisionShape2D = %cat_mouth_area_polygon | ||
|
||
func tick(blackboard: Dictionary) -> int: | ||
blackboard[action] = true | ||
|
||
detection_area_polygon.disabled = true | ||
cat_mouth_area_polygon.disabled = true | ||
|
||
blackboard[need] -= 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(action) | ||
|
||
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
extends BTCondition | ||
|
||
func tick(blackboard: Dictionary) -> int: | ||
var cheeses: Array = get_tree().get_nodes_in_group("cheeses") | ||
if cheeses.size() > 0: | ||
blackboard["cheese"] = cheeses[0] | ||
return SUCCESS | ||
return FAILURE |
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,11 @@ | ||
extends BTCondition | ||
|
||
func tick(blackboard: Dictionary) -> int: | ||
var sprite = blackboard.get("food") | ||
|
||
# Food is on the plate | ||
if sprite.texture == preload("res://assets/cat/stuff/plate-food.png"): | ||
return SUCCESS | ||
# Plate is empty | ||
else: | ||
return FAILURE |
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,11 @@ | ||
extends BTCondition | ||
|
||
@export var target: String | ||
|
||
func tick(blackboard: Dictionary) -> int: | ||
var sprite = blackboard.get(target) | ||
|
||
if sprite != null: | ||
return SUCCESS | ||
else: | ||
return FAILURE |
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,5 @@ | ||
extends BTAction | ||
|
||
func tick(blackboard: Dictionary) -> int: | ||
blackboard["food"].texture = load("res://assets/cat/stuff/plate-empty.png") | ||
return SUCCESS |
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,8 @@ | ||
extends BTAction | ||
|
||
func tick(blackboard: Dictionary) -> int: | ||
var actor = blackboard["actor"] | ||
var animated_sprite = actor.get_node("animated_sprite_cat") | ||
animated_sprite.play("sit") | ||
|
||
return SUCCESS |
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,35 @@ | ||
extends BTAction | ||
|
||
@export var target: String | ||
@export var min_distance_to_target: float | ||
@onready var nav_agent: NavigationAgent2D = %NavigationAgent2D | ||
|
||
var wander_speed = 100 | ||
var wander_target = Vector2.ZERO | ||
|
||
func tick(blackboard: Dictionary) -> int: | ||
|
||
# Get actor variable | ||
var actor = blackboard["actor"] | ||
var animated_sprite = actor.get_node("animated_sprite_cat") | ||
|
||
# Get position of bed | ||
wander_target = blackboard[target].global_position | ||
# Make a path to the target | ||
# NOTE: This does not need to be calculated every tick | ||
nav_agent.target_position = wander_target | ||
|
||
# Go to bed if not close enough | ||
if (wander_target - actor.global_position).length() > min_distance_to_target: | ||
# Move cat and play walking animation | ||
var next_position = nav_agent.get_next_path_position() | ||
var direction = (next_position - actor.global_position).normalized() | ||
|
||
actor.velocity = direction * wander_speed | ||
animated_sprite.play("walk") | ||
actor.move_and_slide() | ||
actor.rotation = actor.velocity.angle() | ||
return RUNNING | ||
# At bed, continue to next node | ||
else: | ||
return SUCCESS |
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,44 @@ | ||
extends BTAction | ||
|
||
var wander_speed = 10 | ||
var wander_target = Vector2.ZERO | ||
var wander_time = 0 | ||
var wander_interval = 3 | ||
|
||
func tick(blackboard: Dictionary) -> int: | ||
wander(blackboard) | ||
return RUNNING | ||
|
||
func wander(blackboard: Dictionary) -> void: | ||
var delta = blackboard["delta"] | ||
var actor = blackboard["actor"] | ||
var animated_sprite = actor.get_node("animated_sprite_cat") | ||
|
||
wander_time += delta | ||
|
||
# Update wander direction after a short interval | ||
if wander_time >= wander_interval: | ||
wander_time = 0 | ||
|
||
# Define an angle range for forward movement (in radians) | ||
var forward_angle = actor.rotation | ||
var max_turn_angle = deg_to_rad(45) # Limit turn to within 90 degrees forward | ||
|
||
# Generate a random angle within the forward-facing cone | ||
var random_angle = forward_angle + randf_range(-max_turn_angle, max_turn_angle) | ||
|
||
# Calculate the new forward wander direction | ||
var direction = Vector2(cos(random_angle), sin(random_angle)).normalized() | ||
|
||
# Set the new wander target based on the forward-facing direction | ||
wander_target = actor.global_position + direction * randf_range(50, 100) | ||
|
||
# Go to target | ||
if actor.global_position.distance_to(wander_target) > 5: | ||
actor.velocity = (wander_target - actor.global_position).normalized() * wander_speed | ||
animated_sprite.play("walk") | ||
actor.move_and_slide() | ||
actor.rotation = actor.velocity.angle() | ||
# Chill at target | ||
else: | ||
actor.velocity = Vector2.ZERO |
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,8 @@ | ||
class_name BTNode extends Node | ||
|
||
enum { SUCCESS, FAILURE, RUNNING } | ||
|
||
## Executes this node and returns a status code. | ||
## This method must be overwritten. | ||
func tick(_blackboard: Dictionary) -> int: | ||
return SUCCESS |
Oops, something went wrong.