From 1a473af37d1d57ea61431ceef8b087041452b8f7 Mon Sep 17 00:00:00 2001 From: yuki Date: Sat, 15 Nov 2025 06:57:01 -0300 Subject: [PATCH] overhaul ball and add prettier animated sprite --- scenes/ball/ball-spritesheet.aseprite | Bin 0 -> 609 bytes scenes/ball/ball-spritesheet.png | Bin 0 -> 514 bytes scenes/ball/ball-spritesheet.png.import | 40 +++++++ scenes/ball/ball.ase | Bin 649 -> 0 bytes scenes/ball/ball.aseprite | Bin 0 -> 1809 bytes scenes/ball/ball.gd | 37 ++++++- scenes/ball/ball.png | Bin 316 -> 0 bytes scenes/ball/ball.tscn | 100 ++++++++++++++++-- scenes/ball/ballshadow.png | Bin 0 -> 286 bytes ...{ball.png.import => ballshadow.png.import} | 8 +- scenes/main.tscn | 2 +- 11 files changed, 168 insertions(+), 19 deletions(-) create mode 100644 scenes/ball/ball-spritesheet.aseprite create mode 100644 scenes/ball/ball-spritesheet.png create mode 100644 scenes/ball/ball-spritesheet.png.import delete mode 100644 scenes/ball/ball.ase create mode 100644 scenes/ball/ball.aseprite delete mode 100644 scenes/ball/ball.png create mode 100644 scenes/ball/ballshadow.png rename scenes/ball/{ball.png.import => ballshadow.png.import} (74%) diff --git a/scenes/ball/ball-spritesheet.aseprite b/scenes/ball/ball-spritesheet.aseprite new file mode 100644 index 0000000000000000000000000000000000000000..050dacccb87a1c54668aa16d6bf3f84fc206e64f GIT binary patch literal 609 zcmYdfVqkc%l#!u0{Qv*|`;n#9{|y+L8B&+bW?=aDzqMtGmDMu_hX2ox zo}1I!lC2qS7`-&xFlFig?w)(WK|M>CE)5C_nlfd|zbR8DPx<%%|I+_JT|mshQ0oaa z(8@}KDeynTe17-V_h+?DaM2M-xGtN7qOBu zZck>0^Rc(iQ=TvJea7|2y+xMRzkkjIlHMnm8+;0?nd-eSRIhGj&2;^JyIIJ|3I*$2NBH^{Ef%&(Y&+t1sFWW$?#Lf2Z1$wZ=Oizbr}p zA#Nu7Ok4l+2mKtYGwkwuHvfMtEBe{wtq)UwA3kjJ?eO&$ U@o&e|e_sDTfB!o3=Ta7p0EptwZU6uP literal 0 HcmV?d00001 diff --git a/scenes/ball/ball-spritesheet.png b/scenes/ball/ball-spritesheet.png new file mode 100644 index 0000000000000000000000000000000000000000..9d0189991ca9a2f6396cf65a65249f23e24cb67e GIT binary patch literal 514 zcmeAS@N?(olHy`uVBq!ia0vp^4L~fw!3-o{wzcm9QjEnx?oJHr&dIz4a*6_cLR^6~ z5d2@8+-%73|NsB*N0wIqH(+RHNL@0Uf#Ki()|M$&R?mP6o*z9or?n+pGukkEX|`d? z(*NB(_kx3ZmM&cy6cjXN%9MXorc9pl@Bja$|AD%In1P|z6KJ57l?GGbe}?}~42;Rg z7+Tu?-(xubAj=$RrCLdlUogl@!oZ^5bScp7Jf1F&As(Gir+TkDY{22#oN`k5SuDfv z`^n5dnAHBR2>NPOafXlSZnC;ppL6$`z7_UqixOL>ZR}9#zIv>7pRuv}=Bvj_@0~DO z>&&fkll7eFV^-yx-_Lj4`F`T4Uc*n;#YRe;zqN&XJe>ZWVo^5wK2uw{dBXXf{Krg- zWhF%Htk*Lv`*1VzR-H;xe1Q|osqDs!J2^d`m;a7^aF;j6@54jhn7j>~F0VTs_L=pw zF8b`E5Py61fu0SUEj=w+rzrOv)LbBw$UKM1PG52A?|U<~3_f%E%FfUXxbe9sctOET z|Heb}rhk6m%&T_opx%a!N2mTgcY6J>OZq=5tnkhB(N z1Cs8d>_9R=K>$c5Xn@E}Gmx1K>_R}2PgEXA%A5NDNmb`$AgSYB10)RsJAkBR@IoNz zAF~WdGVt>PNe(G-ASvKz3?xOu-GQV;K1i2TRUVL3oHPkY+AUZOB>w{e1H&0jO(1Ea zc?Kl%?c4uKpg}C4@CSJv=tZFafSv>T4CpPOpMV|$`UdC~pg(|~0Qvyve4yKb4hOm# z=wzUKfsO^b6zEK#8-Wf4x(?_xpu2#M0=fw39H3i(4gtC1|9_zUAj`jflLuL>zzif| z0O%qHb_Sos%G4qS!%QHDRRJRP9~f5<07@+tb6Wcy`4|*An9tiZAN{{S&?@XvZuNvR zr>3(xtX|rWoYnjUj+!o5`-!!vi|zPFt{ZbcnlFBJ_kG3zMx}<|eM~hQ-1G{*&u_b2 K&aA#g#uWgw43`K1 diff --git a/scenes/ball/ball.aseprite b/scenes/ball/ball.aseprite new file mode 100644 index 0000000000000000000000000000000000000000..377b2c902ab499f16577f1ecc97734ef1c0479ab GIT binary patch literal 1809 zcmWe+XJB}+l!HM42ss!S85kH+fEWSP7#KlurvLiL2DX(AXsj3zvnznD zM6#p?$Yue#P7NaXe{FKJA;bUw|GytuTK(UEp_w6d$!rFOfB#!srdU}$V_^9I{OGwk ztu5J_(T34Wvkg<0{_pO&7aY{Hbm`Kdpr9#Jru>^SW%87N|Nk%j57Y(33=FlNKm)C; zG?)VaGyHdAU`#&7(9-t*9)mo{ZUtr}*Zc>v*%^EiD^rUU3{}9=OlZ~b;@Sf zbk1ZGl_;Av)xTDc`_*w=0W+V$%r6F5RZ zPIUm=4J62PJ19Bfa{JW&jl2wo9LyVAo~YHbCH$AY&**aLUuik-F&~AEYz5ytUKHuX zrf!L0T)pDekGC~*i{jKv8zL{wV7B<;@J9Lf--LfZ86Ft0p5FzugPLy6!sF&ppqmdk za2&DVd@1!yUg7t9i3bm+?r(0}66SS_hY-v(EHvMbIe0LuPjo?J9 z$4<|f@)B2;N<4FzGwJi+2md}ZeSOUOny#UJ9unFPI*L0z=QG}@KVHr-am)LzV&)l| zCnDH8ILhBY(^#7p5!NVG6Z+wHjql9sOT-Lji+pDA`{nSa`EQ-U|C$F;tmpSoIkbsQ z-M2pjv+D65E}qL~J2vD#1E!D&Pw_dydJDHSi71*j32l)Frf$3McP-DmFSNei`i0-3 zb>XyyFBvyFf2(fZeV%#utpQ8jZFbBl|7GV(KvTC);|56T_L-Nu#fG^o@ao6gKdmlT z&OO5%GBFU8y4NVb2B+?IksQGTl)7hqv1gzlb+0(f_J5#K_rmiGH|vk9vq4jL>H=u$ n_BfXoagNFK$GQjGf6mH`o4m6jOXU?Pb+2ju3QFA*f;oZ#^!E?F literal 0 HcmV?d00001 diff --git a/scenes/ball/ball.gd b/scenes/ball/ball.gd index 427e87c..edfbf14 100644 --- a/scenes/ball/ball.gd +++ b/scenes/ball/ball.gd @@ -1,22 +1,48 @@ extends RigidBody2D @onready var hurtbox: Area2D = $HurtArea2D +@onready var sprite: AnimatedSprite2D = $AnimatedSprite2D -@export var launch_speed: float = 200 +@export var launch_speed: Vector2 = Vector2(150, 250) @export var speed_mult: float = 1.08 +var current_decel_tween: Tween = null var is_hit: bool = false # Called when the node enters the scene tree for the first time. func _ready() -> void: + #connect("body_entered", _on_collision) hurtbox.connect("area_entered", _on_hit) launch() -func launch(angle: float = 0, min_speed: float = 150, max_speed: float = 250) -> void: +func launch(angle: float = 0) -> void: angle = randf_range(-PI/3, PI/3) + PI * float(randi()%2) if angle == 0 else angle - linear_velocity = Vector2(cos(angle), sin(angle)) * randf_range(min_speed, max_speed) + linear_velocity = Vector2(cos(angle), sin(angle)) * randf_range(launch_speed.x, launch_speed.y) + var length: float = linear_velocity.length()/100 + play_animation(length) + decelerate_to_stop(length*2) + + +func play_animation(speed_scale: float = 0) -> void: + assert(speed_scale != 0, "speed_scale is zero for aniumation") + sprite.speed_scale = speed_scale * (1 if randi()%2 == 0 else -1) + sprite.play("default") + + +func decelerate_to_stop(duration: float = 0.3) -> void: # Call this after collision + # KILL ANY EXISTING TWEEN (one at a time guaranteed!) + if current_decel_tween: + current_decel_tween.kill() + + # CREATE NEW ONE + current_decel_tween = create_tween() + current_decel_tween.tween_property(sprite, "speed_scale", 0.0, duration) + current_decel_tween.tween_callback(func() -> void: + sprite.pause() # Freeze on last frame + current_decel_tween = null # Clean up + ) func _on_hit(hitbox: Area2D) -> void: @@ -37,3 +63,8 @@ func _on_hit(hitbox: Area2D) -> void: func _on_hit_end() -> void: is_hit = false + +func _on_collision(_body: Node) -> void: + var length: float = linear_velocity.length()/100 + play_animation(length) + decelerate_to_stop(length) diff --git a/scenes/ball/ball.png b/scenes/ball/ball.png deleted file mode 100644 index 99721f49ca43e889a36036ab3dade16de233116b..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 316 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!63?wyl`GbK}et=JiE09(ZW{9$ps0fnnPg7k| zX}GOL|NH`%tDB-kSQ!*J7z`vhtcBU!McD%s1QIj^GR-6y*oF8+<>k$NRGpJ`ylV^s zJ1m12`o}C|;OFI#5*KhZ772Hk$WNB4%2S*)$!@{w|NsA=(bP22JoEqCH?9WvLqIE4 zOM?7@8GsUa0Z2jF4Dl|YhHy_8#}J9BrRNXw9#G(6K2T%J#{2vHjT?m%DkivZ^mkI- zXmLTK?bUKY(H&hJH{7+j+-8JbxqfM7$C1TR?rT=GoO ey0~|7|Ji@b$+&K>n|~i@1%s!npUXO@geCw6(t!Q| diff --git a/scenes/ball/ball.tscn b/scenes/ball/ball.tscn index 6e2c35f..ae0477a 100644 --- a/scenes/ball/ball.tscn +++ b/scenes/ball/ball.tscn @@ -1,36 +1,114 @@ -[gd_scene load_steps=6 format=3 uid="uid://cmgwv41ht3q4j"] +[gd_scene load_steps=16 format=3 uid="uid://cmgwv41ht3q4j"] [ext_resource type="Script" uid="uid://d2s0fid28eihy" path="res://scenes/ball/ball.gd" id="1_nv6q1"] -[ext_resource type="Texture2D" uid="uid://c44hadxh2458n" path="res://scenes/ball/ball.png" id="1_oqv3d"] +[ext_resource type="Texture2D" uid="uid://b8x8g212emfuo" path="res://scenes/ball/ball-spritesheet.png" id="2_nv6q1"] +[ext_resource type="Texture2D" uid="uid://dpcrumi6jrsp4" path="res://scenes/ball/ballshadow.png" id="2_stoaj"] [sub_resource type="PhysicsMaterial" id="PhysicsMaterial_oqv3d"] friction = 0.0 bounce = 0.3 -[sub_resource type="CircleShape2D" id="CircleShape2D_oqv3d"] -radius = 11.0 +[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_nv6q1"] +radius = 9.0 +height = 22.0 -[sub_resource type="CircleShape2D" id="CircleShape2D_nv6q1"] -radius = 8.062258 +[sub_resource type="AtlasTexture" id="AtlasTexture_stoaj"] +atlas = ExtResource("2_nv6q1") +region = Rect2(0, 0, 16, 16) + +[sub_resource type="AtlasTexture" id="AtlasTexture_xotqv"] +atlas = ExtResource("2_nv6q1") +region = Rect2(16, 0, 16, 16) + +[sub_resource type="AtlasTexture" id="AtlasTexture_jbgth"] +atlas = ExtResource("2_nv6q1") +region = Rect2(32, 0, 16, 16) + +[sub_resource type="AtlasTexture" id="AtlasTexture_yjhvv"] +atlas = ExtResource("2_nv6q1") +region = Rect2(48, 0, 16, 16) + +[sub_resource type="AtlasTexture" id="AtlasTexture_a81tc"] +atlas = ExtResource("2_nv6q1") +region = Rect2(64, 0, 16, 16) + +[sub_resource type="AtlasTexture" id="AtlasTexture_r8c1m"] +atlas = ExtResource("2_nv6q1") +region = Rect2(80, 0, 16, 16) + +[sub_resource type="AtlasTexture" id="AtlasTexture_rp1mh"] +atlas = ExtResource("2_nv6q1") +region = Rect2(96, 0, 16, 16) + +[sub_resource type="AtlasTexture" id="AtlasTexture_lsomj"] +atlas = ExtResource("2_nv6q1") +region = Rect2(112, 0, 16, 16) + +[sub_resource type="SpriteFrames" id="SpriteFrames_43gob"] +animations = [{ +"frames": [{ +"duration": 1.0, +"texture": SubResource("AtlasTexture_stoaj") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_xotqv") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_jbgth") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_yjhvv") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_a81tc") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_r8c1m") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_rp1mh") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_lsomj") +}], +"loop": true, +"name": &"default", +"speed": 10.0 +}] + +[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_stoaj"] +radius = 7.0 +height = 16.0 [node name="Ball" type="RigidBody2D"] collision_layer = 16 collision_mask = 5 physics_material_override = SubResource("PhysicsMaterial_oqv3d") gravity_scale = 0.0 +lock_rotation = true continuous_cd = 1 script = ExtResource("1_nv6q1") -[node name="Sprite2D" type="Sprite2D" parent="."] -texture = ExtResource("1_oqv3d") - [node name="HurtArea2D" type="Area2D" parent="."] collision_layer = 32 collision_mask = 64 [node name="CollisionShape2D" type="CollisionShape2D" parent="HurtArea2D"] -shape = SubResource("CircleShape2D_oqv3d") +position = Vector2(0, -1) +rotation = 1.5707964 +shape = SubResource("CapsuleShape2D_nv6q1") debug_color = Color(0.8785819, 0.30416045, 0.40790904, 0.41960785) +[node name="ShadowSprite2D" type="Sprite2D" parent="."] +modulate = Color(1, 1, 1, 0.28235295) +texture = ExtResource("2_stoaj") + +[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."] +sprite_frames = SubResource("SpriteFrames_43gob") +frame = 6 +frame_progress = 0.2223859 + [node name="CollisionShape2D" type="CollisionShape2D" parent="."] -shape = SubResource("CircleShape2D_nv6q1") +position = Vector2(0, -1) +rotation = 1.5707964 +shape = SubResource("CapsuleShape2D_stoaj") diff --git a/scenes/ball/ballshadow.png b/scenes/ball/ballshadow.png new file mode 100644 index 0000000000000000000000000000000000000000..4eab555f686d3bff9df4f62b36c819fc3fe5a0f7 GIT binary patch literal 286 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!63?wyl`GbKJV{wqX6T`Z5GB1Igq5z)|S0D`p z|JNor8#4U=|Nr}urPcop7@8SUm&|5h`1ilHWr~&6GoXU!N6*b^ZOPV*HjG}HZJ4t3 ze|OKl;GmwROP2-(1x=YU<=>Pklc)Uq|9|O!pe`V0V5s#38fayu!4&wP;lC3DWAZVE zmbU-*7>+;4G6!0zRubeF46>3iu&6g(3e=(D>Eak7F*P|sfzP0cQA%9#$cYZELm=G2 lmZ98`sJra2!Q8%AmJA_#7`8GM2tEe+%+uA+Wt~$(69CU!fkglS literal 0 HcmV?d00001 diff --git a/scenes/ball/ball.png.import b/scenes/ball/ballshadow.png.import similarity index 74% rename from scenes/ball/ball.png.import rename to scenes/ball/ballshadow.png.import index 5b0acc4..65ef9aa 100644 --- a/scenes/ball/ball.png.import +++ b/scenes/ball/ballshadow.png.import @@ -2,16 +2,16 @@ importer="texture" type="CompressedTexture2D" -uid="uid://c44hadxh2458n" -path="res://.godot/imported/ball.png-20bc590ed01e3c3d037babb65682d093.ctex" +uid="uid://dpcrumi6jrsp4" +path="res://.godot/imported/ballshadow.png-e64f35ba237f664be60971bc060213c8.ctex" metadata={ "vram_texture": false } [deps] -source_file="res://scenes/ball/ball.png" -dest_files=["res://.godot/imported/ball.png-20bc590ed01e3c3d037babb65682d093.ctex"] +source_file="res://scenes/ball/ballshadow.png" +dest_files=["res://.godot/imported/ballshadow.png-e64f35ba237f664be60971bc060213c8.ctex"] [params] diff --git a/scenes/main.tscn b/scenes/main.tscn index fd4ad17..c46ca84 100644 --- a/scenes/main.tscn +++ b/scenes/main.tscn @@ -25,4 +25,4 @@ position = Vector2(154, 97) id = 2 [node name="Ball" parent="." instance=ExtResource("3_r0du0")] -position = Vector2(193, 130) +position = Vector2(162, 115)