Skip to content

Commit

Permalink
Add flying enemy, add find_player to utils and add player to group pl…
Browse files Browse the repository at this point in the history
…ayer, expand world
  • Loading branch information
Nartynka committed Sep 26, 2022
1 parent 2650006 commit 32b66ec
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 7 deletions.
21 changes: 21 additions & 0 deletions Enemies/FlyingEnemy.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
extends "res://Enemies/Enemy.gd"

export(int) var ACCELERATION = 400
onready var sprite = $Sprite
var player = null

func _ready():
player = Utils.find_player()

func _physics_process(delta):
if player != null:
chase_player(delta)

func chase_player(delta):
var direction = (player.global_position - global_position)
if direction.x > 400 || direction.y > 400 :
return
motion += direction * ACCELERATION * delta
motion = motion.clamped(MAX_SPEED)
sprite.flip_h = global_position < player.global_position
motion = move_and_slide(motion)
80 changes: 80 additions & 0 deletions Enemies/FlyingEnemy.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
[gd_scene load_steps=9 format=2]

[ext_resource path="res://Enemies/FlyingEnemy.png" type="Texture" id=1]
[ext_resource path="res://Enemies/Enemy.tscn" type="PackedScene" id=2]
[ext_resource path="res://Enemies/FlyingEnemy.gd" type="Script" id=3]

[sub_resource type="CircleShape2D" id=3]
radius = 5.0

[sub_resource type="Animation" id=1]
resource_name = "Animate"
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( -2, -2, -2, -2, -2, -2 ),
"update": 1,
"values": [ 0, 1, 2, 3, 4, 5 ]
}

[sub_resource type="Animation" id=2]
length = 0.001
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 ),
"transitions": PoolRealArray( 1 ),
"update": 0,
"values": [ 0 ]
}

[sub_resource type="CircleShape2D" id=4]
radius = 6.0

[sub_resource type="CircleShape2D" id=5]
radius = 4.0

[node name="FlyingEnemy" instance=ExtResource( 2 )]
collision_layer = 0
collision_mask = 0
script = ExtResource( 3 )
MAX_SPEED = 40
ACCELERATION = 400

[node name="Sprite" parent="." index="0"]
texture = ExtResource( 1 )
hframes = 6

[node name="Collision" parent="." index="1"]
position = Vector2( 0, -1 )
shape = SubResource( 3 )

[node name="AnimationPlayer" parent="." index="2"]
autoplay = "Animate"
anims/Animate = SubResource( 1 )
anims/RESET = SubResource( 2 )

[node name="Collision" parent="Hurtbox" index="0"]
position = Vector2( 0, -2 )
shape = SubResource( 4 )

[node name="EnemyStats" parent="." index="4"]
max_health = 3

[node name="CollisionShape2D" parent="Hitbox" index="0"]
position = Vector2( 0, -2 )
shape = SubResource( 5 )

[editable path="Hurtbox"]
[editable path="Hitbox"]
3 changes: 2 additions & 1 deletion Player/Player.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ tracks/0/keys = {
"values": [ true ]
}

[node name="Player" type="KinematicBody2D"]
[node name="Player" type="KinematicBody2D" groups=["Player"]]
collision_mask = 2
script = ExtResource( 2 )

Expand Down Expand Up @@ -200,6 +200,7 @@ wait_time = 0.5
one_shot = true

[node name="Node" type="Node2D" parent="."]
visible = false
position = Vector2( -40, -24 )
z_index = 100

Expand Down
3 changes: 3 additions & 0 deletions Utils.gd
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ func _ready():
if Input.get_connected_joypads():
controller_connected = true
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)

func find_player():
return get_tree().get_nodes_in_group("Player")[0]
Loading

0 comments on commit 32b66ec

Please sign in to comment.