Major collision detection improvements, more file organization, and added key interactable

This commit is contained in:
VoidTwo
2021-12-04 00:07:33 -06:00
parent ca2ea40b23
commit fcea3cee03
18 changed files with 155 additions and 59 deletions

View File

@@ -9,20 +9,20 @@ var velocity: Vector2 = Vector2.ZERO
func _physics_process(_delta: float) -> void: func _physics_process(_delta: float) -> void:
velocity = Vector2.ZERO velocity = Vector2.ZERO
if player: if player and position.distance_to(player.position) > 1:
velocity = position.direction_to(player.position).normalized() * SPEED velocity = position.direction_to(player.position).normalized() * SPEED
velocity = move_and_slide(velocity) velocity = move_and_slide(velocity)
return return
func _on_player_detector_area_entered(area: Area2D) -> void: func _on_player_detector_body_entered(body: Node) -> void:
if area.get_parent().name == 'Player': if 'player' in body.get_groups():
player = area.get_parent() player = body
return return
func _on_player_detector_area_exited(area: Area2D): func _on_player_detector_body_exited(body: Node) -> void:
if area.get_parent().name == 'Player': if 'player' in body.get_groups():
player = null player = null
return return

View File

@@ -1,10 +1,14 @@
[gd_scene load_steps=7 format=2] [gd_scene load_steps=8 format=2]
[ext_resource path="res://Resources/Level_5_Enemy_Glowing_Ghost_Occluder.tres" type="OccluderPolygon2D" id=1] [ext_resource path="res://Resources/Level_5_Enemy_Glowing_Ghost_Occluder.tres" type="OccluderPolygon2D" id=1]
[ext_resource path="res://Sprites/Assets/Light.png" type="Texture" id=2] [ext_resource path="res://Sprites/Assets/Light.png" type="Texture" id=2]
[ext_resource path="res://Sprites/Enemies/Glowing_Ghost.png" type="Texture" id=3] [ext_resource path="res://Sprites/Enemies/Glowing_Ghost.png" type="Texture" id=3]
[ext_resource path="res://Enemies/Glowing Ghost.gd" type="Script" id=4] [ext_resource path="res://Enemies/Glowing Ghost.gd" type="Script" id=4]
[sub_resource type="CapsuleShape2D" id=3]
radius = 1.5
height = 3.0
[sub_resource type="CapsuleShape2D" id=1] [sub_resource type="CapsuleShape2D" id=1]
radius = 3.0 radius = 3.0
height = 2.0 height = 2.0
@@ -12,18 +16,29 @@ height = 2.0
[sub_resource type="CircleShape2D" id=2] [sub_resource type="CircleShape2D" id=2]
radius = 50.0 radius = 50.0
[node name="Glowing Ghost" type="KinematicBody2D" groups=["enemies"]] [node name="Glowing Ghost" type="KinematicBody2D" groups=["enemy"]]
collision_layer = 2 collision_layer = 4
collision_mask = 5
script = ExtResource( 4 ) script = ExtResource( 4 )
[node name="Sprite" type="Sprite" parent="."] [node name="Sprite" type="Sprite" parent="."]
light_mask = 4 light_mask = 4
position = Vector2( 0, -3 ) position = Vector2( 0, -3 )
texture = ExtResource( 3 ) texture = ExtResource( 3 )
offset = Vector2( 0, 0.5 )
[node name="Hitbox" type="CollisionShape2D" parent="."] [node name="Collision" type="CollisionShape2D" parent="."]
visible = false visible = false
position = Vector2( 0, -3 ) rotation = 1.5708
shape = SubResource( 3 )
[node name="Hitbox" type="Area2D" parent="." groups=["enemy_hitbox"]]
collision_layer = 4
collision_mask = 2
[node name="CollisionShape2D" type="CollisionShape2D" parent="Hitbox"]
visible = false
position = Vector2( 0, -2.5 )
shape = SubResource( 1 ) shape = SubResource( 1 )
[node name="Player Detector" type="Area2D" parent="."] [node name="Player Detector" type="Area2D" parent="."]
@@ -36,22 +51,22 @@ monitorable = false
visible = false visible = false
shape = SubResource( 2 ) shape = SubResource( 2 )
[node name="Light2D" type="Light2D" parent="."] [node name="Light" type="Light2D" parent="."]
scale = Vector2( 0.5, 0.5 ) scale = Vector2( 0.5, 0.5 )
texture = ExtResource( 2 ) texture = ExtResource( 2 )
color = Color( 0.984314, 0.94902, 0.211765, 0.392157 ) color = Color( 0.984314, 0.94902, 0.211765, 0.392157 )
energy = 2.0 energy = 2.0
range_item_cull_mask = 11 range_item_cull_mask = 11
[node name="Light2DEyes" type="Light2D" parent="."] [node name="Eyes" type="Light2D" parent="."]
scale = Vector2( 0.1, 0.1 ) scale = Vector2( 0.1, 0.1 )
texture = ExtResource( 2 ) texture = ExtResource( 2 )
offset = Vector2( 5, -40 ) offset = Vector2( 5, -35 )
range_item_cull_mask = 4 range_item_cull_mask = 4
[node name="LightOccluder2D" type="LightOccluder2D" parent="."] [node name="Occluder" type="LightOccluder2D" parent="."]
show_behind_parent = true show_behind_parent = true
occluder = ExtResource( 1 ) occluder = ExtResource( 1 )
[connection signal="area_entered" from="Player Detector" to="." method="_on_player_detector_area_entered"] [connection signal="body_entered" from="Player Detector" to="." method="_on_player_detector_body_entered"]
[connection signal="area_exited" from="Player Detector" to="." method="_on_player_detector_area_exited"] [connection signal="body_exited" from="Player Detector" to="." method="_on_player_detector_body_exited"]

View File

@@ -11,7 +11,7 @@
[node name="Level Select Menu" type="Node"] [node name="Level Select Menu" type="Node"]
script = ExtResource( 7 ) script = ExtResource( 7 )
[node name="MarginContainer" type="MarginContainer" parent="."] [node name="Menu" type="CenterContainer" parent="."]
margin_left = 10.0 margin_left = 10.0
margin_top = 10.0 margin_top = 10.0
margin_right = 310.0 margin_right = 310.0
@@ -21,54 +21,50 @@ __meta__ = {
"_edit_use_anchors_": false "_edit_use_anchors_": false
} }
[node name="CenterContainer" type="CenterContainer" parent="MarginContainer"] [node name="Menu Options" type="HBoxContainer" parent="Menu"]
margin_right = 300.0
margin_bottom = 160.0
[node name="HBoxContainer" type="HBoxContainer" parent="MarginContainer/CenterContainer"]
margin_left = 20.0 margin_left = 20.0
margin_top = 60.0 margin_top = 60.0
margin_right = 280.0 margin_right = 280.0
margin_bottom = 100.0 margin_bottom = 100.0
[node name="Hub World" type="TextureButton" parent="MarginContainer/CenterContainer/HBoxContainer"] [node name="Hub World" type="TextureButton" parent="Menu/Menu Options"]
margin_right = 40.0 margin_right = 40.0
margin_bottom = 40.0 margin_bottom = 40.0
texture_normal = ExtResource( 6 ) texture_normal = ExtResource( 6 )
[node name="Level 1" type="TextureButton" parent="MarginContainer/CenterContainer/HBoxContainer"] [node name="Level 1" type="TextureButton" parent="Menu/Menu Options"]
margin_left = 44.0 margin_left = 44.0
margin_right = 84.0 margin_right = 84.0
margin_bottom = 40.0 margin_bottom = 40.0
texture_normal = ExtResource( 2 ) texture_normal = ExtResource( 2 )
[node name="Level 2" type="TextureButton" parent="MarginContainer/CenterContainer/HBoxContainer"] [node name="Level 2" type="TextureButton" parent="Menu/Menu Options"]
margin_left = 88.0 margin_left = 88.0
margin_right = 128.0 margin_right = 128.0
margin_bottom = 40.0 margin_bottom = 40.0
texture_normal = ExtResource( 4 ) texture_normal = ExtResource( 4 )
[node name="Level 3" type="TextureButton" parent="MarginContainer/CenterContainer/HBoxContainer"] [node name="Level 3" type="TextureButton" parent="Menu/Menu Options"]
margin_left = 132.0 margin_left = 132.0
margin_right = 172.0 margin_right = 172.0
margin_bottom = 40.0 margin_bottom = 40.0
texture_normal = ExtResource( 1 ) texture_normal = ExtResource( 1 )
[node name="Level 4" type="TextureButton" parent="MarginContainer/CenterContainer/HBoxContainer"] [node name="Level 4" type="TextureButton" parent="Menu/Menu Options"]
margin_left = 176.0 margin_left = 176.0
margin_right = 216.0 margin_right = 216.0
margin_bottom = 40.0 margin_bottom = 40.0
texture_normal = ExtResource( 3 ) texture_normal = ExtResource( 3 )
[node name="Level 5" type="TextureButton" parent="MarginContainer/CenterContainer/HBoxContainer"] [node name="Level 5" type="TextureButton" parent="Menu/Menu Options"]
margin_left = 220.0 margin_left = 220.0
margin_right = 260.0 margin_right = 260.0
margin_bottom = 40.0 margin_bottom = 40.0
texture_normal = ExtResource( 5 ) texture_normal = ExtResource( 5 )
[connection signal="pressed" from="MarginContainer/CenterContainer/HBoxContainer/Hub World" to="." method="_on_hub_world_button_pressed"] [connection signal="pressed" from="Menu/Menu Options/Hub World" to="." method="_on_hub_world_button_pressed"]
[connection signal="pressed" from="MarginContainer/CenterContainer/HBoxContainer/Level 1" to="." method="_on_level_1_button_pressed"] [connection signal="pressed" from="Menu/Menu Options/Level 1" to="." method="_on_level_1_button_pressed"]
[connection signal="pressed" from="MarginContainer/CenterContainer/HBoxContainer/Level 2" to="." method="_on_level_2_button_pressed"] [connection signal="pressed" from="Menu/Menu Options/Level 2" to="." method="_on_level_2_button_pressed"]
[connection signal="pressed" from="MarginContainer/CenterContainer/HBoxContainer/Level 3" to="." method="_on_level_3_button_pressed"] [connection signal="pressed" from="Menu/Menu Options/Level 3" to="." method="_on_level_3_button_pressed"]
[connection signal="pressed" from="MarginContainer/CenterContainer/HBoxContainer/Level 4" to="." method="_on_level_4_button_pressed"] [connection signal="pressed" from="Menu/Menu Options/Level 4" to="." method="_on_level_4_button_pressed"]
[connection signal="pressed" from="MarginContainer/CenterContainer/HBoxContainer/Level 5" to="." method="_on_level_5_button_pressed"] [connection signal="pressed" from="Menu/Menu Options/Level 5" to="." method="_on_level_5_button_pressed"]

View File

@@ -0,0 +1,9 @@
extends Area2D
func _on_silver_key_pickup_body_entered(body: Node):
if 'player' in body.get_groups():
body.add_item('Silver Key')
call_deferred('queue_free')
return

View File

@@ -0,0 +1,23 @@
[gd_scene load_steps=4 format=2]
[ext_resource path="res://Sprites/Levels/Interactables/Silver_Key.png" type="Texture" id=1]
[ext_resource path="res://Levels/Interactables/Silver Key Pickup.gd" type="Script" id=2]
[sub_resource type="CircleShape2D" id=1]
[node name="Silver Key Pickup" type="Area2D"]
collision_layer = 0
collision_mask = 2
monitorable = false
script = ExtResource( 2 )
[node name="Sprite" type="Sprite" parent="."]
texture = ExtResource( 1 )
centered = false
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
visible = false
position = Vector2( 8, 8 )
shape = SubResource( 1 )
[connection signal="body_entered" from="." to="." method="_on_silver_key_pickup_body_entered"]

View File

@@ -1,4 +1,4 @@
[gd_scene load_steps=11 format=2] [gd_scene load_steps=12 format=2]
[ext_resource path="res://Player/Player.tscn" type="PackedScene" id=1] [ext_resource path="res://Player/Player.tscn" type="PackedScene" id=1]
[ext_resource path="res://Levels/Level 5.gd" type="Script" id=2] [ext_resource path="res://Levels/Level 5.gd" type="Script" id=2]
@@ -10,6 +10,7 @@
[ext_resource path="res://Resources/Level_5_Walls_Tileset.tres" type="TileSet" id=8] [ext_resource path="res://Resources/Level_5_Walls_Tileset.tres" type="TileSet" id=8]
[ext_resource path="res://Enemies/Glowing Ghost.tscn" type="PackedScene" id=9] [ext_resource path="res://Enemies/Glowing Ghost.tscn" type="PackedScene" id=9]
[ext_resource path="res://Levels/Traps/Spawn Trap.tscn" type="PackedScene" id=10] [ext_resource path="res://Levels/Traps/Spawn Trap.tscn" type="PackedScene" id=10]
[ext_resource path="res://Levels/Interactables/Silver Key Pickup.tscn" type="PackedScene" id=11]
[node name="Void Level" type="Node2D"] [node name="Void Level" type="Node2D"]
script = ExtResource( 2 ) script = ExtResource( 2 )
@@ -52,6 +53,11 @@ position = Vector2( 281, 109 )
[node name="Glowing Ghost 1" parent="YSort/Enemies" instance=ExtResource( 9 )] [node name="Glowing Ghost 1" parent="YSort/Enemies" instance=ExtResource( 9 )]
position = Vector2( 328.5, 20 ) position = Vector2( 328.5, 20 )
[node name="Interactables" type="Node2D" parent="."]
[node name="Silver Key Pickup" parent="Interactables" instance=ExtResource( 11 )]
position = Vector2( 240, 80 )
[node name="Traps" type="Node2D" parent="."] [node name="Traps" type="Node2D" parent="."]
[node name="Spawn Trap" parent="Traps" instance=ExtResource( 10 )] [node name="Spawn Trap" parent="Traps" instance=ExtResource( 10 )]

View File

@@ -45,13 +45,18 @@ func add_currency(amount: int) -> void:
return return
func add_item(item: String) -> void:
print('%s added to inventory' % [item])
return
func _on_Inventory_update_currency(amount: int) -> void: func _on_Inventory_update_currency(amount: int) -> void:
hud.update_currency(amount) hud.update_currency(amount)
return return
func _on_Hitbox_body_entered(body: Node) -> void: func _on_hitbox_area_entered(area: Area2D) -> void:
if not 'enemies' in body.get_groups(): if not 'enemy_hitbox' in area.get_groups():
return return
if health_index != 0: if health_index != 0:

View File

@@ -8,25 +8,25 @@
[sub_resource type="SpriteFrames" id=1] [sub_resource type="SpriteFrames" id=1]
animations = [ { animations = [ {
"frames": [ ExtResource( 2 ) ],
"loop": false,
"name": "look_right",
"speed": 5.0
}, {
"frames": [ ExtResource( 3 ) ], "frames": [ ExtResource( 3 ) ],
"loop": false, "loop": false,
"name": "look_down", "name": "look_down",
"speed": 5.0 "speed": 5.0
}, { }, {
"frames": [ ExtResource( 4 ) ], "frames": [ ExtResource( 2 ) ],
"loop": false, "loop": false,
"name": "look_up", "name": "look_right",
"speed": 5.0 "speed": 5.0
}, { }, {
"frames": [ ExtResource( 2 ) ], "frames": [ ExtResource( 2 ) ],
"loop": false, "loop": false,
"name": "look_left", "name": "look_left",
"speed": 5.0 "speed": 5.0
}, {
"frames": [ ExtResource( 4 ) ],
"loop": false,
"name": "look_up",
"speed": 5.0
} ] } ]
[sub_resource type="CapsuleShape2D" id=2] [sub_resource type="CapsuleShape2D" id=2]
@@ -180,7 +180,7 @@ graph_offset = Vector2( -3591.37, -302.6 )
[sub_resource type="AnimationNodeStateMachinePlayback" id=14] [sub_resource type="AnimationNodeStateMachinePlayback" id=14]
[node name="Player" type="KinematicBody2D"] [node name="Player" type="KinematicBody2D" groups=["player"]]
collision_layer = 2 collision_layer = 2
script = ExtResource( 1 ) script = ExtResource( 1 )
@@ -188,16 +188,17 @@ script = ExtResource( 1 )
light_mask = 2 light_mask = 2
frames = SubResource( 1 ) frames = SubResource( 1 )
animation = "look_right" animation = "look_right"
offset = Vector2( 0, -5 ) offset = Vector2( 0, -4 )
[node name="Collision" type="CollisionShape2D" parent="."] [node name="Collision" type="CollisionShape2D" parent="."]
visible = false visible = false
rotation = 1.5708 rotation = 1.5708
shape = SubResource( 2 ) shape = SubResource( 2 )
[node name="Hitbox" type="Area2D" parent="."] [node name="Hitbox" type="Area2D" parent="." groups=["player_hitbox"]]
collision_layer = 2 collision_layer = 2
collision_mask = 2 collision_mask = 4
input_pickable = false
[node name="CollisionShape2D" type="CollisionShape2D" parent="Hitbox"] [node name="CollisionShape2D" type="CollisionShape2D" parent="Hitbox"]
visible = false visible = false
@@ -220,5 +221,5 @@ parameters/Idle/blend_position = Vector2( 0.0760697, 0 )
[node name="Inventory" parent="." instance=ExtResource( 5 )] [node name="Inventory" parent="." instance=ExtResource( 5 )]
[connection signal="body_entered" from="Hitbox" to="." method="_on_Hitbox_body_entered"] [connection signal="area_entered" from="Hitbox" to="." method="_on_hitbox_area_entered"]
[connection signal="update_currency" from="Inventory" to="." method="_on_Inventory_update_currency"] [connection signal="update_currency" from="Inventory" to="." method="_on_Inventory_update_currency"]

View File

