Asteroid collisions, camera shake, sound effects

This commit is contained in:
ToasterPanic 2025-12-01 19:10:54 -05:00
parent ad7c280c24
commit 66ed42e3cb
10 changed files with 56 additions and 5 deletions

View file

@ -1,7 +1,8 @@
[gd_scene load_steps=6 format=3 uid="uid://bauklhpieuivd"]
[gd_scene load_steps=7 format=3 uid="uid://bauklhpieuivd"]
[ext_resource type="Texture2D" uid="uid://dtwo7g0ipc4k" path="res://textures/ship_1.png" id="1_uwrxv"]
[ext_resource type="Script" uid="uid://bfxfkrkaebxk0" path="res://scripts/player.gd" id="1_yqjtg"]
[ext_resource type="AudioStream" uid="uid://5tr30e1tmdp6" path="res://sounds/collision.mp3" id="2_lbhrr"]
[ext_resource type="PackedScene" uid="uid://dgng5vdhn6anc" path="res://scenes/asteroid.tscn" id="3_lnu2h"]
[sub_resource type="CircleShape2D" id="CircleShape2D_uwrxv"]
@ -16,15 +17,18 @@ radius = 20.0
linear_damp = 6.247
script = ExtResource("1_yqjtg")
[node name="Collision" type="AudioStreamPlayer" parent="Player"]
stream = ExtResource("2_lbhrr")
[node name="Sprite" type="Sprite2D" parent="Player"]
texture = ExtResource("1_uwrxv")
[node name="CollisionShape" type="CollisionShape2D" parent="Player"]
shape = SubResource("CircleShape2D_uwrxv")
[node name="Camera2D" type="Camera2D" parent="Player"]
[node name="Camera" type="Camera2D" parent="Player"]
ignore_rotation = false
position_smoothing_enabled = true
limit_enabled = false
position_smoothing_speed = 8.0
rotation_smoothing_enabled = true
rotation_smoothing_speed = 15.0
@ -46,3 +50,5 @@ position = Vector2(-216, 134)
[node name="Asteroid4" parent="." instance=ExtResource("3_lnu2h")]
position = Vector2(-192, -427)
[connection signal="body_shape_entered" from="Player/Hitbox" to="Player" method="_on_hitbox_body_shape_entered"]

View file

@ -1,7 +1,21 @@
extends RigidBody2D
var health = 1000
var time_since_last_collision = 0
var time_since_last_collision = 1
var camera_shake_power = 0
func _process(delta: float) -> void:
$Camera.offset.x = randi_range(-camera_shake_power, camera_shake_power)
$Camera.offset.y = randi_range(-camera_shake_power, camera_shake_power)
if camera_shake_power > 0:
camera_shake_power -= delta * 20
if camera_shake_power < 0:
camera_shake_power = 0
if time_since_last_collision <= 1:
time_since_last_collision += delta
func _physics_process(delta: float) -> void:
var axis = Input.get_axis("turn_left", "turn_right")
@ -10,5 +24,17 @@ func _physics_process(delta: float) -> void:
var new_velocity = transform.y * Input.get_axis("forward", "backward") * 512
if new_velocity.length() > linear_velocity.length() - 12:
if (new_velocity.length() > linear_velocity.length() - 12) :
linear_velocity = transform.y * Input.get_axis("forward", "backward") * 512
if time_since_last_collision < 1:
linear_velocity *= (time_since_last_collision + 0.15) * 2
func _on_hitbox_body_shape_entered(body_rid: RID, body: Node2D, body_shape_index: int, local_shape_index: int) -> void:
if body.linear_velocity.length() + linear_velocity.length() > 256:
health -= 100
camera_shake_power = 4
$Collision.play()
time_since_last_collision = 0

BIN
sounds/2050_bass.mp3 Normal file

Binary file not shown.

BIN
sounds/2050_drums.mp3 Normal file

Binary file not shown.

BIN
sounds/2050_music.mp3 Normal file

Binary file not shown.

BIN
sounds/boost.mp3 Normal file

Binary file not shown.

BIN
sounds/collision.mp3 Normal file

Binary file not shown.

View file

@ -0,0 +1,19 @@
[remap]
importer="mp3"
type="AudioStreamMP3"
uid="uid://5tr30e1tmdp6"
path="res://.godot/imported/collision.mp3-ad2e20193b236573f2e90119a231d4b9.mp3str"
[deps]
source_file="res://sounds/collision.mp3"
dest_files=["res://.godot/imported/collision.mp3-ad2e20193b236573f2e90119a231d4b9.mp3str"]
[params]
loop=false
loop_offset=0
bpm=0
beat_count=0
bar_beats=4

BIN
sounds/explode.mp3 Normal file

Binary file not shown.

BIN
sounds/fire.mp3 Normal file

Binary file not shown.