From 104eee37f6e00ee4ffa53ab5f764b2cd03b88c9d Mon Sep 17 00:00:00 2001 From: Guilherme Oliveira Date: Tue, 2 Jul 2019 17:04:48 -0300 Subject: [PATCH] Checkpoint and checkpoints node added --- hook!-full-game/project.godot | 6 ++++++ .../src/Objects/Checkpoint/Checkpoint.gd | 9 ++++----- .../src/Objects/Checkpoint/Checkpoint.tscn | 6 ++++-- .../src/Objects/Checkpoint/Checkpoints.gd | 17 +++++++++++++++++ .../src/Objects/Checkpoint/Checkpoints.tscn | 7 +++++++ hook!-full-game/src/Player/Player.gd | 2 +- hook!-full-game/src/Singletons/Events.gd | 3 ++- 7 files changed, 41 insertions(+), 9 deletions(-) create mode 100644 hook!-full-game/src/Objects/Checkpoint/Checkpoints.gd create mode 100644 hook!-full-game/src/Objects/Checkpoint/Checkpoints.tscn diff --git a/hook!-full-game/project.godot b/hook!-full-game/project.godot index 18c081b..e3f5ba9 100644 --- a/hook!-full-game/project.godot +++ b/hook!-full-game/project.godot @@ -34,6 +34,11 @@ _global_script_classes=[ { "language": "GDScript", "path": "res://src/HookTarget.gd" }, { +"base": "KinematicBody2D", +"class": "Player", +"language": "GDScript", +"path": "res://src/Player/Player.gd" +}, { "base": "Node", "class": "State", "language": "GDScript", @@ -55,6 +60,7 @@ _global_script_class_icons={ "Hit": "", "Hook": "", "HookTarget": "", +"Player": "", "State": "", "StateMachine": "", "Stats": "" diff --git a/hook!-full-game/src/Objects/Checkpoint/Checkpoint.gd b/hook!-full-game/src/Objects/Checkpoint/Checkpoint.gd index 9734d00..a93b1c2 100644 --- a/hook!-full-game/src/Objects/Checkpoint/Checkpoint.gd +++ b/hook!-full-game/src/Objects/Checkpoint/Checkpoint.gd @@ -1,8 +1,7 @@ extends Area2D -signal reached(checkpoint) -var is_unlocked := false +var is_visited := false func _ready() -> void: @@ -10,9 +9,9 @@ func _ready() -> void: func _on_body_entered(body: PhysicsBody2D) -> void: - if is_unlocked or not body is Player: + if is_visited or not body is Player: return - body.checkpoints.append(global_position) modulate = Color(0.65, 0.65, 0.65) - is_unlocked = true + is_visited = true + Events.emit_signal("checkpoint_visited", self) diff --git a/hook!-full-game/src/Objects/Checkpoint/Checkpoint.tscn b/hook!-full-game/src/Objects/Checkpoint/Checkpoint.tscn index 17b1d0c..cf42493 100644 --- a/hook!-full-game/src/Objects/Checkpoint/Checkpoint.tscn +++ b/hook!-full-game/src/Objects/Checkpoint/Checkpoint.tscn @@ -1,7 +1,7 @@ [gd_scene load_steps=4 format=2] -[ext_resource path="res://src/objects/Checkpoint/Checkpoint.gd" type="Script" id=1] -[ext_resource path="res://assets/tilesets/basic-circle.png" type="Texture" id=2] +[ext_resource path="res://src/Objects/Checkpoint/Checkpoint.gd" type="Script" id=1] +[ext_resource path="res://assets/tilesets/basic.png" type="Texture" id=2] [sub_resource type="CircleShape2D" id=1] radius = 12.5 @@ -16,4 +16,6 @@ shape = SubResource( 1 ) [node name="Sprite" type="Sprite" parent="."] texture = ExtResource( 2 ) +region_enabled = true +region_rect = Rect2( 0, 50, 50, 50 ) diff --git a/hook!-full-game/src/Objects/Checkpoint/Checkpoints.gd b/hook!-full-game/src/Objects/Checkpoint/Checkpoints.gd new file mode 100644 index 0000000..8422686 --- /dev/null +++ b/hook!-full-game/src/Objects/Checkpoint/Checkpoints.gd @@ -0,0 +1,17 @@ +extends Node +""" +Saves information about visited checkpoints +""" + +var visited_checkpoints := [] + + +func _ready() -> void: + Events.connect("checkpoint_visited", self, "_on_Events_checkpointed_visited") + + +func _on_Events_checkpointed_visited(checkpoint: Node2D) -> void: + visited_checkpoints.append({ + "path": checkpoint.get_path(), + "checkpoint": checkpoint + }) diff --git a/hook!-full-game/src/Objects/Checkpoint/Checkpoints.tscn b/hook!-full-game/src/Objects/Checkpoint/Checkpoints.tscn new file mode 100644 index 0000000..dfd3d7c --- /dev/null +++ b/hook!-full-game/src/Objects/Checkpoint/Checkpoints.tscn @@ -0,0 +1,7 @@ +[gd_scene load_steps=2 format=2] + +[ext_resource path="res://src/Objects/Checkpoint/Checkpoints.gd" type="Script" id=1] + +[node name="Checkpoints" type="Node"] +script = ExtResource( 1 ) + diff --git a/hook!-full-game/src/Player/Player.gd b/hook!-full-game/src/Player/Player.gd index b059a70..10abcbc 100644 --- a/hook!-full-game/src/Player/Player.gd +++ b/hook!-full-game/src/Player/Player.gd @@ -1,5 +1,5 @@ extends KinematicBody2D - +class_name Player onready var hook: Position2D = $Hook onready var camera_rig: Position2D = $CameraRig diff --git a/hook!-full-game/src/Singletons/Events.gd b/hook!-full-game/src/Singletons/Events.gd index 233596d..c40a1c0 100644 --- a/hook!-full-game/src/Singletons/Events.gd +++ b/hook!-full-game/src/Singletons/Events.gd @@ -3,4 +3,5 @@ extends Node signal player_info_updated(dict) signal player_state_changed(state) -signal player_moved(player) \ No newline at end of file +signal player_moved(player) +signal checkpoint_visited(checkpoint)