add mine that explodes on contact with player, shot by arrow, or other mine's explosions

This commit is contained in:
Haze Weathers 2023-02-17 15:12:15 -05:00
parent c577f0a57c
commit 8a47c20d94
12 changed files with 338 additions and 7 deletions

View file

@ -0,0 +1,10 @@
extends "res://objects/enemy/enemy.gd"
func _ready():
$AnimatedSprite.play("explode")
func _on_animation_finished():
queue_free()
func die():
return

View file

@ -0,0 +1,55 @@
[gd_scene load_steps=11 format=2]
[ext_resource path="res://objects/enemy/explosion.gd" type="Script" id=1]
[ext_resource path="res://graphics/enemy/explosion.png" type="Texture" id=2]
[sub_resource type="AtlasTexture" id=1]
atlas = ExtResource( 2 )
region = Rect2( 0, 0, 64, 64 )
[sub_resource type="AtlasTexture" id=2]
atlas = ExtResource( 2 )
region = Rect2( 64, 0, 64, 64 )
[sub_resource type="AtlasTexture" id=3]
atlas = ExtResource( 2 )
region = Rect2( 128, 0, 64, 64 )
[sub_resource type="AtlasTexture" id=4]
atlas = ExtResource( 2 )
region = Rect2( 192, 0, 64, 64 )
[sub_resource type="AtlasTexture" id=5]
atlas = ExtResource( 2 )
region = Rect2( 256, 0, 64, 64 )
[sub_resource type="AtlasTexture" id=6]
atlas = ExtResource( 2 )
region = Rect2( 320, 0, 64, 64 )
[sub_resource type="SpriteFrames" id=7]
animations = [ {
"frames": [ SubResource( 1 ), SubResource( 2 ), SubResource( 3 ), SubResource( 4 ), SubResource( 5 ), SubResource( 6 ) ],
"loop": false,
"name": "explode",
"speed": 10.0
} ]
[sub_resource type="RectangleShape2D" id=8]
extents = Vector2( 24, 24 )
[node name="Explosion" type="Node2D"]
script = ExtResource( 1 )
blood = false
[node name="AnimatedSprite" type="AnimatedSprite" parent="."]
frames = SubResource( 7 )
animation = "explode"
[node name="Hitbox" type="Area2D" parent="." groups=["enemy_hitbox", "explosion"]]
[node name="CollisionShape2D" type="CollisionShape2D" parent="Hitbox"]
shape = SubResource( 8 )
[connection signal="animation_finished" from="AnimatedSprite" to="." method="_on_animation_finished"]
[connection signal="area_entered" from="Hitbox" to="." method="_on_Hitbox_area_entered"]

28
objects/enemy/mine.gd Normal file
View file

@ -0,0 +1,28 @@
extends "res://objects/enemy/enemy.gd"
const Explosion = preload("res://objects/enemy/explosion.tscn")
onready var chain = $Chain
onready var hitbox = $Hitbox
func _ready():
var ground_cast = $GroundCast
ground_cast.force_raycast_update()
if ground_cast.is_colliding():
chain.points[1].y = chain.to_local(ground_cast.get_collision_point()).y
func _process(delta):
chain.points[0].x = hitbox.position.x
func _on_Hitbox_area_entered(area):
if area.is_in_group("explosion"):
var timer = get_tree().create_timer(0.2, false)
timer.connect("timeout", self, "die")
if area.is_in_group("player"):
die()
func die():
var explosion = Explosion.instance()
explosion.global_position = hitbox.global_position
get_parent().call_deferred("add_child", explosion)
queue_free()

101
objects/enemy/mine.tscn Normal file
View file

@ -0,0 +1,101 @@
[gd_scene load_steps=7 format=2]
[ext_resource path="res://objects/enemy/mine.gd" type="Script" id=1]
[ext_resource path="res://graphics/enemy/mine.png" type="Texture" id=2]
[ext_resource path="res://graphics/enemy/chain.png" type="Texture" id=3]
[sub_resource type="RectangleShape2D" id=1]
extents = Vector2( 8, 8 )
[sub_resource type="Animation" id=2]
length = 0.001
tracks/0/type = "value"
tracks/0/path = NodePath("Hitbox:position")
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": [ Vector2( 8, 8 ) ]
}
tracks/1/type = "bezier"
tracks/1/path = NodePath("Hitbox:position:x")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/keys = {
"points": PoolRealArray( 8, -0.25, 0, 0.25, 0 ),
"times": PoolRealArray( 0 )
}
tracks/2/type = "bezier"
tracks/2/path = NodePath("Hitbox:position:y")
tracks/2/interp = 1
tracks/2/loop_wrap = true
tracks/2/imported = false
tracks/2/enabled = true
tracks/2/keys = {
"points": PoolRealArray( 8, -0.25, 0, 0.25, 0 ),
"times": PoolRealArray( 0 )
}
[sub_resource type="Animation" id=3]
resource_name = "sway"
length = 8.0
loop = true
tracks/0/type = "bezier"
tracks/0/path = NodePath("Hitbox:position:x")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/keys = {
"points": PoolRealArray( 4, -1.7, -0.0788159, 1.7, 0.0788159, 12, -1.9, -0.00271606, 1.9, 0.00271606, 4, -1.6, -0.0139103, 1.6, 0.0139103 ),
"times": PoolRealArray( 0, 4, 8 )
}
tracks/1/type = "bezier"
tracks/1/path = NodePath("Hitbox:position:y")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/keys = {
"points": PoolRealArray( 8, -0.25, 0, 0.25, 0, 8, -0.25, 0, 0.25, 0, 8, -0.25, 0, 0.25, 0, 8, -0.25, 0, 0.25, 0, 8, -0.25, 0, 0.25, 0 ),
"times": PoolRealArray( 0, 2, 4, 6, 8 )
}
[node name="Mine" type="Node2D"]
script = ExtResource( 1 )
blood = false
[node name="GroundCast" type="RayCast2D" parent="."]
visible = false
position = Vector2( 8, 8 )
cast_to = Vector2( 0, 192 )
[node name="Chain" type="Line2D" parent="."]
position = Vector2( 0, 8 )
points = PoolVector2Array( 8, 0, 8, 16 )
width = 4.0
default_color = Color( 1, 1, 1, 1 )
texture = ExtResource( 3 )
texture_mode = 1
[node name="Hitbox" type="Area2D" parent="." groups=["enemy_hitbox"]]
position = Vector2( 8, 8 )
[node name="Sprite" type="Sprite" parent="Hitbox"]
texture = ExtResource( 2 )
[node name="CollisionShape2D" type="CollisionShape2D" parent="Hitbox"]
shape = SubResource( 1 )
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
autoplay = "sway"
anims/RESET = SubResource( 2 )
anims/sway = SubResource( 3 )
[connection signal="area_entered" from="Hitbox" to="." method="_on_Hitbox_area_entered"]