diff --git a/GameScreen.tscn b/GameScreen.tscn index 9aa46cc..b599473 100644 --- a/GameScreen.tscn +++ b/GameScreen.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=17 format=2] +[gd_scene load_steps=21 format=2] [ext_resource path="res://GameScreen.gd" type="Script" id=1] [ext_resource path="res://assets/0x72_16x16DungeonTileset.v4.png" type="Texture" id=2] @@ -6,6 +6,9 @@ [ext_resource path="res://lib/player/Player.tscn" type="PackedScene" id=4] [ext_resource path="res://lib/bow/Bow.tscn" type="PackedScene" id=5] [ext_resource path="res://lib/ui/HUD.tscn" type="PackedScene" id=6] +[ext_resource path="res://assets/0x72_16x16DungeonTileset_walls.v2.png" type="Texture" id=7] +[ext_resource path="res://assets/Structures.png" type="Texture" id=8] +[ext_resource path="res://lib/door/Door.tscn" type="PackedScene" id=9] [sub_resource type="ConvexPolygonShape2D" id=11] points = PoolVector2Array( 16, 16, 0, 16, 0, 16, 16, 16 ) @@ -34,6 +37,9 @@ points = PoolVector2Array( 0, 0, 16, 0, 16, 16, 0, 16 ) [sub_resource type="ConvexPolygonShape2D" id=19] points = PoolVector2Array( 16, 16, 0, 16, 0, 0, 16, 0 ) +[sub_resource type="ConvexPolygonShape2D" id=21] +points = PoolVector2Array( 0, 0, 32, 0, 32, 32, 0, 32 ) + [sub_resource type="TileSet" id=20] 0/name = "0x72_16x16DungeonTileset.v4.png 0" 0/texture = ExtResource( 2 ) @@ -153,6 +159,55 @@ points = PoolVector2Array( 16, 16, 0, 16, 0, 0, 16, 0 ) 2/shape_one_way_margin = 0.0 2/shapes = [ ] 2/z_index = 0 +3/name = "closed_door" +3/texture = ExtResource( 7 ) +3/tex_offset = Vector2( 0, 0 ) +3/modulate = Color( 1, 1, 1, 1 ) +3/region = Rect2( 112, 16, 32, 32 ) +3/tile_mode = 0 +3/occluder_offset = Vector2( 0, 0 ) +3/navigation_offset = Vector2( 0, 0 ) +3/shape_offset = Vector2( 0, 0 ) +3/shape_transform = Transform2D( 1, 0, 0, 1, 0, 0 ) +3/shape = SubResource( 21 ) +3/shape_one_way = false +3/shape_one_way_margin = 1.0 +3/shapes = [ { +"autotile_coord": Vector2( 0, 0 ), +"one_way": false, +"one_way_margin": 1.0, +"shape": SubResource( 21 ), +"shape_transform": Transform2D( 1, 0, 0, 1, 0, 0 ) +} ] +3/z_index = 0 +4/name = "0x72_16x16DungeonTileset_walls.v2.png 4" +4/texture = ExtResource( 7 ) +4/tex_offset = Vector2( 0, 0 ) +4/modulate = Color( 1, 1, 1, 1 ) +4/region = Rect2( 176, 16, 32, 32 ) +4/tile_mode = 0 +4/occluder_offset = Vector2( 0, 0 ) +4/navigation_offset = Vector2( 0, 0 ) +4/shape_offset = Vector2( 0, 0 ) +4/shape_transform = Transform2D( 1, 0, 0, 1, 0, 0 ) +4/shape_one_way = false +4/shape_one_way_margin = 0.0 +4/shapes = [ ] +4/z_index = 0 +5/name = "Structures.png 5" +5/texture = ExtResource( 8 ) +5/tex_offset = Vector2( 0, 0 ) +5/modulate = Color( 1, 1, 1, 1 ) +5/region = Rect2( 96, 0, 16, 16 ) +5/tile_mode = 0 +5/occluder_offset = Vector2( 0, 0 ) +5/navigation_offset = Vector2( 0, 0 ) +5/shape_offset = Vector2( 0, 0 ) +5/shape_transform = Transform2D( 1, 0, 0, 1, 0, 0 ) +5/shape_one_way = false +5/shape_one_way_margin = 0.0 +5/shapes = [ ] +5/z_index = 0 [node name="GameScreen" type="Node"] script = ExtResource( 1 ) @@ -164,10 +219,13 @@ script = ExtResource( 1 ) [node name="TileMap" type="TileMap" parent="Level/Level0"] tile_set = SubResource( 20 ) cell_size = Vector2( 16, 16 ) +show_collision = true collision_layer = 32 -collision_mask = 0 format = 1 -tile_data = PoolIntArray( 65538, 0, 2, 65539, 0, 2, 65540, 0, 2, 65541, 0, 2, 65542, 0, 2, 65543, 0, 2, 65544, 0, 2, 65545, 0, 2, 65546, 0, 2, 65547, 0, 2, 65548, 0, 2, 65549, 0, 2, 65550, 0, 2, 65551, 0, 2, 65552, 0, 2, 65553, 0, 2, 65554, 0, 2, 65555, 0, 2, 131074, 0, 65536, 131075, 0, 65536, 131076, 1, 3, 131077, 0, 65536, 131078, 0, 262149, 131079, 0, 65536, 131080, 0, 65536, 131081, 0, 65536, 131082, 1, 5, 131083, 0, 65536, 131084, 0, 65536, 131085, 0, 65536, 131086, 0, 65536, 131087, 0, 65539, 131088, 0, 65536, 131089, 0, 65536, 131090, 0, 65536, 131091, 0, 65536, 196610, 0, 65536, 196611, 0, 131072, 196612, 0, 131072, 196613, 0, 131072, 196614, 0, 327685, 196615, 0, 131072, 196616, 0, 131072, 196617, 0, 131072, 196618, 0, 131072, 196619, 0, 131072, 196620, 0, 131072, 196621, 0, 131072, 196622, 0, 131072, 196623, 0, 131075, 196624, 0, 131072, 196625, 0, 131072, 196626, 0, 131072, 196627, 0, 65536, 262146, 0, 65536, 262147, 0, 196610, 262148, 0, 196610, 262149, 0, 196610, 262150, 0, 196610, 262151, 0, 196610, 262152, 0, 196610, 262153, 0, 196610, 262154, 0, 196610, 262155, 0, 196610, 262156, 0, 196610, 262157, 0, 196610, 262158, 0, 196610, 262159, 0, 196610, 262160, 0, 196610, 262161, 0, 196610, 262162, 0, 196610, 262163, 0, 65536, 327682, 0, 65536, 327683, 0, 196610, 327684, 0, 196610, 327685, 0, 196610, 327686, 0, 196610, 327687, 0, 196610, 327688, 0, 196610, 327689, 0, 196610, 327690, 0, 196610, 327691, 0, 196610, 327692, 0, 196610, 327693, 0, 196610, 327694, 0, 196610, 327695, 0, 196610, 327696, 0, 196610, 327697, 0, 196610, 327698, 0, 196610, 327699, 0, 65536, 393218, 0, 65536, 393219, 0, 196610, 393220, 0, 196610, 393221, 0, 196610, 393222, 0, 196610, 393223, 0, 393216, 393224, 0, 393217, 393225, 0, 393217, 393226, 0, 393217, 393227, 0, 393217, 393228, 0, 393219, 393229, 0, 196610, 393230, 0, 196610, 393231, 0, 196610, 393232, 0, 196610, 393233, 0, 196610, 393234, 0, 196610, 393235, 0, 65536, 458754, 0, 65536, 458755, 0, 196610, 458756, 0, 196610, 458757, 0, 196610, 458758, 0, 196610, 458759, 0, 458752, 458760, 0, 458756, 458761, 0, 458756, 458762, 0, 458756, 458763, 0, 458756, 458764, 0, 458755, 458765, 0, 196610, 458766, 0, 196610, 458767, 0, 196610, 458768, 0, 196610, 458769, 0, 196610, 458770, 0, 196610, 458771, 0, 65536, 524290, 0, 65536, 524291, 0, 196610, 524292, 0, 196610, 524293, 0, 196610, 524294, 0, 196610, 524295, 0, 524288, 524296, 0, 524289, 524297, 0, 524289, 524298, 0, 524289, 524299, 0, 524289, 524300, 0, 458755, 524301, 0, 196610, 524302, 0, 196610, 524303, 0, 196610, 524304, 0, 196610, 524305, 0, 196610, 524306, 0, 196610, 524307, 0, 65536, 589826, 0, 65536, 589827, 0, 196610, 589828, 0, 196610, 589829, 0, 196610, 589830, 0, 196610, 589831, 0, 196610, 589832, 0, 196610, 589833, 0, 196610, 589834, 0, 196610, 589835, 0, 196610, 589836, 0, 458755, 589837, 0, 196610, 589838, 0, 196610, 589839, 0, 196610, 589840, 0, 196610, 589841, 0, 196610, 589842, 0, 196610, 589843, 0, 65536, 655362, 0, 65536, 655363, 0, 196610, 655364, 0, 196610, 655365, 0, 196610, 655366, 0, 196610, 655367, 0, 196610, 655368, 0, 196610, 655369, 0, 196610, 655370, 0, 196610, 655371, 0, 196610, 655372, 0, 196610, 655373, 0, 196610, 655374, 0, 196610, 655375, 0, 196610, 655376, 0, 196610, 655377, 0, 196610, 655378, 0, 196610, 655379, 0, 65536, 720898, 0, 65536, 720899, 0, 196610, 720900, 0, 196610, 720901, 0, 196610, 720902, 0, 196610, 720903, 0, 196610, 720904, 0, 196610, 720905, 0, 196610, 720906, 0, 196610, 720907, 0, 196610, 720908, 0, 196610, 720909, 0, 196610, 720910, 0, 196610, 720911, 0, 196610, 720912, 0, 196610, 720913, 0, 196610, 720914, 0, 196610, 720915, 0, 65536, 786434, 0, 65536, 786435, 0, 196610, 786436, 0, 196610, 786437, 0, 196610, 786438, 0, 196610, 786439, 0, 196610, 786440, 0, 196610, 786441, 0, 196610, 786442, 0, 196610, 786443, 0, 196610, 786444, 0, 196610, 786445, 0, 196610, 786446, 0, 196610, 786447, 0, 196610, 786448, 0, 196610, 786449, 0, 196610, 786450, 0, 196610, 786451, 0, 65536, 851970, 0, 65536, 851971, 0, 65536, 851972, 0, 65536, 851973, 0, 65536, 851974, 0, 65536, 851975, 0, 65536, 851976, 0, 65536, 851977, 0, 65536, 851978, 0, 65536, 851979, 0, 65536, 851980, 0, 65536, 851981, 0, 65536, 851982, 0, 65536, 851983, 0, 65536, 851984, 0, 65536, 851985, 0, 65536, 851986, 0, 65536, 851987, 0, 65536 ) +tile_data = PoolIntArray( -65536, 0, 196608, -65535, 0, 196608, -65534, 0, 196608, -65533, 0, 196608, -65532, 0, 196608, -65531, 0, 196608, -65530, 0, 196608, -65527, 0, 196608, -65526, 0, 196608, -65525, 0, 196608, -65524, 0, 196608, -65523, 0, 196608, -65522, 0, 196608, -65521, 0, 196608, -65520, 0, 196608, 7, 0, 6, 8, 0, 6, 65538, 0, 2, 65539, 0, 2, 65540, 0, 2, 65541, 0, 2, 65542, 0, 2, 65543, 0, 6, 65544, 0, 6, 65545, 0, 2, 65546, 0, 2, 65547, 0, 2, 65548, 0, 2, 65549, 0, 2, 65550, 0, 2, 65551, 0, 2, 65552, 0, 2, 65553, 0, 2, 65554, 0, 2, 65555, 0, 2, 131074, 0, 65536, 131075, 0, 65536, 131076, 1, 3, 131077, 0, 65536, 131078, 0, 262149, 131079, 0, 6, 131080, 0, 6, 131081, 0, 65536, 131082, 1, 5, 131083, 0, 65536, 131084, 5, 0, 131085, 0, 65536, 131086, 0, 65536, 131087, 0, 65539, 131088, 0, 65536, 131089, 0, 65536, 131090, 0, 65536, 131091, 0, 65536, 196610, 0, 65536, 196611, 0, 131072, 196612, 0, 131072, 196613, 0, 131072, 196614, 0, 327685, 196615, 0, 131072, 196616, 0, 131072, 196617, 0, 131072, 196618, 0, 131072, 196619, 0, 131072, 196620, 0, 131072, 196621, 0, 131072, 196622, 0, 131072, 196623, 0, 131075, 196624, 0, 131072, 196625, 0, 131072, 196626, 0, 131072, 196627, 0, 65536, 262146, 0, 65536, 262147, 0, 196610, 262148, 0, 196610, 262149, 0, 196610, 262150, 0, 196610, 262151, 0, 196610, 262152, 0, 196610, 262153, 0, 196610, 262154, 0, 196610, 262155, 0, 196610, 262156, 0, 196610, 262157, 0, 196610, 262158, 0, 196610, 262159, 0, 196610, 262160, 0, 196610, 262161, 0, 196610, 262162, 0, 196610, 262163, 0, 65536, 327682, 0, 65536, 327683, 0, 196610, 327684, 0, 196610, 327685, 0, 196610, 327686, 0, 196610, 327687, 0, 196610, 327688, 0, 196610, 327689, 0, 196610, 327690, 0, 196610, 327691, 0, 196610, 327692, 0, 196610, 327693, 0, 196610, 327694, 0, 196610, 327695, 0, 196610, 327696, 0, 196610, 327697, 0, 196610, 327698, 0, 196610, 327699, 0, 65536, 393218, 0, 65536, 393219, 0, 196610, 393220, 0, 196610, 393221, 0, 196610, 393222, 0, 196610, 393223, 0, 393216, 393224, 0, 393217, 393225, 0, 393217, 393226, 0, 393217, 393227, 0, 393217, 393228, 0, 393219, 393229, 0, 196610, 393230, 0, 196610, 393231, 0, 196610, 393232, 0, 196610, 393233, 0, 196610, 393234, 0, 196610, 393235, 0, 65536, 458754, 0, 65536, 458755, 0, 196610, 458756, 0, 196610, 458757, 0, 196610, 458758, 0, 196610, 458759, 0, 458752, 458760, 0, 458756, 458761, 0, 458756, 458762, 0, 458756, 458763, 0, 458756, 458764, 0, 458755, 458765, 0, 196610, 458766, 0, 196610, 458767, 0, 196610, 458768, 0, 196610, 458769, 0, 196610, 458770, 0, 196610, 458771, 0, 65536, 524290, 0, 65536, 524291, 0, 196610, 524292, 0, 196610, 524293, 0, 196610, 524294, 0, 196610, 524295, 0, 524288, 524296, 0, 524289, 524297, 0, 524289, 524298, 0, 524289, 524299, 0, 524289, 524300, 0, 458755, 524301, 0, 196610, 524302, 0, 196610, 524303, 0, 196610, 524304, 0, 196610, 524305, 0, 196610, 524306, 0, 196610, 524307, 0, 65536, 589826, 0, 65536, 589827, 0, 196610, 589828, 0, 196610, 589829, 0, 196610, 589830, 0, 196610, 589831, 0, 196610, 589832, 0, 196610, 589833, 0, 196610, 589834, 0, 196610, 589835, 0, 196610, 589836, 0, 458755, 589837, 0, 196610, 589838, 0, 196610, 589839, 0, 196610, 589840, 0, 196610, 589841, 0, 196610, 589842, 0, 196610, 589843, 0, 65536, 655362, 0, 65536, 655363, 0, 196610, 655364, 0, 196610, 655365, 0, 196610, 655366, 0, 196610, 655367, 0, 196610, 655368, 0, 196610, 655369, 0, 196610, 655370, 0, 196610, 655371, 0, 196610, 655372, 0, 196610, 655373, 0, 196610, 655374, 0, 196610, 655375, 0, 196610, 655376, 0, 196610, 655377, 0, 196610, 655378, 0, 196610, 655379, 0, 65536, 720898, 0, 65536, 720899, 0, 196610, 720900, 0, 196610, 720901, 0, 196610, 720902, 0, 196610, 720903, 0, 196610, 720904, 0, 196610, 720905, 0, 196610, 720906, 0, 196610, 720907, 0, 196610, 720908, 0, 196610, 720909, 0, 196610, 720910, 0, 196610, 720911, 0, 196610, 720912, 0, 196610, 720913, 0, 196610, 720914, 0, 196610, 720915, 0, 65536, 786434, 0, 65536, 786435, 0, 196610, 786436, 0, 196610, 786437, 0, 196610, 786438, 0, 196610, 786439, 0, 196610, 786440, 0, 196610, 786441, 0, 196610, 786442, 0, 196610, 786443, 0, 196610, 786444, 0, 196610, 786445, 0, 196610, 786446, 0, 196610, 786447, 0, 196610, 786448, 0, 196610, 786449, 0, 196610, 786450, 0, 196610, 786451, 0, 65536, 851970, 0, 65536, 851971, 0, 65536, 851972, 0, 65536, 851973, 0, 65536, 851974, 0, 65536, 851975, 0, 65536, 851976, 0, 65536, 851977, 0, 65536, 851978, 0, 65536, 851979, 0, 65536, 851980, 0, 65536, 851981, 0, 65536, 851982, 0, 65536, 851983, 0, 65536, 851984, 0, 65536, 851985, 0, 65536, 851986, 0, 65536, 851987, 0, 65536 ) + +[node name="Door" parent="Level/Level0" instance=ExtResource( 9 )] +position = Vector2( 128, 32 ) [node name="King" parent="Level/Level0" instance=ExtResource( 3 )] visible = false diff --git a/assets/0x72_16x16DungeonTileset_walls.v2.png.import b/assets/0x72_16x16DungeonTileset_walls.v2.png.import index 2c53255..3260c68 100644 --- a/assets/0x72_16x16DungeonTileset_walls.v2.png.import +++ b/assets/0x72_16x16DungeonTileset_walls.v2.png.import @@ -20,7 +20,7 @@ compress/hdr_mode=0 compress/bptc_ldr=0 compress/normal_map=0 flags/repeat=0 -flags/filter=true +flags/filter=false flags/mipmaps=false flags/anisotropic=false flags/srgb=2 diff --git a/entites/weapons/Arrow.gd b/entites/weapons/Arrow.gd index 04bb45e..fc53a0d 100644 --- a/entites/weapons/Arrow.gd +++ b/entites/weapons/Arrow.gd @@ -8,3 +8,7 @@ func _ready(): func _physics_process(delta): translate(velocity*direction*delta) + + +func _on_VisibilityNotifier2D_screen_exited(): + queue_free() diff --git a/entites/weapons/Arrow.tscn b/entites/weapons/Arrow.tscn index c87420e..eff01c4 100644 --- a/entites/weapons/Arrow.tscn +++ b/entites/weapons/Arrow.tscn @@ -59,3 +59,7 @@ scale_amount_curve = SubResource( 3 ) color_ramp = SubResource( 4 ) anim_speed = 0.5 anim_speed_random = 1.0 + +[node name="VisibilityNotifier2D" type="VisibilityNotifier2D" parent="." index="2"] + +[connection signal="screen_exited" from="VisibilityNotifier2D" to="." method="_on_VisibilityNotifier2D_screen_exited"] diff --git a/lib/SenseArea.gd b/lib/SenseArea.gd index da56fb4..9c59105 100644 --- a/lib/SenseArea.gd +++ b/lib/SenseArea.gd @@ -1,3 +1,4 @@ +tool extends Area2D export(Array,String) var sensing_groups diff --git a/lib/bow/Bow.gd b/lib/bow/Bow.gd index 09734ad..d15c7ad 100644 --- a/lib/bow/Bow.gd +++ b/lib/bow/Bow.gd @@ -35,6 +35,9 @@ func shoot(): arrow.direction = direction get_node(entity).get_parent().add_child(arrow) +func disable_player_on_weapon(): + $BodyArea.monitoring = false + $BodyArea/CollisionShape2D.disabled = true func _on_BodyArea_body_entered(body): print("{0} is on bow".format({0:body})) diff --git a/lib/door/Door.gd b/lib/door/Door.gd new file mode 100644 index 0000000..5ecd8c1 --- /dev/null +++ b/lib/door/Door.gd @@ -0,0 +1,27 @@ +extends Node2D + + +export(Vector2) var closed_door_region_position +export(Vector2) var opened_door_region_position + +var is_opened := false setget set_opened + +func _ready(): + set_opened(false) + + +func set_opened(opened): + if opened: + $Sprite.region_rect.position = opened_door_region_position + #$SenseArea.set_collision_mask_bit(0,false) + else: + $Sprite.region_rect.position = closed_door_region_position + #$SenseArea.set_collision_mask_bit(0,true) + + +func _on_SenseArea_mouse_entered(): + set_opened(true) + + +func _on_SenseArea_mouse_exited(): + set_opened(false) diff --git a/lib/door/Door.tscn b/lib/door/Door.tscn new file mode 100644 index 0000000..07beff1 --- /dev/null +++ b/lib/door/Door.tscn @@ -0,0 +1,32 @@ +[gd_scene load_steps=5 format=2] + +[ext_resource path="res://assets/0x72_16x16DungeonTileset_walls.v2.png" type="Texture" id=1] +[ext_resource path="res://lib/SenseArea.tscn" type="PackedScene" id=2] +[ext_resource path="res://lib/door/Door.gd" type="Script" id=3] + +[sub_resource type="RectangleShape2D" id=1] +extents = Vector2( 16, 12 ) + +[node name="Door" type="Area2D"] +collision_layer = 64 +collision_mask = 17 +script = ExtResource( 3 ) +closed_door_region_position = Vector2( 112, 16 ) +opened_door_region_position = Vector2( 176, 16 ) + +[node name="Sprite" type="Sprite" parent="."] +texture = ExtResource( 1 ) +region_enabled = true +region_rect = Rect2( 112, 16, 32, 32 ) + +[node name="SenseArea" parent="." instance=ExtResource( 2 )] +collision_layer = 64 +collision_mask = 17 +radius = 32.787 + +[node name="CollisionShape2D" type="CollisionShape2D" parent="."] +position = Vector2( 0, 4 ) +shape = SubResource( 1 ) + +[connection signal="mouse_entered" from="SenseArea" to="." method="_on_SenseArea_mouse_entered"] +[connection signal="mouse_exited" from="SenseArea" to="." method="_on_SenseArea_mouse_exited"] diff --git a/lib/knife/Knife.tscn b/lib/knife/Knife.tscn index 6ef6a86..6fbdd27 100644 --- a/lib/knife/Knife.tscn +++ b/lib/knife/Knife.tscn @@ -6,6 +6,7 @@ [node name="Knife" type="Node2D"] script = ExtResource( 1 ) +icon_texture = ExtResource( 2 ) [node name="Sprite" type="Sprite" parent="."] position = Vector2( 1, 0 ) diff --git a/lib/player/Player.gd b/lib/player/Player.gd index 34db416..e9ed445 100644 --- a/lib/player/Player.gd +++ b/lib/player/Player.gd @@ -9,7 +9,7 @@ onready var weapon_position = $WeaponPosition onready var animation_tree = $AnimationTree onready var animation_state = animation_tree.get("parameters/playback") -onready var weapon = $WeaponPosition/Knife +onready var weapon = inventory.get_child(0) var is_moving := false var weapon_position_distance :=0.0 @@ -19,14 +19,32 @@ func _ready(): movement.connect("moved",self,"on_moved") movement.connect("stopped",self,"on_stopped") EventBus.connect("player_on_weapon",self, "on_player_on_weapon") + EventBus.connect("player_exchange_weapon",self,"on_player_exchange_weapon") animation_state.travel("idle") weapon_position_distance = global_position.distance_to(weapon_position.position) +func on_player_exchange_weapon(new_weapon: Node2D): + print("on_player_exchange_weapon()") + + for item in inventory.get_children(): + item.visible = false + + new_weapon.visible = true + inventory.move_child(new_weapon,0) + weapon = inventory.get_child(0) + EventBus.emit_signal("weapon_modifed") + + func on_player_on_weapon(_weapon): print("on_player_on_weapon") + add_weapon_to_inventory(_weapon) + +func add_weapon_to_inventory(_weapon): if inventory.has_free_slot(): _weapon.get_parent().remove_child(_weapon) _weapon.visible = false + _weapon.entity = get_path() + _weapon.disable_player_on_weapon() inventory.add_item(_weapon) func _physics_process(delta): @@ -34,8 +52,10 @@ func _physics_process(delta): #if is_moving: var mouse_position = get_global_mouse_position() movement.direction = lerp(movement.direction,(mouse_position - global_position).normalized(),0.9) - weapon_position.look_at(mouse_position) - weapon.on_mouse_moved(get_weapon_position(),movement.direction) + + if weapon: + weapon_position.look_at(mouse_position) + weapon.on_mouse_moved(get_weapon_position(),movement.direction) # var mouse_position = get_global_mouse_position() # movement.direction = (mouse_position - get_weapon_position()).normalized() diff --git a/lib/player/Player.tscn b/lib/player/Player.tscn index 5a4ec05..dd8483c 100644 --- a/lib/player/Player.tscn +++ b/lib/player/Player.tscn @@ -513,7 +513,7 @@ tracks/1/keys = { [node name="Player" type="KinematicBody2D"] position = Vector2( 128, 137 ) -collision_mask = 33 +collision_mask = 96 script = ExtResource( 1 ) [node name="Sprite" type="Sprite" parent="."] @@ -527,6 +527,9 @@ shape = SubResource( 21 ) [node name="Inventory" parent="." instance=ExtResource( 5 )] +[node name="Knife" parent="Inventory" instance=ExtResource( 12 )] +position = Vector2( 116, 140 ) + [node name="SenseArea" parent="." instance=ExtResource( 6 )] [node name="KinematicMovementComponent" type="Node" parent="."] @@ -536,7 +539,7 @@ group = "player" [node name="AnimatedSprite" type="AnimatedSprite" parent="."] frames = SubResource( 37 ) animation = "idle_left" -frame = 3 +frame = 4 playing = true [node name="AnimationTree" type="AnimationTree" parent="."] @@ -559,6 +562,3 @@ anims/walk_up = SubResource( 74 ) [node name="WeaponPosition" type="Position2D" parent="."] position = Vector2( -11.3785, 5.77687 ) - -[node name="Knife" parent="WeaponPosition" instance=ExtResource( 12 )] -position = Vector2( -0.621498, -2.77687 ) diff --git a/lib/ui/HUD.gd b/lib/ui/HUD.gd index 80988d1..b29d783 100644 --- a/lib/ui/HUD.gd +++ b/lib/ui/HUD.gd @@ -3,23 +3,42 @@ extends CanvasLayer onready var num_items = $"%MenuItems" onready var inventory_ui = $InventoryContainer +onready var inventory_items_ui = $"%GridContainer" export(NodePath) var player_path - -var player +onready var player = get_node(player_path) # Called when the node enters the scene tree for the first time. func _ready(): EventBus.connect("inventory_modified",self, "on_inventory_modified") + EventBus.connect("weapon_modifed",self,"on_weapon_modified") inventory_ui.visible = false - player = get_node(player_path) + +func _update_invetory_ui(): + for el in inventory_items_ui.get_children(): + el.texture = null + el.item = null + + + print(" ui invntory slots: ",inventory_items_ui.get_child_count()) + var pos = 0 + for inventory_item in player.inventory.get_children(): + #inventory_ui.show_item(inventory_item) + #var path = "InventoryItemIcon{0}".format({0:pos}) + var node = inventory_items_ui.get_child(pos) + print(" -> ",node) + node.texture = inventory_item.icon_texture + node.item = inventory_item + + +func on_weapon_modified(): + _update_invetory_ui() func on_inventory_modified(inventory): print("inventory modified") num_items.text = str(inventory.get_child_count()) - for inventory_item in inventory.get_children(): - inventory_ui.show_item(inventory_item) + _update_invetory_ui() func _on_TextureRect_mouse_entered(): @@ -38,10 +57,6 @@ func _on_InventoryContainer_mouse_exited(): enable_player_input(true) - - -func _on_ColorRect_mouse_exited(): +func _on_Button_button_down(): inventory_ui.visible = false enable_player_input(true) - - diff --git a/lib/ui/HUD.tscn b/lib/ui/HUD.tscn index 73c0f48..8c99c2e 100644 --- a/lib/ui/HUD.tscn +++ b/lib/ui/HUD.tscn @@ -56,23 +56,75 @@ texture = ExtResource( 2 ) unique_name_in_owner = true anchor_top = 1.0 anchor_bottom = 1.0 -margin_left = 10.0 +margin_left = 2.0 margin_top = -197.0 margin_right = 165.0 margin_bottom = -25.0 script = ExtResource( 4 ) [node name="ColorRect" type="ColorRect" parent="InventoryContainer"] -margin_right = 155.0 +margin_right = 163.0 margin_bottom = 172.0 color = Color( 0.505882, 0.505882, 0.505882, 0.403922 ) -[node name="GridContainer" type="GridContainer" parent="InventoryContainer/ColorRect"] +[node name="HBoxContainer" type="HBoxContainer" parent="InventoryContainer/ColorRect"] +margin_left = 10.0 +margin_top = 10.0 margin_right = 40.0 margin_bottom = 40.0 -[node name="InventoryItemIcon" parent="InventoryContainer/ColorRect/GridContainer" instance=ExtResource( 5 )] +[node name="GridContainer" type="GridContainer" parent="InventoryContainer/ColorRect/HBoxContainer"] +unique_name_in_owner = true +margin_right = 56.0 +margin_bottom = 36.0 +size_flags_horizontal = 3 +size_flags_vertical = 3 +columns = 3 + +[node name="InventoryItemIcon1" parent="InventoryContainer/ColorRect/HBoxContainer/GridContainer" instance=ExtResource( 5 )] +rect_min_size = Vector2( 16, 16 ) +texture = null + +[node name="InventoryItemIcon2" parent="InventoryContainer/ColorRect/HBoxContainer/GridContainer" instance=ExtResource( 5 )] +margin_left = 20.0 +margin_right = 36.0 +rect_min_size = Vector2( 16, 16 ) +texture = null + +[node name="InventoryItemIcon3" parent="InventoryContainer/ColorRect/HBoxContainer/GridContainer" instance=ExtResource( 5 )] +margin_left = 40.0 +margin_right = 56.0 +rect_min_size = Vector2( 16, 16 ) +texture = null + +[node name="InventoryItemIcon4" parent="InventoryContainer/ColorRect/HBoxContainer/GridContainer" instance=ExtResource( 5 )] +margin_top = 20.0 +margin_bottom = 36.0 +rect_min_size = Vector2( 16, 16 ) +texture = null + +[node name="InventoryItemIcon5" parent="InventoryContainer/ColorRect/HBoxContainer/GridContainer" instance=ExtResource( 5 )] +margin_left = 20.0 +margin_top = 20.0 +margin_right = 36.0 +margin_bottom = 36.0 +rect_min_size = Vector2( 16, 16 ) +texture = null + +[node name="InventoryItemIcon6" parent="InventoryContainer/ColorRect/HBoxContainer/GridContainer" instance=ExtResource( 5 )] +margin_left = 40.0 +margin_top = 20.0 +margin_right = 56.0 +margin_bottom = 36.0 +rect_min_size = Vector2( 16, 16 ) +texture = null + +[node name="Button" type="Button" parent="InventoryContainer/ColorRect/HBoxContainer"] +margin_left = 60.0 +margin_right = 80.0 +margin_bottom = 36.0 +text = "X" [connection signal="mouse_entered" from="InventoryIconContainer/HBoxContainer/MarginContainer/TextureRect" to="." method="_on_TextureRect_mouse_entered"] [connection signal="mouse_exited" from="InventoryContainer" to="." method="_on_InventoryContainer_mouse_exited"] -[connection signal="mouse_exited" from="InventoryContainer/ColorRect" to="." method="_on_ColorRect_mouse_exited"] +[connection signal="button_down" from="InventoryContainer/ColorRect/HBoxContainer/Button" to="." method="_on_Button_button_down"] diff --git a/lib/ui/InventoryContainer.gd b/lib/ui/InventoryContainer.gd index cc80039..a7f8793 100644 --- a/lib/ui/InventoryContainer.gd +++ b/lib/ui/InventoryContainer.gd @@ -2,7 +2,7 @@ extends MarginContainer var InventoryItemIcon = preload("res://lib/ui/InventoryItemIcon.tscn") -onready var icons_container = $ColorRect/GridContainer +onready var icons_container = $"%GridContainer" func show_item(item): var item_ui = InventoryItemIcon.instance() @@ -10,3 +10,5 @@ func show_item(item): item_ui.texture = item.icon_texture icons_container.add_child(item_ui) + + diff --git a/lib/ui/InventoryItemIcon.gd b/lib/ui/InventoryItemIcon.gd index 906f342..426c0e0 100644 --- a/lib/ui/InventoryItemIcon.gd +++ b/lib/ui/InventoryItemIcon.gd @@ -2,3 +2,12 @@ extends TextureRect class_name InventoryItemIcon var item = null + + + + +func _on_InventoryItemIcon_gui_input(event): + if Input.is_mouse_button_pressed(BUTTON_LEFT): +# if event is InputEventMouseButton: +# if event.button_index == BUTTON_LEFT: + EventBus.emit_signal("player_exchange_weapon",item) diff --git a/lib/ui/InventoryItemIcon.tscn b/lib/ui/InventoryItemIcon.tscn index ef693f1..5d8b023 100644 --- a/lib/ui/InventoryItemIcon.tscn +++ b/lib/ui/InventoryItemIcon.tscn @@ -6,5 +6,8 @@ [node name="InventoryItemIcon" type="TextureRect"] margin_right = 16.0 margin_bottom = 16.0 +mouse_filter = 0 texture = ExtResource( 1 ) script = ExtResource( 2 ) + +[connection signal="gui_input" from="." to="." method="_on_InventoryItemIcon_gui_input"] diff --git a/project.godot b/project.godot index b7b3c04..a0348b0 100644 --- a/project.godot +++ b/project.godot @@ -114,6 +114,7 @@ fire={ 2d_physics/layer_4="bullets" 2d_physics/layer_5="enemies" 2d_physics/layer_6="walls" +2d_physics/layer_7="doors" [physics] diff --git a/utils/EventBus.gd b/utils/EventBus.gd index 42330bb..ad64b05 100644 --- a/utils/EventBus.gd +++ b/utils/EventBus.gd @@ -4,10 +4,12 @@ extends Node signal player_moved() signal player_on_weapon(weapon) +signal player_exchange_weapon(new_weapon) signal pocket_modified() signal inventory_modified() signal coins_modified() +signal weapon_modifed() signal pick_coin(coin)