mirror of
https://github.com/GDQuest/godot-platformer-2d.git
synced 2026-07-18 00:44:53 +00:00
Checkpoint and checkpoints node added
This commit is contained in:
parent
9d954335b6
commit
104eee37f6
7 changed files with 41 additions and 9 deletions
|
|
@ -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": ""
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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 )
|
||||
|
||||
|
|
|
|||
17
hook!-full-game/src/Objects/Checkpoint/Checkpoints.gd
Normal file
17
hook!-full-game/src/Objects/Checkpoint/Checkpoints.gd
Normal file
|
|
@ -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
|
||||
})
|
||||
7
hook!-full-game/src/Objects/Checkpoint/Checkpoints.tscn
Normal file
7
hook!-full-game/src/Objects/Checkpoint/Checkpoints.tscn
Normal file
|
|
@ -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 )
|
||||
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
extends KinematicBody2D
|
||||
|
||||
class_name Player
|
||||
|
||||
onready var hook: Position2D = $Hook
|
||||
onready var camera_rig: Position2D = $CameraRig
|
||||
|
|
|
|||
|
|
@ -3,4 +3,5 @@ extends Node
|
|||
|
||||
signal player_info_updated(dict)
|
||||
signal player_state_changed(state)
|
||||
signal player_moved(player)
|
||||
signal player_moved(player)
|
||||
signal checkpoint_visited(checkpoint)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue