1
Fork 0
mirror of https://github.com/Steffo99/swear-jar.git synced 2024-11-25 09:04:19 +00:00

Fix collisions

This commit is contained in:
Steffo 2023-10-02 18:29:05 +02:00
parent 91a5182912
commit 17e939e4a4
Signed by: steffo
GPG key ID: 2A24051445686895
10 changed files with 73 additions and 33 deletions

View file

@ -105,8 +105,8 @@ texture = ExtResource("1_qvgnf")
4:4/0/physics_layer_0/polygon_0/points = PackedVector2Array(-8, -8, 8, -8, 8, 8, -8, 8) 4:4/0/physics_layer_0/polygon_0/points = PackedVector2Array(-8, -8, 8, -8, 8, 8, -8, 8)
[sub_resource type="TileSet" id="TileSet_tr7be"] [sub_resource type="TileSet" id="TileSet_tr7be"]
physics_layer_0/collision_layer = 3 physics_layer_0/collision_layer = 18
physics_layer_0/collision_mask = 3 physics_layer_0/collision_mask = 0
physics_layer_0/physics_material = SubResource("PhysicsMaterial_y0g3v") physics_layer_0/physics_material = SubResource("PhysicsMaterial_y0g3v")
sources/1 = SubResource("TileSetAtlasSource_6tyce") sources/1 = SubResource("TileSetAtlasSource_6tyce")

View file

@ -60,10 +60,12 @@ size = Vector2(26, 4)
size = Vector2(26, 5) size = Vector2(26, 5)
[sub_resource type="RectangleShape2D" id="RectangleShape2D_jeo5f"] [sub_resource type="RectangleShape2D" id="RectangleShape2D_jeo5f"]
size = Vector2(26, 8.83334) size = Vector2(26, 10)
[node name="CopperConverter" type="StaticBody2D" node_paths=PackedStringArray("sprite_front", "conversion_timer", "sound_working", "sound_complete", "spawner")] [node name="CopperConverter" type="StaticBody2D" node_paths=PackedStringArray("sprite_front", "conversion_timer", "sound_working", "sound_complete", "spawner")]
scale = Vector2(3, 3) scale = Vector2(3, 3)
collision_layer = 8
collision_mask = 0
script = ExtResource("1_mas6k") script = ExtResource("1_mas6k")
sprite_front = NodePath("SpriteFront") sprite_front = NodePath("SpriteFront")
conversion_timer = NodePath("ConversionTimer") conversion_timer = NodePath("ConversionTimer")
@ -125,9 +127,6 @@ debug_color = Color(0.701961, 0, 0, 0.419608)
wait_time = 0.5 wait_time = 0.5
one_shot = true one_shot = true
[node name="SoundAbsorb" type="AudioStreamPlayer" parent="."]
stream = ExtResource("10_6hhch")
[node name="SoundWorking" type="AudioStreamPlayer" parent="."] [node name="SoundWorking" type="AudioStreamPlayer" parent="."]
stream = ExtResource("10_6hhch") stream = ExtResource("10_6hhch")

View file

@ -48,6 +48,8 @@ size = Vector2(26, 10)
[node name="SilverConverter" type="StaticBody2D" node_paths=PackedStringArray("sprite_front", "conversion_timer", "sound_working", "sound_complete", "spawner")] [node name="SilverConverter" type="StaticBody2D" node_paths=PackedStringArray("sprite_front", "conversion_timer", "sound_working", "sound_complete", "spawner")]
scale = Vector2(3, 3) scale = Vector2(3, 3)
collision_layer = 8
collision_mask = 0
script = ExtResource("1_chhfg") script = ExtResource("1_chhfg")
sprite_front = NodePath("SpriteFront") sprite_front = NodePath("SpriteFront")
conversion_timer = NodePath("ConversionTimer") conversion_timer = NodePath("ConversionTimer")

View file

