Skip to content

Commit

Permalink
inventory with weapon exchange. start work on doors
Browse files Browse the repository at this point in the history
  • Loading branch information
ProfAndreaPollini committed Jul 27, 2022
1 parent c37a0f2 commit 0a3d19a
Show file tree
Hide file tree
Showing 18 changed files with 262 additions and 28 deletions.
64 changes: 61 additions & 3 deletions GameScreen.tscn
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
[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]
[ext_resource path="res://entites/King.tscn" type="PackedScene" id=3]
[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 )
Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -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 )
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion assets/0x72_16x16DungeonTileset_walls.v2.png.import
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions entites/weapons/Arrow.gd
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ func _ready():

func _physics_process(delta):
translate(velocity*direction*delta)


func _on_VisibilityNotifier2D_screen_exited():
queue_free()
4 changes: 4 additions & 0 deletions entites/weapons/Arrow.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
1 change: 1 addition & 0 deletions lib/SenseArea.gd
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
tool
extends Area2D

export(Array,String) var sensing_groups
Expand Down
3 changes: 3 additions & 0 deletions lib/bow/Bow.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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}))
Expand Down
27 changes: 27 additions & 0 deletions lib/door/Door.gd
Original file line number Diff line number Diff line change
@@ -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)
32 changes: 32 additions & 0 deletions lib/door/Door.tscn
Original file line number Diff line number Diff line change
@@ -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"]
1 change: 1 addition & 0 deletions lib/knife/Knife.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
26 changes: 23 additions & 3 deletions lib/player/Player.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -19,23 +19,43 @@ 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):
movement.update(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()
Expand Down
10 changes: 5 additions & 5 deletions lib/player/Player.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -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="."]
Expand All @@ -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="."]
Expand All @@ -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="."]
Expand All @@ -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 )
35 changes: 25 additions & 10 deletions lib/ui/HUD.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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)


Loading

0 comments on commit 0a3d19a

Please sign in to comment.