Skip to content

Commit

Permalink
Merge pull request #36 from rasmussvala/dev
Browse files Browse the repository at this point in the history
Hand In
  • Loading branch information
rasmussvala authored Oct 28, 2024
2 parents 2e97e78 + 72eae64 commit 2777c44
Show file tree
Hide file tree
Showing 187 changed files with 12,696 additions and 293 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
.godot/
/android/
*.tmp
*.import
*.import
/.vscode
Binary file added assets/cat/movement/eating.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/cat/movement/eating_player.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/cat/movement/idle.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/cat/movement/idle_sit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/cat/movement/sleep.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/cat/movement/stretch.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/cat/movement/walk.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/cat/stuff/bed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/cat/stuff/fish.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/cat/stuff/fish_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/cat/stuff/plate-empty.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/cat/stuff/plate-food.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/characters/enemies/bug_damaged.wav
Binary file not shown.
Binary file added assets/characters/enemies/bug_death.wav
Binary file not shown.
Binary file added assets/characters/enemies/bug_flying/damaged.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/characters/enemies/bug_flying/death.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/characters/enemies/bug_flying/idle.png
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 added assets/characters/enemies/mouse_trap/idle.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/characters/enemies/mouse_trap/pow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/characters/enemies/mouse_trap/slap.wav
Binary file not shown.
Binary file added assets/characters/enemies/mouse_trap/trapped.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/characters/enemies/mouse_trap/trapped_bug.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/characters/enemies/projectile.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/characters/mouse/attack_1.wav
Binary file not shown.
Binary file added assets/characters/mouse/attack_2.wav
Binary file not shown.
Binary file added assets/characters/mouse/damaged.wav
Binary file not shown.
Binary file added assets/characters/mouse/falling.wav
Binary file not shown.
Binary file added assets/characters/mouse/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/characters/mouse/icon_2.png
Binary file added assets/characters/mouse/icon_loop.png
Binary file added assets/characters/mouse/jump.wav
Binary file not shown.
Binary file added assets/characters/mouse/rolling.wav
Binary file not shown.
Binary file added assets/characters/mouse/walking.wav
Binary file not shown.
Binary file added assets/collectibles/cheese/eating.wav
Binary file not shown.
Binary file added assets/collectibles/pills/health.wav
Binary file not shown.
Binary file added assets/collectibles/pills/idle.png
Binary file modified assets/furnishings/couch.png
Binary file added assets/heart/idle.png
Binary file added assets/music/Billion_dollar_brie.wav
Binary file not shown.
Binary file added assets/music/Cheese_on_the_moon.wav
Binary file not shown.
Binary file added assets/music/Lactose.wav
Binary file not shown.
Binary file added assets/testlevel/BEANBEAVERSTUDIOS.png
Binary file added assets/testlevel/Cheddar chase.png
Binary file added assets/testlevel/level_icon.png
Binary file added assets/testlevel/level_icon_allstar.png
Binary file added assets/testlevel/level_icon_completed.png
Binary file added assets/testlevel/star-hud-empty.png
Binary file added assets/testlevel/star-hud-filled.png
Binary file added assets/testlevel/star_empty.png
Binary file added assets/testlevel/star_filled.png
Binary file modified assets/testlevel/tile_map_decoration.png
Binary file modified assets/testlevel/tile_map_floor.png
Binary file added assets/testlevel/world_1.png
Binary file added assets/testlevel/world_background.png
Binary file added assets/testlevel/world_background_cloud_1.png
Binary file added assets/testlevel/world_background_cloud_2.png
Binary file added assets/testlevel/world_background_house_1.png
Binary file added assets/testlevel/world_background_loop.png
Binary file added assets/tools/slider-grabber.png
31 changes: 31 additions & 0 deletions behavior-tree/TREE.md
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)
```
39 changes: 39 additions & 0 deletions behavior-tree/cat/can_see_player.gd
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
12 changes: 12 additions & 0 deletions behavior-tree/cat/cat_mouth.gd
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()
45 changes: 45 additions & 0 deletions behavior-tree/cat/chase_player.gd
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
17 changes: 17 additions & 0 deletions behavior-tree/cat/check_need.gd
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
26 changes: 26 additions & 0 deletions behavior-tree/cat/do_need.gd
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
21 changes: 21 additions & 0 deletions behavior-tree/cat/eat_player.gd
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
8 changes: 8 additions & 0 deletions behavior-tree/cat/is_cheese_available.gd
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
11 changes: 11 additions & 0 deletions behavior-tree/cat/is_food_on_plate.gd
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
11 changes: 11 additions & 0 deletions behavior-tree/cat/is_target_available.gd
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
5 changes: 5 additions & 0 deletions behavior-tree/cat/remove_food.gd
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
8 changes: 8 additions & 0 deletions behavior-tree/cat/sit.gd
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
35 changes: 35 additions & 0 deletions behavior-tree/cat/walk_to_target.gd
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
44 changes: 44 additions & 0 deletions behavior-tree/cat/wander.gd
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
8 changes: 8 additions & 0 deletions behavior-tree/nodes/bt_node.gd
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
Loading

0 comments on commit 2777c44

Please sign in to comment.