-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add flying enemy, add find_player to utils and add player to group pl…
…ayer, expand world
- Loading branch information
Showing
5 changed files
with
136 additions
and
7 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,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) |
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,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"] |
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
Oops, something went wrong.