From 73cdf2aa180a89e821e0a95190f1b5c7ef5885f7 Mon Sep 17 00:00:00 2001 From: Luna Brovchuk Date: Mon, 2 Oct 2023 23:44:25 +0200 Subject: [PATCH] Pause Button --- src/models/enemies/ghost/ghost.gd | 63 +++++++++++----------- src/scenes/game/Game.tscn | 27 +++++++--- src/scenes/game/game.gd | 8 ++- src/scenes/game/sprites/pause.png | Bin 0 -> 1836 bytes src/scenes/game/sprites/pause.png.import | 35 ++++++++++++ src/scenes/game/sprites/resume.png | Bin 0 -> 2060 bytes src/scenes/game/sprites/resume.png.import | 35 ++++++++++++ 7 files changed, 128 insertions(+), 40 deletions(-) create mode 100644 src/scenes/game/sprites/pause.png create mode 100644 src/scenes/game/sprites/pause.png.import create mode 100644 src/scenes/game/sprites/resume.png create mode 100644 src/scenes/game/sprites/resume.png.import diff --git a/src/models/enemies/ghost/ghost.gd b/src/models/enemies/ghost/ghost.gd index fc196b1..0bef006 100644 --- a/src/models/enemies/ghost/ghost.gd +++ b/src/models/enemies/ghost/ghost.gd @@ -12,35 +12,36 @@ func _ready(): hp = 8 func _physics_process(delta): - var dist = global_position.distance_to(player.global_position) - if dist > 25 and dash_target == Vector2.ZERO: - $Aim.visible = false - global_position = global_position.move_toward(player.global_position, clamp(dist * delta * speed_multiplier, -1, 1)) - else: - if dash_target == Vector2.ZERO: - var angle = global_position.angle_to_point(player.global_position) + PI - $Aim.rotation_degrees = 0 - $Aim.rotate(angle) - $Aim.visible = true - $Aim.frame = 0 - $Aim.play("idle") - dash_target = global_position + Vector2(60, 0).rotated(angle) - if dash_target != Vector2.ZERO: - dash_timer += delta - if dash_timer >= 1.0: + if Global.playing: + var dist = global_position.distance_to(player.global_position) + if dist > 25 and dash_target == Vector2.ZERO: $Aim.visible = false - dash_timer = 0 - dashing = true - - if dashing: - global_position = global_position.move_toward(dash_target, 10) - if global_position == dash_target: - dashing = false - afterdash = true - - if afterdash: - afterdash_timer += delta - if afterdash_timer >= 1: - afterdash = false - afterdash_timer = .0 - dash_target = Vector2.ZERO + global_position = global_position.move_toward(player.global_position, clamp(dist * delta * speed_multiplier, -1, 1)) + else: + if dash_target == Vector2.ZERO: + var angle = global_position.angle_to_point(player.global_position) + PI + $Aim.rotation_degrees = 0 + $Aim.rotate(angle) + $Aim.visible = true + $Aim.frame = 0 + $Aim.play("idle") + dash_target = global_position + Vector2(60, 0).rotated(angle) + if dash_target != Vector2.ZERO: + dash_timer += delta + if dash_timer >= 1.0: + $Aim.visible = false + dash_timer = 0 + dashing = true + + if dashing: + global_position = global_position.move_toward(dash_target, 10) + if global_position == dash_target: + dashing = false + afterdash = true + + if afterdash: + afterdash_timer += delta + if afterdash_timer >= 1: + afterdash = false + afterdash_timer = .0 + dash_target = Vector2.ZERO diff --git a/src/scenes/game/Game.tscn b/src/scenes/game/Game.tscn index 6b78608..7603b6e 100644 --- a/src/scenes/game/Game.tscn +++ b/src/scenes/game/Game.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=25 format=2] +[gd_scene load_steps=26 format=2] [ext_resource path="res://src/scenes/menu/background/background.png" type="Texture" id=1] [ext_resource path="res://src/scenes/game/sprites/background_houses.png" type="Texture" id=2] @@ -22,6 +22,7 @@ [ext_resource path="res://src/scenes/game/camera.gd" type="Script" id=20] [ext_resource path="res://src/scenes/game/sprites/shake_border.png" type="Texture" id=21] [ext_resource path="res://src/scenes/game/sprites/damage.png" type="Texture" id=22] +[ext_resource path="res://src/scenes/game/sprites/pause.png" type="Texture" id=23] [sub_resource type="RectangleShape2D" id=2] extents = Vector2( 10, 60 ) @@ -234,14 +235,14 @@ margin_right = 40.0 margin_bottom = 44.0 [node name="CastTime" type="Sprite" parent="UIWrapper/UI/Right/CastTime"] -position = Vector2( 256, 140 ) +position = Vector2( 231, 140 ) texture = ExtResource( 7 ) [node name="CastTimeLabel" type="Label" parent="UIWrapper/UI/Right/CastTime"] modulate = Color( 1, 0.870588, 0, 1 ) -margin_left = 266.0 +margin_left = 241.0 margin_top = 133.0 -margin_right = 306.0 +margin_right = 281.0 margin_bottom = 147.0 theme = ExtResource( 4 ) text = "0.8" @@ -252,18 +253,28 @@ margin_right = 40.0 margin_bottom = 41.0 [node name="Damage" type="Sprite" parent="UIWrapper/UI/Right/Damage"] -position = Vector2( 256, 160 ) +position = Vector2( 231, 160 ) texture = ExtResource( 22 ) [node name="DamageLabel" type="Label" parent="UIWrapper/UI/Right/Damage"] modulate = Color( 1, 0.870588, 0, 1 ) -margin_left = 266.0 +margin_left = 241.0 margin_top = 153.0 -margin_right = 306.0 +margin_right = 281.0 margin_bottom = 167.0 theme = ExtResource( 4 ) text = "15" +[node name="Pause" type="Button" parent="UIWrapper/UI/Right"] +margin_left = 272.0 +margin_top = 143.0 +margin_right = 298.0 +margin_bottom = 163.0 +toggle_mode = true +icon = ExtResource( 23 ) +flat = true +icon_align = 1 + [node name="Cards" type="Control" parent="UIWrapper/UI"] visible = false margin_right = 320.0 @@ -310,3 +321,5 @@ id = 2 [node name="AudioCardSelect" type="AudioStreamPlayer" parent="UIWrapper/UI/Cards/RightPlaceholder"] stream = ExtResource( 9 ) + +[connection signal="pressed" from="UIWrapper/UI/Right/Pause" to="." method="pause_pressed"] diff --git a/src/scenes/game/game.gd b/src/scenes/game/game.gd index 20965f4..7203417 100644 --- a/src/scenes/game/game.gd +++ b/src/scenes/game/game.gd @@ -26,7 +26,7 @@ var spells = [ func _ready(): Global.playing = true - Global.play_time = .0 + Global.play_time = 300 Global.health = 5 Global.add_health(0) @@ -73,9 +73,13 @@ func select_card(): func _process(delta): update_ui() - + func update_ui(): var player = $View/Player $UIWrapper/UI/Right/CastTime/CastTimeLabel.text = String(player.get_recharge()) $UIWrapper/UI/Right/Damage/DamageLabel.text = String(player.get_damage()) $UIWrapper/UI/Left/LevelLabel.text = String(difficulty + 1) + $UIWrapper/UI/Right/Pause.pressed = Global.playing + +func pause_pressed(): + Global.playing = !Global.playing diff --git a/src/scenes/game/sprites/pause.png b/src/scenes/game/sprites/pause.png new file mode 100644 index 0000000000000000000000000000000000000000..21b9e668e98823ba42da015bf32b3361f54dfbab GIT binary patch literal 1836 zcmcIlO>f*p71FDM9Vd66iBS}rrRjZChST$MCnRRZynE!cde{F#&)us za6sy%D&jy-NEJVzryjX*-~d8g=?~x^AjAc6Knkz-tD&?Z7gq9mJbvEiedc*z&ph1O z{_ygp)k}(^T<&(-yKui!U#~60|FsVK8EzNz&fQW`R<7391?BPAuPe&(S4nTL+6zAl zm`t0L%SbfGX%1*bxv@6RDccv78i{_AwY1;9{Z3O8-qP;aArA8mF-SVcg}8mZ-DAi5 z%;(zLP4&h&0D@FhR2`?otPI92ZNeMCxSrNEbpomOTiSY^P~8i6)D2k()omJxVT@JR zZ<5Hdsq4S58rU#&?C8Wq#0@MbAeK7&X^^hqaj@Ionk9p$mNuxWJka&gXw)2;O*hNkHPT~?cikY%R#rNm|LC>Q#!DCI%H#O9&Ms>VE7K9H3x2l5r#7O(%I zkh4X?{Gb?4?BProLy-b^30N}Gmj@e#pp`6oQV!>p+L>om4YO&h*Y6}5m!tCCTG1>( zv}q+;8dMGHg%LJ;7zd^kVCOw-1{hDFAv6M~6+ItV@+3Yw4>SyeZdO(_W1`z`X&|bZ zBs}mU%kw?YMxJMy$n`7_MKN)ZaD{1b%o+2Yi7tq5OLkB@QO8gFmP-a43pWGC4VPov zM3&D?WDAQTV5i6sOiT}4NZNXcS8uw&Q5#aRIli_=DAU{nET$*;>leGcc)2i^91@A@P5*U8D+ z($doRpDjOA8Y{i4jfblz=A$PUt~`1A``T*w=^GEe+}g4p|KU8_ZmcZ*aP94P3gwGm XF24EApFh4;pJ(08?e^1K_wN4<#F0DI literal 0 HcmV?d00001 diff --git a/src/scenes/game/sprites/pause.png.import b/src/scenes/game/sprites/pause.png.import new file mode 100644 index 0000000..300bbd8 --- /dev/null +++ b/src/scenes/game/sprites/pause.png.import @@ -0,0 +1,35 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/pause.png-73f4605a5328cf93fa6ccbedbb975603.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://src/scenes/game/sprites/pause.png" +dest_files=[ "res://.import/pause.png-73f4605a5328cf93fa6ccbedbb975603.stex" ] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=false +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=2 +process/fix_alpha_border=true +process/premult_alpha=false +process/HDR_as_SRGB=false +process/invert_color=false +process/normal_map_invert_y=false +stream=false +size_limit=0 +detect_3d=false +svg/scale=1.0 diff --git a/src/scenes/game/sprites/resume.png b/src/scenes/game/sprites/resume.png new file mode 100644 index 0000000000000000000000000000000000000000..be3901661a4d1fe1fbfcb7f22bb64f83fdf0ad40 GIT binary patch literal 2060 zcmcIlO>f*p7&euFlBQKr4+RcjToC1B)-(RLm2F9~p&O|iqI9JM#G&Jv@vh0P$JkDG zlM~{C5WRo|hYG?ap4zmK}ei>;((BV*WQn&kSWK zY_%>2O!jM(%TUyY{S?rOvT$*jQnoD$H58pVscW~sx~Zu#uWOrj3%Al`(T$t?nYgmQ z)@J+L%;(z03+lo!0D`_Ks5*t$9-9HiBWMeZz-d7b1^WTH6D)Zg?HvW$Y6YuF zUeJVz)ka+dQMEYc0T&!Qp&%$Cp@)QP2^5;1ja-vD25~%(n^C0;_BSNkDKk;-ANiI` z1{~9D1`%^yJB(apbKxP=1~xykG2-0Ck%5KF`RJ6u_Hq_O>(Jgo)>0J*Mn;$yQpZHT z8`+4NmW3!G9KoW&ux$!AGBove+-2F5Sxa)ruBoY<1(D496#NtSX-DX3(ka~x>=3sZ z=TN%6aerJ9Z;YRMv09lfpse(IU1MdD1=q&Q@gdnen$8jJpeulMM)60mTt>x!W@51e znf_06>30*K)7{z9z0mS}4=U|>rion7@=zEN2P_~=gJaH^?@W&Vzepdam33*-5%A{J zwR=Cz(Of*E4hQ?{Ug~i8Vf6BSIdYi(PxIY2@1y}1p*2fu=Hr?!(ayBG7bcy7U2YIU zF(MI#F10NK`5`Ar7?wi}2NUYig(_|@{`YPxq`shxAk*_*WcU_EUKB=%N8BeiW-fNk z1G_7pkqmvd-U@kOQb6cx3C2(PI30ZOV>&uT0#(moFn-8C_zi~Y+G=C5eg3`A-v9cP zq8?wm@%vvlFTefjStQ>5<4pV7Q_AVb++4;>| uZ~pq}Yxh6*&6lTtI8r{_%$&{pI6wUazjKH9lXu`qtm{SA}E% literal 0 HcmV?d00001 diff --git a/src/scenes/game/sprites/resume.png.import b/src/scenes/game/sprites/resume.png.import new file mode 100644 index 0000000..1fdcae5 --- /dev/null +++ b/src/scenes/game/sprites/resume.png.import @@ -0,0 +1,35 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/resume.png-9833efb9cb068bfb68c4ea72b39d9d12.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://src/scenes/game/sprites/resume.png" +dest_files=[ "res://.import/resume.png-9833efb9cb068bfb68c4ea72b39d9d12.stex" ] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=true +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=2 +process/fix_alpha_border=true +process/premult_alpha=false +process/HDR_as_SRGB=false +process/invert_color=false +process/normal_map_invert_y=false +stream=false +size_limit=0 +detect_3d=true +svg/scale=1.0