attached script to NPC_static

added simple interaction script to NPC
added a basic ingame UI
added ui into World
tagged player as player
master
Zac 5 years ago
parent 6e87ca3b09
commit e2ba115c8f

@ -0,0 +1,41 @@
[gd_scene format=2]
[node name="InGameUI" type="CanvasLayer"]
pause_mode = 2
layer = 1
offset = Vector2( 0, 0 )
rotation = 0.0
scale = Vector2( 1, 1 )
transform = Transform2D( 1, 0, 0, 1, 0, 0 )
[node name="Container" type="Container" parent="." index="0"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 1.0
anchor_bottom = 1.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 0
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 1
[node name="DialogWindow" type="PopupDialog" parent="Container" index="0"]
anchor_left = 0.0
anchor_top = 1.0
anchor_right = 1.0
anchor_bottom = 1.0
margin_top = -180.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 0
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 1
popup_exclusive = true
_sections_unfolded = [ "Popup" ]

@ -1,6 +1,7 @@
[gd_scene load_steps=4 format=2]
[gd_scene load_steps=5 format=2]
[ext_resource path="res://images/troll.png" type="Texture" id=1]
[ext_resource path="res://scripts/NPC_base.gd" type="Script" id=1]
[ext_resource path="res://images/troll.png" type="Texture" id=2]
[sub_resource type="RectangleShape2D" id=1]
@ -12,7 +13,7 @@ extents = Vector2( 29.9994, 40.5807 )
custom_solver_bias = 0.0
extents = Vector2( 60.0752, 66.6499 )
[node name="NPC" type="StaticBody2D" index="0"]
[node name="NPC" type="StaticBody2D"]
input_pickable = false
collision_layer = 4
@ -21,6 +22,7 @@ constant_linear_velocity = Vector2( 0, 0 )
constant_angular_velocity = 0.0
friction = 1.0
bounce = 0.0
script = ExtResource( 1 )
[node name="npc_collision" type="CollisionShape2D" parent="." index="0"]
@ -29,7 +31,6 @@ shape = SubResource( 1 )
[node name="interact_area" type="Area2D" parent="." index="1"]
editor/display_folded = true
scale = Vector2( 0.4, 0.4 )
input_pickable = true
gravity_vec = Vector2( 0, 1 )
@ -48,7 +49,11 @@ shape = SubResource( 2 )
[node name="Sprite" type="Sprite" parent="." index="2"]
scale = Vector2( 0.4, 0.4 )
texture = ExtResource( 1 )
texture = ExtResource( 2 )
hframes = 3
[connection signal="body_entered" from="interact_area" to="." method="_on_body_entered"]
[connection signal="body_exited" from="interact_area" to="." method="_on_body_exited"]

@ -3,7 +3,9 @@
[ext_resource path="res://scripts/Player.gd" type="Script" id=1]
[ext_resource path="res://images/test_char.png" type="Texture" id=2]
[node name="Player" type="KinematicBody2D"]
[node name="Player" type="KinematicBody2D" groups=[
"player",
]]
input_pickable = false
collision_layer = 1
@ -19,6 +21,7 @@ position = Vector2( 0.00320625, -0.00740051 )
scale = Vector2( 0.403093, 0.403093 )
build_mode = 0
polygon = PoolVector2Array( -26.5097, -40.0408, -36.4849, -29.9804, -36.3144, 14.9503, -16.4493, 40.016, 18.5063, 40.016, 36.4956, 14.9503, 36.4956, -4.82946, 23.4512, -39.9556 )
_sections_unfolded = [ "Transform" ]
[node name="Sprite" type="Sprite" parent="CollisionPolygon2D" index="0"]

@ -1,8 +1,9 @@
[gd_scene load_steps=4 format=2]
[gd_scene load_steps=5 format=2]
[ext_resource path="res://resources/tiles.res" type="TileSet" id=1]
[ext_resource path="res://scenes/NPC_static.tscn" type="PackedScene" id=2]
[ext_resource path="res://scenes/Player.tscn" type="PackedScene" id=3]
[ext_resource path="res://scenes/InGameUI.tscn" type="PackedScene" id=4]
[node name="World" type="Node2D" index="0"]
@ -61,4 +62,6 @@ position = Vector2( 544.265, 95.9369 )
Speed = 20
[node name="InGameUI" parent="." index="3" instance=ExtResource( 4 )]

@ -0,0 +1,40 @@
extends Node2D
# "onready" is a keyword that makes sure that the variable assignment
# happens *after* _ready() runs.
# the $"" notation is a shorthand for getting a node.
# a longer way would be to write get_node("/root")
onready var DialogWindow = $"/root".find_node("InGameUI", true, false)
# start off not ready for interaction, gotta wait until the player is near us
var interact_ready = false
func _process(delta):
# if we're ready for interaction then we should check every frame if "interact" has been pressed
if interact_ready and Input.is_action_just_pressed("interact"):
print("INTERACTION")
# this function gets called when a physics body enters into the interact_area node's area
# if you look in the scene inspector (in the NPC_static scene) you'll see that the interact_area
# node has a little wifi signal icon. that means that it has a signal coming out of it attached
# to another node. click on it to look at the signal's panel
func _on_body_entered(body):
# in godot you can set a node to be in a group (in the signal panel)
# this checks to see if the body entering the area is in the "player" group
if body.is_in_group("player"):
# if the player is this close to us, then we should be ready to interact
interact_ready = true
# as you may have guessed, this function runs when a physics body exits the interact area
func _on_body_exited(body):
if body.is_in_group("player"):
# the player is leaving our vicinity, so we're not ready for interacting
interact_ready = false
Loading…
Cancel
Save