summaryrefslogtreecommitdiff
path: root/Game.gd
blob: bb99ada98e87322b5987e5a651737594414755d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
extends Node


@warning_ignore("unused_signal")
signal boss_initialized(hp: int)
@warning_ignore("unused_signal")
signal boss_hp_changed
@warning_ignore("unused_signal")
signal boss_defeated

signal score_changed

var score = 0 :
	set(value):
		score = value
		score_changed.emit()

var player_state := {
	"hp": null,
	"life": 4,
}


func _ready():
	var canvas_layer = CanvasLayer.new()
	canvas_layer.name = "ScreenTransition"
	
	var color_rect = ColorRect.new()
	color_rect.name = "ColorRect"
	color_rect.size = get_tree().current_scene.get_viewport_rect().size
	color_rect.color = Color(1,1,1,0)
	
	canvas_layer.add_child(color_rect)
	
	get_tree().root.add_child.call_deferred(canvas_layer)
	
	get_tree().root.add_child.call_deferred(preload("res://BackgroundColor.tscn").instantiate())


func fade_out_screen():
	var color_rect = get_tree().root.get_node("ScreenTransition/ColorRect")
	color_rect.color = Color(1,1,1,0)
	
	var tween = get_tree().create_tween()
	tween.tween_property(
		color_rect,
		"color",
		Color(1,1,1,1),
		0.3
	)
	
	return tween

func fade_in_screen():
	var color_rect = get_tree().root.get_node("ScreenTransition/ColorRect")
	color_rect.color = Color(1,1,1,1)
	
	var tween = get_tree().create_tween()
	tween.tween_property(
		color_rect,
		"color",
		Color(1,1,1,0),
		0.3
	)
	
	return tween


func transition_to_scene(path: String):
	var scene = load(path).instantiate()
	
	(func():
		var tween = Game.fade_out_screen()
		get_tree().current_scene.process_mode = Node.PROCESS_MODE_DISABLED
		await tween.finished
		
		get_tree().current_scene.free()
		get_tree().root.add_child(scene)
		get_tree().current_scene = scene
		
		Game.fade_in_screen()
	).call_deferred()

func transition_scene_with_door(door: Door):
		var scene = load(door.target_scene).instantiate()
		scene.starting_position = door.target_position
		scene.fade_in_from_door = true
		
		var tween = Game.fade_out_screen()
		get_tree().current_scene.process_mode = Node.PROCESS_MODE_DISABLED
		await tween.finished
		
		(func():
			get_tree().current_scene.free()
			get_tree().root.add_child(scene)
			get_tree().current_scene = scene
			
			Game.fade_in_screen()
		).call_deferred()


func hit_enemy(enemy: Enemy, projectile_position: Vector2):
	enemy.on_hit(projectile_position)