@ -1,18 +1,19 @@
[gd_scene load_steps=8 format=3 uid="uid://c3kitncwpi42j"] [gd_scene load_steps=9 format=3 uid="uid://c3kitncwpi42j"]
[ext_resource type="PhysicsMaterial" uid="uid://c6kn1an85lccr" path="res://entity/coin_physics_material.tres" id="1_1fypc"] [ext_resource type="PhysicsMaterial" uid="uid://c6kn1an85lccr" path="res://entity/coin_physics_material.tres" id="1_1fypc"]
[ext_resource type="Script" path="res://entity/coin_copper/coin_copper.gd" id="2_1r8w3"]
[ext_resource type="Texture2D" uid="uid://dbdkb4vt7dh85" path="res://entity/coin_copper/coin_copper_4.png" id="2_4pvkj"] [ext_resource type="Texture2D" uid="uid://dbdkb4vt7dh85" path="res://entity/coin_copper/coin_copper_4.png" id="2_4pvkj"]
[ext_resource type="Texture2D" uid="uid://2vtvoj6ua3cb" path="res://entity/coin_copper/coin_copper_outline_2.png" id="3_dq1f7"] [ext_resource type="Texture2D" uid="uid://2vtvoj6ua3cb" path="res://entity/coin_copper/coin_copper_outline_2.png" id="3_dq1f7"]
[ext_resource type="PackedScene" uid="uid://bk1vvq5rug01m" path="res://collector/collectible.tscn" id="4_npwn2"] [ext_resource type="PackedScene" uid="uid://bk1vvq5rug01m" path="res://collector/collectible.tscn" id="4_npwn2"]
[ext_resource type="PackedScene" uid="uid://ujpra0s1kpqi" path="res://value/valuable.tscn" id="5_fd0r7"] [ext_resource type="PackedScene" uid="uid://ujpra0s1kpqi" path="res://value/valuable.tscn" id="5_fd0r7"]
[ext_resource type="AudioStream" uid="uid://wy7f2j0wg1ur" path="res://audio/tap/click5.wav" id="7_fxd28"] [ext_resource type="AudioStream" uid="uid://ds2rl6eg5jr1" path="res://audio/tap/click5.wav" id="7_fxd28"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_c6byl"] [sub_resource type="RectangleShape2D" id="RectangleShape2D_c6byl"]
size = Vector2(14, 3) size = Vector2(14, 3)
[node name="CoinCopper" type="RigidBody2D"] [node name="CoinCopper" type="RigidBody2D"]
collision_layer = 5 collision_layer = 4
collision_mask = 7 collision_mask = 6
inertia = 1000.0 inertia = 1000.0
physics_material_override = ExtResource("1_1fypc") physics_material_override = ExtResource("1_1fypc")
continuous_cd = 1 continuous_cd = 1
@ -20,6 +21,7 @@ max_contacts_reported = 1
contact_monitor = true contact_monitor = true
linear_damp = 0.1 linear_damp = 0.1
angular_damp = 0.1 angular_damp = 0.1
script = ExtResource("2_1r8w3")
[node name="CollisionShape2D" type="CollisionShape2D" parent="."] [node name="CollisionShape2D" type="CollisionShape2D" parent="."]
scale = Vector2(2, 2) scale = Vector2(2, 2)

View file

@ -10,8 +10,8 @@
size = Vector2(27, 5) size = Vector2(27, 5)
[node name="CoinGold" type="RigidBody2D"] [node name="CoinGold" type="RigidBody2D"]
collision_layer = 5 collision_layer = 4
collision_mask = 7 collision_mask = 6
mass = 2.0 mass = 2.0
inertia = 600.0 inertia = 600.0
physics_material_override = ExtResource("1_nfq5t") physics_material_override = ExtResource("1_nfq5t")

View file

@ -11,8 +11,8 @@
size = Vector2(21, 4) size = Vector2(21, 4)
[node name="CoinSilver" type="RigidBody2D"] [node name="CoinSilver" type="RigidBody2D"]
collision_layer = 5 collision_layer = 4
collision_mask = 7 collision_mask = 6
mass = 1.5 mass = 1.5
inertia = 800.0 inertia = 800.0
physics_material_override = ExtResource("1_4sq1a") physics_material_override = ExtResource("1_4sq1a")

View file

@ -14,8 +14,8 @@ radius = 4.0
height = 10.0 height = 10.0
[node name="Gem" type="RigidBody2D"] [node name="Gem" type="RigidBody2D"]
collision_layer = 5 collision_layer = 4
collision_mask = 7 collision_mask = 6
mass = 1.5 mass = 1.5
inertia = 800.0 inertia = 800.0
physics_material_override = ExtResource("1_vmemd") physics_material_override = ExtResource("1_vmemd")

View file

@ -1,4 +1,4 @@
[gd_scene load_steps=23 format=3 uid="uid://c3rxmcwa5nqng"] [gd_scene load_steps=24 format=3 uid="uid://c3rxmcwa5nqng"]
[ext_resource type="Script" path="res://game/game.gd" id="1_i3ly0"] [ext_resource type="Script" path="res://game/game.gd" id="1_i3ly0"]
[ext_resource type="PackedScene" uid="uid://bllsprv8orpn4" path="res://bottle/bottle.tscn" id="1_y7o2l"] [ext_resource type="PackedScene" uid="uid://bllsprv8orpn4" path="res://bottle/bottle.tscn" id="1_y7o2l"]
@ -7,6 +7,7 @@
[ext_resource type="PackedScene" uid="uid://c67lfbk4gf1ga" path="res://spawner/spawner.tscn" id="3_qwsty"] [ext_resource type="PackedScene" uid="uid://c67lfbk4gf1ga" path="res://spawner/spawner.tscn" id="3_qwsty"]
[ext_resource type="PackedScene" uid="uid://c3kitncwpi42j" path="res://entity/coin_copper/coin_copper.tscn" id="4_5oayc"] [ext_resource type="PackedScene" uid="uid://c3kitncwpi42j" path="res://entity/coin_copper/coin_copper.tscn" id="4_5oayc"]
[ext_resource type="Texture2D" uid="uid://taojrwr7xrp4" path="res://interface/upgrade_gold.png" id="4_i557v"] [ext_resource type="Texture2D" uid="uid://taojrwr7xrp4" path="res://interface/upgrade_gold.png" id="4_i557v"]
[ext_resource type="Texture2D" uid="uid://pj3ip6vlatms" path="res://converters/copper_to_silver/copper_converter.png" id="6_0jj8g"]
[ext_resource type="PackedScene" uid="uid://beg758fa6o0cs" path="res://value/evaluator.tscn" id="6_my6nv"] [ext_resource type="PackedScene" uid="uid://beg758fa6o0cs" path="res://value/evaluator.tscn" id="6_my6nv"]
[ext_resource type="PackedScene" uid="uid://ratkps4plkhl" path="res://converters/copper_to_silver/copper_converter.tscn" id="7_ipeok"] [ext_resource type="PackedScene" uid="uid://ratkps4plkhl" path="res://converters/copper_to_silver/copper_converter.tscn" id="7_ipeok"]
[ext_resource type="PackedScene" uid="uid://4d0al27t7axe" path="res://bottle/placeable_area.tscn" id="7_muqgj"] [ext_resource type="PackedScene" uid="uid://4d0al27t7axe" path="res://bottle/placeable_area.tscn" id="7_muqgj"]
@ -40,8 +41,11 @@ upgrade_copper_texture = ExtResource("11_lt33g")
upgrade_silver_texture = ExtResource("3_8wvr1") upgrade_silver_texture = ExtResource("3_8wvr1")
upgrade_gold_texture = ExtResource("4_i557v") upgrade_gold_texture = ExtResource("4_i557v")
[node name="Ghost" parent="." instance=ExtResource("16_8vhx6")] [node name="Ghost" parent="." node_paths=PackedStringArray("target") instance=ExtResource("16_8vhx6")]
position = Vector2(90, 306) position = Vector2(90, 306)
preview_texture = ExtResource("6_0jj8g")
scene_to_instantiate = ExtResource("7_ipeok")
target = NodePath("..")
[node name="Bottle" parent="." instance=ExtResource("1_y7o2l")] [node name="Bottle" parent="." instance=ExtResource("1_y7o2l")]

View file

@ -11,12 +11,20 @@ class_name Ghost
## The [Sprite2D] node previewing the scene. ## The [Sprite2D] node previewing the scene.
@onready var preview_sprite: Sprite2D = $PlacementShape/PreviewSprite @onready var preview_sprite: Sprite2D = $PlacementShape/PreviewSprite
## The collision mask of objects that should prevent this object's placement.
@export_flags_2d_physics var collision_mask_prevent_placement: int
## The collision mask of objects that should be deleted on this object's placement.
@export_flags_2d_physics var collision_mask_delete_placement: int
## The texture that the preview sprite should display. ## The texture that the preview sprite should display.
@export var preview_texture: Texture2D: @export var preview_texture: Texture2D:
get: get:
return preview_texture return preview_texture
set(value): set(value):
preview_texture = value preview_texture = value
# Quick priority fix
if preview_sprite:
preview_sprite.texture = value preview_sprite.texture = value
## Whether the ghost can be placed at the current location of the ghost. ## Whether the ghost can be placed at the current location of the ghost.
@ -35,6 +43,11 @@ var can_place: bool:
var last_input_event: InputEvent var last_input_event: InputEvent
func _ready():
collision_mask = collision_mask_prevent_placement | collision_mask_delete_placement
preview_sprite.texture = preview_texture
func _input(event: InputEvent): func _input(event: InputEvent):
# Handle mouse click # Handle mouse click
if event is InputEventMouseButton: if event is InputEventMouseButton:
@ -57,18 +70,38 @@ func _input(event: InputEvent):
position += delta position += delta
last_input_event = event last_input_event = event
func _physics_process(_delta: float):
var overlapping_bodies = get_overlapping_bodies()
var no_overlapping_bodies = true
var is_enclosed_by_placeable_area = false
# DIRTY HACK: Relies on the placeable area being perfectly surrounded by solid bodies. # DIRTY HACK: Relies on the placeable area being perfectly surrounded by solid bodies.
func _physics_process(_delta: float):
var no_overlapping_bodies: bool = true
var overlapping_bodies = get_overlapping_bodies()
for body in overlapping_bodies:
if body is TileMap:
no_overlapping_bodies = false
elif body is PhysicsBody2D:
var body_prevents_placement = bool(body.collision_layer & collision_mask_prevent_placement)
no_overlapping_bodies = no_overlapping_bodies and not body_prevents_placement
var is_in_placeable_area: bool = false
var overlapping_areas = get_overlapping_areas() var overlapping_areas = get_overlapping_areas()
for area in overlapping_areas: for area in overlapping_areas:
if not area is PlaceableArea: if area is PlaceableArea:
continue is_in_placeable_area = true
is_enclosed_by_placeable_area = true
can_place = no_overlapping_bodies and is_enclosed_by_placeable_area can_place = no_overlapping_bodies and is_in_placeable_area
## The [PackedScene] that this node should instantiate.
@export var scene_to_instantiate: PackedScene
## The [Node] instatiated scenes should be added as children to.
@export var target: Node
## Emitted when the [materialize] function has finished executing.
signal materialized(node: Node)
func materialize():
var instantiated = scene_to_instantiate.instantiate()
instantiated.global_position = global_position
instantiated.rotation = rotation
target.add_child(instantiated)
materialized.emit(instantiated)

View file

@ -1,14 +1,15 @@
[gd_scene load_steps=4 format=3 uid="uid://qtk4tm6l367w"] [gd_scene load_steps=3 format=3 uid="uid://qtk4tm6l367w"]
[ext_resource type="Script" path="res://interface/ghost.gd" id="1_gvls7"] [ext_resource type="Script" path="res://interface/ghost.gd" id="1_gvls7"]
[ext_resource type="Texture2D" uid="uid://pj3ip6vlatms" path="res://converters/copper_to_silver/copper_converter.png" id="1_lo8gj"]
[ext_resource type="PackedScene" uid="uid://c3p0jdf7416ac" path="res://converters/full_converter_shape.tscn" id="3_lskcf"] [ext_resource type="PackedScene" uid="uid://c3p0jdf7416ac" path="res://converters/full_converter_shape.tscn" id="3_lskcf"]
[node name="Ghost" type="Area2D"] [node name="Ghost" type="Area2D"]
collision_layer = 0 collision_layer = 0
collision_mask = 16 collision_mask = 4294967295
input_pickable = false input_pickable = false
script = ExtResource("1_gvls7") script = ExtResource("1_gvls7")
collision_mask_prevent_placement = 16
collision_mask_delete_placement = 4
[node name="PlacementShape" parent="." instance=ExtResource("3_lskcf")] [node name="PlacementShape" parent="." instance=ExtResource("3_lskcf")]
scale = Vector2(3, 3) scale = Vector2(3, 3)
@ -16,4 +17,3 @@ scale = Vector2(3, 3)
[node name="PreviewSprite" type="Sprite2D" parent="PlacementShape"] [node name="PreviewSprite" type="Sprite2D" parent="PlacementShape"]
modulate = Color(1, 1, 1, 0.5) modulate = Color(1, 1, 1, 0.5)
z_index = 10 z_index = 10
texture = ExtResource("1_lo8gj")