Skip to content

Commit

Permalink
Finished part 12 (Checkpoints)
Browse files Browse the repository at this point in the history
  • Loading branch information
uheartbeast committed Aug 3, 2022
1 parent abdc7a6 commit e4eca16
Show file tree
Hide file tree
Showing 10 changed files with 122 additions and 17 deletions.
12 changes: 12 additions & 0 deletions Checkpoint.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
extends Area2D

onready var animatedSprite: = $AnimatedSprite

var active = true

func _on_Checkpoint_body_entered(body):
if not body is Player: return
if not active: return
animatedSprite.play("Checked")
active = false
Events.emit_signal("hit_checkpoint", position)
46 changes: 46 additions & 0 deletions Checkpoint.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
[gd_scene load_steps=8 format=2]

[ext_resource path="res://tiles_packed.png" type="Texture" id=1]
[ext_resource path="res://Checkpoint.gd" type="Script" id=2]

[sub_resource type="AtlasTexture" id=1]
atlas = ExtResource( 1 )
region = Rect2( 198, 90, 18, 18 )

[sub_resource type="AtlasTexture" id=2]
atlas = ExtResource( 1 )
region = Rect2( 216, 90, 18, 18 )

[sub_resource type="AtlasTexture" id=3]
atlas = ExtResource( 1 )
region = Rect2( 198, 108, 18, 18 )

[sub_resource type="SpriteFrames" id=4]
animations = [ {
"frames": [ SubResource( 1 ), SubResource( 2 ) ],
"loop": true,
"name": "Checked",
"speed": 5.0
}, {
"frames": [ SubResource( 3 ) ],
"loop": true,
"name": "Unchecked",
"speed": 5.0
} ]

[sub_resource type="RectangleShape2D" id=5]
extents = Vector2( 9, 9 )

[node name="Checkpoint" type="Area2D"]
script = ExtResource( 2 )

[node name="AnimatedSprite" type="AnimatedSprite" parent="."]
position = Vector2( 0, -9 )
frames = SubResource( 4 )
animation = "Unchecked"

