Skip to content

Commit

Permalink
Sunset, win condition and win/lose screens
Browse files Browse the repository at this point in the history
  • Loading branch information
ricargoes committed Feb 15, 2024
1 parent 615f66c commit 17fc4aa
Show file tree
Hide file tree
Showing 7 changed files with 210 additions and 12 deletions.
19 changes: 19 additions & 0 deletions scenes/end_screen.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
extends CenterContainer

signal game_restarted

func show_win():
%YouWin.text = "You Win"
%WinDescription.text = "You managed to escape the hordes of daylight vampires till the sun was set. Now you are free and badass."
show()

func show_lose(elapsed_time: float):
%YouWin.text = "You Lose"
%WinDescription.text = "The hordes of daylight vampires got to you after %d seconds of daring espace. Tough luck." % elapsed_time
show()

func _on_quit_pressed() -> void:
get_tree().quit()

func _on_play_again_pressed() -> void:
game_restarted.emit()
56 changes: 56 additions & 0 deletions scenes/end_screen.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
[gd_scene load_steps=2 format=3 uid="uid://df4mxycb4gc4m"]

[ext_resource type="Script" path="res://scenes/end_screen.gd" id="1_bhwbg"]

[node name="EndScreen" type="CenterContainer"]
process_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("1_bhwbg")

[node name="VBoxContainer" type="VBoxContainer" parent="."]
custom_minimum_size = Vector2(800, 0)
layout_mode = 2
theme_override_constants/separation = 50
alignment = 1

[node name="YouWin" type="Label" parent="VBoxContainer"]
unique_name_in_owner = true
layout_mode = 2
theme_override_colors/font_color = Color(0, 0, 0, 1)
theme_override_colors/font_shadow_color = Color(0, 0, 0, 1)
theme_override_colors/font_outline_color = Color(0, 0, 0, 1)
theme_override_font_sizes/font_size = 100
text = "You Win"
horizontal_alignment = 1

[node name="WinDescription" type="Label" parent="VBoxContainer"]
unique_name_in_owner = true
layout_mode = 2
theme_override_colors/font_color = Color(0, 0, 0, 1)
theme_override_font_sizes/font_size = 20
text = "Motivational text"
autowrap_mode = 2

[node name="HSeparator" type="HSeparator" parent="VBoxContainer"]
layout_mode = 2

[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer"]
custom_minimum_size = Vector2(0, 50)
layout_mode = 2

[node name="PlayAgain" type="Button" parent="VBoxContainer/HBoxContainer"]
layout_mode = 2
size_flags_horizontal = 3
text = "Play Again"

[node name="Quit" type="Button" parent="VBoxContainer/HBoxContainer"]
layout_mode = 2
size_flags_horizontal = 3
text = "Quit"

[connection signal="pressed" from="VBoxContainer/HBoxContainer/PlayAgain" to="." method="_on_play_again_pressed"]
[connection signal="pressed" from="VBoxContainer/HBoxContainer/Quit" to="." method="_on_quit_pressed"]
5 changes: 1 addition & 4 deletions scenes/enermy.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ extends CharacterBody2D

@export
var xp_value: int = 200

@export
var life_points: float = 50.0

var life_points: float = 100.0
@export
var contact_dps: float = 50.0

Expand All @@ -28,7 +26,6 @@ func _process(delta: float) -> void:

func hurt(damage: float):
life_points -= damage
OnScreenTerminal.log(life_points)
if life_points <= 0:
die()

Expand Down
25 changes: 25 additions & 0 deletions scenes/game.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ extends Node2D

const BULLET_SCENE = preload("res://scenes/bullet.tscn")

@export
var run_time: float = 300.0

const ANIMATION_BASE_RUNTIME: float = 300.0

func _ready() -> void:
$SunsetAnimator.speed_scale = ANIMATION_BASE_RUNTIME/run_time
$SunsetTime.start(run_time)

func spawn_bullet(starting_position: Vector2, orientation: float, is_player: bool):
var bullet = BULLET_SCENE.instantiate()
Expand All @@ -13,3 +21,20 @@ func spawn_bullet(starting_position: Vector2, orientation: float, is_player: boo

func _on_hero_shot(spawn_position: Vector2, orientation: float) -> void:
spawn_bullet(spawn_position, orientation, true)


func win() -> void:
get_tree().paused = true
$CanvasLayer/SunsetTint.color = Color("ff010000")
$CanvasLayer/EndScreen.show_win()
await $CanvasLayer/EndScreen.game_restarted
get_tree().paused = false
get_tree().reload_current_scene()

func lose() -> void:
get_tree().paused = true
$CanvasLayer/SunsetTint.color = Color("ff010000")
$CanvasLayer/EndScreen.show_lose(run_time - $SunsetTime.time_left)
await $CanvasLayer/EndScreen.game_restarted
get_tree().paused = false
get_tree().reload_current_scene()
103 changes: 100 additions & 3 deletions scenes/game.tscn
Original file line number Diff line number Diff line change
@@ -1,15 +1,78 @@
[gd_scene load_steps=6 format=3 uid="uid://dwl37y77358r2"]
[gd_scene load_steps=10 format=3 uid="uid://dwl37y77358r2"]

[ext_resource type="PackedScene" uid="uid://f31q7ameb6hm" path="res://scenes/hero.tscn" id="1_2n3he"]
[ext_resource type="Script" path="res://scenes/game.gd" id="1_17qkh"]
[ext_resource type="Texture2D" uid="uid://5rou5wm7frds" path="res://resources/icon.svg" id="1_hu7ex"]
[ext_resource type="PackedScene" uid="uid://csfarad5ilhw6" path="res://scenes/enermy.tscn" id="3_i8n50"]
[ext_resource type="PackedScene" uid="uid://df4mxycb4gc4m" path="res://scenes/end_screen.tscn" id="5_52ho5"]

[sub_resource type="RectangleShape2D" id="RectangleShape2D_y7e0y"]
size = Vector2(127.778, 128)

[sub_resource type="Animation" id="Animation_afjr1"]
resource_name = "sunset"
length = 300.0
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("Infinity/Sun:position")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0, 300),
"transitions": PackedFloat32Array(1, 1),
"update": 0,
"values": [Vector2(883, 281), Vector2(883, 800)]
}
tracks/1/type = "value"
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/path = NodePath("../CanvasLayer/SunsetTint:color")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/keys = {
"times": PackedFloat32Array(0, 200, 240.9, 270.2, 300),
"transitions": PackedFloat32Array(1, 1, 1, 1, 1),
"update": 0,
"values": [Color(1, 0.00392157, 0, 0), Color(1, 0.00392157, 0, 0), Color(0.533333, 0.368627, 0, 0.270588), Color(0.419608, 0.0196078, 0.00392157, 0.54902), Color(0, 0, 0, 1)]
}

