mirror of
https://github.com/RYGhub/the-cold-night.git
synced 2024-11-24 21:54:18 +00:00
✨ Create basic enemy attracted to the fire
This commit is contained in:
parent
ea2422077a
commit
19f0f88807
3 changed files with 49 additions and 1 deletions
18
src/entities/Enemy.tscn
Normal file
18
src/entities/Enemy.tscn
Normal file
|
@ -0,0 +1,18 @@
|
|||
[gd_scene load_steps=4 format=2]
|
||||
|
||||
[ext_resource path="res://src/mechanics/Black.png" type="Texture" id=1]
|
||||
[ext_resource path="res://src/entities/behaviours/AttractedTo.gd" type="Script" id=2]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id=1]
|
||||
extents = Vector2( 16, 16 )
|
||||
|
||||
[node name="Enemy" type="KinematicBody2D"]
|
||||
|
||||
[node name="AttractedTo" type="Node" parent="."]
|
||||
script = ExtResource( 2 )
|
||||
|
||||
[node name="Sprite" type="Sprite" parent="."]
|
||||
texture = ExtResource( 1 )
|
||||
|
||||
[node name="Shape" type="CollisionShape2D" parent="."]
|
||||
shape = SubResource( 1 )
|
26
src/entities/behaviours/AttractedTo.gd
Normal file
26
src/entities/behaviours/AttractedTo.gd
Normal file
|
@ -0,0 +1,26 @@
|
|||
extends Node
|
||||
|
||||
|
||||
export var movement_per_second: float = 32.0
|
||||
|
||||
|
||||
onready var target: KinematicBody2D = get_parent()
|
||||
# TODO: Use a better algorithm
|
||||
onready var goal: StaticBody2D = get_parent().get_parent().get_node("Fire")
|
||||
|
||||
|
||||
signal touching_goal
|
||||
var goal_reached_triggered: bool = false
|
||||
signal goal_reached
|
||||
|
||||
|
||||
func _physics_process(_delta):
|
||||
var direction: Vector2 = (goal.global_position - target.global_position).normalized()
|
||||
var _motion: Vector2 = target.move_and_slide(direction * movement_per_second, Vector2.ZERO)
|
||||
for slide_no in target.get_slide_count():
|
||||
var slide = target.get_slide_collision(slide_no)
|
||||
if slide.collider == goal:
|
||||
emit_signal("touching_goal")
|
||||
if not goal_reached_triggered:
|
||||
emit_signal("goal_reached")
|
||||
goal_reached_triggered = true
|
|
@ -1,9 +1,10 @@
|
|||
[gd_scene load_steps=5 format=2]
|
||||
[gd_scene load_steps=6 format=2]
|
||||
|
||||
[ext_resource path="res://src/mechanics/Background.tscn" type="PackedScene" id=1]
|
||||
[ext_resource path="res://src/mechanics/Darkness.tscn" type="PackedScene" id=2]
|
||||
[ext_resource path="res://src/entities/Fire.tscn" type="PackedScene" id=3]
|
||||
[ext_resource path="res://src/entities/Player.tscn" type="PackedScene" id=4]
|
||||
[ext_resource path="res://src/entities/Enemy.tscn" type="PackedScene" id=5]
|
||||
|
||||
[node name="Game" type="Node2D"]
|
||||
|
||||
|
@ -19,3 +20,6 @@ intensity = 1.0
|
|||
|
||||
[node name="Player" parent="." instance=ExtResource( 4 )]
|
||||
position = Vector2( 500, 438 )
|
||||
|
||||
[node name="Enemy" parent="." instance=ExtResource( 5 )]
|
||||
position = Vector2( 755, 508 )
|
||||
|
|
Loading…
Reference in a new issue