@@ -1,4 +1,4 @@
[gd_resource type="OccluderPolygon2D" format=2] [gd_resource type="OccluderPolygon2D" format=2]
[resource] [resource]
polygon = PoolVector2Array( -3, -1, 3, -1, 1.5, 1, -1.5, 1 ) polygon = PoolVector2Array( -3, -0.5, 3, -0.5, 1.5, 1.5, -1.5, 1.5 )

View File

@@ -1,6 +1,6 @@
[gd_resource type="TileSet" load_steps=2 format=2] [gd_resource type="TileSet" load_steps=2 format=2]
[ext_resource path="res://Sprites/Assets/Level_5_Floor_Tileset.png" type="Texture" id=1] [ext_resource path="res://Sprites/Levels/Tilesets/Level_5_Floor_Tileset.png" type="Texture" id=1]
[resource] [resource]
0/name = "void_level_base_tileset.png 0" 0/name = "void_level_base_tileset.png 0"

View File

@@ -1,6 +1,6 @@
[gd_resource type="TileSet" load_steps=96 format=2] [gd_resource type="TileSet" load_steps=96 format=2]
[ext_resource path="res://Sprites/Assets/Level_5_Walls_Tileset.png" type="Texture" id=1] [ext_resource path="res://Sprites/Levels/Tilesets/Level_5_Walls_Tileset.png" type="Texture" id=1]
[sub_resource type="OccluderPolygon2D" id=48] [sub_resource type="OccluderPolygon2D" id=48]
polygon = PoolVector2Array( 0, 0, 16, 0, 16, 16, 0, 16 ) polygon = PoolVector2Array( 0, 0, 16, 0, 16, 16, 0, 16 )

Binary file not shown.

After

Width:  |  Height:  |  Size: 160 B

View File

@@ -2,15 +2,15 @@
importer="texture" importer="texture"
type="StreamTexture" type="StreamTexture"
path="res://.import/Level_5_Floor_Tileset.png-8417e5e7747082b0687716c91f243b2e.stex" path="res://.import/Silver_Key.png-257bee058565f7389053b11d401f95fc.stex"
metadata={ metadata={
"vram_texture": false "vram_texture": false
} }
[deps] [deps]
source_file="res://Sprites/Assets/Level_5_Floor_Tileset.png" source_file="res://Sprites/Levels/Interactables/Silver_Key.png"
dest_files=[ "res://.import/Level_5_Floor_Tileset.png-8417e5e7747082b0687716c91f243b2e.stex" ] dest_files=[ "res://.import/Silver_Key.png-257bee058565f7389053b11d401f95fc.stex" ]
[params] [params]

View File

Before

Width:  |  Height:  |  Size: 761 B

After

Width:  |  Height:  |  Size: 761 B

View File

@@ -0,0 +1,35 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/Level_5_Floor_Tileset.png-6659a9a904b381125cc681dd7104e9c4.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://Sprites/Levels/Tilesets/Level_5_Floor_Tileset.png"
dest_files=[ "res://.import/Level_5_Floor_Tileset.png-6659a9a904b381125cc681dd7104e9c4.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=2
flags/repeat=0
flags/filter=false
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=0
process/fix_alpha_border=false
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

View File

Before

Width:  |  Height:  |  Size: 694 B

After

Width:  |  Height:  |  Size: 694 B

View File

@@ -2,15 +2,15 @@
importer="texture" importer="texture"
type="StreamTexture" type="StreamTexture"
path="res://.import/Level_5_Walls_Tileset.png-d7ec241820f3c5ab4d160dc1b4772cd2.stex" path="res://.import/Level_5_Walls_Tileset.png-c7ee165ac033cd739afab432c8bab7bd.stex"
metadata={ metadata={
"vram_texture": false "vram_texture": false
} }
[deps] [deps]
source_file="res://Sprites/Assets/Level_5_Walls_Tileset.png" source_file="res://Sprites/Levels/Tilesets/Level_5_Walls_Tileset.png"
dest_files=[ "res://.import/Level_5_Walls_Tileset.png-d7ec241820f3c5ab4d160dc1b4772cd2.stex" ] dest_files=[ "res://.import/Level_5_Walls_Tileset.png-c7ee165ac033cd739afab432c8bab7bd.stex" ]
[params] [params]

View File

@@ -55,6 +55,12 @@ screenshot={
] ]
} }
[layer_names]
2d_physics/layer_1="Immovable"
2d_physics/layer_2="Player"
2d_physics/layer_3="Enemies"
[physics] [physics]
common/enable_pause_aware_picking=true common/enable_pause_aware_picking=true