Skip to content

Commit

Permalink
add custom data to save (missiles and boss defeated) - finish save sy…
Browse files Browse the repository at this point in the history
…stem
  • Loading branch information
Nartynka committed Oct 18, 2022
1 parent b32e0b2 commit bb2172d
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 9 deletions.
5 changes: 5 additions & 0 deletions Enemies/BossEnemy.gd
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ export(int) var ACCELERATION = 70

signal boss_died

func _ready():
if SaveAndLoad.custom_data.boss_defeated:
queue_free()

func _process(delta):
bossBar.visible = visible
chase_player(delta)
Expand Down Expand Up @@ -40,4 +44,5 @@ func _on_Hurtbox_hit(damage):

func _on_EnemyStats_enemy_death():
emit_signal("boss_died")
SaveAndLoad.custom_data.boss_defeated = true
._on_EnemyStats_enemy_death()
7 changes: 4 additions & 3 deletions Levels/Level_02.gd
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ func _ready():
boss.set_process(false)

func _on_Trigger_area_triggered():
block_door(true)
boss.set_process(true)
boss.visible = true
if is_instance_valid(boss):
block_door(true)
boss.set_process(true)
boss.visible = true

func _on_BossEnemy_boss_died():
block_door(false)
Expand Down
6 changes: 5 additions & 1 deletion Levels/Level_free.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=24 format=2]
[gd_scene load_steps=25 format=2]

[ext_resource path="res://Enemies/WalkingEnemy.tscn" type="PackedScene" id=1]
[ext_resource path="res://Levels/Level.tscn" type="PackedScene" id=2]
Expand All @@ -10,6 +10,7 @@
[ext_resource path="res://World/Brick.tscn" type="PackedScene" id=8]
[ext_resource path="res://Levels/Door.tscn" type="PackedScene" id=9]
[ext_resource path="res://Player/MissilesPowerup.tscn" type="PackedScene" id=10]
[ext_resource path="res://World/SaveStation.tscn" type="PackedScene" id=11]

[sub_resource type="Animation" id=1]
resource_name = "Loop"
Expand Down Expand Up @@ -694,6 +695,9 @@ position = Vector2( 1216, 624 )
[node name="MissilesPowerup4" parent="." index="11" instance=ExtResource( 10 )]
position = Vector2( 1800, 592 )

[node name="SaveStation" parent="." index="12" instance=ExtResource( 11 )]
position = Vector2( 83, 752 )

[editable path="MovingPlatforms/MovingPlatform7"]
[editable path="MovingPlatforms/MovingPlatform2"]
[editable path="MovingPlatforms/MovingPlatform3"]
Expand Down
1 change: 1 addition & 0 deletions Player/Player.gd
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ onready var cameraFollow = $CameraFollow

func _ready():
PlayerStats.connect("player_death", self, "on_death")
PlayerStats.missiles_unlocked = SaveAndLoad.custom_data.missiles_unlocked
call_deferred("set_camera_follow")


Expand Down
3 changes: 2 additions & 1 deletion Player/PlayerStats.gd
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ func set_missiles(new_value):

func set_missiles_unlocked(new_value):
missiles_unlocked = new_value
emit_signal("missiles_unlocked")
SaveAndLoad.custom_data.missiles_unlocked = new_value
emit_signal("missiles_unlocked", new_value)

func refill_stats():
self.health = max_health
Expand Down
15 changes: 14 additions & 1 deletion SaveAndLoad.gd
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
extends Node

var custom_data = {
missiles_unlocked = false,
boss_defeated = false
}


var is_loading : bool = false

func save_game():
var save_file = File.new()
save_file.open("user://savegame.save", File.WRITE)

save_file.store_line(to_json(custom_data))

var persistingNodes = get_tree().get_nodes_in_group("Persists")
for node in persistingNodes:
var node_data = node.save()
Expand All @@ -21,7 +30,11 @@ func load_game():
node.queue_free()

save_file.open("user://savegame.save", File.READ)
while !save_file.eof_reached():

if not save_file.eof_reached():
custom_data = parse_json(save_file.get_line())

while not save_file.eof_reached():
var current_line = parse_json(save_file.get_line())
if current_line != null:
var newNode = load(current_line["filename"]).instance()
Expand Down
4 changes: 2 additions & 2 deletions UI/MissilesUI.gd
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ func _ready():
func _on_missiles_change(amount):
label.text = str(amount)

func _on_missiles_unlocked():
visible = true
func _on_missiles_unlocked(visable):
visible = visable
2 changes: 1 addition & 1 deletion World/SaveStation.gd
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
extends StaticBody2D

onready var animationPlayer = $AnimationPlayer

onready var PlayerStats = ResourceLoader.PlayerStats
func _on_SaveArea_body_entered(body):
if body is Player:
animationPlayer.play("Save")
Expand Down

0 comments on commit bb2172d

Please sign in to comment.