diff options
author | Daniel Weipert <code@drogueronin.de> | 2023-08-10 11:48:05 +0200 |
---|---|---|
committer | Daniel Weipert <code@drogueronin.de> | 2023-08-10 11:48:05 +0200 |
commit | 46556d864b9685c3b09a0038f5de83966fe7ff94 (patch) | |
tree | c68082eacd35559e14565d1598dd694972fb8e0e /Scenes/Entities/Objects |
Initial commit
Diffstat (limited to 'Scenes/Entities/Objects')
-rw-r--r-- | Scenes/Entities/Objects/Box.gd | 28 | ||||
-rw-r--r-- | Scenes/Entities/Objects/Box.tscn | 106 | ||||
-rw-r--r-- | Scenes/Entities/Objects/Coin.gd | 16 | ||||
-rw-r--r-- | Scenes/Entities/Objects/Coin.tscn | 21 |
4 files changed, 171 insertions, 0 deletions
diff --git a/Scenes/Entities/Objects/Box.gd b/Scenes/Entities/Objects/Box.gd new file mode 100644 index 0000000..c7b7d4e --- /dev/null +++ b/Scenes/Entities/Objects/Box.gd @@ -0,0 +1,28 @@ +extends StaticBody2D + + +func _ready(): + var collision_area = Utilities.Collision.Area.new(self, $CollisionShape2D, false) + collision_area.connect("collided", Callable(self, "_collide")) + add_child(collision_area) + + +func hit_by_explosion(): + $AnimationPlayer.play("breaking") + await $AnimationPlayer.animation_finished + + if randi_range(1, 3) == 1: + call_deferred("spawn_coin") + + queue_free() + + +func spawn_coin(): + var coin = preload("res://Scenes/Entities/Objects/Coin.tscn").instantiate() + coin.position = self.position + get_tree().get_current_scene().add_child(coin) + + +func _collide(area: Area2D): + if area.is_in_group("explosions"): + self.hit_by_explosion() diff --git a/Scenes/Entities/Objects/Box.tscn b/Scenes/Entities/Objects/Box.tscn new file mode 100644 index 0000000..6acb93f --- /dev/null +++ b/Scenes/Entities/Objects/Box.tscn @@ -0,0 +1,106 @@ +[gd_scene load_steps=7 format=3 uid="uid://bugyo0c505kdw"] + +[ext_resource type="Script" path="res://Scenes/Entities/Objects/Box.gd" id="1_owgyi"] +[ext_resource type="Texture2D" uid="uid://5dk0c1kpvdgs" path="res://Assets/bomb_party_v4.png" id="1_yqw0v"] + +[sub_resource type="RectangleShape2D" id="RectangleShape2D_rwppg"] +size = Vector2(16, 16) + +[sub_resource type="Animation" id="Animation_ihbs5"] +resource_name = "breaking" +length = 0.2 +tracks/0/type = "value" +tracks/0/imported = false +tracks/0/enabled = true +tracks/0/path = NodePath("Sprite2D:modulate") +tracks/0/interp = 1 +tracks/0/loop_wrap = true +tracks/0/keys = { +"times": PackedFloat32Array(0, 0.1, 0.2), +"transitions": PackedFloat32Array(1, 1, 1), +"update": 0, +"values": [Color(1, 1, 1, 1), Color(1, 1, 0, 1), Color(1, 0, 0, 1)] +} + +[sub_resource type="Animation" id="Animation_5u23n"] +length = 0.001 +tracks/0/type = "bezier" +tracks/0/imported = false +tracks/0/enabled = true +tracks/0/path = NodePath("Sprite2D:modulate:r") +tracks/0/interp = 1 +tracks/0/loop_wrap = true +tracks/0/keys = { +"handle_modes": PackedInt32Array(0), +"points": PackedFloat32Array(1, -0.25, 0, 0.25, 0), +"times": PackedFloat32Array(0) +} +tracks/1/type = "bezier" +tracks/1/imported = false +tracks/1/enabled = true +tracks/1/path = NodePath("Sprite2D:modulate:g") +tracks/1/interp = 1 +tracks/1/loop_wrap = true +tracks/1/keys = { +"handle_modes": PackedInt32Array(0), +"points": PackedFloat32Array(1, -0.25, 0, 0.25, 0), +"times": PackedFloat32Array(0) +} +tracks/2/type = "bezier" +tracks/2/imported = false +tracks/2/enabled = true +tracks/2/path = NodePath("Sprite2D:modulate:b") +tracks/2/interp = 1 +tracks/2/loop_wrap = true +tracks/2/keys = { +"handle_modes": PackedInt32Array(0), +"points": PackedFloat32Array(1, -0.25, 0, 0.25, 0), +"times": PackedFloat32Array(0) +} +tracks/3/type = "bezier" +tracks/3/imported = false +tracks/3/enabled = true +tracks/3/path = NodePath("Sprite2D:modulate:a") +tracks/3/interp = 1 +tracks/3/loop_wrap = true +tracks/3/keys = { +"handle_modes": PackedInt32Array(0), +"points": PackedFloat32Array(1, -0.25, 0, 0.25, 0), +"times": PackedFloat32Array(0) +} +tracks/4/type = "value" +tracks/4/imported = false +tracks/4/enabled = true +tracks/4/path = NodePath("Sprite2D:modulate") +tracks/4/interp = 1 +tracks/4/loop_wrap = true +tracks/4/keys = { +"times": PackedFloat32Array(0), +"transitions": PackedFloat32Array(1), +"update": 0, +"values": [Color(1, 1, 0, 1)] +} + +[sub_resource type="AnimationLibrary" id="AnimationLibrary_cqvgo"] +_data = { +"RESET": SubResource("Animation_5u23n"), +"breaking": SubResource("Animation_ihbs5") +} + +[node name="Box" type="StaticBody2D" groups=["breakables"]] +collision_layer = 8 +collision_mask = 32 +script = ExtResource("1_owgyi") + +[node name="CollisionShape2D" type="CollisionShape2D" parent="."] +shape = SubResource("RectangleShape2D_rwppg") + +[node name="Sprite2D" type="Sprite2D" parent="."] +texture = ExtResource("1_yqw0v") +region_enabled = true +region_rect = Rect2(144.052, 208.08, 16, 16) + +[node name="AnimationPlayer" type="AnimationPlayer" parent="."] +libraries = { +"": SubResource("AnimationLibrary_cqvgo") +} diff --git a/Scenes/Entities/Objects/Coin.gd b/Scenes/Entities/Objects/Coin.gd new file mode 100644 index 0000000..77fc6c2 --- /dev/null +++ b/Scenes/Entities/Objects/Coin.gd @@ -0,0 +1,16 @@ +extends StaticBody2D + + +func _ready(): + var collision_area = Utilities.Collision.Area.new(self, $CollisionShape2D, false) + collision_area.connect("collided", Callable(self, "_collide")) + add_child(collision_area) + + +func hit_by_explosion(): + queue_free() + + +func _collide(area: Area2D): + if area.is_in_group("player"): + queue_free() diff --git a/Scenes/Entities/Objects/Coin.tscn b/Scenes/Entities/Objects/Coin.tscn new file mode 100644 index 0000000..aacb70b --- /dev/null +++ b/Scenes/Entities/Objects/Coin.tscn @@ -0,0 +1,21 @@ +[gd_scene load_steps=4 format=3 uid="uid://cl7jri45a43t0"] + +[ext_resource type="Script" path="res://Scenes/Entities/Objects/Coin.gd" id="1_kjrye"] +[ext_resource type="Texture2D" uid="uid://5dk0c1kpvdgs" path="res://Assets/bomb_party_v4.png" id="2_0mghm"] + +[sub_resource type="RectangleShape2D" id="RectangleShape2D_rwppg"] +size = Vector2(16, 16) + +[node name="Coin" type="StaticBody2D" groups=["breakables"]] +collision_layer = 8 +collision_mask = 34 +script = ExtResource("1_kjrye") + +[node name="CollisionShape2D" type="CollisionShape2D" parent="."] +shape = SubResource("RectangleShape2D_rwppg") + +[node name="Sprite2D" type="Sprite2D" parent="."] +self_modulate = Color(1, 0, 1, 1) +texture = ExtResource("2_0mghm") +region_enabled = true +region_rect = Rect2(48.8626, 208.456, 15.1374, 15.5442) |