Skip to content

Commit

Permalink
adde knight, door ok
Browse files Browse the repository at this point in the history
  • Loading branch information
ProfAndreaPollini committed Jul 27, 2022
1 parent 0a3d19a commit e24efb3
Show file tree
Hide file tree
Showing 27 changed files with 398 additions and 18 deletions.
9 changes: 8 additions & 1 deletion GameScreen.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=21 format=2]
[gd_scene load_steps=22 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]
Expand All @@ -9,6 +9,7 @@
[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]
[ext_resource path="res://lib/toggle/ToggleElement.tscn" type="PackedScene" id=10]

[sub_resource type="ConvexPolygonShape2D" id=11]
points = PoolVector2Array( 16, 16, 0, 16, 0, 16, 16, 16 )
Expand Down Expand Up @@ -226,6 +227,9 @@ tile_data = PoolIntArray( -65536, 0, 196608, -65535, 0, 196608, -65534, 0, 19660

[node name="Door" parent="Level/Level0" instance=ExtResource( 9 )]
position = Vector2( 128, 32 )
context = {
"toggle": NodePath("../ToggleElement")
}

[node name="King" parent="Level/Level0" instance=ExtResource( 3 )]
visible = false
Expand All @@ -246,4 +250,7 @@ position = Vector2( 217, 102 )
[node name="HUD" parent="Level/Level0" instance=ExtResource( 6 )]
player_path = NodePath("../Player")

[node name="ToggleElement" parent="Level/Level0" instance=ExtResource( 10 )]
position = Vector2( 184, 72 )

[node name="Overlays" type="Node" parent="."]
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
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
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
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
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
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
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
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
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
1 change: 1 addition & 0 deletions lib/SenseArea.gd
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
tool
extends Area2D
class_name SenseArea

export(Array,String) var sensing_groups
export(NodePath) var entity
Expand Down
2 changes: 1 addition & 1 deletion lib/SenseArea.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[ext_resource path="res://lib/SenseArea.gd" type="Script" id=1]

[sub_resource type="CircleShape2D" id=22]
radius = 25.423
radius = 32.787

[node name="SenseArea" type="Area2D"]
script = ExtResource( 1 )
Expand Down
26 changes: 24 additions & 2 deletions lib/door/Door.gd
Original file line number Diff line number Diff line change
@@ -1,23 +1,45 @@
extends Node2D
extends StaticBody2D


export(Vector2) var closed_door_region_position
export(Vector2) var opened_door_region_position

export(Dictionary) var context = {}

onready var conditions = $Conditions.get_children()

var is_opened := false setget set_opened

func _ready():
for condition in conditions:
condition.setup(context)
set_opened(false)


func check_conditions():

for condition in conditions:
if not condition.check():
print("no")
return false
return true

func set_opened(opened):

if opened:
opened = check_conditions()

if opened:

$Sprite.region_rect.position = opened_door_region_position
#$SenseArea.set_collision_mask_bit(0,false)
set_collision_mask_bit(0,false)

else:
$Sprite.region_rect.position = closed_door_region_position
#$SenseArea.set_collision_mask_bit(0,true)

set_collision_mask_bit(0,true)
is_opened = opened

func _on_SenseArea_mouse_entered():
set_opened(true)
Expand Down
15 changes: 13 additions & 2 deletions lib/door/Door.tscn
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
[gd_scene load_steps=5 format=2]
[gd_scene load_steps=8 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]
[ext_resource path="res://lib/toggle/Interactor.tscn" type="PackedScene" id=4]
[ext_resource path="res://lib/toggle/Interactor.gd" type="Script" id=5]
[ext_resource path="res://lib/door/ToggleEnabledCondition.gd" type="Script" id=6]

[sub_resource type="RectangleShape2D" id=1]
extents = Vector2( 16, 12 )

[node name="Door" type="Area2D"]
[node name="Door" type="StaticBody2D"]
collision_layer = 64
collision_mask = 17
script = ExtResource( 3 )
Expand All @@ -28,5 +31,13 @@ radius = 32.787
position = Vector2( 0, 4 )
shape = SubResource( 1 )

[node name="Conditions" type="Node" parent="."]

[node name="ToggleEnabledCondition" type="Node" parent="Conditions"]
script = ExtResource( 6 )

[node name="Interactor" parent="." instance=ExtResource( 4 )]
script = ExtResource( 5 )

[connection signal="mouse_entered" from="SenseArea" to="." method="_on_SenseArea_mouse_entered"]
[connection signal="mouse_exited" from="SenseArea" to="." method="_on_SenseArea_mouse_exited"]
15 changes: 15 additions & 0 deletions lib/door/DoorWithKey.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[gd_scene load_steps=4 format=2]

[ext_resource path="res://lib/door/Door.tscn" type="PackedScene" id=1]
[ext_resource path="res://lib/door/HasKeyCondition.gd" type="Script" id=2]
[ext_resource path="res://lib/door/IsEnabledCondition.gd" type="Script" id=3]

[node name="DoorWithKey" instance=ExtResource( 1 )]

[node name="Conditions" type="Node" parent="." index="3"]

[node name="InventoryContainsCondition" type="Node" parent="Conditions" index="0"]
script = ExtResource( 2 )

[node name="IsEnabledCondition" type="Node" parent="Conditions" index="1"]
script = ExtResource( 3 )
7 changes: 7 additions & 0 deletions lib/door/HasKeyCondition.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
extends Node

export(NodePath) var player
export(String) var object_id

func check():
return true
6 changes: 6 additions & 0 deletions lib/door/InventoryContainsCondition.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[gd_scene load_steps=2 format=2]

[ext_resource path="res://lib/door/HasKeyCondition.gd" type="Script" id=1]

[node name="InventoryContainsCondition" type="Node"]
script = ExtResource( 1 )
5 changes: 5 additions & 0 deletions lib/door/IsEnabledCondition.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
extends Node


func check() -> bool:
return true
6 changes: 6 additions & 0 deletions lib/door/IsEnabledCondition.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[gd_scene load_steps=2 format=2]

[ext_resource path="res://lib/door/IsEnabledCondition.gd" type="Script" id=1]

[node name="IsEnabledCondition" type="Node"]
script = ExtResource( 1 )
16 changes: 16 additions & 0 deletions lib/door/ToggleEnabledCondition.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
extends Node

onready var toggle

func setup(context) -> void:
toggle = get_parent().get_parent().get_node(context.get("toggle"))


func check() -> bool:

if toggle.is_toggled:
print("toggled")
else:
print("not toggled")
return toggle.is_toggled

Loading

0 comments on commit e24efb3

Please sign in to comment.