diff --git a/src/models/bullet/bullet.gd b/src/models/bullet/bullet.gd index 4b906ee..0122649 100644 --- a/src/models/bullet/bullet.gd +++ b/src/models/bullet/bullet.gd @@ -1,5 +1,7 @@ extends KinematicBody2D +var explosion_preload = preload("res://src/models/explosion/Explosion.tscn") +var explode = false var velocity = Vector2.ZERO var speed = 128 var poison_damage = 0 @@ -12,6 +14,7 @@ var prev_target var target var explosive_damage = 0 var speed_modifier = 1 +var target_center func choose_target(): target = null @@ -20,6 +23,7 @@ func choose_target(): var enemies = get_tree().get_nodes_in_group("enemy") for enemy in enemies: enemy.material = null + if enemy.global_position.y < 20 or enemy.global_position.x < 20 or enemy.global_position.x > 300 or enemy.global_position.y > 120: continue enemy_dist = global_position.distance_to(enemy.global_position) if enemy_dist < least_dist and enemy != prev_target: least_dist = enemy_dist @@ -29,7 +33,7 @@ func _physics_process(delta): if target != null and is_instance_valid(target) and not target.dead: var target_texture = target.get_node("Sprite").frames.get_frame("idle", 0) var target_sprite_size = Vector2(target_texture.get_width(), target_texture.get_width()) - var target_center = target.global_position + (target_sprite_size / 2) + target_center = target.global_position + (target_sprite_size / 2) if target.is_in_group("rat"): target_center = target.global_position + Vector2(0, 2) self.global_position = self.global_position.move_toward(target_center, delta * speed * speed_modifier) @@ -45,6 +49,11 @@ func area_entered(area): parent.frozen_timer = 0 parent.poison_damage = poison_damage parent.poisoned_timer = 0 + if not explode and explosive_damage != 0: + explode = true + var explosion = explosion_preload.instance() + explosion.global_position = target_center + Vector2(0, -16) + get_parent().add_child(explosion) if bounced >= ricochet_count: call_deferred("free") choose_target() diff --git a/src/models/enemies/bat/Bat.tscn b/src/models/enemies/bat/Bat.tscn index 8620912..f5ef64e 100644 --- a/src/models/enemies/bat/Bat.tscn +++ b/src/models/enemies/bat/Bat.tscn @@ -22,7 +22,7 @@ script = ExtResource( 2 ) use_parent_material = true frames = ExtResource( 1 ) animation = "idle" -frame = 3 +frame = 2 playing = true centered = false diff --git a/src/models/enemies/bat/bat.gd b/src/models/enemies/bat/bat.gd index 5d89c57..0e60c36 100644 --- a/src/models/enemies/bat/bat.gd +++ b/src/models/enemies/bat/bat.gd @@ -11,24 +11,28 @@ var shot = false var sonic_wave func _ready(): + randomize() + self.global_position.x = ([-1, 1][randi()%2] * 320) + randi()%40 + 20 + self.global_position.y = ([-1, 1][randi()%2] * 180) + randi()%40 + 20 hp = 7 func _physics_process(delta): - if Global.playing: - if not shooting: - shooting_timer += delta - if shooting_timer >= 2.0: - shooting = true - shooting_timer = .0 - if shooting: - attack_timer += delta - if attack_timer >= .5 and not shot: - _shoot() - shot = true - if attack_timer >= 1.0: - attack_timer = 0 - shooting = false - shot = false + if not (global_position.y < 20 or global_position.x < 20 or global_position.x > 300 or global_position.y > 120): + if Global.playing: + if not shooting: + shooting_timer += delta + if shooting_timer >= 2.0: + shooting = true + shooting_timer = .0 + if shooting: + attack_timer += delta + if attack_timer >= .5 and not shot: + _shoot() + shot = true + if attack_timer >= 1.0: + attack_timer = 0 + shooting = false + shot = false var player_position = player.global_position + Vector2(12, 12) var angle = get_angle_to(player_position) diff --git a/src/models/enemies/ghost/ghost.gd b/src/models/enemies/ghost/ghost.gd index dcdd6d6..fc196b1 100644 --- a/src/models/enemies/ghost/ghost.gd +++ b/src/models/enemies/ghost/ghost.gd @@ -7,6 +7,8 @@ var dash_timer = .0 var dashing = false func _ready(): + self.global_position.x = ([-1, 1][randi()%2] * 320) + randi()%120 + 50 + self.global_position.y = ([-1, 1][randi()%2] * 180) + randi()%40 + 20 hp = 8 func _physics_process(delta): diff --git a/src/models/explosion/Explosion.tscn b/src/models/explosion/Explosion.tscn new file mode 100644 index 0000000..0763b44 --- /dev/null +++ b/src/models/explosion/Explosion.tscn @@ -0,0 +1,35 @@ +[gd_scene load_steps=9 format=2] + +[ext_resource path="res://src/models/explosion/explosion.gd" type="Script" id=1] +[ext_resource path="res://src/models/explosion/sprites/4.png" type="Texture" id=2] +[ext_resource path="res://src/models/explosion/sprites/3.png" type="Texture" id=3] +[ext_resource path="res://src/models/explosion/sprites/2.png" type="Texture" id=4] +[ext_resource path="res://src/models/explosion/sprites/1.png" type="Texture" id=5] +[ext_resource path="res://src/models/explosion/sprites/0.png" type="Texture" id=6] + +[sub_resource type="CapsuleShape2D" id=1] +radius = 16.0 +height = 10.0 + +[sub_resource type="SpriteFrames" id=2] +animations = [ { +"frames": [ ExtResource( 6 ), ExtResource( 5 ), ExtResource( 4 ), ExtResource( 3 ), ExtResource( 2 ) ], +"loop": true, +"name": "default", +"speed": 10.0 +} ] + +[node name="Explosion" type="StaticBody2D"] +script = ExtResource( 1 ) + +[node name="Area2D" type="Area2D" parent="."] + +[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"] +rotation = 1.5708 +shape = SubResource( 1 ) + +[node name="AnimatedSprite" type="AnimatedSprite" parent="."] +frames = SubResource( 2 ) +playing = true + +[connection signal="animation_finished" from="AnimatedSprite" to="." method="animation_finished"] diff --git a/src/models/explosion/explosion.gd b/src/models/explosion/explosion.gd new file mode 100644 index 0000000..9a5f338 --- /dev/null +++ b/src/models/explosion/explosion.gd @@ -0,0 +1,13 @@ +extends StaticBody2D + +var damage = 10 + +func _ready(): + var areas = $Area2D.get_overlapping_areas() + for area in areas: + var parent = area.get_parent() + if parent.is_in_group("enemy"): + parent.deal_damage(damage) + +func animation_finished(): + call_deferred("free") diff --git a/src/models/explosion/sprites/0.png b/src/models/explosion/sprites/0.png new file mode 100644 index 0000000..90f9b23 Binary files /dev/null and b/src/models/explosion/sprites/0.png differ diff --git a/src/models/explosion/sprites/0.png.import b/src/models/explosion/sprites/0.png.import new file mode 100644 index 0000000..0ce64f7 --- /dev/null +++ b/src/models/explosion/sprites/0.png.import @@ -0,0 +1,35 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/0.png-d73025098797765d024006d9d769fa4e.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://src/models/explosion/sprites/0.png" +dest_files=[ "res://.import/0.png-d73025098797765d024006d9d769fa4e.stex" ] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=false +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=2 +process/fix_alpha_border=true +process/premult_alpha=false +process/HDR_as_SRGB=false +process/invert_color=false +process/normal_map_invert_y=false +stream=false +size_limit=0 +detect_3d=false +svg/scale=1.0 diff --git a/src/models/explosion/sprites/1.png b/src/models/explosion/sprites/1.png new file mode 100644 index 0000000..30f0398 Binary files /dev/null and b/src/models/explosion/sprites/1.png differ diff --git a/src/models/explosion/sprites/1.png.import b/src/models/explosion/sprites/1.png.import new file mode 100644 index 0000000..7719f8d --- /dev/null +++ b/src/models/explosion/sprites/1.png.import @@ -0,0 +1,35 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/1.png-6c970d4aadcef0ae8ef956266e565aed.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://src/models/explosion/sprites/1.png" +dest_files=[ "res://.import/1.png-6c970d4aadcef0ae8ef956266e565aed.stex" ] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=false +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=2 +process/fix_alpha_border=true +process/premult_alpha=false +process/HDR_as_SRGB=false +process/invert_color=false +process/normal_map_invert_y=false +stream=false +size_limit=0 +detect_3d=false +svg/scale=1.0 diff --git a/src/models/explosion/sprites/2.png b/src/models/explosion/sprites/2.png new file mode 100644 index 0000000..43d80e5 Binary files /dev/null and b/src/models/explosion/sprites/2.png differ diff --git a/src/models/explosion/sprites/2.png.import b/src/models/explosion/sprites/2.png.import new file mode 100644 index 0000000..2daa70f --- /dev/null +++ b/src/models/explosion/sprites/2.png.import @@ -0,0 +1,35 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/2.png-41242ab1d12bd2382159018fca8a7c9f.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://src/models/explosion/sprites/2.png" +dest_files=[ "res://.import/2.png-41242ab1d12bd2382159018fca8a7c9f.stex" ] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=false +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=2 +process/fix_alpha_border=true +process/premult_alpha=false +process/HDR_as_SRGB=false +process/invert_color=false +process/normal_map_invert_y=false +stream=false +size_limit=0 +detect_3d=false +svg/scale=1.0 diff --git a/src/models/explosion/sprites/3.png b/src/models/explosion/sprites/3.png new file mode 100644 index 0000000..d814f64 Binary files /dev/null and b/src/models/explosion/sprites/3.png differ diff --git a/src/models/explosion/sprites/3.png.import b/src/models/explosion/sprites/3.png.import new file mode 100644 index 0000000..1d95ac9 --- /dev/null +++ b/src/models/explosion/sprites/3.png.import @@ -0,0 +1,35 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/3.png-5688b816e8f3e17c802b934c1cd11fac.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://src/models/explosion/sprites/3.png" +dest_files=[ "res://.import/3.png-5688b816e8f3e17c802b934c1cd11fac.stex" ] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=false +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=2 +process/fix_alpha_border=true +process/premult_alpha=false +process/HDR_as_SRGB=false +process/invert_color=false +process/normal_map_invert_y=false +stream=false +size_limit=0 +detect_3d=false +svg/scale=1.0 diff --git a/src/models/explosion/sprites/4.png b/src/models/explosion/sprites/4.png new file mode 100644 index 0000000..01f47ad Binary files /dev/null and b/src/models/explosion/sprites/4.png differ diff --git a/src/models/explosion/sprites/4.png.import b/src/models/explosion/sprites/4.png.import new file mode 100644 index 0000000..6ff975f --- /dev/null +++ b/src/models/explosion/sprites/4.png.import @@ -0,0 +1,35 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/4.png-5590e0566be025759130a2112c402cbe.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://src/models/explosion/sprites/4.png" +dest_files=[ "res://.import/4.png-5590e0566be025759130a2112c402cbe.stex" ] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=false +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=2 +process/fix_alpha_border=true +process/premult_alpha=false +process/HDR_as_SRGB=false +process/invert_color=false +process/normal_map_invert_y=false +stream=false +size_limit=0 +detect_3d=false +svg/scale=1.0 diff --git a/src/models/player/player.gd b/src/models/player/player.gd index 2265644..5352b01 100644 --- a/src/models/player/player.gd +++ b/src/models/player/player.gd @@ -54,6 +54,7 @@ func choose_target(): var enemies = get_tree().get_nodes_in_group("enemy") for enemy in enemies: enemy.material = null + if enemy.global_position.y < 20 or enemy.global_position.x < 20 or enemy.global_position.x > 300 or enemy.global_position.y > 120: continue enemy_dist = global_position.distance_to(enemy.global_position) if enemy_dist < least_dist: least_dist = enemy_dist