Skip to content

Commit

Permalink
extra keys
Browse files Browse the repository at this point in the history
  • Loading branch information
ReloadedK-git committed Oct 23, 2023
1 parent 853c984 commit 2cbdc64
Show file tree
Hide file tree
Showing 7 changed files with 153 additions and 37 deletions.
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# ReloadedK's Godot Fangame Engine (v1.1)
# ReloadedK's Godot Fangame Engine

A Godot 4.x fangame engine, created by ReloadedK.

Expand Down Expand Up @@ -27,5 +27,12 @@ You can check the [engine's documentation](https://github.com/ReloadedK-git/Relo

### v1.3 (30-09-23)

* Changed ***objInvisibleBlock***
* Slightly reduced volume for ***sndBlockChange***
* Changed ***objInvisibleBlock***.
* Slightly reduced volume for ***sndBlockChange***.

### v1.4 (23-10-23)

* Numpad arrows and controller stick can be used to control the player or interact with different objects, if the setting is toggled on.
* Added an "extra keys" option in the settings menu.
* Added extra functionality to the player (movement, walljumping) and dialog sign (interaction).
* Added extra actions in the input map.
13 changes: 11 additions & 2 deletions Rooms/00_Title_and_menus/rMenuSettings.tscn
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ offset_top = -10.0
offset_bottom = 10.0
grow_horizontal = 2
grow_vertical = 2
theme_override_constants/separation = 72
theme_override_constants/separation = 64
alignment = 1

[node name="MusicVolume" parent="SettingsContainer" instance=ExtResource("4_k2tdr")]
Expand Down Expand Up @@ -82,13 +82,21 @@ layout_mode = 2
focus_neighbor_left = NodePath(".")
focus_neighbor_top = NodePath("../Vsync")
focus_neighbor_right = NodePath(".")
focus_neighbor_bottom = NodePath("../ExtraKeys")
action_mode = 0

[node name="ExtraKeys" parent="SettingsContainer" instance=ExtResource("4_k2tdr")]
layout_mode = 2
focus_neighbor_left = NodePath(".")
focus_neighbor_top = NodePath("../AutoReset")
focus_neighbor_right = NodePath(".")
focus_neighbor_bottom = NodePath("../Reset")
action_mode = 0

[node name="Reset" parent="SettingsContainer" instance=ExtResource("4_k2tdr")]
layout_mode = 2
focus_neighbor_left = NodePath(".")
focus_neighbor_top = NodePath("../AutoReset")
focus_neighbor_top = NodePath("../ExtraKeys")
focus_neighbor_right = NodePath(".")
focus_neighbor_bottom = NodePath("../Controls")
action_mode = 0
Expand All @@ -114,6 +122,7 @@ action_mode = 0
[connection signal="pressed" from="SettingsContainer/Fullscreen" to="." method="_on_fullscreen_pressed"]
[connection signal="pressed" from="SettingsContainer/Vsync" to="." method="_on_vsync_pressed"]
[connection signal="pressed" from="SettingsContainer/AutoReset" to="." method="_on_auto_reset_pressed"]
[connection signal="pressed" from="SettingsContainer/ExtraKeys" to="." method="_on_extra_keys_pressed"]
[connection signal="pressed" from="SettingsContainer/Reset" to="." method="_on_defaults_pressed"]
[connection signal="pressed" from="SettingsContainer/Controls" to="." method="_on_controls_pressed"]
[connection signal="pressed" from="SettingsContainer/Back" to="." method="_on_back_pressed"]
16 changes: 12 additions & 4 deletions Scripts/Dialog/scrSign.gd
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,18 @@ func _physics_process(_delta):
# pressed
if player_is_colliding:
if dialog_scene != null:
if Input.is_action_just_pressed("button_up"):
if get_tree().get_nodes_in_group("Dialog").size() < 1:
var dialog_box_id = dialog_scene.instantiate()
get_parent().add_child(dialog_box_id)

# Extra keys off/on
if !GLOBAL_SETTINGS.EXTRA_KEYS:
if Input.is_action_just_pressed("button_up"):
if get_tree().get_nodes_in_group("Dialog").size() < 1:
var dialog_box_id = dialog_scene.instantiate()
get_parent().add_child(dialog_box_id)
else:
if (Input.is_action_just_pressed("button_up") or Input.is_action_just_pressed("button_up_extra")):
if get_tree().get_nodes_in_group("Dialog").size() < 1:
var dialog_box_id = dialog_scene.instantiate()
get_parent().add_child(dialog_box_id)

# Toggles the label's visibility by checking if the player exists and
# is frozen
Expand Down
7 changes: 6 additions & 1 deletion Scripts/Globals/scrGlobalSettings.gd
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ var SOUND_VOLUME: float = 1.0
var FULLSCREEN: bool = false
var VSYNC: bool = true
var AUTORESET: bool = false
var EXTRA_KEYS: bool = false

# Default values, for when you need to reset them from the settings menu
const DEFAULT_MUSIC_VOLUME: float = 1.0
const DEFAULT_SOUND_VOLUME: float = 1.0
var DEFAULT_FULLSCREEN: bool = false
const DEFAULT_FULLSCREEN: bool = false
const DEFAULT_VSYNC: bool = true
const DEFAULT_AUTORESET: bool = false
const DEFAULT_EXTRA_KEYS: bool = false

# Window related variables, for handling window modes
var INITIAL_WINDOW_WIDTH: int = DisplayServer.window_get_size().x
Expand Down Expand Up @@ -46,6 +48,7 @@ func save_settings() -> void:
configFile.set_value("settings", "fullscreen", FULLSCREEN)
configFile.set_value("settings", "vsync", VSYNC)
configFile.set_value("settings", "autoreset", AUTORESET)
configFile.set_value("settings", "extra_keys", EXTRA_KEYS)

for action in InputMap.get_actions():
configFile.set_value("controls", action, InputMap.action_get_events(action))
Expand All @@ -63,6 +66,7 @@ func load_settings() -> void:
FULLSCREEN = configFile.get_value("settings", "fullscreen", FULLSCREEN)
VSYNC = configFile.get_value("settings", "vsync", VSYNC)
AUTORESET = configFile.get_value("settings", "autoreset", AUTORESET)
EXTRA_KEYS = configFile.get_value("settings", "extra_keys", EXTRA_KEYS)

AudioServer.set_bus_volume_db(AudioServer.get_bus_index("Sounds"), linear_to_db(SOUND_VOLUME))
AudioServer.set_bus_volume_db(AudioServer.get_bus_index("Music"), linear_to_db(MUSIC_VOLUME))
Expand All @@ -86,6 +90,7 @@ func default_settings() -> void:
FULLSCREEN = DEFAULT_FULLSCREEN
VSYNC = DEFAULT_VSYNC
AUTORESET = DEFAULT_AUTORESET
EXTRA_KEYS = DEFAULT_EXTRA_KEYS

AudioServer.set_bus_volume_db(AudioServer.get_bus_index("Music"), linear_to_db(MUSIC_VOLUME))
AudioServer.set_bus_volume_db(AudioServer.get_bus_index("Sounds"), linear_to_db(SOUND_VOLUME))
Expand Down
102 changes: 76 additions & 26 deletions Scripts/Player/scrPlayer.gd
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,37 @@ func handle_movement() -> void:

# Get the input direction and handle the movement
var main_direction = Input.get_axis("button_left", "button_right")
velocity.x = main_direction * h_speed
var extra_direction_keys = Input.get_axis("button_left_extra", "button_right_extra")

# Set where the player is looking at (for things like flipping the sprite
# or setting the direction bullets should fire towards)
if velocity.x != 0:
xscale = main_direction
# Lambda function, also called "anonymous function".
# It's a method that only works inside of this event, declared inside
# of a variable and executed by using "call()".
# Useful for keeping code cleaner and less repetitive in certain cases,
# but it's not mandatory.
# Changes xscale using a direction argument
var xscale_to_direction = func(h_direction):
if velocity.x != 0:
xscale = h_direction

# Extra keys off/on
if !GLOBAL_SETTINGS.EXTRA_KEYS:
velocity.x = main_direction * h_speed
xscale_to_direction.call(main_direction)
else:

# If not pressing/activating extra keys, use normal direction vector.
# Also ensures that the controller's deadzone is either -1, 0 or 1, so
# the player's speed will always remain constant
if (extra_direction_keys > -1) and (extra_direction_keys < 1):
velocity.x = main_direction * h_speed
xscale_to_direction.call(main_direction)

# Adds velocity from extra_direction_keys, the secondary direction
# vector
else:
velocity.x = extra_direction_keys * h_speed
xscale_to_direction.call(extra_direction_keys)



# Jumping logic
Expand Down Expand Up @@ -235,29 +260,54 @@ func handle_walljumping():
# Walljumping should only happen if we hold the jump button first
if Input.is_action_pressed("button_jump"):

# Walljump to the right
if Input.is_action_pressed("button_right") and (jump_direction == Vector2.RIGHT):
if !Input.is_action_pressed("button_left"):
walljumping_action.call()

# Walljump to the left
if Input.is_action_pressed("button_left") and (jump_direction == Vector2.LEFT):
if !Input.is_action_pressed("button_right"):
walljumping_action.call()
# Extra keys off/on
if !GLOBAL_SETTINGS.EXTRA_KEYS:

# Walljump to the right
if (Input.is_action_pressed("button_right")) and (jump_direction == Vector2.RIGHT):
if !Input.is_action_pressed("button_left"):
walljumping_action.call()

# Walljump to the left
if Input.is_action_pressed("button_left") and (jump_direction == Vector2.LEFT):
if !Input.is_action_pressed("button_right"):
walljumping_action.call()
else:

# Walljump to the right
if (Input.is_action_pressed("button_right") or Input.is_action_pressed("button_right_extra")) and (jump_direction == Vector2.RIGHT):
if (!Input.is_action_pressed("button_left") or !Input.is_action_pressed("button_left_extra")):
walljumping_action.call()

# Walljump to the left
if (Input.is_action_pressed("button_left") or Input.is_action_pressed("button_left_extra")) and (jump_direction == Vector2.LEFT):
if (!Input.is_action_pressed("button_right") or !Input.is_action_pressed("button_right_extra")):
walljumping_action.call()
else:

# Not holding the jump button, but pressing left or right on the
# opposite direction to the vine, leaves it and stops the
# walljumping state.
# This won't work if both the left and right buttons are pressed
# at the same time. Feels cleaner this way
if Input.is_action_pressed("button_right") and (jump_direction == Vector2.RIGHT):
if !Input.is_action_pressed("button_left"):
is_walljumping = false

if Input.is_action_pressed("button_left") and (jump_direction == Vector2.LEFT):
if !Input.is_action_pressed("button_right"):
is_walljumping = false
# Extra keys off/on
if !GLOBAL_SETTINGS.EXTRA_KEYS:

# Not holding the jump button, but pressing left or right on the
# opposite direction to the vine, leaves it and stops the
# walljumping state.
# This won't work if both the left and right buttons are pressed
# at the same time. Feels cleaner this way
if Input.is_action_pressed("button_right") and (jump_direction == Vector2.RIGHT):
if !Input.is_action_pressed("button_left"):
is_walljumping = false

if Input.is_action_pressed("button_left") and (jump_direction == Vector2.LEFT):
if !Input.is_action_pressed("button_right"):
is_walljumping = false
else:
if (Input.is_action_pressed("button_right") or Input.is_action_pressed("button_right_extra")) and (jump_direction == Vector2.RIGHT):
if (!Input.is_action_pressed("button_left") or !Input.is_action_pressed("button_left_extra")):
is_walljumping = false

if (Input.is_action_pressed("button_left") or Input.is_action_pressed("button_left_extra")) and (jump_direction == Vector2.LEFT):
if (!Input.is_action_pressed("button_right") or !Input.is_action_pressed("button_right_extra")):
is_walljumping = false
else:

# Sets things back to normal (not walljumping anymore).
Expand Down
15 changes: 14 additions & 1 deletion Scripts/UI/scrSettingsMenu.gd
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ var volume_step: float = 0.1
var fullscreen_on: bool = false
var vsync_on: bool = true
var autoreset_on: bool = false
var extra_keys_on: bool = false



Expand Down Expand Up @@ -92,7 +93,12 @@ func _on_vsync_pressed():
# Autoreset on/off
func _on_auto_reset_pressed():
autoreset_on = !autoreset_on



# Extra keys on/off
func _on_extra_keys_pressed():
extra_keys_on = !extra_keys_on


# Reset the setting's values back to their default ones. Also plays a
# confirmation sound effect
Expand Down Expand Up @@ -131,6 +137,7 @@ func load_from_global_settings():
fullscreen_on = GLOBAL_SETTINGS.FULLSCREEN
vsync_on = GLOBAL_SETTINGS.VSYNC
autoreset_on = GLOBAL_SETTINGS.AUTORESET
extra_keys_on = GLOBAL_SETTINGS.EXTRA_KEYS


# Sets and updates the text from each one of the button's labels
Expand All @@ -140,6 +147,7 @@ func set_labels_text():
$SettingsContainer/Fullscreen/Label.text = "Fullscreen: " + str(bool_to_on_off(fullscreen_on))
$SettingsContainer/Vsync/Label.text = "Vsync: " + str(bool_to_on_off(vsync_on))
$SettingsContainer/AutoReset/Label.text = "Reset on Death: " + str(bool_to_on_off(autoreset_on))
$SettingsContainer/ExtraKeys/Label.text = "Extra keys: " + str(bool_to_on_off(extra_keys_on))
$SettingsContainer/Reset/Label.text = "Reset"
$SettingsContainer/Controls/Label.text = "Controls"
$SettingsContainer/Back/Label.text = "Back"
Expand All @@ -152,6 +160,7 @@ func save_on_exit():
GLOBAL_SETTINGS.MUSIC_VOLUME = music_volume
GLOBAL_SETTINGS.SOUND_VOLUME = sound_volume
GLOBAL_SETTINGS.AUTORESET = autoreset_on
GLOBAL_SETTINGS.EXTRA_KEYS = extra_keys_on

# Saving (includes fullscreen and vsync, but we don't need to set them
# from here again)
Expand All @@ -166,6 +175,7 @@ func reset_settings_to_default():
fullscreen_on = false
vsync_on = true
autoreset_on = false
extra_keys_on = false

GLOBAL_SETTINGS.default_settings()

Expand All @@ -180,3 +190,6 @@ func bool_to_on_off(bool_value):






24 changes: 24 additions & 0 deletions project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,30 @@ button_quitgame={
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":true,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194335,"key_label":0,"unicode":0,"echo":false,"script":null)
]
}
button_left_extra={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194442,"key_label":0,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":0,"axis_value":-1.0,"script":null)
]
}
button_right_extra={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194444,"key_label":0,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":0,"axis_value":1.0,"script":null)
]
}
button_up_extra={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194446,"key_label":0,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":1,"axis_value":-1.0,"script":null)
]
}
button_down_extra={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194440,"key_label":0,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":1,"axis_value":1.0,"script":null)
]
}

[layer_names]

Expand Down

0 comments on commit 2cbdc64

Please sign in to comment.