Skip to content

Commit

Permalink
Added looping path enemies and introduced tool mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
uheartbeast committed Jul 28, 2022
1 parent dd4bec6 commit 6de04c3
Show file tree
Hide file tree
Showing 3 changed files with 140 additions and 1 deletion.
30 changes: 30 additions & 0 deletions MovingSpikeEnemy.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
tool
extends Path2D

enum ANIMATION_TYPE {
LOOP,
BOUNCE
}

export(ANIMATION_TYPE) var animation_type setget set_animation_type
export(int) var speed = 1 setget set_speed

onready var animationPlayer: = $AnimationPlayer

func set_animation_type(value):
animation_type = value
var ap = find_node("AnimationPlayer")
if ap: play_updated_animation(ap)

func set_speed(value):
speed = value
var ap = find_node("AnimationPlayer")
if ap: ap.playback_speed = speed

func _ready():
play_updated_animation(animationPlayer)

func play_updated_animation(ap):
match animation_type:
ANIMATION_TYPE.LOOP: ap.play("MoveAlongPathLoop")
ANIMATION_TYPE.BOUNCE: ap.play("MoveAlongPathBounce")
87 changes: 87 additions & 0 deletions MovingSpikeEnemy.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
[gd_scene load_steps=9 format=2]

[ext_resource path="res://characters_packed.png" type="Texture" id=1]
[ext_resource path="res://Hitbox.tscn" type="PackedScene" id=2]
[ext_resource path="res://MovingSpikeEnemy.gd" type="Script" id=3]

[sub_resource type="Curve2D" id=7]
_data = {
"points": PoolVector2Array( )
}

[sub_resource type="CircleShape2D" id=2]
radius = 8.0

[sub_resource type="Animation" id=6]
resource_name = "MoveAlongPathBounce"
length = 6.0
loop = true
tracks/0/type = "value"
tracks/0/path = NodePath("PathFollow2D:unit_offset")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/keys = {
"times": PoolRealArray( 0, 3 ),
"transitions": PoolRealArray( 1, 1 ),
"update": 0,
"values": [ 0.0, 1.0 ]
}

[sub_resource type="Animation" id=4]
resource_name = "MoveAlongPathLoop"
length = 6.0
loop = true
tracks/0/type = "value"
tracks/0/path = NodePath("PathFollow2D:unit_offset")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/keys = {
"times": PoolRealArray( 0, 6 ),
"transitions": PoolRealArray( 1, 1 ),
"update": 0,
"values": [ 0.0, 1.0 ]
}

[sub_resource type="Animation" id=5]
length = 0.001
tracks/0/type = "value"
tracks/0/path = NodePath("PathFollow2D:unit_offset")
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": [ 1.0 ]
}

[node name="MovingSpikeEnemy" type="Path2D"]
curve = SubResource( 7 )
script = ExtResource( 3 )

[node name="PathFollow2D" type="PathFollow2D" parent="."]
rotate = false

[node name="Enemy" type="Node2D" parent="PathFollow2D"]

[node name="Sprite" type="Sprite" parent="PathFollow2D/Enemy"]
texture = ExtResource( 1 )
region_enabled = true
region_rect = Rect2( 192, 0, 24, 24 )

[node name="Hitbox" parent="PathFollow2D/Enemy" instance=ExtResource( 2 )]

[node name="CollisionShape2D" type="CollisionShape2D" parent="PathFollow2D/Enemy/Hitbox"]
shape = SubResource( 2 )

[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
autoplay = "MoveAlongPathLoop"
anims/MoveAlongPathBounce = SubResource( 6 )
anims/MoveAlongPathLoop = SubResource( 4 )
anims/RESET = SubResource( 5 )
24 changes: 23 additions & 1 deletion World.tscn
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
[gd_scene load_steps=7 format=2]
[gd_scene load_steps=10 format=2]

[ext_resource path="res://TileMap.tscn" type="PackedScene" id=1]
[ext_resource path="res://Player.tscn" type="PackedScene" id=2]
[ext_resource path="res://Spikes.tscn" type="PackedScene" id=3]
[ext_resource path="res://World.gd" type="Script" id=4]
[ext_resource path="res://WalkingEnemy.tscn" type="PackedScene" id=5]
[ext_resource path="res://Ladder.tscn" type="PackedScene" id=6]
[ext_resource path="res://MovingSpikeEnemy.tscn" type="PackedScene" id=7]

[sub_resource type="Curve2D" id=1]
_data = {
"points": PoolVector2Array( 0, 0, 0, 0, -5, -9, 0, 0, 0, 0, 35, -9, 0, 0, 0, 0, 35, -72, 0, 0, 0, 0, -45, -72, 0, 0, 0, 0, -45, -9, 0, 0, 0, 0, -5, -9 )
}

[sub_resource type="Curve2D" id=2]
_data = {
"points": PoolVector2Array( 0, 0, 0, 0, 0, -18, 0, 0, 0, 0, 0, 45 )
}

[node name="World" type="Node2D"]
script = ExtResource( 4 )
Expand Down Expand Up @@ -46,3 +57,14 @@ position = Vector2( 126, 72 )

[node name="Ladder6" parent="." instance=ExtResource( 6 )]
position = Vector2( 126, 90 )

[node name="MovingSpikeEnemy" parent="." instance=ExtResource( 7 )]
position = Vector2( 31.5, 52.7143 )
scale = Vector2( 0.9, 0.857143 )
curve = SubResource( 1 )

[node name="MovingSpikeEnemy2" parent="." instance=ExtResource( 7 )]
position = Vector2( 189, 63 )
curve = SubResource( 2 )
animation_type = 1
speed = 2

0 comments on commit 6de04c3

Please sign in to comment.