[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
position = Vector2( 0, -9 )
shape = SubResource( 5 )

[connection signal="body_entered" from="." to="." method="_on_Checkpoint_body_entered"]
4 changes: 4 additions & 0 deletions Events.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
extends Node

signal player_died
signal hit_checkpoint(checkpoint_position)
2 changes: 1 addition & 1 deletion MovingSpikeEnemy.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ tracks/0/keys = {
"times": PoolRealArray( 0, 3 ),
"transitions": PoolRealArray( 1, 1 ),
"update": 0,
"values": [ 0.0, 1.0 ]
"values": [ 0.0, 0.99 ]
}

[sub_resource type="Animation" id=4]
Expand Down
8 changes: 7 additions & 1 deletion Player.gd
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ onready var animatedSprite: = $AnimatedSprite
onready var ladderCheck: = $LadderCheck
onready var jumpBufferTimer: = $JumpBufferTimer
onready var coyoteJumpTimer: = $CoyoteJumpTimer
onready var remoteTransform2D: = $RemoteTransform2D

func _physics_process(delta):
var input = Vector2.ZERO
Expand Down Expand Up @@ -78,7 +79,12 @@ func climb_state(input):

func player_die():
SoundPlayer.play_sound(SoundPlayer.HURT)
get_tree().reload_current_scene()
queue_free()
Events.emit_signal("player_died")

func connect_camera(camera):
var camera_path = camera.get_path()
remoteTransform2D.remote_path = camera_path

func input_jump_release():
if Input.is_action_just_released("ui_up") and velocity.y < moveData.JUMP_RELEASE_FORCE:
Expand Down
11 changes: 6 additions & 5 deletions Player.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,18 @@ script = ExtResource( 2 )
moveData = ExtResource( 3 )

[node name="AnimatedSprite" type="AnimatedSprite" parent="."]
position = Vector2( 0, -12 )
frames = ExtResource( 1 )
animation = "Jump"
playing = true
flip_h = true

[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
position = Vector2( 0, 3.5 )
position = Vector2( 0, -8.5 )
shape = SubResource( 3 )

[node name="Camera2D" type="Camera2D" parent="."]
current = true

[node name="LadderCheck" type="RayCast2D" parent="."]
position = Vector2( 0, -4 )
position = Vector2( 0, -16 )
enabled = true
cast_to = Vector2( 0, 15 )
collide_with_areas = true
Expand All @@ -40,5 +38,8 @@ one_shot = true
wait_time = 0.2
one_shot = true

[node name="RemoteTransform2D" type="RemoteTransform2D" parent="."]
position = Vector2( 0, -12 )

[connection signal="timeout" from="JumpBufferTimer" to="." method="_on_JumpBufferTimer_timeout"]
[connection signal="timeout" from="CoyoteJumpTimer" to="." method="_on_CoyoteJumpTimer_timeout"]
18 changes: 9 additions & 9 deletions PlayerBlueSkin.tres
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
atlas = ExtResource( 1 )
region = Rect2( 48, 0, 24, 24 )

[sub_resource type="AtlasTexture" id=2]
atlas = ExtResource( 1 )
region = Rect2( 72, 0, 24, 24 )

[sub_resource type="AtlasTexture" id=3]
atlas = ExtResource( 1 )
region = Rect2( 72, 0, 24, 24 )
Expand All @@ -14,24 +18,20 @@ region = Rect2( 72, 0, 24, 24 )
atlas = ExtResource( 1 )
region = Rect2( 48, 0, 24, 24 )

[sub_resource type="AtlasTexture" id=2]
atlas = ExtResource( 1 )
region = Rect2( 72, 0, 24, 24 )

[resource]
animations = [ {
"frames": [ SubResource( 1 ) ],
"loop": true,
"name": "Idle",
"speed": 5.0
}, {
"frames": [ SubResource( 3 ), SubResource( 4 ) ],
"loop": true,
"name": "Run",
"speed": 5.0
}, {
"frames": [ SubResource( 2 ) ],
"loop": false,
"name": "Jump",
"speed": 5.0
}, {
"frames": [ SubResource( 3 ), SubResource( 4 ) ],
"loop": true,
"name": "Run",
"speed": 5.0
} ]
23 changes: 23 additions & 0 deletions World.gd
Original file line number Diff line number Diff line change
@@ -1,4 +1,27 @@
extends Node2D

const PlayerScene = preload("res://Player.tscn")

var player_spawn_location = Vector2.ZERO

onready var camera: = $Camera2D
onready var player: = $Player
onready var timer: = $Timer

func _ready():
VisualServer.set_default_clear_color(Color.lightblue)
player.connect_camera(camera)
player_spawn_location = player.global_position
Events.connect("player_died", self, "_on_player_died")
Events.connect("hit_checkpoint", self, "_on_hit_checkpoint")

func _on_player_died():
timer.start(1.0)
yield(timer, "timeout")
var player = PlayerScene.instance()
player.position = player_spawn_location
add_child(player)
player.connect_camera(camera)

func _on_hit_checkpoint(checkpoint_position):
player_spawn_location = checkpoint_position
14 changes: 13 additions & 1 deletion World.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=10 format=2]
[gd_scene load_steps=11 format=2]

[ext_resource path="res://TileMap.tscn" type="PackedScene" id=1]
[ext_resource path="res://Player.tscn" type="PackedScene" id=2]
Expand All @@ -7,6 +7,7 @@
[ext_resource path="res://WalkingEnemy.tscn" type="PackedScene" id=5]
[ext_resource path="res://Ladder.tscn" type="PackedScene" id=6]
[ext_resource path="res://MovingSpikeEnemy.tscn" type="PackedScene" id=7]
[ext_resource path="res://Checkpoint.tscn" type="PackedScene" id=8]

[sub_resource type="Curve2D" id=1]
_data = {
Expand Down Expand Up @@ -68,3 +69,14 @@ position = Vector2( 189, 63 )
curve = SubResource( 2 )
animation_type = 1
speed = 2

[node name="Camera2D" type="Camera2D" parent="."]
current = true

[node name="Timer" type="Timer" parent="."]

[node name="Checkpoint" parent="." instance=ExtResource( 8 )]
position = Vector2( 207, 0 )

[node name="Checkpoint2" parent="." instance=ExtResource( 8 )]
position = Vector2( 99, 108 )
1 change: 1 addition & 0 deletions project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ config/icon="res://icon.png"
[autoload]

SoundPlayer="*res://Sounds/SoundPlayer.tscn"
Events="*res://Events.gd"

[display]

Expand Down

0 comments on commit e4eca16

Please sign in to comment.