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/Bombs |
Initial commit
Diffstat (limited to 'Scenes/Entities/Bombs')
-rw-r--r-- | Scenes/Entities/Bombs/Bomb.gd | 165 | ||||
-rw-r--r-- | Scenes/Entities/Bombs/Bomb__Breakables.gd | 4 | ||||
-rw-r--r-- | Scenes/Entities/Bombs/Bomb__Breakables.tscn | 50 | ||||
-rw-r--r-- | Scenes/Entities/Bombs/Bomb__Normal.gd | 1 | ||||
-rw-r--r-- | Scenes/Entities/Bombs/Bomb__Normal.tscn | 49 | ||||
-rw-r--r-- | Scenes/Entities/Bombs/Explosion.gd | 11 | ||||
-rw-r--r-- | Scenes/Entities/Bombs/Explosion.tscn | 63 |
7 files changed, 343 insertions, 0 deletions
diff --git a/Scenes/Entities/Bombs/Bomb.gd b/Scenes/Entities/Bombs/Bomb.gd new file mode 100644 index 0000000..96a5e62 --- /dev/null +++ b/Scenes/Entities/Bombs/Bomb.gd @@ -0,0 +1,165 @@ +extends CharacterBody2D + +class_name Bomb + + +signal body_exited +signal exploded + + +var Explosion = preload("res://Scenes/Entities/Bombs/Explosion.tscn") +var power = 2 + + +func _ready(): + add_to_group("bombs") + + var collision_area = Utilities.Collision.Area.new(self, $CollisionShape2D) + collision_area.connect("collided", Callable(self, "_collide")) + collision_area.connect("body_exited", Callable(self, "_body_exited")) + add_child(collision_area) + + $AnimatedSprite2D.play() + + +func _process(delta): + var collision = move_and_collide(velocity * delta) + if collision: + velocity = Vector2(0, 0) + + +func explode(): + $CollisionShape2D.disabled = true + + # explode on the spot + var explosion = self.spawn_explosion(self.global_position) + + # explode in all directions + var directions = [ + Vector2.UP, + Vector2.RIGHT, + Vector2.DOWN, + Vector2.LEFT, + ] + + for j in range(directions.size()): + var direction = directions[j] + + for i in range(self.get_power()): + var to = Utilities.from_grid_to_position( + Utilities.from_position_to_grid(self.global_position) + (direction * (i + 1)) + ) + + var query = PhysicsPointQueryParameters2D.new() + query.set_position(to) + query.set_collision_mask(explosion.collision_mask) + + var explosion_intersection = get_world_2d().direct_space_state.intersect_point(query) + if explosion_intersection: + var collider = explosion_intersection[0].collider + + # call collision function and get collision type + var collision_type + if collider.is_in_group("player"): + collision_type = self._on_collide_group_player() + elif collider.is_in_group("enemies"): + collision_type = self._on_collide_group_enemies() + elif collider.is_in_group("explosions"): + collision_type = self._on_collide_group_explosions() + elif collider.is_in_group("bombs"): + collision_type = self._on_collide_group_bombs() + elif collider.is_in_group("breakables"): + collision_type = self._on_collide_group_breakables() + else: + collision_type = self._on_collide_group_else() + + # progress loop based on collision type + if collision_type == EXPLOSION_COLLISION_TYPE.STOP: + break + if collision_type == EXPLOSION_COLLISION_TYPE.SPAWN_AND_STOP: + self.spawn_explosion(to) + break + elif collision_type == EXPLOSION_COLLISION_TYPE.SKIP: + continue + elif collision_type == EXPLOSION_COLLISION_TYPE.CONTINUE: + pass + elif collision_type == EXPLOSION_COLLISION_TYPE.HIT_STOP: + if collider.has_method("hit_by_explosion"): + collider.hit_by_explosion() + break + elif collision_type == EXPLOSION_COLLISION_TYPE.HIT_CONTINUE: + if collider.has_method("hit_by_explosion"): + collider.hit_by_explosion() + continue + + self.spawn_explosion(to) + + emit_signal("exploded", self) + + queue_free() + + +func get_power(): + return self.power + + +func spawn_explosion(spawn_position: Vector2): + var explosion = Explosion.instantiate() + explosion.position = spawn_position + get_tree().get_current_scene().add_child(explosion) + + return explosion + + +func hit_by_explosion(): + call_deferred("explode") + + +func _collide(area: Area2D): + if area.is_in_group("explosions"): + call_deferred("explode") + + +func _on_Timer_timeout(): + self.explode() + + +func _body_exited(body): + emit_signal("body_exited", body) + + +### Explosion Collision ### + + +enum EXPLOSION_COLLISION_TYPE { + STOP, + SKIP, + CONTINUE, + SPAWN_AND_STOP, + HIT_STOP, + HIT_CONTINUE, +} + + +func _on_collide_group_player(): + return EXPLOSION_COLLISION_TYPE.CONTINUE + + +func _on_collide_group_enemies(): + return EXPLOSION_COLLISION_TYPE.CONTINUE + + +func _on_collide_group_explosions(): + return EXPLOSION_COLLISION_TYPE.SKIP + + +func _on_collide_group_bombs(): + return EXPLOSION_COLLISION_TYPE.HIT_STOP + + +func _on_collide_group_breakables(): + return EXPLOSION_COLLISION_TYPE.HIT_STOP + + +func _on_collide_group_else(): + return EXPLOSION_COLLISION_TYPE.STOP diff --git a/Scenes/Entities/Bombs/Bomb__Breakables.gd b/Scenes/Entities/Bombs/Bomb__Breakables.gd new file mode 100644 index 0000000..177d86e --- /dev/null +++ b/Scenes/Entities/Bombs/Bomb__Breakables.gd @@ -0,0 +1,4 @@ +extends "res://Scenes/Entities/Bombs/Bomb.gd" + +func _on_collide_group_breakables(): + return EXPLOSION_COLLISION_TYPE.HIT_CONTINUE diff --git a/Scenes/Entities/Bombs/Bomb__Breakables.tscn b/Scenes/Entities/Bombs/Bomb__Breakables.tscn new file mode 100644 index 0000000..a4bb192 --- /dev/null +++ b/Scenes/Entities/Bombs/Bomb__Breakables.tscn @@ -0,0 +1,50 @@ +[gd_scene load_steps=7 format=3 uid="uid://bcdo4xwalfyw2"] + +[ext_resource type="Script" path="res://Scenes/Entities/Bombs/Bomb__Breakables.gd" id="1_53dqw"] +[ext_resource type="Texture2D" uid="uid://tb10jfeilqxk" path="res://Assets/16_bit_animated_bomb/16_bit_bomb3.png" id="2_xuubc"] +[ext_resource type="Texture2D" uid="uid://ptkpqpfgcoug" path="res://Assets/16_bit_animated_bomb/16bit_bomb1.png" id="3_3gndm"] +[ext_resource type="Texture2D" uid="uid://dsomaiq14ajhf" path="res://Assets/16_bit_animated_bomb/16_bit_bomb2.png" id="4_u38sl"] + +[sub_resource type="CircleShape2D" id="1"] +radius = 7.9 + +[sub_resource type="SpriteFrames" id="2"] +animations = [{ +"frames": [{ +"duration": 1.0, +"texture": ExtResource("2_xuubc") +}, { +"duration": 1.0, +"texture": ExtResource("3_3gndm") +}, { +"duration": 1.0, +"texture": ExtResource("4_u38sl") +}, { +"duration": 1.0, +"texture": ExtResource("2_xuubc") +}], +"loop": false, +"name": &"default", +"speed": 1.0 +}] + +[node name="Bomb__Breakables" type="CharacterBody2D"] +collision_layer = 4 +collision_mask = 62 +script = ExtResource("1_53dqw") + +[node name="CollisionShape2D" type="CollisionShape2D" parent="."] +shape = SubResource("1") + +[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."] +modulate = Color(1, 0, 0, 1) +position = Vector2(1, -1) +scale = Vector2(1.23978, 1.23978) +sprite_frames = SubResource("2") + +[node name="Timer" type="Timer" parent="."] +wait_time = 4.0 +one_shot = true +autostart = true + +[connection signal="timeout" from="Timer" to="." method="_on_Timer_timeout"] diff --git a/Scenes/Entities/Bombs/Bomb__Normal.gd b/Scenes/Entities/Bombs/Bomb__Normal.gd new file mode 100644 index 0000000..2c89be6 --- /dev/null +++ b/Scenes/Entities/Bombs/Bomb__Normal.gd @@ -0,0 +1 @@ +extends "res://Scenes/Entities/Bombs/Bomb.gd" diff --git a/Scenes/Entities/Bombs/Bomb__Normal.tscn b/Scenes/Entities/Bombs/Bomb__Normal.tscn new file mode 100644 index 0000000..011c298 --- /dev/null +++ b/Scenes/Entities/Bombs/Bomb__Normal.tscn @@ -0,0 +1,49 @@ +[gd_scene load_steps=7 format=3 uid="uid://elsifewesoyx"] + +[ext_resource type="Script" path="res://Scenes/Entities/Bombs/Bomb__Normal.gd" id="1_3o4t3"] +[ext_resource type="Texture2D" uid="uid://tb10jfeilqxk" path="res://Assets/16_bit_animated_bomb/16_bit_bomb3.png" id="2_qio5f"] +[ext_resource type="Texture2D" uid="uid://ptkpqpfgcoug" path="res://Assets/16_bit_animated_bomb/16bit_bomb1.png" id="3_nom56"] +[ext_resource type="Texture2D" uid="uid://dsomaiq14ajhf" path="res://Assets/16_bit_animated_bomb/16_bit_bomb2.png" id="4_xndnu"] + +[sub_resource type="CircleShape2D" id="1"] +radius = 7.9 + +[sub_resource type="SpriteFrames" id="2"] +animations = [{ +"frames": [{ +"duration": 1.0, +"texture": ExtResource("2_qio5f") +}, { +"duration": 1.0, +"texture": ExtResource("3_nom56") +}, { +"duration": 1.0, +"texture": ExtResource("4_xndnu") +}, { +"duration": 1.0, +"texture": ExtResource("2_qio5f") +}], +"loop": false, +"name": &"default", +"speed": 1.0 +}] + +[node name="Bomb__Normal" type="CharacterBody2D"] +collision_layer = 4 +collision_mask = 62 +script = ExtResource("1_3o4t3") + +[node name="CollisionShape2D" type="CollisionShape2D" parent="."] +shape = SubResource("1") + +[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."] +position = Vector2(1, -1) +scale = Vector2(1.23978, 1.23978) +sprite_frames = SubResource("2") + +[node name="Timer" type="Timer" parent="."] +wait_time = 4.0 +one_shot = true +autostart = true + +[connection signal="timeout" from="Timer" to="." method="_on_Timer_timeout"] diff --git a/Scenes/Entities/Bombs/Explosion.gd b/Scenes/Entities/Bombs/Explosion.gd new file mode 100644 index 0000000..eba8b29 --- /dev/null +++ b/Scenes/Entities/Bombs/Explosion.gd @@ -0,0 +1,11 @@ +extends Area2D + + +func _ready(): + add_to_group("explosions") + + $AnimatedSprite2D.play() + + +func _on_AnimatedSprite_animation_finished(): + queue_free() diff --git a/Scenes/Entities/Bombs/Explosion.tscn b/Scenes/Entities/Bombs/Explosion.tscn new file mode 100644 index 0000000..2521dfb --- /dev/null +++ b/Scenes/Entities/Bombs/Explosion.tscn @@ -0,0 +1,63 @@ +[gd_scene load_steps=8 format=3 uid="uid://c8cg25hagp4lj"] + +[ext_resource type="Texture2D" uid="uid://5dk0c1kpvdgs" path="res://Assets/bomb_party_v4.png" id="1"] +[ext_resource type="Script" path="res://Scenes/Entities/Bombs/Explosion.gd" id="2"] + +[sub_resource type="AtlasTexture" id="3"] +atlas = ExtResource("1") +region = Rect2(224, 288, 16, 16) + +[sub_resource type="AtlasTexture" id="4"] +atlas = ExtResource("1") +region = Rect2(224, 272, 16, 16) + +[sub_resource type="AtlasTexture" id="5"] +atlas = ExtResource("1") +region = Rect2(224, 256, 16, 16) + +[sub_resource type="SpriteFrames" id="1"] +animations = [{ +"frames": [{ +"duration": 1.0, +"texture": SubResource("3") +}, { +"duration": 1.0, +"texture": SubResource("3") +}, { +"duration": 1.0, +"texture": SubResource("4") +}, { +"duration": 1.0, +"texture": SubResource("4") +}, { +"duration": 1.0, +"texture": SubResource("4") +}, { +"duration": 1.0, +"texture": SubResource("5") +}, { +"duration": 1.0, +"texture": SubResource("5") +}], +"loop": false, +"name": &"default", +"speed": 60.0 +}] + +[sub_resource type="CircleShape2D" id="2"] +radius = 7.5 + +[node name="Explosion" type="Area2D"] +collision_layer = 32 +collision_mask = 62 +script = ExtResource("2") + +[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."] +position = Vector2(-2.98023e-08, -2.98023e-08) +scale = Vector2(0.913346, 0.913346) +sprite_frames = SubResource("1") + +[node name="CollisionShape2D" type="CollisionShape2D" parent="."] +shape = SubResource("2") + +[connection signal="animation_finished" from="AnimatedSprite2D" to="." method="_on_AnimatedSprite_animation_finished"] |