-
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.
- Loading branch information
Showing
9 changed files
with
147 additions
and
16 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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
extends Node | ||
class_name VelocityComponent | ||
|
||
@export var max_speed: int = 40 | ||
@export var acceleration: float = 5 | ||
|
||
var velocity := Vector2.ZERO | ||
|
||
|
||
func accelerate_to_player(): | ||
var owner_node2d = owner as Node2D | ||
if owner_node2d == null: | ||
return | ||
|
||
var player = get_tree().get_first_node_in_group("player") as Node2D | ||
if player == null: | ||
return | ||
|
||
var direction = (player.global_position - owner_node2d.global_position).normalized() | ||
accelerate_in_direction(direction) | ||
|
||
|
||
func accelerate_in_direction(direction: Vector2): | ||
var desired_velocity = direction * max_speed | ||
velocity = velocity.lerp(desired_velocity, 1 - exp(-acceleration * get_process_delta_time())) | ||
|
||
|
||
func move(character_body: CharacterBody2D): | ||
character_body.velocity = velocity | ||
character_body.move_and_slide() | ||
|
||
velocity = character_body.velocity |
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,6 @@ | ||
[gd_scene load_steps=2 format=3 uid="uid://cn4jjvvblm8lp"] | ||
|
||
[ext_resource type="Script" path="res://scenes/component/velocity_component.gd" id="1_pusvs"] | ||
|
||
[node name="VelocityComponent" type="Node"] | ||
script = ExtResource("1_pusvs") |
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
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 |
---|---|---|
@@ -1,23 +1,13 @@ | ||
extends CharacterBody2D | ||
|
||
const MAX_SPEED = 40 | ||
|
||
@onready var health_component: HealthComponent = $HealthComponent | ||
@onready var visuals := $Visuals | ||
@onready var velocity_component: VelocityComponent = $VelocityComponent | ||
|
||
|
||
func _process(delta): | ||
var direction = get_direction_to_player() | ||
velocity = direction * MAX_SPEED | ||
move_and_slide() | ||
velocity_component.accelerate_to_player() | ||
velocity_component.move(self) | ||
|
||
var move_sign = sign(velocity.x) | ||
if move_sign != 0: | ||
visuals.scale = Vector2(-move_sign, 1) | ||
|
||
|
||
func get_direction_to_player(): | ||
var player_node = get_tree().get_first_node_in_group("player") as Node2D | ||
if player_node != null: | ||
return (player_node.global_position - global_position).normalized() | ||
return 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
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,13 @@ | ||
extends CharacterBody2D | ||
|
||
@onready var visuals := $Visuals | ||
@onready var velocity_component: VelocityComponent = $VelocityComponent | ||
|
||
|
||
func _process(delta): | ||
velocity_component.accelerate_to_player() | ||
velocity_component.move(self) | ||
|
||
var move_sign = sign(velocity.x) | ||
if move_sign != 0: | ||
visuals.scale = Vector2(move_sign, 1) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,34 @@ | ||
[remap] | ||
|
||
importer="texture" | ||
type="CompressedTexture2D" | ||
uid="uid://bj74fspmmt8fp" | ||
path="res://.godot/imported/wizard_enemy.png-ea4dcbc1cd21f78193df73188d66741a.ctex" | ||
metadata={ | ||
"vram_texture": false | ||
} | ||
|
||
[deps] | ||
|
||
source_file="res://scenes/game_object/wizard_enemy/wizard_enemy.png" | ||
dest_files=["res://.godot/imported/wizard_enemy.png-ea4dcbc1cd21f78193df73188d66741a.ctex"] | ||
|
||
[params] | ||
|
||
compress/mode=0 | ||
compress/high_quality=false | ||
compress/lossy_quality=0.7 | ||
compress/hdr_compression=1 | ||
compress/normal_map=0 | ||
compress/channel_pack=0 | ||
mipmaps/generate=false | ||
mipmaps/limit=-1 | ||
roughness/mode=0 | ||
roughness/src_normal="" | ||
process/fix_alpha_border=true | ||
process/premult_alpha=false | ||
process/normal_map_invert_y=false | ||
process/hdr_as_srgb=false | ||
process/hdr_clamp_exposure=false | ||
process/size_limit=0 | ||
detect_3d/compress_to=1 |
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,51 @@ | ||
[gd_scene load_steps=10 format=3 uid="uid://biw4lngphcynu"] | ||
|
||
[ext_resource type="PackedScene" uid="uid://d32bhk07dm6w8" path="res://scenes/component/health_component.tscn" id="1_5bkfq"] | ||
[ext_resource type="Texture2D" uid="uid://bj74fspmmt8fp" path="res://scenes/game_object/wizard_enemy/wizard_enemy.png" id="1_beb02"] | ||
[ext_resource type="Script" path="res://scenes/game_object/wizard_enemy/wizard_enemy.gd" id="1_ta3ds"] | ||
[ext_resource type="PackedScene" uid="uid://cn4jjvvblm8lp" path="res://scenes/component/velocity_component.tscn" id="2_2sxlo"] | ||
[ext_resource type="PackedScene" uid="uid://cjxiijis5jocn" path="res://scenes/component/death_component.tscn" id="2_aml71"] | ||
[ext_resource type="PackedScene" uid="uid://gsyk0iqo1m50" path="res://scenes/component/hurtbox_component.tscn" id="3_2ak7l"] | ||
[ext_resource type="PackedScene" uid="uid://ci3popyfx4vbv" path="res://scenes/component/vial_drop_component.tscn" id="4_blfg5"] | ||
|
||
[sub_resource type="CircleShape2D" id="CircleShape2D_40784"] | ||
radius = 8.0 | ||
|
||
[sub_resource type="CircleShape2D" id="CircleShape2D_6q0gl"] | ||
radius = 5.0 | ||
|
||
[node name="WizardEnemy" type="CharacterBody2D" groups=["enemy"]] | ||
position = Vector2(0, -8) | ||
collision_layer = 8 | ||
collision_mask = 9 | ||
script = ExtResource("1_ta3ds") | ||
|
||
[node name="HealthComponent" parent="." instance=ExtResource("1_5bkfq")] | ||
max_health = 30.0 | ||
|
||
[node name="VelocityComponent" parent="." instance=ExtResource("2_2sxlo")] | ||
max_speed = 60 | ||
acceleration = 2.0 | ||
|
||
[node name="VialDropComponent" parent="." node_paths=PackedStringArray("health_component") instance=ExtResource("4_blfg5")] | ||
health_component = NodePath("../HealthComponent") | ||
|
||
[node name="DeathComponent" parent="." node_paths=PackedStringArray("health_component", "sprite") instance=ExtResource("2_aml71")] | ||
health_component = NodePath("../HealthComponent") | ||
sprite = NodePath("../Visuals/Sprite2D") | ||
|
||
[node name="HurtboxComponent" parent="." node_paths=PackedStringArray("health_component") instance=ExtResource("3_2ak7l")] | ||
health_component = NodePath("../HealthComponent") | ||
|
||
[node name="CollisionShape2D" type="CollisionShape2D" parent="HurtboxComponent"] | ||
position = Vector2(0, 1) | ||
shape = SubResource("CircleShape2D_40784") | ||
|
||
[node name="Visuals" type="Node2D" parent="."] | ||
|
||
[node name="Sprite2D" type="Sprite2D" parent="Visuals"] | ||
texture = ExtResource("1_beb02") | ||
|
||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."] | ||
position = Vector2(0, 3) | ||
shape = SubResource("CircleShape2D_6q0gl") |