diff options
| author | Jan Tuomi <jan@jantuomi.fi> | 2025-11-14 14:05:22 +0200 |
|---|---|---|
| committer | Jan Tuomi <jan@jantuomi.fi> | 2025-11-14 14:05:22 +0200 |
| commit | 9d71ad993ec77108874db9697256b4fef385ce16 (patch) | |
| tree | 72bd20d86c7f1e5b8e3c433f98d138eaae06e43a | |
| parent | c80c35213bb13ca7db939639d5a707f6944f8196 (diff) | |
Add camera offsetting when moving
| -rw-r--r-- | docs/index.html | 2 | ||||
| -rw-r--r-- | docs/index.pck | bin | 1941152 -> 1943232 bytes | |||
| -rw-r--r-- | docs/index.service.worker.js | 2 | ||||
| -rw-r--r-- | game_camera.gd | 34 | ||||
| -rw-r--r-- | game_camera.gd.uid | 1 | ||||
| -rw-r--r-- | game_camera.tscn | 37 | ||||
| -rw-r--r-- | level_test.tscn | 38 | ||||
| -rw-r--r-- | player.gd | 6 | ||||
| -rw-r--r-- | player.tscn | 3 |
9 files changed, 86 insertions, 37 deletions
diff --git a/docs/index.html b/docs/index.html index 0a80fda..e9dd045 100644 --- a/docs/index.html +++ b/docs/index.html @@ -112,7 +112,7 @@ body { <script src="index.js"></script> <script> -const GODOT_CONFIG = {"args":[],"canvasResizePolicy":2,"emscriptenPoolSize":8,"ensureCrossOriginIsolationHeaders":false,"executable":"index","experimentalVK":false,"fileSizes":{"index.pck":1941152,"index.wasm":38034280},"focusCanvas":true,"gdextensionLibs":[],"godotPoolSize":4,"serviceWorker":"index.service.worker.js"}; +const GODOT_CONFIG = {"args":[],"canvasResizePolicy":2,"emscriptenPoolSize":8,"ensureCrossOriginIsolationHeaders":false,"executable":"index","experimentalVK":false,"fileSizes":{"index.pck":1943232,"index.wasm":38034280},"focusCanvas":true,"gdextensionLibs":[],"godotPoolSize":4,"serviceWorker":"index.service.worker.js"}; const GODOT_THREADS_ENABLED = false; const engine = new Engine(GODOT_CONFIG); diff --git a/docs/index.pck b/docs/index.pck Binary files differindex c45d6a2..6e1678b 100644 --- a/docs/index.pck +++ b/docs/index.pck diff --git a/docs/index.service.worker.js b/docs/index.service.worker.js index 2c13202..c928d77 100644 --- a/docs/index.service.worker.js +++ b/docs/index.service.worker.js @@ -4,7 +4,7 @@ // Incrementing CACHE_VERSION will kick off the install event and force // previously cached resources to be updated from the network. /** @type {string} */ -const CACHE_VERSION = '1763116851|5866973052'; +const CACHE_VERSION = '1763121903|10918918109'; /** @type {string} */ const CACHE_PREFIX = 'MobileMetroidvan-sw-cache-'; const CACHE_NAME = CACHE_PREFIX + CACHE_VERSION; diff --git a/game_camera.gd b/game_camera.gd new file mode 100644 index 0000000..9e6fd2b --- /dev/null +++ b/game_camera.gd @@ -0,0 +1,34 @@ +extends Camera2D + +@onready var parent = get_parent() +@onready var is_parent_player = parent is Player + +## Amount to smoothly offset the camera if the parent is a Player. +@export var offset_amt: Vector2 + +var time_since_floor: float = 0.0 +var time_since_floor_max: float = 1.0 + +# Called when the node enters the scene tree for the first time. +func _ready() -> void: + pass # Replace with function body. + + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(_delta: float) -> void: + #if player.is_on_floor(): + # time_since_floor = 0 + #elif time_since_floor < time_since_floor_max: + # time_since_floor += delta + + if is_parent_player: + var player: Player = parent + position.x = player.get_facing() * offset_amt.x + + if not player.is_on_floor(): + position.y = offset_amt.y + else: + position.y = 0 + + #offset.y = lerpf(0.0, look_down_on_jump_amt, ease(time_since_floor, 0.2)) + #print_debug("offset y:", offset.y) diff --git a/game_camera.gd.uid b/game_camera.gd.uid new file mode 100644 index 0000000..ab2ea12 --- /dev/null +++ b/game_camera.gd.uid @@ -0,0 +1 @@ +uid://dul8m52uio8t5 diff --git a/game_camera.tscn b/game_camera.tscn new file mode 100644 index 0000000..4bac6bd --- /dev/null +++ b/game_camera.tscn @@ -0,0 +1,37 @@ +[gd_scene load_steps=8 format=3 uid="uid://dfyvkc2qlcdac"] + +[ext_resource type="PackedScene" uid="uid://dwl0fylftkrn7" path="res://touch_screen_button.tscn" id="1_kci6r"] +[ext_resource type="Script" uid="uid://dul8m52uio8t5" path="res://game_camera.gd" id="1_sfxhn"] +[ext_resource type="Texture2D" uid="uid://dxwflmdxikfiu" path="res://assets/kenney_1-bit-input-prompts-pixel-16/Tiles (Black)/tile_0758.png" id="2_sfxhn"] +[ext_resource type="Texture2D" uid="uid://bhpl1ew34plow" path="res://assets/kenney_1-bit-input-prompts-pixel-16/Tiles (Black)/tile_0760.png" id="3_4qcmi"] +[ext_resource type="Texture2D" uid="uid://m46a5qu4rgui" path="res://assets/kenney_1-bit-input-prompts-pixel-16/Tiles (Black)/tile_0757.png" id="4_2jofw"] +[ext_resource type="Texture2D" uid="uid://dsetjcrrlp7gu" path="res://assets/kenney_1-bit-input-prompts-pixel-16/Tiles (Black)/tile_0769.png" id="5_5dmry"] + +[sub_resource type="RectangleShape2D" id="RectangleShape2D_k6i1l"] +size = Vector2(40, 26) + +[node name="GameCamera" type="Camera2D"] +position_smoothing_enabled = true +position_smoothing_speed = 16.0 +script = ExtResource("1_sfxhn") + +[node name="TouchScreenButtonRight" parent="." instance=ExtResource("1_kci6r")] +position = Vector2(-36, 34) +action = "move_right" +texture = ExtResource("2_sfxhn") + +[node name="TouchScreenButtonLeft" parent="." instance=ExtResource("1_kci6r")] +position = Vector2(-76, 34) +action = "move_left" +texture = ExtResource("3_4qcmi") + +[node name="TouchScreenButtonJump" parent="." instance=ExtResource("1_kci6r")] +position = Vector2(76, 34) +action = "jump" +texture = ExtResource("4_2jofw") + +[node name="TouchScreenButtonMenu" parent="." instance=ExtResource("1_kci6r")] +position = Vector2(76, -41) +shape = SubResource("RectangleShape2D_k6i1l") +action = "menu" +texture = ExtResource("5_5dmry") diff --git a/level_test.tscn b/level_test.tscn index 18f2aa5..9d86227 100644 --- a/level_test.tscn +++ b/level_test.tscn @@ -1,14 +1,10 @@ -[gd_scene load_steps=13 format=4 uid="uid://cfj21o6wsd3hv"] +[gd_scene load_steps=8 format=4 uid="uid://cfj21o6wsd3hv"] [ext_resource type="Texture2D" uid="uid://o0yy2jkyp0dy" path="res://assets/kenney_1-bit-platformer-pack/Tilemap/monochrome_tilemap_transparent_packed.png" id="1_56xti"] [ext_resource type="Script" uid="uid://b3xwng3dkn5s7" path="res://level_test.gd" id="1_mge0y"] [ext_resource type="PackedScene" uid="uid://coxnsharboouu" path="res://player.tscn" id="2_mge0y"] -[ext_resource type="PackedScene" uid="uid://dwl0fylftkrn7" path="res://touch_screen_button.tscn" id="3_hpvma"] -[ext_resource type="Texture2D" uid="uid://dxwflmdxikfiu" path="res://assets/kenney_1-bit-input-prompts-pixel-16/Tiles (Black)/tile_0758.png" id="4_k6i1l"] -[ext_resource type="Texture2D" uid="uid://bhpl1ew34plow" path="res://assets/kenney_1-bit-input-prompts-pixel-16/Tiles (Black)/tile_0760.png" id="5_lmggl"] -[ext_resource type="Texture2D" uid="uid://m46a5qu4rgui" path="res://assets/kenney_1-bit-input-prompts-pixel-16/Tiles (Black)/tile_0757.png" id="6_25u55"] +[ext_resource type="PackedScene" uid="uid://dfyvkc2qlcdac" path="res://game_camera.tscn" id="4_6ih1o"] [ext_resource type="Script" uid="uid://rjab5emlyx6" path="res://esc_listener.gd" id="8_hpvma"] -[ext_resource type="Texture2D" uid="uid://dsetjcrrlp7gu" path="res://assets/kenney_1-bit-input-prompts-pixel-16/Tiles (Black)/tile_0769.png" id="8_k6i1l"] [sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_0e48y"] texture = ExtResource("1_56xti") @@ -440,9 +436,6 @@ texture = ExtResource("1_56xti") physics_layer_0/collision_layer = 1 sources/1 = SubResource("TileSetAtlasSource_0e48y") -[sub_resource type="RectangleShape2D" id="RectangleShape2D_k6i1l"] -size = Vector2(40, 26) - [node name="LevelTest" type="Node2D"] script = ExtResource("1_mge0y") @@ -458,29 +451,10 @@ jump_strength = 200.0 coyote_max = 10 jump_held_coef = 0.8 -[node name="Camera2D" type="Camera2D" parent="Player"] -position = Vector2(0, -15) - -[node name="TouchScreenButtonRight" parent="Player/Camera2D" instance=ExtResource("3_hpvma")] -position = Vector2(-36, 34) -action = "move_right" -texture = ExtResource("4_k6i1l") - -[node name="TouchScreenButtonLeft" parent="Player/Camera2D" instance=ExtResource("3_hpvma")] -position = Vector2(-76, 34) -action = "move_left" -texture = ExtResource("5_lmggl") - -[node name="TouchScreenButtonJump" parent="Player/Camera2D" instance=ExtResource("3_hpvma")] -position = Vector2(76, 34) -action = "jump" -texture = ExtResource("6_25u55") - -[node name="TouchScreenButtonMenu" parent="Player/Camera2D" instance=ExtResource("3_hpvma")] -position = Vector2(76, -41) -shape = SubResource("RectangleShape2D_k6i1l") -action = "menu" -texture = ExtResource("8_k6i1l") +[node name="GameCamera" parent="Player" instance=ExtResource("4_6ih1o")] +process_callback = 0 +position_smoothing_speed = 3.0 +offset_amt = Vector2(40, 14) [node name="EscListener" type="Node" parent="."] script = ExtResource("8_hpvma") @@ -17,6 +17,12 @@ var coyote: int = 0 # Called when the node enters the scene tree for the first time. func _ready() -> void: pass # Replace with function body. + +func get_facing() -> int: + if $AnimatedSprite2D.flip_h: + return -1 + else: + return 1 # Called every frame. 'delta' is the elapsed time since the previous frame. func _process(_delta: float) -> void: diff --git a/player.tscn b/player.tscn index 4ee3ad4..9b551b1 100644 --- a/player.tscn +++ b/player.tscn @@ -110,9 +110,6 @@ sprite_frames = SubResource("SpriteFrames_rj586") animation = &"idle" autoplay = "idle" -[node name="Camera2D" type="Camera2D" parent="AnimatedSprite2D"] -position = Vector2(0, -15) - [node name="CollisionShape2D" type="CollisionShape2D" parent="."] position = Vector2(0, 3) shape = SubResource("RectangleShape2D_onrkg") |
