a game about throwing hammers made for the github game off
51 files changed, 559 insertions, 411 deletions
@@ -33,6 +33,7 @@ position = Vector2(128, 96) [node name="Start" parent="." instance=ExtResource("2_vg2cv")] layer_0/tile_data = PackedInt32Array(131072, 0, 1, 196608, 0, 1, 262144, 262144, 1, 327680, 196608, 1, 393216, 196608, 2, 589824, 196608, 0, 655360, 196608, 1, 720896, 262144, 2, 786432, 0, 1, 851968, 0, 1, 917504, 0, 1, 983040, 0, 2, 983041, 65536, 2, 2, 65536, 0, 983042, 327680, 3, 3, 65536, 0, 983043, 65536, 3, 4, 65536, 0, 983044, 65536, 3, 5, 327680, 0, 983045, 65536, 3, 6, 131072, 3, 393222, 0, 0, 524294, 0, 1, 589830, 0, 2, 983046, 131072, 3, 524295, 65536, 1, 589831, 65536, 2, 393224, 65536, 0, 458760, 65536, 1, 524296, 65536, 1, 589832, 65536, 2, 9, 0, 0, 393225, 131072, 0, 458761, 131072, 1, 524297, 131072, 1, 589833, 131072, 2, 983049, 0, 3, 10, 327680, 0, 983050, 65536, 3, 11, 65536, 3, 983051, 65536, 3, 12, 393216, 0, 983052, 65536, 3, 13, 65536, 0, 983053, 65536, 3, 14, 65536, 0, 983054, 65536, 3, 15, 131072, 0, 65551, 458752, 1, 131087, 196608, 1, 196623, 196608, 1, 262159, 196608, 1, 327695, 196608, 1, 393231, 196608, 2, 589839, 196608, 0, 655375, 196608, 1, 720911, 196608, 1, 786447, 196608, 1, 851983, 196608, 1, 917519, 196608, 1, 983055, 458752, 3, 65536, 0, 1, 0, 0, 0, 1, 65536, 0, 458758, 0, 1, 393223, 65536, 0, 458759, 65536, 1, 917516, 196609, 0, 917517, 262145, 0, 851982, 196609, 0, 917518, 327681, 0, 917505, 65536, 1, 917506, 131072, 1, 851970, 131072, 0, 851969, 327680, 2, 786433, 131072, 1, 720897, 131072, 0, 786439, 0, 0, 786440, 327680, 0, 851976, 131072, 2, 851975, 0, 2, 786441, 131072, 3, 393220, 196608, 2, 327684, 196608, 1, 262148, 458752, 1, 393228, 196608, 0, 458764, 196608, 1, 524300, 196608, 1, 589836, 196608, 2, 262147, 65536, 2, 262146, 65536, 2, 262145, 65536, 2, 196609, 65536, 1, 131073, 65536, 1, 65537, 65536, 1, 65538, 65536, 1, 131074, 65536, 1, 196610, 65536, 1, 65539, 65536, 1, 131075, 65536, 1, 196611, 65536, 1, 196612, 131072, 1, 131076, 327680, 1, 131077, 131072, 2, 65540, 65536, 1, 65548, 0, 1, 65549, 327680, 1, 131085, 458752, 1, 131084, 0, 2, 196621, 196608, 2, 65550, 65536, 2, 65546, 131072, 1, 131082, 131072, 2, 65545, 0, 1, 131081, 262144, 1, 196617, 196608, 2, 65541, 131072, 1) +layer_0/tile_data = PackedInt32Array(131072, 0, 1, 196608, 0, 1, 262144, 262144, 1, 327680, 196608, 1, 393216, 196608, 2, 589824, 196608, 0, 655360, 196608, 1, 720896, 262144, 2, 786432, 0, 1, 851968, 0, 1, 917504, 0, 1, 983040, 0, 2, 983041, 65536, 2, 2, 65536, 0, 983042, 327680, 3, 3, 65536, 0, 983043, 65536, 3, 4, 65536, 0, 983044, 65536, 3, 5, 327680, 0, 983045, 65536, 3, 6, 131072, 3, 393222, 0, 0, 524294, 0, 1, 589830, 0, 2, 983046, 131072, 3, 524295, 65536, 1, 589831, 65536, 2, 393224, 65536, 0, 458760, 65536, 1, 524296, 65536, 1, 589832, 65536, 2, 9, 0, 0, 393225, 131072, 0, 458761, 131072, 1, 524297, 131072, 1, 589833, 131072, 2, 983049, 0, 3, 10, 327680, 0, 983050, 65536, 3, 11, 65536, 3, 983051, 65536, 3, 12, 393216, 0, 983052, 65536, 3, 13, 65536, 0, 983053, 65536, 3, 14, 65536, 0, 983054, 65536, 3, 15, 131072, 0, 65551, 458752, 1, 131087, 196608, 1, 196623, 196608, 1, 262159, 196608, 1, 327695, 196608, 1, 393231, 196608, 2, 589839, 196608, 0, 655375, 196608, 1, 720911, 196608, 1, 786447, 196608, 1, 851983, 196608, 1, 917519, 196608, 1, 983055, 458752, 3, 65536, 0, 1, 0, 0, 0, 1, 65536, 0, 458758, 0, 1, 393223, 65536, 0, 458759, 65536, 1, 917516, 196609, 0, 917517, 262145, 0, 851982, 196609, 0, 917518, 327681, 0, 917505, 65536, 1, 917506, 131072, 1, 851970, 131072, 0, 851969, 327680, 2, 786433, 131072, 1, 720897, 131072, 0, 786439, 0, 0, 786440, 327680, 0, 851976, 131072, 2, 851975, 0, 2, 786441, 131072, 3, 393220, 196608, 2, 327684, 196608, 1, 262148, 458752, 1, 393228, 196608, 0, 458764, 196608, 1, 524300, 196608, 1, 589836, 196608, 2, 262147, 65536, 2, 262146, 65536, 2, 262145, 65536, 2, 196609, 65536, 1, 131073, 65536, 1, 65537, 65536, 1, 65538, 65536, 1, 131074, 65536, 1, 196610, 65536, 1, 65539, 65536, 1, 131075, 65536, 1, 196611, 65536, 1, 196612, 131072, 1, 131076, 327680, 1, 131077, 131072, 2, 65540, 65536, 1, 65548, 0, 1, 65549, 327680, 1, 131085, 458752, 1, 131084, 0, 2, 196621, 196608, 2, 65550, 65536, 2, 65546, 131072, 1, 131082, 131072, 2, 65545, 0, 1, 131081, 262144, 1, 196617, 196608, 2, 65541, 131072, 1) [node name="LevelManager" type="Node" parent="." node_paths=PackedStringArray("current_level", "player")] unique_name_in_owner = true diff --git a/assets/sfx/click.ogg b/assets/sfx/click.ogg Binary files differnew file mode 100644 index 0000000..2bbaa60 --- /dev/null +++ b/assets/sfx/click.ogg diff --git a/assets/sfx/click.ogg.import b/assets/sfx/click.ogg.import new file mode 100644 index 0000000..524f3f2 --- /dev/null +++ b/assets/sfx/click.ogg.import @@ -0,0 +1,19 @@ +[remap] + +importer="oggvorbisstr" +type="AudioStreamOggVorbis" +uid="uid://xjahlbdjvnfr" +path="res://.godot/imported/click.ogg-9bd5432ec500ad951a481b3187a152d7.oggvorbisstr" + +[deps] + +source_file="res://assets/sfx/click.ogg" +dest_files=["res://.godot/imported/click.ogg-9bd5432ec500ad951a481b3187a152d7.oggvorbisstr"] + +[params] + +loop=false +loop_offset=0.0 +bpm=0.0 +beat_count=0 +bar_beats=4 diff --git a/assets/sfx/death.ogg b/assets/sfx/death.ogg Binary files differnew file mode 100644 index 0000000..daaa6f1 --- /dev/null +++ b/assets/sfx/death.ogg diff --git a/assets/sfx/death.ogg.import b/assets/sfx/death.ogg.import new file mode 100644 index 0000000..c1f101e --- /dev/null +++ b/assets/sfx/death.ogg.import @@ -0,0 +1,19 @@ +[remap] + +importer="oggvorbisstr" +type="AudioStreamOggVorbis" +uid="uid://f7fbwx88h8ql" +path="res://.godot/imported/death.ogg-025db449efadaa224dc44be32198a6cc.oggvorbisstr" + +[deps] + +source_file="res://assets/sfx/death.ogg" +dest_files=["res://.godot/imported/death.ogg-025db449efadaa224dc44be32198a6cc.oggvorbisstr"] + +[params] + +loop=false +loop_offset=0.0 +bpm=0.0 +beat_count=0 +bar_beats=4 diff --git a/assets/sfx/jump.ogg b/assets/sfx/jump.ogg Binary files differnew file mode 100644 index 0000000..194ce73 --- /dev/null +++ b/assets/sfx/jump.ogg diff --git a/assets/sfx/jump.ogg.import b/assets/sfx/jump.ogg.import new file mode 100644 index 0000000..a35fd67 --- /dev/null +++ b/assets/sfx/jump.ogg.import @@ -0,0 +1,19 @@ +[remap] + +importer="oggvorbisstr" +type="AudioStreamOggVorbis" +uid="uid://6vix1jv7ewni" +path="res://.godot/imported/jump.ogg-98cb6aa3c09225058a328d1da24a0202.oggvorbisstr" + +[deps] + +source_file="res://assets/sfx/jump.ogg" +dest_files=["res://.godot/imported/jump.ogg-98cb6aa3c09225058a328d1da24a0202.oggvorbisstr"] + +[params] + +loop=false +loop_offset=0.0 +bpm=0.0 +beat_count=0 +bar_beats=4 diff --git a/assets/sfx/step.ogg b/assets/sfx/step.ogg Binary files differnew file mode 100644 index 0000000..a21d321 --- /dev/null +++ b/assets/sfx/step.ogg diff --git a/assets/sfx/step.ogg.import b/assets/sfx/step.ogg.import new file mode 100644 index 0000000..13e4916 --- /dev/null +++ b/assets/sfx/step.ogg.import @@ -0,0 +1,19 @@ +[remap] + +importer="oggvorbisstr" +type="AudioStreamOggVorbis" +uid="uid://cti7201mfcxpw" +path="res://.godot/imported/step.ogg-b58f343399318fc762d607c2754686f6.oggvorbisstr" + +[deps] + +source_file="res://assets/sfx/step.ogg" +dest_files=["res://.godot/imported/step.ogg-b58f343399318fc762d607c2754686f6.oggvorbisstr"] + +[params] + +loop=false +loop_offset=0.0 +bpm=0.0 +beat_count=0 +bar_beats=4 diff --git a/assets/sfx/woosh.ogg b/assets/sfx/woosh.ogg Binary files differnew file mode 100644 index 0000000..5d31b30 --- /dev/null +++ b/assets/sfx/woosh.ogg diff --git a/assets/sfx/woosh.ogg.import b/assets/sfx/woosh.ogg.import new file mode 100644 index 0000000..90aadd5 --- /dev/null +++ b/assets/sfx/woosh.ogg.import @@ -0,0 +1,19 @@ +[remap] + +importer="oggvorbisstr" +type="AudioStreamOggVorbis" +uid="uid://cofkgb6d18878" +path="res://.godot/imported/woosh.ogg-086991c27fb473d9153beaf708338a14.oggvorbisstr" + +[deps] + +source_file="res://assets/sfx/woosh.ogg" +dest_files=["res://.godot/imported/woosh.ogg-086991c27fb473d9153beaf708338a14.oggvorbisstr"] + +[params] + +loop=false +loop_offset=0.0 +bpm=0.0 +beat_count=0 +bar_beats=4 diff --git a/autoloads/Globals.gd b/autoloads/Globals.gd index e7d17ac..0b745c9 100644 --- a/autoloads/Globals.gd +++ b/autoloads/Globals.gd @@ -3,5 +3,6 @@ extends Node var player: Player = null var levelmanager: LevelManager = null + func _init() -> void: - RenderingServer.set_default_clear_color(Color.BLACK) + RenderingServer.set_default_clear_color(Color.BLACK) diff --git a/autoloads/sound_manager.gd b/autoloads/sound_manager.gd new file mode 100644 index 0000000..ae617a7 --- /dev/null +++ b/autoloads/sound_manager.gd @@ -0,0 +1,23 @@ +extends Node + +const sounds_path = "res://assets/sfx/%s.ogg" +const sounds := { + "step": preload(sounds_path % "step"), + "death": preload(sounds_path % "death"), + "jump": preload(sounds_path % "jump"), + "click": preload(sounds_path % "click"), + "throw": preload(sounds_path % "woosh"), +} + +@onready var sound_players := get_children() + + +func play(sound: String, volume_db := 0, pitch_scale := randf() + 0.4): + for player in sound_players: + if not player.playing: + player.pitch_scale = pitch_scale + player.volume_db = volume_db + player.stream = sounds[sound] + player.play() + return + print("sounds overflow, discrding") diff --git a/autoloads/sound_manager.tscn b/autoloads/sound_manager.tscn new file mode 100644 index 0000000..c1570c1 --- /dev/null +++ b/autoloads/sound_manager.tscn @@ -0,0 +1,18 @@ +[gd_scene load_steps=2 format=3 uid="uid://d46rocis5fg6"] + +[ext_resource type="Script" path="res://autoloads/sound_manager.gd" id="1_4j4vb"] + +[node name="SoundManager" type="Node"] +script = ExtResource("1_4j4vb") + +[node name="player" type="AudioStreamPlayer" parent="."] + +[node name="player2" type="AudioStreamPlayer" parent="."] + +[node name="player3" type="AudioStreamPlayer" parent="."] + +[node name="player4" type="AudioStreamPlayer" parent="."] + +[node name="player5" type="AudioStreamPlayer" parent="."] + +[node name="player6" type="AudioStreamPlayer" parent="."] diff --git a/enemys/Enemy.gd b/enemys/Enemy.gd index 6457c8f..92e92a3 100644 --- a/enemys/Enemy.gd +++ b/enemys/Enemy.gd @@ -9,15 +9,18 @@ signal died ## Current health @onready var health := max_health: - set(value): - health = clamp(value, 0, max_health) - if health == 0: - died.emit() # ~~voodoo magic makes this signal connect to die()~~ - die() # the voodoo magic broke ;-; + set(value): + health = clamp(value, 0, max_health) + if health == 0: + died.emit() # ~~voodoo magic makes this signal connect to die()~~ + die() # the voodoo magic broke ;-; + func hit(damage: int) -> void: - health -= damage + health -= damage + func die() -> void: - Utils.instance_scene_on_main(preload("res://fx/enemy_death.tscn"), global_position) - queue_free() + Utils.instance_scene_on_main(preload("res://fx/enemy_death.tscn"), global_position) + SoundManager.play("death", -20) + queue_free() diff --git a/enemys/wrencher.gd b/enemys/wrencher.gd index 771a878..4952726 100644 --- a/enemys/wrencher.gd +++ b/enemys/wrencher.gd @@ -11,75 +11,81 @@ extends Enemy var axis := 0 var current_dir := 0 -enum States {MOVE, FIRE} +enum States { MOVE, FIRE } var state := States.MOVE var bullet_timer: SceneTreeTimer = null + func _ready() -> void: - up_direction = global_position.direction_to(muzzle.global_position).round() - axis = 1 if up_direction.x != 0 else 0 - current_dir = -1 if randi() % 2 == 0 else 1 + up_direction = global_position.direction_to(muzzle.global_position).round() + axis = 1 if up_direction.x != 0 else 0 + current_dir = -1 if randi() % 2 == 0 else 1 func _physics_process(_delta: float) -> void: - match state: - States.MOVE: - var dir := brain() - animator.play(&"normal") + match state: + States.MOVE: + var dir := brain() + animator.play(&"normal") - velocity[axis] += dir * ACCELERATION - velocity[axis] = clampf(velocity[axis], -MAX_SPEED, MAX_SPEED) - if (dir == 0): - velocity[axis] = lerpf(velocity[axis], 0, FRICTION) - floorcast.position.x = 0 + (dir * 10) - move_and_slide() - States.FIRE: - animator.play(&"fire") - await animator.animation_finished - state = States.MOVE + velocity[axis] += dir * ACCELERATION + velocity[axis] = clampf(velocity[axis], -MAX_SPEED, MAX_SPEED) + if dir == 0: + velocity[axis] = lerpf(velocity[axis], 0, FRICTION) + if up_direction in [Vector2.DOWN, Vector2.LEFT]: + floorcast.position.x = -(sign(dir) * 10) + else: + floorcast.position.x = (sign(dir) * 10) + move_and_slide() + States.FIRE: + animator.play(&"fire") + await animator.animation_finished + state = States.MOVE func fire() -> void: - var hammer: Hammer = Utils.get_hammer().instantiate() - hammer.global_position = muzzle.global_position - hammer.steer_force = 0.01 # cheat - hammer.target = Globals.player - hammer.direction = up_direction - bullet_timer = get_tree().create_timer(SHOT_COOLDOWN) - player_cast.enabled = false - Globals.levelmanager.current_level.add_child(hammer) + var hammer: Hammer = Utils.get_hammer().instantiate() + hammer.global_position = muzzle.global_position + hammer.steer_force = 0.01 # cheat + hammer.target = Globals.player + hammer.direction = up_direction + bullet_timer = get_tree().create_timer(SHOT_COOLDOWN) + player_cast.enabled = false + Globals.levelmanager.current_level.add_child(hammer) + func brain() -> float: - var dir := 0.0 - if bullet_timer == null or bullet_timer.time_left < 0: - if not player_cast.enabled: - bullet_timer = null - player_cast.force_shapecast_update() - player_cast.enabled = true - for i in player_cast.get_collision_count(): - if player_cast.get_collider(i) is Player: - if player_cast.get_collision_count() != 1: - player_cast.target_position.y = -((global_position.y-Globals.player.global_position.y) + 30) - player_cast.force_shapecast_update() - player_cast.target_position.y = -170 - if player_cast.get_collision_count() == 1: - state = States.FIRE - break - if not state == States.FIRE: - if is_on_wall(): - dir = -get_wall_axis() - elif not floorcast.is_colliding(): - dir = -current_dir - else: - dir = current_dir - current_dir = roundi(dir) - return dir + var dir := 0.0 + if bullet_timer == null or bullet_timer.time_left < 0: + if not player_cast.enabled: + bullet_timer = null + player_cast.force_shapecast_update() + player_cast.enabled = true + for i in player_cast.get_collision_count(): + if player_cast.get_collider(i) is Player: + if player_cast.get_collision_count() != 1: + player_cast.target_position.y = -((global_position.y - Globals.player.global_position.y) + 30) + player_cast.force_shapecast_update() + player_cast.target_position.y = -170 + if player_cast.get_collision_count() == 1: + state = States.FIRE + break + if not state == States.FIRE: + if is_on_wall(): + dir = -get_wall_axis() + elif not floorcast.is_colliding(): + dir = -current_dir + else: + dir = current_dir + current_dir = roundi(dir) + return dir + func get_wall_axis() -> int: - var left := up_direction - left[axis] = -1 - var right := up_direction - right[axis] = 1 - var is_right_wall := test_move(transform, left) - var is_left_wall := test_move(transform, right) - return int(is_left_wall) - int(is_right_wall) + var left := up_direction + left[axis] = -1 + var right := up_direction + right[axis] = 1 + var is_right_wall := test_move(transform, left) + var is_left_wall := test_move(transform, right) + return int(is_left_wall) - int(is_right_wall) diff --git a/enemys/wrencher.tscn b/enemys/wrencher.tscn index 128d043..28df5b8 100644 --- a/enemys/wrencher.tscn +++ b/enemys/wrencher.tscn @@ -77,6 +77,7 @@ _data = { size = Vector2(20, 50) [node name="Wrencher" node_paths=PackedStringArray("muzzle", "floorcast", "animator", "player_cast") instance=ExtResource("1_7mo8u")] +position = Vector2(0, -5) floor_max_angle = 0.802851 script = ExtResource("2_ydgi0") ACCELERATION = 3 @@ -89,22 +90,25 @@ animator = NodePath("AnimationPlayer") player_cast = NodePath("PlayerCast") [node name="Sprite" parent="." index="0"] -position = Vector2(0, -8) +position = Vector2(0, -3) texture = ExtResource("2_0jx2r") hframes = 9 frame = 4 [node name="Collision" parent="." index="1"] -position = Vector2(0, -5) shape = ExtResource("3_fsg5e") +[node name="Hurtbox" parent="." index="2"] +position = Vector2(0, 5) + [node name="Collision" parent="Hurtbox" index="0"] -visible = false position = Vector2(0, -5) shape = ExtResource("3_fsg5e") +[node name="Hitbox" parent="." index="3"] +position = Vector2(0, 5) + [node name="Collision" parent="Hitbox" index="0"] -visible = false position = Vector2(0, -5) shape = ExtResource("3_fsg5e") @@ -115,16 +119,16 @@ libraries = { [node name="Muzzle" type="Marker2D" parent="." index="5"] visible = false -position = Vector2(0, -6) +position = Vector2(0, -1) [node name="FloorCast" type="RayCast2D" parent="." index="6"] visible = false -position = Vector2(0, -3) +position = Vector2(0, 2) target_position = Vector2(0, 5) [node name="PlayerCast" type="ShapeCast2D" parent="." index="7"] visible = false -position = Vector2(0, -25) +position = Vector2(0, -20) shape = SubResource("RectangleShape2D_j3gtw") target_position = Vector2(0, -170) collision_mask = 3 @@ -1,6 +1,6 @@ { "@bendn/remap": { - "version": "4.2.0", - "integrity": "sha512-ce6itKgaxdYEwTy3L7j6DARFJWOu345A/SarvycreDme0MRPyp388xdKtjG1XGELJb3vwmWhRzZOGDiAqZvFvQ==" + "version": "4.2.1", + "integrity": "sha512-h27qQ9jEgHA+4ZY8QrcNOYz4j1W93mjkOQ9XY8VxBndYLoD5aqDhSbYfnJj5n8clniH3JkP4wo9gN7vCX58ElQ==" } }
\ No newline at end of file diff --git a/godot.package b/godot.package index 1469413..64b3566 100644 --- a/godot.package +++ b/godot.package @@ -1,6 +1,6 @@ { "name": "hammer_space", "packages": { - "@bendn/remap": "4.2.0" + "@bendn/remap": "4.2.1" } }
\ No newline at end of file diff --git a/hammers/hammer.gd b/hammers/hammer.gd index 358e7ba..96cfc3c 100644 --- a/hammers/hammer.gd +++ b/hammers/hammer.gd @@ -14,7 +14,7 @@ var direction := Vector2.ZERO @export var acceleration := 100.0 ## Maximum speed -@export var top_speed := 200.0 +@export var top_speed := 3.0 ## The amount it can turn towards its target @export var steer_force = 0.05 @@ -26,14 +26,11 @@ var direction := Vector2.ZERO @export var hit_enemys := false ## The amount of time before gravity kicks in. -@export var lifetime := 1.0 +@export var lifetime := 3.0 ## The gravity @export var grav := 4.0 -## Terminal velocity -@export var terminal_velocity := 15.0 - ## The target var target: Node2D = null @@ -42,70 +39,82 @@ var target: Node2D = null @onready var target_finder := $TargetFinder as Area2D @onready var hitbox := $Hitbox as Hitbox + func _ready() -> void: - set_masks() + set_masks() + ## Sets the collision masks. func set_masks() -> void: - set_collision_mask_value(3, hit_player) - set_collision_mask_value(4, hit_enemys) - target_finder.set_collision_mask_value(3, hit_player) - target_finder.set_collision_mask_value(4, hit_enemys) - hitbox.collision_mask = target_finder.collision_mask - target_finder.monitoring = not is_instance_valid(target) - hitbox.monitoring = hit_player || hit_enemys + set_collision_mask_value(3, hit_player) + set_collision_mask_value(4, hit_enemys) + target_finder.set_collision_mask_value(3, hit_player) + target_finder.set_collision_mask_value(4, hit_enemys) + hitbox.collision_mask = target_finder.collision_mask + target_finder.monitoring = not is_instance_valid(target) + hitbox.monitoring = hit_player || hit_enemys + ## Moves the direction towards the target. func seek() -> void: - if is_instance_valid(target): - direction = direction + (global_position.direction_to(target.global_position) - direction) * steer_force - elif not target == null: - # target died (!) - target = null - target_finder.monitoring = true + if is_instance_valid(target): + direction = lerp( + direction, global_position.direction_to(target.global_position), steer_force * clampf(lifetime, 0, 1) + ) + elif target_finder.monitoring == false: + target = null + target_finder.monitoring = true + ## Highlights this hammer. See also [method unhighlight]. func highlight() -> void: - outline_shader.set_shader_parameter(&"line_width", .75) + outline_shader.set_shader_parameter(&"line_width", .75) + ## Un-highlights this hammer. See also [method highlight]. func unhighlight() -> void: - outline_shader.set_shader_parameter(&"line_width", 0) + outline_shader.set_shader_parameter(&"line_width", 0) + func _physics_process(delta: float) -> void: - lifetime -= delta - if lifetime < 0: - velocity.y += grav * delta - velocity.y = clampf(velocity.y, -terminal_velocity, terminal_velocity) - else: - seek() - velocity = (direction * acceleration * delta) - velocity.y = lerpf(velocity.y, 0, .2) # hard to move up - velocity = velocity.limit_length(top_speed) - rotation = velocity.angle() + PI/2 # face forward - global_position += velocity + lifetime -= delta + if lifetime < 0: + velocity.y += grav * delta + else: + seek() + velocity += (direction * acceleration * delta) + if velocity.y < 0: + velocity.y = lerpf(velocity.y, 0, .1) # hard to move up + velocity.x = clampf(velocity.x, -top_speed, top_speed) + velocity.y = clampf(velocity.y, -top_speed, top_speed) + rotation = velocity.angle() + PI / 2 # face forward + global_position += velocity + func _on_body_entered(_body: Node2D) -> void: - trail.emitting = false - target_finder.monitoring = false - hitbox.monitoring = false - set_collision_layer_value(7, true) - global_position += velocity.limit_length(1) # go into the wall a little - velocity = Vector2.ZERO - target = null - steer_force = 0.05 - set_physics_process(false) - trail.clear_points() + trail.emitting = false + target_finder.monitoring = false + hitbox.monitoring = false + set_collision_layer_value(7, true) + global_position += velocity.limit_length(1) # go into the wall a little + velocity = Vector2.ZERO + target = null + steer_force = 0.05 + lifetime = 3 + set_physics_process(false) + trail.clear_points() + ## Throws this [Hammer]. func throw(p_direction: Vector2) -> void: - set_collision_layer_value(7, false) - direction = p_direction - trail.emitting = true - set_physics_process(true) - set_masks() + print("throw") + set_collision_layer_value(7, false) + direction = p_direction + trail.emitting = true + set_physics_process(true) + set_masks() func _on_target_finder_node_entered(n: Node2D) -> void: - target = n - target_finder.set_deferred(&"monitoring", false) + target = n + target_finder.set_deferred(&"monitoring", false) diff --git a/levels/rand/01.tscn b/levels/rand/01.tscn index a31828a..1355203 100644 --- a/levels/rand/01.tscn +++ b/levels/rand/01.tscn @@ -8,8 +8,8 @@ layer_0/tile_data = PackedInt32Array(131072, 0, 1, 196608, 0, 1, 262144, 262144, enabled_walls = 0 [node name="Wrencher" parent="Enemys" index="0" instance=ExtResource("2_02iql")] -position = Vector2(16, 192) +position = Vector2(22, 192) rotation = 1.57079 [node name="Wrencher2" parent="Enemys" index="1" instance=ExtResource("2_02iql")] -position = Vector2(144, 96) +position = Vector2(144, 91) diff --git a/levels/rand/02.tscn b/levels/rand/02.tscn index eacedcf..4d8b77c 100644 --- a/levels/rand/02.tscn +++ b/levels/rand/02.tscn @@ -8,5 +8,5 @@ layer_0/tile_data = PackedInt32Array(131072, 196608, 1, 196608, 196608, 1, 26214 enabled_walls = 0 [node name="Wrencher" parent="Enemys" index="0" instance=ExtResource("2_6rw4g")] -position = Vector2(32, 16) +position = Vector2(33, 21) rotation = -3.14159 diff --git a/levels/rand/03.tscn b/levels/rand/03.tscn index 741ed96..d4cc759 100644 --- a/levels/rand/03.tscn +++ b/levels/rand/03.tscn @@ -8,4 +8,7 @@ layer_0/tile_data = PackedInt32Array(131072, 0, 1, 196608, 0, 1, 262144, 0, 1, 3 enabled_walls = 0 [node name="Wrencher" parent="Enemys" index="0" instance=ExtResource("2_kmhwi")] -position = Vector2(64, 160) +position = Vector2(65, 155) + +[node name="Wrencher2" parent="Enemys" index="1" instance=ExtResource("2_kmhwi")] +position = Vector2(151, 155) diff --git a/levels/rand/04.tscn b/levels/rand/04.tscn index dcd250e..01237dc 100644 --- a/levels/rand/04.tscn +++ b/levels/rand/04.tscn @@ -8,5 +8,5 @@ layer_0/tile_data = PackedInt32Array(131072, 196608, 1, 196608, 196608, 1, 26214 enabled_walls = 1 [node name="Wrencher" parent="Enemys" index="0" instance=ExtResource("2_kvkn2")] -position = Vector2(32, 16) +position = Vector2(34, 21) rotation = 3.14159 diff --git a/levels/rand/05.tscn b/levels/rand/05.tscn index 7d1ab04..8a126ba 100644 --- a/levels/rand/05.tscn +++ b/levels/rand/05.tscn @@ -8,5 +8,5 @@ layer_0/tile_data = PackedInt32Array(131072, 196608, 1, 196608, 196608, 1, 26214 enabled_walls = 2 [node name="Wrencher" parent="Enemys" index="0" instance=ExtResource("2_biat4")] -position = Vector2(240, 96) +position = Vector2(235, 97) rotation = -1.57079 diff --git a/levels/rand/06.tscn b/levels/rand/06.tscn index d69b17b..191944f 100644 --- a/levels/rand/06.tscn +++ b/levels/rand/06.tscn @@ -8,5 +8,5 @@ layer_0/tile_data = PackedInt32Array(131072, 262144, 1, 196608, 196608, 1, 26214 enabled_walls = 3 [node name="Wrencher" parent="Enemys" index="0" instance=ExtResource("2_8k0h1")] -position = Vector2(77, 80) +position = Vector2(80, 85) rotation = 3.14159 diff --git a/levels/rand/07.tscn b/levels/rand/07.tscn index e08f2d1..e89d0f5 100644 --- a/levels/rand/07.tscn +++ b/levels/rand/07.tscn @@ -8,4 +8,4 @@ layer_0/tile_data = PackedInt32Array(131072, 196608, 1, 196608, 196608, 1, 26214 enabled_walls = 4 [node name="Wrencher" parent="Enemys" index="0" instance=ExtResource("2_5j31a")] -position = Vector2(81, 240) +position = Vector2(82, 235) diff --git a/levels/rand/08.tscn b/levels/rand/08.tscn index c3911a5..5c456fa 100644 --- a/levels/rand/08.tscn +++ b/levels/rand/08.tscn @@ -8,8 +8,8 @@ layer_0/tile_data = PackedInt32Array(131072, 0, 1, 196608, 0, 1, 262144, 0, 1, 3 enabled_walls = 5 [node name="Wrencher" parent="Enemys" index="0" instance=ExtResource("2_qq88x")] -position = Vector2(152, 192) +position = Vector2(152, 187) [node name="Wrencher2" parent="Enemys" index="1" instance=ExtResource("2_qq88x")] -position = Vector2(106, 80) +position = Vector2(109, 85) rotation = 3.14159 diff --git a/levels/rand/09.tscn b/levels/rand/09.tscn index 21af1cf..263f0e9 100644 --- a/levels/rand/09.tscn +++ b/levels/rand/09.tscn @@ -8,8 +8,8 @@ layer_0/tile_data = PackedInt32Array(131072, 196608, 1, 196608, 196608, 1, 26214 enabled_walls = 6 [node name="Wrencher" parent="Enemys" index="0" instance=ExtResource("2_hr1sv")] -position = Vector2(71, 240) +position = Vector2(74, 235) [node name="Wrencher2" parent="Enemys" index="1" instance=ExtResource("2_hr1sv")] -position = Vector2(240, 109) +position = Vector2(235, 109) rotation = -1.57079 diff --git a/levels/rand/10.tscn b/levels/rand/10.tscn index 2704098..a01370f 100644 --- a/levels/rand/10.tscn +++ b/levels/rand/10.tscn @@ -7,25 +7,22 @@ layer_0/tile_data = PackedInt32Array(131072, 0, 1, 196608, 262144, 1, 262144, 196608, 1, 327680, 196608, 1, 393216, 196608, 2, 589824, 196608, 0, 655360, 196608, 1, 720896, 196608, 1, 786432, 262144, 2, 851968, 0, 1, 917504, 0, 1, 983040, 0, 2, 983041, 65536, 2, 2, 65536, 0, 983042, 65536, 2, 3, 327680, 0, 983043, 327680, 3, 4, 65536, 3, 983044, 65536, 3, 5, 65536, 3, 983045, 65536, 3, 6, 65536, 3, 983046, 65536, 3, 9, 65536, 3, 983049, 65536, 3, 10, 65536, 3, 983050, 65536, 3, 11, 65536, 3, 983051, 65536, 3, 12, 65536, 3, 983052, 65536, 3, 13, 65536, 3, 983053, 393216, 3, 14, 65536, 3, 983054, 65536, 2, 15, 458752, 0, 65551, 196608, 1, 131087, 196608, 1, 196623, 196608, 1, 262159, 196608, 1, 327695, 196608, 1, 393231, 196608, 1, 589839, 196608, 1, 655375, 196608, 1, 720911, 196608, 1, 786447, 196608, 1, 851983, 458752, 2, 917519, 131072, 1, 983055, 131072, 2, 65536, 0, 1, 0, 0, 0, 1, 65536, 0, 983047, 65536, 3, 983048, 65536, 3, 524303, 196608, 1, 458767, 196608, 1, 8, 65536, 3, 7, 65536, 3, 65537, 65536, 1, 131073, 327680, 1, 131074, 131072, 2, 65538, 327680, 1, 65539, 131072, 2, 196609, 131072, 2, 917505, 65536, 1, 851969, 327680, 2, 786433, 131072, 0, 851970, 131072, 0, 917506, 327680, 2, 917507, 131072, 0, 917518, 393216, 2, 917517, 0, 0, 851982, 0, 0) enabled_walls = 7 -[node name="Blocks" parent="." index="0"] -layer_0/tile_data = PackedInt32Array(458750, 0, 3, 458751, 131072, 3, 655359, 131072, 3, -131066, 196608, 0, -65530, 196608, 2, 1048582, 196608, 0, 1114118, 196608, 2, -65527, 196608, 2, 1048585, 196608, 0, 1114121, 196608, 2, 393232, 0, 3, 589840, 0, 3, 393233, 131072, 3, 589841, 131072, 3, -131063, 196608, 0, 655358, 0, 3, 983052, 0, 3, 983053, 131072, 3) - [node name="Wrencher" parent="Enemys" index="0" instance=ExtResource("2_vbven")] -position = Vector2(150, 240) +position = Vector2(150, 235) rotation = 6.28318 [node name="Wrencher2" parent="Enemys" index="1" instance=ExtResource("2_vbven")] -position = Vector2(113, 240) +position = Vector2(113, 235) rotation = 6.28318 [node name="Wrencher3" parent="Enemys" index="2" instance=ExtResource("2_vbven")] -position = Vector2(240, 154) +position = Vector2(235, 154) rotation = 4.71238 [node name="Wrencher4" parent="Enemys" index="3" instance=ExtResource("2_vbven")] -position = Vector2(240, 102) +position = Vector2(235, 102) rotation = 4.71238 [node name="Wrencher5" parent="Enemys" index="4" instance=ExtResource("2_vbven")] -position = Vector2(132, 16) +position = Vector2(132, 21) rotation = 3.14159 diff --git a/levels/rand/11.tscn b/levels/rand/11.tscn index f476186..939ef07 100644 --- a/levels/rand/11.tscn +++ b/levels/rand/11.tscn @@ -8,9 +8,9 @@ layer_0/tile_data = PackedInt32Array(131072, 196608, 1, 196608, 196608, 1, 26214 enabled_walls = 8 [node name="Wrencher" parent="Enemys" index="0" instance=ExtResource("2_gdari")] -position = Vector2(16, 97) +position = Vector2(21, 97) rotation = 1.57079 [node name="Wrencher2" parent="Enemys" index="1" instance=ExtResource("2_gdari")] -position = Vector2(240, 188) +position = Vector2(235, 188) rotation = 4.71238 diff --git a/levels/rand/12.tscn b/levels/rand/12.tscn index b2b7a66..df6621a 100644 --- a/levels/rand/12.tscn +++ b/levels/rand/12.tscn @@ -8,5 +8,5 @@ layer_0/tile_data = PackedInt32Array(131072, 262144, 1, 196608, 196608, 1, 26214 enabled_walls = 9 [node name="Wrencher" parent="Enemys" index="0" instance=ExtResource("2_b1led")] -position = Vector2(16, 189) +position = Vector2(21, 189) rotation = -4.71238 diff --git a/levels/rand/13.tscn b/levels/rand/13.tscn index bb3f606..55c6dd2 100644 --- a/levels/rand/13.tscn +++ b/levels/rand/13.tscn @@ -8,9 +8,9 @@ layer_0/tile_data = PackedInt32Array(131072, 196608, 1, 196608, 196608, 1, 26214 enabled_walls = 10 [node name="Wrencher" parent="Enemys" index="0" instance=ExtResource("2_hl3le")] -position = Vector2(96, 139) +position = Vector2(91, 139) rotation = -1.57079 [node name="Wrencher2" parent="Enemys" index="1" instance=ExtResource("2_hl3le")] -position = Vector2(160, 152) +position = Vector2(165, 152) rotation = -4.71238 diff --git a/levels/rand/14.tscn b/levels/rand/14.tscn index 59f9c60..085b07d 100644 --- a/levels/rand/14.tscn +++ b/levels/rand/14.tscn @@ -8,13 +8,13 @@ layer_0/tile_data = PackedInt32Array(131072, 0, 1, 196608, 0, 1, 262144, 0, 1, 3 enabled_walls = 11 [node name="Wrencher2" parent="Enemys" index="0" instance=ExtResource("2_p4l5b")] -position = Vector2(89, 64) +position = Vector2(89, 69) rotation = 3.14159 [node name="Wrencher3" parent="Enemys" index="1" instance=ExtResource("2_p4l5b")] -position = Vector2(192, 226) +position = Vector2(187, 226) rotation = -1.57079 [node name="Wrencher4" parent="Enemys" index="2" instance=ExtResource("2_p4l5b")] -position = Vector2(64, 129) +position = Vector2(69, 129) rotation = 1.57079 diff --git a/levels/rand/15.tscn b/levels/rand/15.tscn index 2dbad58..e012792 100644 --- a/levels/rand/15.tscn +++ b/levels/rand/15.tscn @@ -8,9 +8,9 @@ layer_0/tile_data = PackedInt32Array(131072, 196608, 1, 196608, 196608, 1, 26214 enabled_walls = 12 [node name="Wrencher" parent="Enemys" index="0" instance=ExtResource("2_dqkom")] -position = Vector2(16, 133) +position = Vector2(21, 133) rotation = -4.71238 [node name="Wrencher2" parent="Enemys" index="1" instance=ExtResource("2_dqkom")] -position = Vector2(68, 240) +position = Vector2(68, 235) rotation = -6.28318 diff --git a/levels/rand/16.tscn b/levels/rand/16.tscn index e789afe..6789641 100644 --- a/levels/rand/16.tscn +++ b/levels/rand/16.tscn @@ -8,5 +8,5 @@ layer_0/tile_data = PackedInt32Array(131072, 0, 1, 196608, 0, 1, 262144, 0, 1, 3 enabled_walls = 13 [node name="Wrencher" parent="Enemys" index="0" instance=ExtResource("2_upx7m")] -position = Vector2(16, 131) +position = Vector2(21, 131) rotation = 1.57079 diff --git a/levels/rand/17.tscn b/levels/rand/17.tscn index d5aa130..c37b83d 100644 --- a/levels/rand/17.tscn +++ b/levels/rand/17.tscn @@ -8,15 +8,15 @@ layer_0/tile_data = PackedInt32Array(131072, 196608, 1, 196608, 196608, 1, 26214 enabled_walls = 14 [node name="Wrencher" parent="Enemys" index="0" instance=ExtResource("2_d40ci")] -position = Vector2(187, 240) +position = Vector2(187, 235) max_health = 7 [node name="Wrencher2" parent="Enemys" index="1" instance=ExtResource("2_d40ci")] -position = Vector2(16, 107) +position = Vector2(21, 107) rotation = 1.57079 max_health = 2 [node name="Wrencher3" parent="Enemys" index="2" instance=ExtResource("2_d40ci")] -position = Vector2(240, 63) +position = Vector2(235, 63) rotation = 4.71238 max_health = 3 diff --git a/levels/rand/18.tscn b/levels/rand/18.tscn index 74cdf50..c8f9a7c 100644 --- a/levels/rand/18.tscn +++ b/levels/rand/18.tscn @@ -8,9 +8,9 @@ layer_0/tile_data = PackedInt32Array(131072, 0, 1, 196608, 0, 1, 262144, 0, 1, 3 enabled_walls = 10 [node name="Wrencher" parent="Enemys" index="0" instance=ExtResource("2_2jv1a")] -position = Vector2(64, 136) +position = Vector2(69, 136) rotation = 1.57079 [node name="Wrencher2" parent="Enemys" index="1" instance=ExtResource("2_2jv1a")] -position = Vector2(32, 115) +position = Vector2(37, 117) rotation = 1.57079 diff --git a/levels/rand/19.tscn b/levels/rand/19.tscn index c517f8e..3abfd77 100644 --- a/levels/rand/19.tscn +++ b/levels/rand/19.tscn @@ -8,8 +8,8 @@ layer_0/tile_data = PackedInt32Array(131072, 196608, 1, 196608, 196608, 1, 26214 enabled_walls = 1 [node name="Wrencher" parent="Enemys" index="0" instance=ExtResource("2_4fs2l")] -position = Vector2(122, 112) +position = Vector2(121, 107) [node name="Wrencher2" parent="Enemys" index="1" instance=ExtResource("2_4fs2l")] -position = Vector2(129, 144) +position = Vector2(135, 149) rotation = -3.14159 diff --git a/levels/rand/20.tscn b/levels/rand/20.tscn index 0189099..fa62cf5 100644 --- a/levels/rand/20.tscn +++ b/levels/rand/20.tscn @@ -8,5 +8,5 @@ layer_0/tile_data = PackedInt32Array(131072, 196608, 1, 196608, 196608, 1, 26214 enabled_walls = 2 [node name="Wrencher" parent="Enemys" index="0" instance=ExtResource("2_ltna7")] -position = Vector2(96, 149) +position = Vector2(91, 151) rotation = -1.57079 diff --git a/levels/rand/21.tscn b/levels/rand/21.tscn index 8154d66..c107978 100644 --- a/levels/rand/21.tscn +++ b/levels/rand/21.tscn @@ -8,8 +8,8 @@ layer_0/tile_data = PackedInt32Array(131072, 0, 1, 196608, 0, 1, 262144, 0, 1, 3 enabled_walls = 4 [node name="Wrencher" parent="Enemys" index="0" instance=ExtResource("2_d5txk")] -position = Vector2(121, 96) +position = Vector2(120, 91) [node name="Wrencher2" parent="Enemys" index="1" instance=ExtResource("2_d5txk")] -position = Vector2(144, 118) +position = Vector2(149, 118) rotation = 1.57079 diff --git a/levels/rand/22.tscn b/levels/rand/22.tscn index 20de9e7..abbce81 100644 --- a/levels/rand/22.tscn +++ b/levels/rand/22.tscn @@ -8,11 +8,11 @@ layer_0/tile_data = PackedInt32Array(131072, 0, 1, 196608, 0, 1, 262144, 0, 1, 3 enabled_walls = 8 [node name="Wrencher" parent="Enemys" index="0" instance=ExtResource("2_cqhis")] -position = Vector2(40, 208) +position = Vector2(40, 203) [node name="Wrencher2" parent="Enemys" index="1" instance=ExtResource("2_cqhis")] -position = Vector2(56, 64) +position = Vector2(56, 69) rotation = -3.14159 [node name="Wrencher3" parent="Enemys" index="2" instance=ExtResource("2_cqhis")] -position = Vector2(87, 112) +position = Vector2(86, 107) diff --git a/player/player.gd b/player/player.gd index 7c4a90f..8e2618b 100644 --- a/player/player.gd +++ b/player/player.gd @@ -26,8 +26,8 @@ signal hp_changed(health: int) ## Friction @export var frict := 0.25 -## How much less movement control to have in the air -@export var air_movement_modifier := 0.95 +## How much movement control to have in the air +@export var air_movement_modifier := 1.2 ## Max hp @export var max_health := 10 @@ -43,10 +43,10 @@ signal hp_changed(health: int) @onready var GRAVITY: float = ProjectSettings.get_setting(&"physics/2d/default_gravity") func _init() -> void: - Globals.player = self + Globals.player = self func _exit_tree() -> void: - Globals.player = null + Globals.player = null ## State enum. enum State { MOVE, WALL_SLIDE, STOP } @@ -70,244 +70,245 @@ var current_hammer: Hammer = null var last_highlit: Hammer = null var health := max_health: - set(hp): - health = hp - hp_changed.emit(hp) - if hp == 0: - queue_free() + set(hp): + health = hp + hp_changed.emit(hp) + if hp == 0: + queue_free() func _physics_process(delta: float) -> void: - just_jumped = false - match state: - State.STOP: - velocity = Vector2.ZERO - play(&"idle") - State.MOVE: - var input := Input.get_axis(&"left", &"right") - if aiming: - input = 0 - apply_force(input, delta) - apply_friction(input) - - jump_check() - - apply_gravity(delta) - - animate(input) - move() - wall_slide_check() - State.WALL_SLIDE: - play(&"wall_slide") - var wall_axis := get_wall_axis() - if wall_axis != 0: - sprite.scale.x = wall_axis - - wall_slide_jump_check(wall_axis) - wall_slide_drop(delta) - move() - wall_detatch(wall_axis, delta) - check_throw() - hammer_highlight() - hammer_pickup() - hammer_move() + just_jumped = false + match state: + State.STOP: + velocity = Vector2.ZERO + play(&"idle") + State.MOVE: + var input := Input.get_axis(&"left", &"right") + if aiming: + input = 0 + elif not is_on_floor(): + input *= air_movement_modifier + apply_force(input, delta) + apply_friction(input) + + jump_check() + + apply_gravity(delta) + + animate(input) + move() + wall_slide_check() + State.WALL_SLIDE: + play(&"wall_slide") + var wall_axis := get_wall_axis() + if wall_axis != 0: + sprite.scale.x = wall_axis + + wall_slide_jump_check(wall_axis) + wall_slide_drop(delta) + move() + wall_detatch(wall_axis, delta) + check_throw() + hammer_highlight() + hammer_pickup() + hammer_move() ## Creates floor dust. func dust() -> void: - var dust_position := global_position - dust_position.x += randf_range(-4, 4) - Utils.instance_scene_on_main(DustEffect, dust_position) - # SoundFx.play("Step", -20) + var dust_position := global_position + dust_position.x += randf_range(-4, 4) + Utils.instance_scene_on_main(DustEffect, dust_position) + SoundManager.play("step", -20) ## Applys gravity. func apply_gravity(delta: float) -> void: - velocity.y += GRAVITY * delta - velocity.y = minf(velocity.y, jump_force) + velocity.y += GRAVITY * delta + velocity.y = minf(velocity.y, jump_force) ## Applys force with the [param input] of the player. func apply_force(input: float, delta: float) -> void: - if input != 0: - velocity.x += input * accel * delta - velocity.x = clampf(velocity.x, -top_speed, top_speed) - if not is_on_floor(): - velocity.x *= air_movement_modifier + if input != 0: + velocity.x += input * accel * delta + velocity.x = clampf(velocity.x, -top_speed, top_speed) ## Applys friction to the player. func apply_friction(input: float) -> void: - if input == 0 and not is_zero_approx(velocity.x) and is_on_floor(): - velocity.x = lerpf(velocity.x, 0, frict) + if input == 0 and not is_zero_approx(velocity.x) and is_on_floor(): + velocity.x = lerpf(velocity.x, 0, frict) func hammer_highlight() -> void: - if not current_hammer: - var hamms := pickup_area.get_overlapping_areas() - if hamms.is_empty(): - if last_highlit: - last_highlit.unhighlight() - last_highlit = null - elif not last_highlit in hamms: - if last_highlit: - last_highlit.unhighlight() - last_highlit = hamms[0] - hamms[0].highlight() + if not current_hammer: + var hamms := pickup_area.get_overlapping_areas() + if hamms.is_empty(): + if last_highlit: + last_highlit.unhighlight() + last_highlit = null + elif not last_highlit in hamms: + if last_highlit: + last_highlit.unhighlight() + last_highlit = hamms[0] + hamms[0].highlight() func hammer_pickup() -> void: - if Input.is_action_just_pressed("pickup") and last_highlit and not current_hammer: - last_highlit.unhighlight() - current_hammer = last_highlit - Globals.levelmanager.current_level.remove_child(current_hammer) - current_hammer.position.y = -14 - add_child(current_hammer) - move_child(current_hammer, 0) + if Input.is_action_just_pressed("pickup") and last_highlit and not current_hammer: + last_highlit.unhighlight() + current_hammer = last_highlit + Globals.levelmanager.current_level.remove_child(current_hammer) + current_hammer.position.y = -14 + add_child(current_hammer) + move_child(current_hammer, 0) func hammer_move() -> void: - if current_hammer: - current_hammer.position.x = 6 * sprite.scale.x - current_hammer.rotation = 0.087 * sprite.scale.x + if current_hammer: + current_hammer.position.x = 6 * sprite.scale.x + current_hammer.rotation = 0.087 * sprite.scale.x func check_throw() -> void: - if current_hammer and Input.is_action_just_pressed("throw"): - aim_gizmo.enabled = true - aiming = true - aim_gizmo.show() + if current_hammer and Input.is_action_just_pressed("throw"): + aim_gizmo.enabled = true + aiming = true + aim_gizmo.show() ## Plays animations for the move state. func animate(input: float) -> void: - if sign(input) != 0: - sprite.scale.x = sign(input) + if sign(input) != 0: + sprite.scale.x = sign(input) - if not is_on_floor(): - play(&"jump") - return + if not is_on_floor(): + play(&"jump") + return - if velocity.x != 0: - play(&"run", sign(velocity.x * sprite.scale.x)) - else: - play(&"idle") + if velocity.x != 0: + play(&"run", sign(velocity.x * sprite.scale.x)) + else: + play(&"idle") ## Plays a [param anim] with a speed of [param speed]. ## If speed is negative, animation plays backwards. func play(anim: StringName, speed: float = 1.0) -> void: - anims.play(anim, -1, speed) + anims.play(anim, -1, speed) ## Checks if we should jump. func jump_check() -> void: - var want2jump := Input.is_action_just_pressed(&"jump") - if want2jump and (is_on_floor() or coyote.time_left > 0): - jump(jump_force) - just_jumped = true - else: - if want2jump and velocity.y < -jump_force / 2: - velocity.y = -jump_force / 2 - - if want2jump and double_jump == true: - jump(jump_force * .75) - double_jump = false + var want2jump := Input.is_action_just_pressed(&"jump") + if want2jump and (is_on_floor() or coyote.time_left > 0): + jump(jump_force) + just_jumped = true + else: + if want2jump and velocity.y < -jump_force / 2: + velocity.y = -jump_force / 2 + + if want2jump and double_jump == true: + jump(jump_force * .75) + double_jump = false ## Jumps with [param force] force. func jump(force: float) -> void: - # SoundFx.play("Jump", -20) - if double_jump: - Utils.instance_scene_on_main(JumpEffect, global_position) - else: - Utils.instance_scene_on_main(DoubleJumpEffect, global_position) - velocity.y = -force + SoundManager.play("jump", -10) + if double_jump: + Utils.instance_scene_on_main(JumpEffect, global_position) + else: + Utils.instance_scene_on_main(DoubleJumpEffect, global_position) + velocity.y = -force ## Uses the velocity to move_and_slide. func move() -> void: - var was_in_air := not is_on_floor() - var was_on_floor := is_on_floor() - var last_position := position - var last_velocity := velocity - move_and_slide() - - # landing - if was_in_air and is_on_floor(): - velocity.x = last_velocity.x - double_jump = true - Utils.instance_scene_on_main(JumpEffect, global_position) - - # just left ground - if was_on_floor and not is_on_floor() and not just_jumped: - position.y = last_position.y - coyote.start() - Utils.instance_scene_on_main(JumpEffect, global_position) + var was_in_air := not is_on_floor() + var was_on_floor := is_on_floor() + var last_position := position + var last_velocity := velocity + move_and_slide() + + # landing + if was_in_air and is_on_floor(): + velocity.x = last_velocity.x + double_jump = true + Utils.instance_scene_on_main(JumpEffect, global_position) + + # just left ground + if was_on_floor and not is_on_floor() and not just_jumped: + position.y = last_position.y + coyote.start() + Utils.instance_scene_on_main(JumpEffect, global_position) ## Checks if we should enter a wall slide. func wall_slide_check(): - if not is_on_floor() and is_on_wall_only(): - state = State.WALL_SLIDE - double_jump = true - dust() + if not is_on_floor() and is_on_wall_only(): + state = State.WALL_SLIDE + double_jump = true + dust() ## Checks what wall we are against. func get_wall_axis() -> int: - var is_right_wall := test_move(transform, Vector2.RIGHT) - var is_left_wall := test_move(transform, Vector2.LEFT) - return int(is_left_wall) - int(is_right_wall) + var is_right_wall := test_move(transform, Vector2.RIGHT) + var is_left_wall := test_move(transform, Vector2.LEFT) + return int(is_left_wall) - int(is_right_wall) ## Checks if we should jump off the [param wall_axis]. func wall_slide_jump_check(wall_axis: int) -> void: - if Input.is_action_just_pressed(&"jump"): - velocity.x = wall_axis * top_speed - velocity.y = -jump_force / 1.25 - state = State.MOVE - wall_dust(wall_axis) - # SoundFx.play("Jump", -20) + if Input.is_action_just_pressed(&"jump"): + velocity.x = wall_axis * top_speed + velocity.y = -jump_force / 1.25 + state = State.MOVE + wall_dust(wall_axis) + SoundManager.play("jump", -10) ## Creates dust against the [param wall_axis]. func wall_dust(wall_axis: int) -> void: - var dust_position = global_position + Vector2(wall_axis * 4, -2) - var dust_fx := Utils.instance_scene_on_main(WallJumpEffect, dust_position) as Node2D - dust_fx.scale.x = wall_axis + var dust_position = global_position + Vector2(wall_axis * 4, -2) + var dust_fx := Utils.instance_scene_on_main(WallJumpEffect, dust_position) as Node2D + dust_fx.scale.x = wall_axis ## Slides down the wall. func wall_slide_drop(delta: float) -> void: - var max_slide_speed := wall_slide_fall_speed - if Input.is_action_pressed("down"): - max_slide_speed = max_wall_slide_fall_speed - velocity.y = min(velocity.y + GRAVITY * delta, max_slide_speed) + var max_slide_speed := wall_slide_fall_speed + if Input.is_action_pressed("down"): + max_slide_speed = max_wall_slide_fall_speed + velocity.y = min(velocity.y + GRAVITY * delta, max_slide_speed) ## Checks if we should detatch from the wall. func wall_detatch(wall_axis: int, delta: float) -> void: - var detached := false - if aiming: return + var detached := false + if aiming: return - if Input.is_action_just_pressed("right"): - velocity.x = accel * delta - detached = true + if Input.is_action_just_pressed("right"): + velocity.x = accel * delta + detached = true - if Input.is_action_just_pressed("left"): - velocity.x = -accel * delta - detached = true + if Input.is_action_just_pressed("left"): + velocity.x = -accel * delta + detached = true - if detached: - state = State.MOVE - wall_dust(wall_axis) + if detached: + state = State.MOVE + wall_dust(wall_axis) - if wall_axis == 0 or is_on_floor(): - state = State.MOVE + if wall_axis == 0 or is_on_floor(): + state = State.MOVE func hit(damage: int) -> void: - health -= damage + health -= damage ## Disable the aim gizmo. func disable_aim_gizmo() -> void: - aiming = false - aim_gizmo.enabled = false - aim_gizmo.hide() + aiming = false + aim_gizmo.enabled = false + aim_gizmo.hide() ## Throws the hammer. func throw(rot: float) -> void: - rot += randf_range(-0.01, 0.01) - remove_child(current_hammer) - current_hammer.position.x = 0 # center - current_hammer.global_position = to_global(current_hammer.position) - Globals.levelmanager.current_level.add_child(current_hammer) - current_hammer.hit_player = false - current_hammer.hit_enemys = true - current_hammer.throw(Vector2.from_angle(rot)) - current_hammer = null - disable_aim_gizmo() + rot += randf_range(-0.01, 0.01) + remove_child(current_hammer) + current_hammer.position.x = 0 # center + current_hammer.global_position = to_global(current_hammer.position) + Globals.levelmanager.current_level.add_child(current_hammer) + current_hammer.hit_player = false + current_hammer.hit_enemys = true + current_hammer.throw(Vector2.from_angle(rot)) + SoundManager.play("throw", -15) + current_hammer = null + disable_aim_gizmo() diff --git a/project.godot b/project.godot index a7024f7..cbe09dd 100644 --- a/project.godot +++ b/project.godot @@ -127,6 +127,8 @@ config/features=PackedStringArray("4.0") Utils="*res://autoloads/Utils.gd" Globals="*res://autoloads/Globals.gd" Events="*res://autoloads/Events.gd" +SoundManager="*res://autoloads/sound_manager.tscn" +MusicPlayer="*res://autoloads/MusicPlayer.gd" [debug] diff --git a/ui/cfg.tscn b/ui/cfg.tscn index 81a0cad..2f68061 100644 --- a/ui/cfg.tscn +++ b/ui/cfg.tscn @@ -30,7 +30,7 @@ grow_horizontal = 2 grow_vertical = 2 alignment = 1 -[node name="graphics" type="Button" parent="V"] +[node name="graphics" type="Button" parent="V" groups=["button"]] offset_top = 7.0 offset_right = 140.0 offset_bottom = 50.0 @@ -38,7 +38,7 @@ focus_neighbor_top = NodePath("../back") focus_neighbor_bottom = NodePath("../keybinds") text = "graphics" -[node name="keybinds" type="Button" parent="V"] +[node name="keybinds" type="Button" parent="V" groups=["button"]] offset_top = 54.0 offset_right = 140.0 offset_bottom = 97.0 @@ -46,7 +46,7 @@ focus_neighbor_top = NodePath("../graphics") focus_neighbor_bottom = NodePath("../back") text = "controls" -[node name="back" type="Button" parent="V"] +[node name="back" type="Button" parent="V" groups=["button"]] offset_top = 101.0 offset_right = 140.0 offset_bottom = 144.0 diff --git a/ui/graphics.tscn b/ui/graphics.tscn index 3aa7a46..4e9d901 100644 --- a/ui/graphics.tscn +++ b/ui/graphics.tscn @@ -22,7 +22,6 @@ script = ExtResource("2_s8nd1") focus = NodePath("Panel2/V/h/vsyncbutton") [node name="Panel" type="Panel" parent="."] -layout_mode = 2 offset_left = 10.0 offset_top = 10.0 offset_right = 310.0 @@ -31,7 +30,6 @@ theme_override_styles/panel = ExtResource("2_g8edo") [node name="Panel2" type="PanelContainer" parent="."] clip_contents = true -layout_mode = 2 offset_left = 10.0 offset_top = 10.0 offset_right = 310.0 @@ -40,7 +38,6 @@ theme_override_styles/panel = ExtResource("3_pgqel") [node name="V" type="VBoxContainer" parent="Panel2"] show_behind_parent = true -layout_mode = 2 offset_left = 15.0 offset_top = 15.0 offset_right = 285.0 @@ -49,15 +46,13 @@ size_flags_horizontal = 3 size_flags_vertical = 3 [node name="h" type="HBoxContainer" parent="Panel2/V"] -layout_mode = 2 offset_right = 270.0 offset_bottom = 43.0 theme_override_constants/separation = 50 alignment = 2 -[node name="vsyncbutton" type="CheckBox" parent="Panel2/V/h"] +[node name="vsyncbutton" type="CheckBox" parent="Panel2/V/h" groups=["button"]] unique_name_in_owner = true -layout_mode = 2 offset_left = 77.0 offset_right = 188.0 offset_bottom = 43.0 @@ -68,8 +63,7 @@ focus_neighbor_right = NodePath("../exit") focus_neighbor_bottom = NodePath("../../windowbutton/button") text = "vsync" -[node name="exit" parent="Panel2/V/h" instance=ExtResource("5_082rc")] -layout_mode = 2 +[node name="exit" parent="Panel2/V/h" groups=["button"] instance=ExtResource("5_082rc")] offset_left = 238.0 offset_right = 270.0 offset_bottom = 43.0 @@ -80,7 +74,6 @@ focus_neighbor_bottom = NodePath("../../windowbutton/button") [node name="windowbutton" parent="Panel2/V" instance=ExtResource("5_kv1ys")] unique_name_in_owner = true -layout_mode = 2 offset_left = 50.0 offset_top = 47.0 offset_right = 220.0 @@ -89,18 +82,15 @@ size_flags_horizontal = 4 options = PackedStringArray("fullscreen", "borderless fs", "windowed") current_option = 2 -[node name="leftcaret" parent="Panel2/V/windowbutton" index="0"] -layout_mode = 2 +[node name="leftcaret" parent="Panel2/V/windowbutton" index="0" groups=["button"]] focus_neighbor_top = NodePath("../../h/vsyncbutton") focus_neighbor_bottom = NodePath("../../h/vsyncbutton") -[node name="button" parent="Panel2/V/windowbutton" index="1"] -layout_mode = 2 +[node name="button" parent="Panel2/V/windowbutton" index="1" groups=["button"]] focus_neighbor_top = NodePath("../../h/vsyncbutton") focus_neighbor_bottom = NodePath("../../h/vsyncbutton") -[node name="rightcaret" parent="Panel2/V/windowbutton" index="2"] -layout_mode = 2 +[node name="rightcaret" parent="Panel2/V/windowbutton" index="2" groups=["button"]] focus_neighbor_top = NodePath("../../h/vsyncbutton") focus_neighbor_bottom = NodePath("../../h/vsyncbutton") diff --git a/ui/hud/health_meter.gd b/ui/hud/health_meter.gd index 248009a..115287a 100644 --- a/ui/hud/health_meter.gd +++ b/ui/hud/health_meter.gd @@ -3,12 +3,14 @@ extends Control @onready var full := $Full as TextureRect @onready var empty := $Empty as TextureRect + func _ready(): - Globals.player.hp_changed.connect(_hp_changed) - var max_hp := Globals.player.max_health - await get_tree().process_frame - full.size.x = max_hp * 5 + 1 - empty.size.x = max_hp * 5 + 1 + Globals.player.hp_changed.connect(_hp_changed) + var max_hp := Globals.player.max_health + await get_tree().process_frame + full.size.x = max_hp * 5 + 1 + empty.size.x = max_hp * 5 + 1 + func _hp_changed(hp: int): - full.size.x = hp * 5 + 1 + full.size.x = hp * 5 + 1 diff --git a/ui/keybinds.tscn b/ui/keybinds.tscn index 7e6f7e5..e1409da 100644 --- a/ui/keybinds.tscn +++ b/ui/keybinds.tscn @@ -50,7 +50,6 @@ script = ExtResource("1_f036x") focus = NodePath("Scroll/V/left") [node name="Panel" type="Panel" parent="."] -layout_mode = 2 offset_left = 10.0 offset_top = 10.0 offset_right = 310.0 @@ -59,7 +58,6 @@ mouse_filter = 2 theme_override_styles/panel = ExtResource("1_wrc13") [node name="Scroll" type="ScrollContainer" parent="."] -layout_mode = 2 offset_left = 10.0 offset_top = 10.0 offset_right = 310.0 @@ -73,7 +71,6 @@ vertical_scroll_mode = 3 [node name="V" type="VBoxContainer" parent="Scroll"] show_behind_parent = true -layout_mode = 2 offset_left = 15.0 offset_top = 15.0 offset_right = 285.0 @@ -87,20 +84,18 @@ font_size = 15 [node name="bbar" type="HBoxContainer" parent="Scroll/V"] show_behind_parent = true -layout_mode = 2 offset_right = 270.0 offset_bottom = 36.0 [node name="space3" type="Control" parent="Scroll/V/bbar"] custom_minimum_size = Vector2(20, 0) -layout_mode = 2 +layout_mode = 3 anchors_preset = 0 offset_right = 20.0 offset_bottom = 36.0 -[node name="reset" type="Button" parent="Scroll/V/bbar"] +[node name="reset" type="Button" parent="Scroll/V/bbar" groups=["button"]] show_behind_parent = true -layout_mode = 2 offset_left = 24.0 offset_right = 79.0 offset_bottom = 36.0 @@ -112,30 +107,28 @@ text = "reset" script = SubResource("GDScript_dodrb") [node name="space" type="Control" parent="Scroll/V/bbar"] -layout_mode = 2 +layout_mode = 3 anchors_preset = 0 offset_left = 83.0 offset_right = 190.0 offset_bottom = 36.0 size_flags_horizontal = 3 -[node name="exit" parent="Scroll/V/bbar" instance=ExtResource("5_w2is5")] -layout_mode = 2 +[node name="exit" parent="Scroll/V/bbar" groups=["button"] instance=ExtResource("5_w2is5")] focus_neighbor_left = NodePath("../reset") focus_neighbor_right = NodePath("../reset") [node name="space2" type="Control" parent="Scroll/V/bbar"] custom_minimum_size = Vector2(40, 0) -layout_mode = 2 +layout_mode = 3 anchors_preset = 0 offset_left = 230.0 offset_right = 270.0 offset_bottom = 36.0 -[node name="left" type="HBoxContainer" parent="Scroll/V"] +[node name="left" type="HBoxContainer" parent="Scroll/V" groups=["button"]] show_behind_parent = true custom_minimum_size = Vector2(42, 42) -layout_mode = 2 offset_top = 40.0 offset_right = 270.0 offset_bottom = 82.0 @@ -147,10 +140,9 @@ icon_size = Vector2(35, 35) font_size = 22 device = -1 -[node name="right" type="HBoxContainer" parent="Scroll/V"] +[node name="right" type="HBoxContainer" parent="Scroll/V" groups=["button"]] show_behind_parent = true custom_minimum_size = Vector2(42, 42) -layout_mode = 2 offset_top = 86.0 offset_right = 270.0 offset_bottom = 128.0 @@ -162,10 +154,9 @@ icon_size = Vector2(35, 35) font_size = 22 device = -1 -[node name="up" type="HBoxContainer" parent="Scroll/V"] +[node name="up" type="HBoxContainer" parent="Scroll/V" groups=["button"]] show_behind_parent = true custom_minimum_size = Vector2(42, 42) -layout_mode = 2 offset_top = 132.0 offset_right = 270.0 offset_bottom = 174.0 @@ -177,10 +168,9 @@ icon_size = Vector2(35, 35) font_size = 22 device = -1 -[node name="down" type="HBoxContainer" parent="Scroll/V"] +[node name="down" type="HBoxContainer" parent="Scroll/V" groups=["button"]] show_behind_parent = true custom_minimum_size = Vector2(42, 42) -layout_mode = 2 offset_top = 178.0 offset_right = 270.0 offset_bottom = 220.0 @@ -192,10 +182,9 @@ icon_size = Vector2(35, 35) font_size = 22 device = -1 -[node name="jump" type="HBoxContainer" parent="Scroll/V"] +[node name="jump" type="HBoxContainer" parent="Scroll/V" groups=["button"]] show_behind_parent = true custom_minimum_size = Vector2(42, 42) -layout_mode = 2 offset_top = 224.0 offset_right = 270.0 offset_bottom = 266.0 @@ -207,10 +196,9 @@ icon_size = Vector2(35, 35) font_size = 22 device = -1 -[node name="fall" type="HBoxContainer" parent="Scroll/V"] +[node name="fall" type="HBoxContainer" parent="Scroll/V" groups=["button"]] show_behind_parent = true custom_minimum_size = Vector2(42, 42) -layout_mode = 2 offset_top = 270.0 offset_right = 270.0 offset_bottom = 312.0 @@ -222,10 +210,9 @@ icon_size = Vector2(35, 35) font_size = 22 device = -1 -[node name="throw" type="HBoxContainer" parent="Scroll/V"] +[node name="throw" type="HBoxContainer" parent="Scroll/V" groups=["button"]] show_behind_parent = true custom_minimum_size = Vector2(42, 42) -layout_mode = 2 offset_top = 316.0 offset_right = 270.0 offset_bottom = 358.0 @@ -237,10 +224,9 @@ icon_size = Vector2(35, 35) font_size = 22 device = -1 -[node name="pickup" type="HBoxContainer" parent="Scroll/V"] +[node name="pickup" type="HBoxContainer" parent="Scroll/V" groups=["button"]] show_behind_parent = true custom_minimum_size = Vector2(42, 42) -layout_mode = 2 offset_top = 362.0 offset_right = 270.0 offset_bottom = 404.0 diff --git a/ui/start.gd b/ui/start.gd index 4ace680..2d725f4 100644 --- a/ui/start.gd +++ b/ui/start.gd @@ -1,7 +1,17 @@ extends Popuppable + func _ready() -> void: - open() + open() + var buttons := get_tree().get_nodes_in_group(&"button") + var play_sound := func plays() -> void: randomize() ; SoundManager.play("click", -10, randf_range(.9, 1.1)) + for butt in buttons: + if butt is Button: + butt.pressed.connect(play_sound) + elif butt is RemapButton: + butt.button.pressed.connect(play_sound) + butt.clear.pressed.connect(play_sound) + func exit() -> void: - pass + pass diff --git a/ui/start.tscn b/ui/start.tscn index 7027255..e0c9756 100644 --- a/ui/start.tscn +++ b/ui/start.tscn @@ -33,7 +33,6 @@ focus = NodePath("VBox/StartButton") metadata/_edit_vertical_guides_ = [] [node name="VBox" type="VBoxContainer" parent="."] -layout_mode = 1 anchors_preset = 8 anchor_left = 0.5 anchor_top = 0.5 @@ -46,22 +45,19 @@ offset_bottom = 76.0 grow_horizontal = 2 grow_vertical = 2 -[node name="StartButton" type="Button" parent="VBox"] -layout_mode = 2 +[node name="StartButton" type="Button" parent="VBox" groups=["button"]] offset_right = 172.0 offset_bottom = 43.0 text = "start" script = SubResource("GDScript_52jbq") -[node name="CfgButtton" type="Button" parent="VBox"] -layout_mode = 2 +[node name="CfgButtton" type="Button" parent="VBox" groups=["button"]] offset_top = 47.0 offset_right = 172.0 offset_bottom = 90.0 text = "configure" -[node name="ExitButton" type="Button" parent="VBox"] -layout_mode = 2 +[node name="ExitButton" type="Button" parent="VBox" groups=["button"]] offset_top = 94.0 offset_right = 172.0 offset_bottom = 137.0 @@ -71,7 +67,6 @@ script = SubResource("GDScript_vtoxm") [node name="cfg" parent="." instance=ExtResource("2_sqamp")] unique_name_in_owner = true visible = false -layout_mode = 1 [connection signal="pressed" from="VBox/CfgButtton" to="cfg" method="open"] [connection signal="close" from="cfg" to="." method="open"] diff --git a/world/door/block_door.gd b/world/door/block_door.gd index 8c5ee6c..202d330 100644 --- a/world/door/block_door.gd +++ b/world/door/block_door.gd @@ -5,17 +5,19 @@ const DustEffect := preload("res://fx/wall_dust.tscn") @onready @export var path_follower: PathFollow2D + func dust(mod: int) -> void: - var i: Node2D = ( - Utils . instance_scene_on_main(DustEffect, global_position + Vector2(randi_range(3, 5), (16 + 7) * mod)) - ) - i.rotation = (PI / 2) * mod + var i: Node2D = ( + Utils . instance_scene_on_main(DustEffect, global_position + Vector2(randi_range(3, 5), (16 + 7) * mod)) + ) + i.rotation = (PI / 2) * mod + ## Opens this door func open() -> void: - dust(1) - dust(-1) - var t := create_tween().set_ease(Tween.EASE_IN) - t.tween_property(path_follower, "progress_ratio", 1, 2) - await t.finished - queue_free() + dust(1) + dust(-1) + var t := create_tween().set_ease(Tween.EASE_IN) + t.tween_property(path_follower, "progress_ratio", 1, 2) + await t.finished + queue_free() |