FlyingEnemy

This commit is contained in:
Felipe M 2021-02-09 18:47:23 +01:00
parent 11b0e77b48
commit 3d940d26c0
Signed by: fmartingr
GPG key ID: 716BC147715E716F
12 changed files with 1543 additions and 1380 deletions

View file

@ -17,7 +17,7 @@ script = ExtResource( 1 )
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
[node name="Hurtbox" parent="." instance=ExtResource( 2 )]
collision_mask = 8
collision_layer = 8
[node name="Hitbox" parent="." instance=ExtResource( 4 )]
collision_mask = 4

View file

@ -0,0 +1,19 @@
extends "res://Scenes/Enemies/Enemy.gd"
export (int) var ACCELERATION = 100
var MainInstances = ResourceLoader.MainInstances
onready var sprite = $Sprite
func _physics_process(delta):
var player = MainInstances.Player
if player != null:
chase_player(player, delta)
func chase_player(player, delta):
var direction = (player.global_position - global_position).normalized()
motion += direction * ACCELERATION * delta
motion = motion.clamped(MAX_SPEED)
sprite.flip_h = global_position < player.global_position
motion = move_and_slide(motion)

View file

@ -0,0 +1,62 @@
[gd_scene load_steps=8 format=2]
[ext_resource path="res://Scenes/Enemies/Enemy.tscn" type="PackedScene" id=1]
[ext_resource path="res://Scenes/Enemies/FlyingEnemy.gd" type="Script" id=2]
[ext_resource path="res://Assets/Enemies/FlyingEnemy.png" type="Texture" id=3]
[sub_resource type="CircleShape2D" id=1]
radius = 4.0
[sub_resource type="Animation" id=2]
resource_name = "Fly"
length = 0.6
loop = true
tracks/0/type = "value"
tracks/0/path = NodePath("Sprite:frame")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/keys = {
"times": PoolRealArray( 0, 0.1, 0.2, 0.3, 0.4, 0.5 ),
"transitions": PoolRealArray( 1, 1, 1, 1, 1, 1 ),
"update": 1,
"values": [ 0, 1, 2, 3, 4, 5 ]
}
[sub_resource type="CircleShape2D" id=3]
radius = 4.0
[sub_resource type="CircleShape2D" id=4]
radius = 4.0
[node name="FlyingEnemy" instance=ExtResource( 1 )]
script = ExtResource( 2 )
MAX_SPEED = 40
[node name="Sprite" parent="." index="0"]
texture = ExtResource( 3 )
flip_h = true
hframes = 6
frame = 1
[node name="Collider" parent="." index="1"]
shape = SubResource( 1 )
[node name="AnimationPlayer" parent="." index="2"]
autoplay = "Fly"
anims/Fly = SubResource( 2 )
[node name="Hurtbox" parent="." index="3"]
collision_layer = 8
collision_mask = 0
[node name="Collider" parent="Hurtbox" index="0"]
shape = SubResource( 3 )
[node name="Collider" parent="Hitbox" index="0"]
shape = SubResource( 4 )
[editable path="Hurtbox"]
[editable path="Hitbox"]