1
Fork 0
mirror of https://github.com/Steffo99/hella-farm.git synced 2024-11-21 15:44:23 +00:00

Create Move and MoveStraight and refactor MoveTowards

This commit is contained in:
Steffo 2024-04-16 04:29:34 +02:00
parent fd0d973658
commit 69b08c09e7
Signed by: steffo
GPG key ID: 5ADA3868646C3FC0
6 changed files with 38 additions and 10 deletions

6
behaviours/move.gd Normal file
View file

@ -0,0 +1,6 @@
@icon("res://behaviours/move.svg")
extends Node2D
class_name Move
signal move(norm: Vector2)

View file

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

View file

@ -3,15 +3,15 @@
importer="texture"
type="CompressedTexture2D"
uid="uid://d10wobjiuh1mm"
path="res://.godot/imported/move_towards.svg-f5d5c8fa66b43d0301cc029ecee0a291.ctex"
path="res://.godot/imported/move.svg-6291495a0c7bf9c3c43cbea535114f1a.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://behaviours/move_towards.svg"
dest_files=["res://.godot/imported/move_towards.svg-f5d5c8fa66b43d0301cc029ecee0a291.ctex"]
source_file="res://behaviours/move.svg"
dest_files=["res://.godot/imported/move.svg-6291495a0c7bf9c3c43cbea535114f1a.ctex"]
[params]

View file

@ -0,0 +1,17 @@
@icon("res://behaviours/move.svg")
extends Move
class_name MoveStraight
## A [Move] that moves in a fixed direction.
@export var direction: Vector2
func randomize_direction() -> void:
direction = Vector2.from_angle(Random.rng.randf_range(0, 2*PI))
func _physics_process(_delta: float) -> void:
move.emit(direction)

View file

@ -0,0 +1,6 @@
[gd_scene load_steps=2 format=3 uid="uid://dk1ipq7dhkhf3"]
[ext_resource type="Script" path="res://behaviours/move_straight.gd" id="1_8yf73"]
[node name="MoveStraight" type="Node2D"]
script = ExtResource("1_8yf73")

View file

@ -1,12 +1,9 @@
@icon("res://behaviours/move_towards.svg")
extends Node2D
@icon("res://behaviours/move.svg")
extends Move
class_name MoveTowards
## A node emitting the [signal move] signal each physics timestep to move towards the position of [field target].
signal move(norm: Vector2)
## A [Move] that moves towards the [field position] of a [field target].
@export var target: Node2D = null
@ -27,4 +24,6 @@ func _physics_process(_delta: float) -> void:
if target:
var gap = target.global_position - global_position
var norm = gap.normalized()
move.emit(norm)
move.emit(norm)
else:
move.emit(Vector2.ZERO)