diff --git a/scenes/game.tscn b/scenes/game.tscn index 5358ee8..43a0101 100644 --- a/scenes/game.tscn +++ b/scenes/game.tscn @@ -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"] diff --git a/scripts/player.gd b/scripts/player.gd index b72e642..6dbde7d 100644 --- a/scripts/player.gd +++ b/scripts/player.gd @@ -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 diff --git a/sounds/2050_bass.mp3 b/sounds/2050_bass.mp3 new file mode 100644 index 0000000..886743e Binary files /dev/null and b/sounds/2050_bass.mp3 differ diff --git a/sounds/2050_drums.mp3 b/sounds/2050_drums.mp3 new file mode 100644 index 0000000..f28f1b5 Binary files /dev/null and b/sounds/2050_drums.mp3 differ diff --git a/sounds/2050_music.mp3 b/sounds/2050_music.mp3 new file mode 100644 index 0000000..450a5e3 Binary files /dev/null and b/sounds/2050_music.mp3 differ diff --git a/sounds/boost.mp3 b/sounds/boost.mp3 new file mode 100644 index 0000000..9ecf03d Binary files /dev/null and b/sounds/boost.mp3 differ diff --git a/sounds/collision.mp3 b/sounds/collision.mp3 new file mode 100644 index 0000000..4b3ef3d Binary files /dev/null and b/sounds/collision.mp3 differ diff --git a/sounds/collision.mp3.import b/sounds/collision.mp3.import new file mode 100644 index 0000000..d5b8ae9 --- /dev/null +++ b/sounds/collision.mp3.import @@ -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 diff --git a/sounds/explode.mp3 b/sounds/explode.mp3 new file mode 100644 index 0000000..3613eb3 Binary files /dev/null and b/sounds/explode.mp3 differ diff --git a/sounds/fire.mp3 b/sounds/fire.mp3 new file mode 100644 index 0000000..e43185b Binary files /dev/null and b/sounds/fire.mp3 differ