From d0e99788fbef1dbe3d0bc6d6607cb67034f19d9c Mon Sep 17 00:00:00 2001 From: CactiChameleon9 Date: Sun, 17 Jul 2022 17:22:52 +0100 Subject: [PATCH] Add a very basic enemy --- Characters/Enemy.gd | 17 +++++++++++++++++ Characters/Enemy.tscn | 11 +++++++++++ 2 files changed, 28 insertions(+) create mode 100644 Characters/Enemy.gd create mode 100644 Characters/Enemy.tscn diff --git a/Characters/Enemy.gd b/Characters/Enemy.gd new file mode 100644 index 0000000..3e64f73 --- /dev/null +++ b/Characters/Enemy.gd @@ -0,0 +1,17 @@ +extends Node2D + +export var map_position : Vector2 = Vector2.ZERO + +var target_position : Vector2 = Vector2.ZERO +var moving : bool = false + + +func _physics_process(delta): + + # If the 2 positions are close enough, then not moving + moving = false if target_position.round() == position.round() else true + + if not moving: return + + #TODO: Replace with tween magic + position += (target_position - position)/2.5 diff --git a/Characters/Enemy.tscn b/Characters/Enemy.tscn new file mode 100644 index 0000000..65fd2fc --- /dev/null +++ b/Characters/Enemy.tscn @@ -0,0 +1,11 @@ +[gd_scene load_steps=3 format=2] + +[ext_resource path="res://icon.png" type="Texture" id=1] +[ext_resource path="res://Characters/Enemy.gd" type="Script" id=2] + +[node name="Enemy" type="Node2D" groups=["Enemy"]] +script = ExtResource( 2 ) + +[node name="Sprite" type="Sprite" parent="."] +modulate = Color( 1, 0, 0, 1 ) +texture = ExtResource( 1 )