diff --git a/src/global.gd b/src/global.gd index a7cb5d4..2e0a596 100644 --- a/src/global.gd +++ b/src/global.gd @@ -7,6 +7,6 @@ var health = 2 func add_health(amount): health = clamp(health + amount, 0, 3) - get_tree().get_root().get_node("Game/UI/Health/HealthSprite").frame = health + get_tree().get_root().get_node("Game/UIWrapper/UI/Health/HealthSprite").frame = health if health == 0: pass # TODO endgame diff --git a/src/models/enemies/bat/Bat.tscn b/src/models/enemies/bat/Bat.tscn index 52955db..aa6ecc7 100644 --- a/src/models/enemies/bat/Bat.tscn +++ b/src/models/enemies/bat/Bat.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=4 format=2] +[gd_scene load_steps=5 format=2] [ext_resource path="res://src/models/enemies/bat/sprite.png" type="Texture" id=1] [ext_resource path="res://src/models/enemies/bat/bat.gd" type="Script" id=2] @@ -6,7 +6,12 @@ [sub_resource type="RectangleShape2D" id=1] extents = Vector2( 4, 3 ) +[sub_resource type="RectangleShape2D" id=2] +extents = Vector2( 6, 4 ) + [node name="Bat" type="KinematicBody2D" groups=["enemy"]] +collision_layer = 2 +collision_mask = 2 script = ExtResource( 2 ) [node name="Sprite" type="Sprite" parent="."] @@ -18,3 +23,7 @@ centered = false [node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"] position = Vector2( 7, 4 ) shape = SubResource( 1 ) + +[node name="SameSpeciesCollider" type="CollisionShape2D" parent="."] +position = Vector2( 7, 4 ) +shape = SubResource( 2 ) diff --git a/src/models/enemies/bat/bat.gd b/src/models/enemies/bat/bat.gd index 2b471d0..7ed31af 100644 --- a/src/models/enemies/bat/bat.gd +++ b/src/models/enemies/bat/bat.gd @@ -29,4 +29,4 @@ func _physics_process(_delta): velocity.y = sin(angle + 180) velocity *= speed * speed_multiplier - move_and_slide(velocity) + velocity = move_and_slide(velocity) diff --git a/src/models/enemies/ghost/Ghost.tscn b/src/models/enemies/ghost/Ghost.tscn new file mode 100644 index 0000000..cec8f87 --- /dev/null +++ b/src/models/enemies/ghost/Ghost.tscn @@ -0,0 +1,21 @@ +[gd_scene load_steps=4 format=2] + +[ext_resource path="res://src/models/enemies/ghost/sprites/ghost.png" type="Texture" id=1] +[ext_resource path="res://src/models/enemies/ghost/ghost.gd" type="Script" id=2] + +[sub_resource type="RectangleShape2D" id=1] +extents = Vector2( 7, 9 ) + +[node name="Ghost" type="KinematicBody2D" groups=["enemy"]] +z_index = 2 +script = ExtResource( 2 ) + +[node name="Sprite" type="Sprite" parent="."] +texture = ExtResource( 1 ) +centered = false + +[node name="Area2D" type="Area2D" parent="."] + +[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"] +position = Vector2( 7, 9 ) +shape = SubResource( 1 ) diff --git a/src/models/enemies/ghost/ghost.gd b/src/models/enemies/ghost/ghost.gd new file mode 100644 index 0000000..be58284 --- /dev/null +++ b/src/models/enemies/ghost/ghost.gd @@ -0,0 +1,27 @@ +extends KinematicBody2D + +onready var player = $"../../Player" +var speed_multiplier = 1 +var dash_target = Vector2.ZERO +var dash_timer = .0 +var dashing = false + +func _physics_process(delta): + var dist = global_position.distance_to(player.global_position) + if dist > 25 and dash_target == Vector2.ZERO: + global_position = global_position.move_toward(player.global_position, dist * delta * speed_multiplier) + else: + if dash_target == Vector2.ZERO: + var angle = global_position.angle_to_point(player.global_position) + PI + dash_target = global_position + Vector2(70, 0).rotated(angle) + if dash_target != Vector2.ZERO: + dash_timer += delta + if dash_timer >= 2.0: + dash_timer = 0 + dashing = true + + if dashing: + global_position = global_position.move_toward(dash_target, 10) + if global_position == dash_target: + dashing = false + dash_target = Vector2.ZERO diff --git a/src/models/enemies/ghost/sprites/ghost.png b/src/models/enemies/ghost/sprites/ghost.png new file mode 100644 index 0000000..5a33c4f Binary files /dev/null and b/src/models/enemies/ghost/sprites/ghost.png differ diff --git a/src/models/enemies/ghost/sprites/ghost.png.import b/src/models/enemies/ghost/sprites/ghost.png.import new file mode 100644 index 0000000..cec9e4b --- /dev/null +++ b/src/models/enemies/ghost/sprites/ghost.png.import @@ -0,0 +1,35 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/ghost.png-97fb088169a5396720410fd8966f5d01.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://src/models/enemies/ghost/sprites/ghost.png" +dest_files=[ "res://.import/ghost.png-97fb088169a5396720410fd8966f5d01.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/enemies/trash_can/TrashCan.tscn b/src/models/enemies/trash_can/TrashCan.tscn index 1cd5245..c13bf15 100644 --- a/src/models/enemies/trash_can/TrashCan.tscn +++ b/src/models/enemies/trash_can/TrashCan.tscn @@ -7,14 +7,15 @@ extents = Vector2( 6, 7 ) [node name="TrashCan" type="KinematicBody2D"] +z_index = 2 script = ExtResource( 2 ) [node name="Sprite" type="Sprite" parent="."] +position = Vector2( 3, 0 ) texture = ExtResource( 1 ) -centered = false [node name="EnemyCollider" type="Area2D" parent="."] [node name="CollisionShape2D" type="CollisionShape2D" parent="EnemyCollider"] -position = Vector2( 6, 7 ) +position = Vector2( 3, 0 ) shape = SubResource( 1 ) diff --git a/src/models/enemies/trash_can/trash_can.gd b/src/models/enemies/trash_can/trash_can.gd index 65b3682..e616c5f 100644 --- a/src/models/enemies/trash_can/trash_can.gd +++ b/src/models/enemies/trash_can/trash_can.gd @@ -45,7 +45,7 @@ func _ready(): last_y = self.global_position.y path_sprite.centered = false - path_sprite.modulate.a = 1 + path_sprite.modulate.a = 0.5 get_parent().call_deferred("add_child", path_sprite) func drop_trash(): @@ -55,10 +55,9 @@ func drop_trash(): func _physics_process(delta): if start_timer < 2: - path_sprite.modulate.a = 2 - start_timer + path_sprite.modulate.a = (2 - start_timer) / 2 start_timer += delta return - drop_timer += delta velocity = Vector2.ZERO diff --git a/src/models/player/Player.tscn b/src/models/player/Player.tscn index ab17ddf..0318b23 100644 --- a/src/models/player/Player.tscn +++ b/src/models/player/Player.tscn @@ -25,6 +25,3 @@ shape = SubResource( 1 ) [node name="CollisionShape2D" type="CollisionShape2D" parent="EnemyCollision"] position = Vector2( 12, 12 ) shape = SubResource( 2 ) - -[connection signal="area_entered" from="EnemyCollision" to="." method="area_entered"] -[connection signal="area_exited" from="EnemyCollision" to="." method="area_exited"] diff --git a/src/models/player/player.gd b/src/models/player/player.gd index 2464bdc..8c5ceef 100644 --- a/src/models/player/player.gd +++ b/src/models/player/player.gd @@ -1,28 +1,29 @@ extends KinematicBody2D var velocity = Vector2.ZERO -var speed_multiplier = 1 +var speed_multiplier: float = 1.0 +var slowed = false var speed = 100 func get_input(): var input_direction = Input.get_vector("left", "right", "up", "down") velocity = input_direction * speed -func area_entered(area): - if area.get_parent().is_in_group("trash_drop"): - speed_multiplier = 0.5 - -func area_exited(area): - # Check if __all__ the drops exited - var exited = true - for area in $EnemyCollision.get_overlapping_areas(): - if area.get_parent().is_in_group("trash_drop"): - exited = false - if exited: - speed_multiplier = 1 - func _physics_process(_delta): get_input() + + var areas = $EnemyCollision.get_overlapping_areas() + slowed = false + for area in areas: + if area.get_parent().is_in_group("trash_drop"): + slowed = true + break + + if slowed: + speed_multiplier = 0.5 + else: + speed_multiplier = 1.0 + velocity = move_and_slide(velocity * speed_multiplier) _choose_target() diff --git a/src/scenes/game/Game.tscn b/src/scenes/game/Game.tscn index 4784134..de2e68a 100644 --- a/src/scenes/game/Game.tscn +++ b/src/scenes/game/Game.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=19 format=2] +[gd_scene load_steps=20 format=2] [ext_resource path="res://src/scenes/menu/background/background.png" type="Texture" id=1] [ext_resource path="res://src/scenes/game/sprites/background_houses.png" type="Texture" id=2] @@ -9,11 +9,12 @@ [ext_resource path="res://src/scenes/game/sprites/health/1.png" type="Texture" id=7] [ext_resource path="res://src/scenes/game/sprites/health/2.png" type="Texture" id=8] [ext_resource path="res://src/scenes/game/sprites/health/0.png" type="Texture" id=9] -[ext_resource path="res://icon.png" type="Texture" id=10] +[ext_resource path="res://src/scenes/game/sprites/player_icon.png" type="Texture" id=10] [ext_resource path="res://src/scenes/game/game.gd" type="Script" id=11] [ext_resource path="res://src/scenes/game/sprites/ui_background.png" type="Texture" id=12] [ext_resource path="res://src/models/enemies/trash_can/TrashCan.tscn" type="PackedScene" id=13] [ext_resource path="res://src/models/enemies/bat/Bat.tscn" type="PackedScene" id=14] +[ext_resource path="res://src/models/enemies/ghost/Ghost.tscn" type="PackedScene" id=15] [sub_resource type="RectangleShape2D" id=2] extents = Vector2( 10, 60 ) @@ -81,29 +82,35 @@ z_index = 1 position = Vector2( 142, 54 ) z_index = 1 +[node name="Ghost" parent="View/Enemies" instance=ExtResource( 15 )] +position = Vector2( 400, 50 ) + [node name="Player" parent="View" instance=ExtResource( 5 )] position = Vector2( 46, 42 ) z_index = 1 -[node name="UI" type="Control" parent="."] +[node name="UIWrapper" type="CanvasLayer" parent="."] +layer = 3 + +[node name="UI" type="Control" parent="UIWrapper"] margin_right = 40.0 margin_bottom = 40.0 -[node name="Background" type="TextureRect" parent="UI"] +[node name="Background" type="TextureRect" parent="UIWrapper/UI"] margin_top = 120.0 margin_right = 320.0 margin_bottom = 180.0 texture = ExtResource( 12 ) expand = true -[node name="SpellHolder" type="Control" parent="UI"] +[node name="SpellHolder" type="Control" parent="UIWrapper/UI"] margin_left = 120.0 margin_top = 145.0 margin_right = 200.0 margin_bottom = 159.0 script = ExtResource( 3 ) -[node name="Text" type="Label" parent="UI/SpellHolder"] +[node name="Text" type="Label" parent="UIWrapper/UI/SpellHolder"] margin_left = 1.0 margin_top = -14.0 margin_right = 79.0 @@ -111,18 +118,17 @@ margin_bottom = 7.0 custom_fonts/font = SubResource( 1 ) text = "spell modifiers" -[node name="Health" type="Control" parent="UI"] +[node name="Health" type="Control" parent="UIWrapper/UI"] margin_right = 40.0 margin_bottom = 40.0 -[node name="HealthSprite" type="AnimatedSprite" parent="UI/Health"] +[node name="HealthSprite" type="AnimatedSprite" parent="UIWrapper/UI/Health"] position = Vector2( 70, 145 ) frames = SubResource( 4 ) frame = 2 centered = false -[node name="PlayerIcon" type="Sprite" parent="UI"] +[node name="PlayerIcon" type="Sprite" parent="UIWrapper/UI"] position = Vector2( 20, 134 ) -scale = Vector2( 0.5, 0.5 ) texture = ExtResource( 10 ) centered = false diff --git a/src/scenes/game/sprites/background_houses.png b/src/scenes/game/sprites/background_houses.png index 1f31d43..8a9acff 100644 Binary files a/src/scenes/game/sprites/background_houses.png and b/src/scenes/game/sprites/background_houses.png differ diff --git a/src/scenes/game/sprites/background_houses_old.png b/src/scenes/game/sprites/background_houses_old.png new file mode 100644 index 0000000..1f31d43 Binary files /dev/null and b/src/scenes/game/sprites/background_houses_old.png differ diff --git a/src/scenes/game/sprites/background_houses_old.png.import b/src/scenes/game/sprites/background_houses_old.png.import new file mode 100644 index 0000000..b3300c5 --- /dev/null +++ b/src/scenes/game/sprites/background_houses_old.png.import @@ -0,0 +1,35 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/background_houses_old.png-1d6d95d92529e7c5e15327686796eba5.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://src/scenes/game/sprites/background_houses_old.png" +dest_files=[ "res://.import/background_houses_old.png-1d6d95d92529e7c5e15327686796eba5.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/scenes/game/sprites/player_icon.png b/src/scenes/game/sprites/player_icon.png new file mode 100644 index 0000000..0416dc9 Binary files /dev/null and b/src/scenes/game/sprites/player_icon.png differ diff --git a/src/scenes/game/sprites/player_icon.png.import b/src/scenes/game/sprites/player_icon.png.import new file mode 100644 index 0000000..92b0154 --- /dev/null +++ b/src/scenes/game/sprites/player_icon.png.import @@ -0,0 +1,35 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/player_icon.png-a729c1dec9fd225b7fe2783392839b49.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://src/scenes/game/sprites/player_icon.png" +dest_files=[ "res://.import/player_icon.png-a729c1dec9fd225b7fe2783392839b49.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/scripts/enemy_class.gd b/src/scripts/enemy_class.gd index 32aa010..104fa3a 100644 --- a/src/scripts/enemy_class.gd +++ b/src/scripts/enemy_class.gd @@ -15,6 +15,6 @@ func check_poisoned(): if poisoned_timer >= 1: hp -= 5 -func _physics_process(delta): +func _physics_process(_delta): check_frozen() check_poisoned()