From bf7693887615823fd0cd654fcba82fdb9167eeed Mon Sep 17 00:00:00 2001 From: Melon Bread Date: Mon, 13 May 2024 17:14:48 -0400 Subject: [PATCH] Made initial GameOver & star background --- assets/_RAW_/star.pxo | Bin 0 -> 451 bytes assets/img/star.png | Bin 0 -> 4226 bytes assets/img/star.png.import | 34 ++++++++++++++ scenes/game.tscn | 25 +++++++++- scenes/game_over_screen.tscn | 87 +++++++++++++++++++++++++++++++++++ scripts/comet_spawner.gd | 1 + scripts/game.gd | 10 ++-- scripts/game_over_screen.gd | 11 +++++ 8 files changed, 164 insertions(+), 4 deletions(-) create mode 100644 assets/_RAW_/star.pxo create mode 100644 assets/img/star.png create mode 100644 assets/img/star.png.import create mode 100644 scenes/game_over_screen.tscn create mode 100644 scripts/game_over_screen.gd diff --git a/assets/_RAW_/star.pxo b/assets/_RAW_/star.pxo new file mode 100644 index 0000000000000000000000000000000000000000..45948bcd112a37cc09c7e194f49f65bb67a58254 GIT binary patch literal 451 zcmV;!0X+UkLr_Kn000005C8zd1^@u70RR9fwJ-f(!37Ns0M^$@ETAXp|NsC0|ARK< z@BVwIL}ij9|0l9{+B-=^fd9Pv9YAc$f45Btq+eRV9Xbl`U4>- zgnT^{>shLBTgvt!1w`Sq^uanN0sK5ns4S81h5-izIUqQw(D8b!v$AC~(`O$p0+_Vv zSL^FwLL|TeRH!W-E*2>CRwx-J_bMV*31rGm28E_*w{GGNY zVFQO_rtQ!zd%=WAKvDwoZuu>!Ut5D*m2DVI2qqsBVqsySFh7-iZEo3erpa=kP9OA` z5QD;Z+W9c4vs@G^+8|*TMr1@rWJE?}L!z+Rig`r>s0Wm^|h%a;wP(T7G1W~~G-P^9~l*BC2|8|?x^WE=! z-|u|qcfRwrXG!Ix2?fSMMx9Pq;4Ak|g+5LEi^t)kbZD^xd`o1&{}4+KP#NWC_U zDg=~8qQ_I|^LVhBEQQ1{(&SjG-f9K-L6~tEK57VFPoxgmFx9|}CqnFD6{+GmZ-IG`Qj5^l(?Q6p~ z4#2w`3%EXKq`kTsb;xAbx4&v5HO3h1LN(x;>C5SS!m4 z?0t4!db9e-$@!lg9&`DRGWqDa&85Q*=UqC1?V11fm|JJIJ+WrZjhEIJV>eouq5Rm? zgLRIFf4cqUoUccWz4p+1C!79k=(YN8;rm~mYMF50fIT+n%&BwkX1V9U2D-3H-hlbH z2lBoYd$?f+;ajtyKFfSYC>lIY9~{b1D*3_eJfczkYD;Zk@sK3s)JV|Y=Vm&KSON>NP3VeC8s1($Sk(lNMWOuMs#85j~9b!{QwB_Um0`6Jd4%TgJ*Nnl+?`ORd zpHRc|dEF*;epZlpQD8L@S$KwGoEDrE1PgAZIfMsEGKAY03nN&a4m&A0a-e+CxWYww zq(T9>Sp*yoaWROV zw~02B?V8Fkr-Z=4ZK@EXiB$VQK#ZU&g;Uw29F)y&p&fR+)8?S;Io{Kd9EVI)F}2dE zxvSg4!eW3}PR&yQ(Dbkt)*~ZMk>r3Rh25rX(ajF~;W!DL!g)Cb0cf@i2inRoPC{W$ z2cW|FB|!|${Woj%@L(>mhb=D`<1qhRO_e@TRcKE7E&Uo6wWEY#+M!@MKD~rESC7)0 z1z71JzK)C5BB&mjbZyg%_ecdhZ?*F_X9#CF%7I&vO~9FumBuZkjk3~qh7mYgVyWw&Kp0NiaLV#`!ida*3AJXlt=L8UgA(1+|dK7Q+l@5byu_WcK3!oC3qTCg~KvU37KP)hPx#W!#lrU37Jdfle8B zW!Ha3m$Cgig`)5;C<&J(>Eyc`;iAAqO`j5u7G`>IW^TeEf` zD0?bCe_789-3$7S7({+pI0aOg&pR$)IL+T`ZQXx)fnf!@)7sj)phr3kqMhe; ZTW{VU{(M#dF5WtwuWXWcduh$WzW|mgoIC&k literal 0 HcmV?d00001 diff --git a/assets/img/star.png.import b/assets/img/star.png.import new file mode 100644 index 0000000..b2b8b00 --- /dev/null +++ b/assets/img/star.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://chuygpyfe3y10" +path="res://.godot/imported/star.png-309e5a4c97bcbe7eab4eb743f683232b.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://assets/img/star.png" +dest_files=["res://.godot/imported/star.png-309e5a4c97bcbe7eab4eb743f683232b.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/scenes/game.tscn b/scenes/game.tscn index c6b5b39..522b96f 100644 --- a/scenes/game.tscn +++ b/scenes/game.tscn @@ -1,8 +1,18 @@ -[gd_scene load_steps=4 format=3 uid="uid://bdarunpk3c2eh"] +[gd_scene load_steps=8 format=3 uid="uid://bdarunpk3c2eh"] [ext_resource type="Script" path="res://scripts/game.gd" id="1_6727i"] [ext_resource type="PackedScene" uid="uid://cbo47ftx0vcro" path="res://scenes/ship.tscn" id="1_esyqo"] [ext_resource type="FontFile" uid="uid://bkcxbtx1vcj8w" path="res://assets/fonts/Color Basic.otf" id="2_gwtm0"] +[ext_resource type="PackedScene" uid="uid://0yktrbyp6cr3" path="res://scenes/game_over_screen.tscn" id="3_yy075"] +[ext_resource type="Texture2D" uid="uid://chuygpyfe3y10" path="res://assets/img/star.png" id="4_jc3cg"] + +[sub_resource type="Curve" id="Curve_8qyxb"] +_data = [Vector2(0, 1), 0.0, 0.0, 0, 0, Vector2(0.606742, 1), 0.052866, 0.052866, 0, 0, Vector2(1, 0.615385), 0.0, 0.0, 0, 0] +point_count = 3 + +[sub_resource type="Gradient" id="Gradient_rnjki"] +offsets = PackedFloat32Array(0, 0.406667, 0.84) +colors = PackedColorArray(0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1) [node name="Game" type="Node2D"] script = ExtResource("1_6727i") @@ -25,6 +35,9 @@ theme_override_font_sizes/font_size = 32 text = "LEVEL: 1" horizontal_alignment = 2 +[node name="GameOverScreen" parent="UI" instance=ExtResource("3_yy075")] +visible = false + [node name="Background" type="CanvasLayer" parent="."] layer = -1 @@ -37,6 +50,16 @@ grow_horizontal = 2 grow_vertical = 2 color = Color(0, 0, 0, 1) +[node name="Stars" type="CPUParticles2D" parent="Background"] +amount = 64 +lifetime = 5.0 +texture = ExtResource("4_jc3cg") +emission_shape = 3 +emission_rect_extents = Vector2(1200, 700) +gravity = Vector2(0, 0) +scale_amount_curve = SubResource("Curve_8qyxb") +color_ramp = SubResource("Gradient_rnjki") + [node name="Ship" parent="." instance=ExtResource("1_esyqo")] z_index = 1 position = Vector2(622, 309) diff --git a/scenes/game_over_screen.tscn b/scenes/game_over_screen.tscn new file mode 100644 index 0000000..5b82ae5 --- /dev/null +++ b/scenes/game_over_screen.tscn @@ -0,0 +1,87 @@ +[gd_scene load_steps=3 format=3 uid="uid://0yktrbyp6cr3"] + +[ext_resource type="FontFile" uid="uid://bkcxbtx1vcj8w" path="res://assets/fonts/Color Basic.otf" id="1_lbk85"] +[ext_resource type="Script" path="res://scripts/game_over_screen.gd" id="1_o2tyf"] + +[node name="GameOverScreen" type="Control"] +layout_mode = 3 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +script = ExtResource("1_o2tyf") + +[node name="ColorRect" type="ColorRect" parent="."] +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +color = Color(0, 0, 0, 0.596078) + +[node name="Panel" type="Panel" parent="."] +layout_mode = 1 +anchors_preset = 8 +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +offset_left = -184.0 +offset_top = -132.0 +offset_right = 192.0 +offset_bottom = 124.0 +grow_horizontal = 2 +grow_vertical = 2 + +[node name="GameOverLabel" type="Label" parent="Panel"] +layout_mode = 1 +anchors_preset = 5 +anchor_left = 0.5 +anchor_right = 0.5 +offset_left = -55.0 +offset_top = 40.0 +offset_right = 55.0 +offset_bottom = 63.0 +grow_horizontal = 2 +theme_override_fonts/font = ExtResource("1_lbk85") +theme_override_font_sizes/font_size = 36 +text = "game over" +horizontal_alignment = 1 + +[node name="RetryButton" type="Button" parent="Panel"] +layout_mode = 1 +anchors_preset = 7 +anchor_left = 0.5 +anchor_top = 1.0 +anchor_right = 0.5 +anchor_bottom = 1.0 +offset_left = -100.0 +offset_top = -96.0 +offset_right = -30.0 +offset_bottom = -65.0 +grow_horizontal = 2 +grow_vertical = 0 +theme_override_fonts/font = ExtResource("1_lbk85") +text = "retry" + +[node name="QuitButton" type="Button" parent="Panel"] +layout_mode = 1 +anchors_preset = 7 +anchor_left = 0.5 +anchor_top = 1.0 +anchor_right = 0.5 +anchor_bottom = 1.0 +offset_left = 28.0 +offset_top = -96.0 +offset_right = 98.0 +offset_bottom = -65.0 +grow_horizontal = 2 +grow_vertical = 0 +theme_override_fonts/font = ExtResource("1_lbk85") +text = "quit +" + +[connection signal="pressed" from="Panel/RetryButton" to="." method="_on_retry_button_pressed"] +[connection signal="pressed" from="Panel/QuitButton" to="." method="_on_quit_button_pressed"] diff --git a/scripts/comet_spawner.gd b/scripts/comet_spawner.gd index a256f30..026cc72 100644 --- a/scripts/comet_spawner.gd +++ b/scripts/comet_spawner.gd @@ -4,6 +4,7 @@ signal comet_shot (size : int) signal screen_cleared const COMET = preload("res://scenes/comet.tscn") + var comet_count := 1 var viewport_size := Vector2.ZERO diff --git a/scripts/game.gd b/scripts/game.gd index 8c35064..f066575 100644 --- a/scripts/game.gd +++ b/scripts/game.gd @@ -1,7 +1,5 @@ extends Node2D -# TODO: Display a game over screen when the ship is hit by a comet with abilty to restart -# TODO: Make a space like background, maybe some scrolling, maybe randomly generated # TODO: Make a small title screen that starts before the game scene # TODO: MAYBE track high score in a file & show it on HUD @@ -9,11 +7,14 @@ const COMET_SPAWNER = preload("res://scenes/comet_spawner.tscn") @export var level : int = 1 +var viewport_size : Vector2 var score : int = 0 var points_per_comet := 300 func _ready() -> void: new_level(level) + viewport_size = get_viewport_rect().size + $Background/Stars.emission_rect_extents = viewport_size func _process(_delta: float) -> void: update_ui() @@ -30,7 +31,10 @@ func level_finished() -> void: new_level(level) func game_over() -> void: - pass + # Wait 1 second before showing the game over screen for "dramatic" effect + await get_tree().create_timer(1.0).timeout + $UI/GameOverScreen.visible = true + # TODO: Set focus on one of the buttons once the game over screen when shown func increase_score(comet_size : int) -> void: # We add one since comet_size starts count at 0 diff --git a/scripts/game_over_screen.gd b/scripts/game_over_screen.gd new file mode 100644 index 0000000..ca8ffe8 --- /dev/null +++ b/scripts/game_over_screen.gd @@ -0,0 +1,11 @@ +extends Control + + +func _on_retry_button_pressed() -> void: + # TODO: Reload main game scene from level 1 + get_tree().change_scene_to_file("res://scenes/game.tscn") + + +func _on_quit_button_pressed() -> void: + # TODO: Go to title screen instead of killing the game + get_tree().quit()