overhaul ball and add prettier animated sprite
This commit is contained in:
parent
6c22f929b2
commit
1a473af37d
11 changed files with 168 additions and 19 deletions
BIN
scenes/ball/ball-spritesheet.aseprite
Normal file
BIN
scenes/ball/ball-spritesheet.aseprite
Normal file
Binary file not shown.
BIN
scenes/ball/ball-spritesheet.png
Normal file
BIN
scenes/ball/ball-spritesheet.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 514 B |
40
scenes/ball/ball-spritesheet.png.import
Normal file
40
scenes/ball/ball-spritesheet.png.import
Normal file
|
|
@ -0,0 +1,40 @@
|
||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="texture"
|
||||||
|
type="CompressedTexture2D"
|
||||||
|
uid="uid://b8x8g212emfuo"
|
||||||
|
path="res://.godot/imported/ball-spritesheet.png-ca47a7f54fb74fcd3e843038e4efe7d7.ctex"
|
||||||
|
metadata={
|
||||||
|
"vram_texture": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://scenes/ball/ball-spritesheet.png"
|
||||||
|
dest_files=["res://.godot/imported/ball-spritesheet.png-ca47a7f54fb74fcd3e843038e4efe7d7.ctex"]
|
||||||
|
|
||||||
|
[params]
|
||||||
|
|
||||||
|
compress/mode=0
|
||||||
|
compress/high_quality=false
|
||||||
|
compress/lossy_quality=0.7
|
||||||
|
compress/uastc_level=0
|
||||||
|
compress/rdo_quality_loss=0.0
|
||||||
|
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/channel_remap/red=0
|
||||||
|
process/channel_remap/green=1
|
||||||
|
process/channel_remap/blue=2
|
||||||
|
process/channel_remap/alpha=3
|
||||||
|
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
|
||||||
Binary file not shown.
BIN
scenes/ball/ball.aseprite
Normal file
BIN
scenes/ball/ball.aseprite
Normal file
Binary file not shown.
|
|
@ -1,22 +1,48 @@
|
||||||
extends RigidBody2D
|
extends RigidBody2D
|
||||||
|
|
||||||
@onready var hurtbox: Area2D = $HurtArea2D
|
@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
|
@export var speed_mult: float = 1.08
|
||||||
|
|
||||||
|
var current_decel_tween: Tween = null
|
||||||
var is_hit: bool = false
|
var is_hit: bool = false
|
||||||
|
|
||||||
# Called when the node enters the scene tree for the first time.
|
# Called when the node enters the scene tree for the first time.
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
|
#connect("body_entered", _on_collision)
|
||||||
hurtbox.connect("area_entered", _on_hit)
|
hurtbox.connect("area_entered", _on_hit)
|
||||||
|
|
||||||
launch()
|
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
|
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:
|
func _on_hit(hitbox: Area2D) -> void:
|
||||||
|
|
@ -37,3 +63,8 @@ func _on_hit(hitbox: Area2D) -> void:
|
||||||
|
|
||||||
func _on_hit_end() -> void:
|
func _on_hit_end() -> void:
|
||||||
is_hit = false
|
is_hit = false
|
||||||
|
|
||||||
|
func _on_collision(_body: Node) -> void:
|
||||||
|
var length: float = linear_velocity.length()/100
|
||||||
|
play_animation(length)
|
||||||
|
decelerate_to_stop(length)
|
||||||
|
|
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 316 B |
|
|
@ -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="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"]
|
[sub_resource type="PhysicsMaterial" id="PhysicsMaterial_oqv3d"]
|
||||||
friction = 0.0
|
friction = 0.0
|
||||||
bounce = 0.3
|
bounce = 0.3
|
||||||
|
|
||||||
[sub_resource type="CircleShape2D" id="CircleShape2D_oqv3d"]
|
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_nv6q1"]
|
||||||
radius = 11.0
|
radius = 9.0
|
||||||
|
height = 22.0
|
||||||
|
|
||||||
[sub_resource type="CircleShape2D" id="CircleShape2D_nv6q1"]
|
[sub_resource type="AtlasTexture" id="AtlasTexture_stoaj"]
|
||||||
radius = 8.062258
|
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"]
|
[node name="Ball" type="RigidBody2D"]
|
||||||
collision_layer = 16
|
collision_layer = 16
|
||||||
collision_mask = 5
|
collision_mask = 5
|
||||||
physics_material_override = SubResource("PhysicsMaterial_oqv3d")
|
physics_material_override = SubResource("PhysicsMaterial_oqv3d")
|
||||||
gravity_scale = 0.0
|
gravity_scale = 0.0
|
||||||
|
lock_rotation = true
|
||||||
continuous_cd = 1
|
continuous_cd = 1
|
||||||
script = ExtResource("1_nv6q1")
|
script = ExtResource("1_nv6q1")
|
||||||
|
|
||||||
[node name="Sprite2D" type="Sprite2D" parent="."]
|
|
||||||
texture = ExtResource("1_oqv3d")
|
|
||||||
|
|
||||||
[node name="HurtArea2D" type="Area2D" parent="."]
|
[node name="HurtArea2D" type="Area2D" parent="."]
|
||||||
collision_layer = 32
|
collision_layer = 32
|
||||||
collision_mask = 64
|
collision_mask = 64
|
||||||
|
|
||||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="HurtArea2D"]
|
[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)
|
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="."]
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||||
shape = SubResource("CircleShape2D_nv6q1")
|
position = Vector2(0, -1)
|
||||||
|
rotation = 1.5707964
|
||||||
|
shape = SubResource("CapsuleShape2D_stoaj")
|
||||||
|
|
|
||||||
BIN
scenes/ball/ballshadow.png
Normal file
BIN
scenes/ball/ballshadow.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 286 B |
|
|
@ -2,16 +2,16 @@
|
||||||
|
|
||||||
importer="texture"
|
importer="texture"
|
||||||
type="CompressedTexture2D"
|
type="CompressedTexture2D"
|
||||||
uid="uid://c44hadxh2458n"
|
uid="uid://dpcrumi6jrsp4"
|
||||||
path="res://.godot/imported/ball.png-20bc590ed01e3c3d037babb65682d093.ctex"
|
path="res://.godot/imported/ballshadow.png-e64f35ba237f664be60971bc060213c8.ctex"
|
||||||
metadata={
|
metadata={
|
||||||
"vram_texture": false
|
"vram_texture": false
|
||||||
}
|
}
|
||||||
|
|
||||||
[deps]
|
[deps]
|
||||||
|
|
||||||
source_file="res://scenes/ball/ball.png"
|
source_file="res://scenes/ball/ballshadow.png"
|
||||||
dest_files=["res://.godot/imported/ball.png-20bc590ed01e3c3d037babb65682d093.ctex"]
|
dest_files=["res://.godot/imported/ballshadow.png-e64f35ba237f664be60971bc060213c8.ctex"]
|
||||||
|
|
||||||
[params]
|
[params]
|
||||||
|
|
||||||
|
|
@ -25,4 +25,4 @@ position = Vector2(154, 97)
|
||||||
id = 2
|
id = 2
|
||||||
|
|
||||||
[node name="Ball" parent="." instance=ExtResource("3_r0du0")]
|
[node name="Ball" parent="." instance=ExtResource("3_r0du0")]
|
||||||
position = Vector2(193, 130)
|
position = Vector2(162, 115)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue