From e53edf82a319e5765f76a8a81dc533cb2ed2579f Mon Sep 17 00:00:00 2001 From: Luna Brovchuk Date: Mon, 2 Oct 2023 18:43:33 +0200 Subject: [PATCH] Shake Camera on Damage and Minor Fixes --- res/themes/default.tres | 1 - src/models/enemies/bat/Bat.tscn | 2 +- src/models/enemies/ghost/ghost.gd | 2 +- src/models/player/player.gd | 5 +++ src/scenes/game/Game.tscn | 31 ++++++++++------ src/scenes/game/camera.gd | 6 +++ src/scenes/game/sprites/shake_border.png | Bin 0 -> 5316 bytes .../game/sprites/shake_border.png.import | 35 ++++++++++++++++++ src/scripts/global.gd | 1 + 9 files changed, 69 insertions(+), 14 deletions(-) create mode 100644 src/scenes/game/camera.gd create mode 100644 src/scenes/game/sprites/shake_border.png create mode 100644 src/scenes/game/sprites/shake_border.png.import diff --git a/res/themes/default.tres b/res/themes/default.tres index 41f81a2..f806a20 100644 --- a/res/themes/default.tres +++ b/res/themes/default.tres @@ -3,7 +3,6 @@ [ext_resource path="res://res/fonts/silkscreen/Silkscreen-Regular.ttf" type="DynamicFontData" id=1] [sub_resource type="DynamicFont" id=1] -size = 8 font_data = ExtResource( 1 ) [resource] diff --git a/src/models/enemies/bat/Bat.tscn b/src/models/enemies/bat/Bat.tscn index 24db929..fed6873 100644 --- a/src/models/enemies/bat/Bat.tscn +++ b/src/models/enemies/bat/Bat.tscn @@ -22,7 +22,7 @@ script = ExtResource( 2 ) use_parent_material = true frames = ExtResource( 1 ) animation = "idle" -frame = 1 +frame = 2 playing = true centered = false diff --git a/src/models/enemies/ghost/ghost.gd b/src/models/enemies/ghost/ghost.gd index 1c9d17d..dcdd6d6 100644 --- a/src/models/enemies/ghost/ghost.gd +++ b/src/models/enemies/ghost/ghost.gd @@ -34,8 +34,8 @@ func _physics_process(delta): global_position = global_position.move_toward(dash_target, 10) if global_position == dash_target: dashing = false - $AudioDash.play() afterdash = true + if afterdash: afterdash_timer += delta if afterdash_timer >= 1: diff --git a/src/models/player/player.gd b/src/models/player/player.gd index 4466554..35db92e 100644 --- a/src/models/player/player.gd +++ b/src/models/player/player.gd @@ -63,6 +63,7 @@ func area_entered(area): Global.add_health(-1) invincible = true invincibility_timer = .0 + get_tree().get_root().get_node("Game/View/Camera2D").current = true func get_recharge(): return 2.0 @@ -122,7 +123,11 @@ func _physics_process(delta): if area.get_parent().is_in_group("trash_drop"): slowed = true break + if area.get_parent().is_in_group("enemy") and not invincible: + area_entered(area) + if invincible and invincibility_timer >= 0.3: + get_tree().get_root().get_node("Game/View/Camera2D").current = false if invincible and invincibility_timer >= 0.9: invincible = false diff --git a/src/scenes/game/Game.tscn b/src/scenes/game/Game.tscn index 710326d..230dede 100644 --- a/src/scenes/game/Game.tscn +++ b/src/scenes/game/Game.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=31 format=2] +[gd_scene load_steps=33 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] @@ -19,6 +19,8 @@ [ext_resource path="res://src/scenes/game/sprites/stun/stun_spriteframes.tres" type="SpriteFrames" id=17] [ext_resource path="res://src/models/card/Card.tscn" type="PackedScene" id=18] [ext_resource path="res://src/scenes/game/sprites/stun/stun_placeholder_spriteframes.tres" type="SpriteFrames" id=19] +[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] [sub_resource type="RectangleShape2D" id=2] extents = Vector2( 10, 60 ) @@ -30,14 +32,14 @@ extents = Vector2( 140, 10.125 ) atlas = ExtResource( 6 ) region = Rect2( 155, 0, 31, 11 ) -[sub_resource type="AtlasTexture" id=9] -atlas = ExtResource( 6 ) -region = Rect2( 93, 0, 31, 11 ) - [sub_resource type="AtlasTexture" id=8] atlas = ExtResource( 6 ) region = Rect2( 124, 0, 31, 11 ) +[sub_resource type="AtlasTexture" id=9] +atlas = ExtResource( 6 ) +region = Rect2( 93, 0, 31, 11 ) + [sub_resource type="AtlasTexture" id=10] atlas = ExtResource( 6 ) region = Rect2( 62, 0, 31, 11 ) @@ -52,10 +54,10 @@ region = Rect2( 0, 0, 31, 11 ) [sub_resource type="SpriteFrames" id=4] animations = [ { -"frames": [ SubResource( 7 ), SubResource( 9 ), SubResource( 8 ), SubResource( 10 ), SubResource( 11 ), SubResource( 12 ) ], -"loop": false, -"name": "idle", -"speed": 0.0 +"frames": [ SubResource( 7 ), SubResource( 8 ), SubResource( 9 ), SubResource( 10 ), SubResource( 11 ), SubResource( 12 ) ], +"loop": true, +"name": "default", +"speed": 5.0 } ] [sub_resource type="Animation" id=5] @@ -96,6 +98,11 @@ script = ExtResource( 11 ) [node name="Background" type="Node2D" parent="View"] +[node name="ShakeBorder" type="Sprite" parent="View/Background"] +texture = ExtResource( 21 ) +centered = false +offset = Vector2( -3, -3 ) + [node name="Stones" type="Sprite" parent="View/Background"] z_index = -2 texture = ExtResource( 1 ) @@ -154,9 +161,12 @@ radial_accel = 4.0 radial_accel_random = 1.0 color = Color( 0.133333, 0.133333, 0.137255, 1 ) +[node name="Camera2D" type="Camera2D" parent="View"] +position = Vector2( 160, 90 ) +script = ExtResource( 20 ) + [node name="UIWrapper" type="CanvasLayer" parent="."] layer = 3 -follow_viewport_enable = true [node name="UI" type="Control" parent="UIWrapper"] margin_right = 320.0 @@ -219,7 +229,6 @@ margin_bottom = 40.0 [node name="HealthSprite" type="AnimatedSprite" parent="UIWrapper/UI/Left/Health"] position = Vector2( 52, 156 ) frames = SubResource( 4 ) -animation = "idle" centered = false [node name="PlayerIcon" type="Sprite" parent="UIWrapper/UI/Left"] diff --git a/src/scenes/game/camera.gd b/src/scenes/game/camera.gd new file mode 100644 index 0000000..4d8ae89 --- /dev/null +++ b/src/scenes/game/camera.gd @@ -0,0 +1,6 @@ +extends Camera2D + +var shake_amount = 2 + +func _process(delta): + set_offset(Vector2(rand_range(-1.0, 1.0) * shake_amount, rand_range(-1.0, 1.0) * shake_amount)) diff --git a/src/scenes/game/sprites/shake_border.png b/src/scenes/game/sprites/shake_border.png new file mode 100644 index 0000000000000000000000000000000000000000..7b792aba7e25369331b29b133e23b66623576d83 GIT binary patch literal 5316 zcmeHLU5wmT6`q8@QWPMx5~xV@%2nF5!DC)4*%nH7`>DjJYb->5)Q^8#-b4^#rtBx+F+LP|vul_K$@{-}jMv{euwH4zkX?3wXQ zw&To}kctPQ$*g_PcfND(@%g#qZynfw&$jDty1rB@ZChHbA1sx&EWq_s*L@hifBTo$ zZiPP|4HsA9Qt4wir2n^+zJKyFrPB6CS#vpAZtSxh-YFB8+qB&4gn%xUcJJwh#5qb6 zWYZQ4YQlxnPYZ~-HQ_$JAveN#+GdOE5k0iNzv-+Wbxc>-a~Im(vw)yO6M}jjKZvbf zO~`mHxK5WP0cDWnXib<)4Wi}70W{Aeij1-%IrYmRS_GO zR#hW`XG7rCBwu)Z)f26r`~og|?pNo#9sMq$Yr?gFSS@oHmGuae|0RJrYW|ET?QRf*|DL%R-SbufSj`xeQ8stN@xya%gDHN0cNyYI5$6lIOt4H>9X# z9qqi21ukEUZ%;QqRG@W|(3${=q>8dBs&W%+mVzx=+a;@(EDxX!$W50dWCDz3QC6DR zOu?FQ8JN4w>(7L`j^**FL*T)&4rx&-3|g7BM#EYP;)DbaU8>gvaJ9^sYw1Y7FkOkGzS>DRf_O_M6s9~79&9pK2HhE>5vMK=vq^b|rw4Jbs@ z07~8PXjLVqrm4<|?TZnE8YliFYwDE?jG9eMN*pYzRnrg^QzK&4vpv!ETodcEW5|Xo zpt0R~?(?X@U5GiXr%&4gdT^Db^;Hw_aB(?JRlhq}G!!U&S;Fb}P`)xlJ{BJi7=&06 zP?|4RX8#cME^wft>#9CnKfrp_U#>HVTAVqeDqt#8$wVs?B3zZz-jLO(wa8+~y8f`+ z9HPgDS3W~oSz5#yY{E(Nle)rinN4}bn+xWEcCAezTvy230W9WTvPL30*Mb<&tP82g z`IxL;*>%U(Jw^6B5wc1VUC2n$RGo^bI@OBiIJRx8mC@FxxemQs%S-M*aeWw8r%i$u zg*hY%SF;(IE~=`DdPT2_uB~Cw#+oTsiJ_@fwy9jDQ#LcbC0ygpI6PRT(L`c}BqA_N zX%yE4FXA0U!q8_UY7a9_@_y)m17X-6(F)lKk zN@i)xPI_8k5UT>Fji_0yE+u}9bmVqgh(c%RqnJX0x(E&%NFCn9 zDDARL{fv|)TKSE(d`xM1&og%xB6n#g5 zr<+!vwHKSU5FGj#oUx{+?pXf*F-6SbPMa2`L@u7?Q4XBGwOl-lXBVD)IPjwj4#WuU zOxkpE-RChyy1Zi|;Rn!y$X+Gu?K8`|&$|dt#=&g~io4M&3{8}}9I#fqD705pnH8oE z3F4#h`=MaJxp)>2^Sc4bz6zKo0JFG`bmPQbZ?giXT%7V`19LDTq;V}=HbchCqn{vi zkPGR#d)kD#Ycv97!&NXQvWPvRi-xW#qG`KWq>5I-N=3$`N(SbAmd~eLdozde3GM0I znC5SWoOr1)iUGW-NH6nuByf|zWuXBaX(M=t5^Y)CS1N7&!%}^&**p2x@9~k(&fR$Y zm7jj;j>FqO{)4Fbr>(a>_WX|Ik)5Aj{9)O@>DIK5_clW98RhIR9ix zsvo=avA?m^M_%3i+;b;hee2Crk3YaqJoC;|3&*@aztD}>s=vPU_xN}I9mltQ^__n? zXCK<*o7X*4`_#hmPyYXNEhDh(d1uS#yZ2X4e&|8<+>g)v*MD^PgJ1tQ DV1VLs literal 0 HcmV?d00001 diff --git a/src/scenes/game/sprites/shake_border.png.import b/src/scenes/game/sprites/shake_border.png.import new file mode 100644 index 0000000..6c61585 --- /dev/null +++ b/src/scenes/game/sprites/shake_border.png.import @@ -0,0 +1,35 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/shake_border.png-b999b04bbadd93aa205e8f30b37b7f73.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://src/scenes/game/sprites/shake_border.png" +dest_files=[ "res://.import/shake_border.png-b999b04bbadd93aa205e8f30b37b7f73.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/scripts/global.gd b/src/scripts/global.gd index 1e0788c..8ba297b 100644 --- a/src/scripts/global.gd +++ b/src/scripts/global.gd @@ -19,6 +19,7 @@ func add_health(amount): get_tree().get_root().get_node("Game/UIWrapper/UI/Left/Health/HealthSprite").frame = health if health == 0: playing = false + get_tree().get_root().get_node("Game/View/Enemies").free() var animplayer = get_tree().get_root().get_node("Game/UIWrapper/UI/Gameover/AnimationPlayer") animplayer.play("gameover") yield(animplayer, "animation_finished")