[sub_resource type="Animation" id="Animation_xw7t4"]
length = 0.001
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("Infinity/Sun:position")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 0,
"values": [Vector2(883, 281)]
}
tracks/1/type = "value"
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/path = NodePath("../CanvasLayer/SunsetTint:color")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 0,
"values": [Color(1, 0.00392157, 0, 0)]
}

[sub_resource type="AnimationLibrary" id="AnimationLibrary_jq34w"]
_data = {
"RESET": SubResource("Animation_xw7t4"),
"sunset": SubResource("Animation_afjr1")
}

[node name="Game" type="Node2D"]
script = ExtResource("1_17qkh")
run_time = 10.0

[node name="Enermies" type="Node2D" parent="."]

Expand All @@ -23,8 +86,8 @@ position = Vector2(1207, 563)
position = Vector2(718, 641)

[node name="StaticBody2D" type="StaticBody2D" parent="."]
position = Vector2(719, 783)
scale = Vector2(9, 1)
position = Vector2(1500, 783)
scale = Vector2(20, 1)
collision_layer = 4
collision_mask = 3
metadata/_edit_group_ = true
Expand All @@ -37,6 +100,40 @@ shape = SubResource("RectangleShape2D_y7e0y")

[node name="Bullets" type="Node2D" parent="."]

[node name="SunsetAnimator" type="AnimationPlayer" parent="."]
root_node = NodePath("../ParallaxBackground")
libraries = {
"": SubResource("AnimationLibrary_jq34w")
}
autoplay = "sunset"

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

[node name="Infinity" type="ParallaxLayer" parent="ParallaxBackground"]
motion_scale = Vector2(0, 0)

[node name="Sun" type="Sprite2D" parent="ParallaxBackground/Infinity"]
position = Vector2(883, 281)
texture = ExtResource("1_hu7ex")

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

[node name="SunsetTint" type="ColorRect" parent="CanvasLayer"]
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
mouse_filter = 2
color = Color(1, 0.00392157, 0, 0)

[node name="EndScreen" parent="CanvasLayer" instance=ExtResource("5_52ho5")]
visible = false

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

[connection signal="defeated" from="Enermies/Enermy" to="Hero" method="_on_enermy_defeated"]
[connection signal="defeated" from="Enermies/Enermy2" to="Hero" method="_on_enermy_defeated"]
[connection signal="died" from="Hero" to="." method="lose"]
[connection signal="shot" from="Hero" to="." method="_on_hero_shot"]
[connection signal="timeout" from="SunsetTime" to="." method="win"]
11 changes: 7 additions & 4 deletions scenes/hero.gd
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ const MAX_JUMP_IMPULSE_TIME: float = 0.3
@export
var player_speed: int = 200
@export
var life_points: float = 100
var max_life_points: int = 50
@export
var life_points: float = 50.0
@export
var arm_rotation_speed: float = 2*PI

Expand All @@ -17,10 +19,11 @@ var xp_threshold: int = 100
var jump_impulse_time: float = 0.0

signal shot(spawn_position: Vector2, orientation: float)
signal died

func _ready() -> void:
velocity.x = player_speed
$UI.sync_life(life_points)
$UI.sync_life(life_points, max_life_points)
level_up()

func _process(delta: float) -> void:
Expand Down Expand Up @@ -55,12 +58,12 @@ func _process(delta: float) -> void:

func hurt(damage: float):
life_points -= damage
$UI.sync_life(life_points)
$UI.sync_life(life_points, max_life_points)
if life_points <= 0:
die()

func die():
get_tree().quit()
died.emit()

func shoot():
var orientation = $ShoulderPivot.rotation
Expand Down
3 changes: 2 additions & 1 deletion scenes/ui.gd
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
extends CanvasLayer


func sync_life(actual_value: float):
func sync_life(actual_value: float, max_value: int):
%LifeBar.max_value = max_value
%LifeBar.value = actual_value

0 comments on commit 17fc4aa

Please sign in to comment.