Compare commits

...

4 commits

Author SHA1 Message Date
Fabio
c77169deba Merge branch 'Rycarus_ObjectConnection' into dev 2024-08-18 20:15:37 +02:00
Fabio
2cd7b66d6c fix block sprite when changing 2024-08-18 20:13:49 +02:00
Fabio
a1bb39eaeb fix problems with the shrinking 2024-08-18 16:29:21 +02:00
Fabio
55f4163ef0 fixed the data_link length 2024-08-18 15:43:21 +02:00
18 changed files with 520 additions and 82 deletions

View file

@ -33,7 +33,7 @@ visible = false
[node name="UILayer" type="CanvasLayer" parent="."] [node name="UILayer" type="CanvasLayer" parent="."]
[node name="UI" type="Control" parent="UILayer" node_paths=PackedStringArray("player")] [node name="UI" type="Control" parent="UILayer"]
layout_mode = 3 layout_mode = 3
anchors_preset = 15 anchors_preset = 15
anchor_right = 1.0 anchor_right = 1.0
@ -41,7 +41,6 @@ anchor_bottom = 1.0
grow_horizontal = 2 grow_horizontal = 2
grow_vertical = 2 grow_vertical = 2
script = ExtResource("3_b82rx") script = ExtResource("3_b82rx")
player = NodePath("../../Player")
[node name="HBoxContainer" type="HBoxContainer" parent="UILayer/UI"] [node name="HBoxContainer" type="HBoxContainer" parent="UILayer/UI"]
layout_mode = 0 layout_mode = 0

File diff suppressed because one or more lines are too long

View file

@ -3,12 +3,11 @@
[ext_resource type="PackedScene" uid="uid://ba6afuig8bqrg" path="res://levels/LevelBase.tscn" id="1_87xn7"] [ext_resource type="PackedScene" uid="uid://ba6afuig8bqrg" path="res://levels/LevelBase.tscn" id="1_87xn7"]
[ext_resource type="Texture2D" uid="uid://c3m4os8kteaix" path="res://textures/level01-spritesheet.png" id="2_wqskp"] [ext_resource type="Texture2D" uid="uid://c3m4os8kteaix" path="res://textures/level01-spritesheet.png" id="2_wqskp"]
[ext_resource type="Shader" path="res://shaders/scrolling.gdshader" id="4_0x2h7"] [ext_resource type="Shader" path="res://shaders/scrolling.gdshader" id="4_0x2h7"]
[ext_resource type="Texture2D" uid="uid://bki6ucvk6bjwk" path="res://textures/Level 01.png" id="5_4p03u"] [ext_resource type="Texture2D" uid="uid://c61y0181w3sq2" path="res://textures/Level 01.png" id="5_4p03u"]
[ext_resource type="PackedScene" uid="uid://d0gpnqknarkg7" path="res://objects/Goal.tscn" id="6_xhax5"] [ext_resource type="PackedScene" path="res://objects/Goal.tscn" id="6_xhax5"]
[ext_resource type="PackedScene" uid="uid://cpa66thuxma15" path="res://objects/MirrorOrb.tscn" id="7_dyi0e"] [ext_resource type="PackedScene" path="res://objects/MirrorOrb.tscn" id="7_dyi0e"]
[ext_resource type="PackedScene" uid="uid://br6fngf5208j0" path="res://objects/ResizableBlock.tscn" id="8_ec71m"] [ext_resource type="PackedScene" uid="uid://vtwswrkfkgas" path="res://objects/EnemyMover.tscn" id="8_16072"]
[ext_resource type="PackedScene" uid="uid://d17jpcgayfg6i" path="res://objects/BoxPushable_1.tscn" id="8_urw3p"] [ext_resource type="PackedScene" uid="uid://br6fngf5208j0" path="res://objects/ResizableBlockBig.tscn" id="8_ec71m"]
[ext_resource type="PackedScene" uid="uid://bnvyaxh2kotd3" path="res://objects/BreakableBlock.tscn" id="9_m0qjy"]
[sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_e817v"] [sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_e817v"]
texture = ExtResource("2_wqskp") texture = ExtResource("2_wqskp")
@ -130,10 +129,10 @@ shader_parameter/scroll_speed = 0.02
[node name="Player" parent="." index="0"] [node name="Player" parent="." index="0"]
position = Vector2(-542, 331) position = Vector2(-542, 331)
scale = Vector2(2, 2) scale = Vector2(2, 2)
jump_strength_max = 400
[node name="UI" parent="UILayer" index="0"] [node name="UI" parent="UILayer" index="0" node_paths=PackedStringArray("player")]
mouse_filter = 2 mouse_filter = 2
player = NodePath("../../Player")
[node name="HBoxContainer" parent="UILayer/UI" index="0"] [node name="HBoxContainer" parent="UILayer/UI" index="0"]
mouse_filter = 0 mouse_filter = 0
@ -171,15 +170,14 @@ position = Vector2(582, -317)
position = Vector2(-431, -212) position = Vector2(-431, -212)
[node name="Block" parent="." index="9" node_paths=PackedStringArray("ui_actions") instance=ExtResource("8_ec71m")] [node name="Block" parent="." index="9" node_paths=PackedStringArray("ui_actions") instance=ExtResource("8_ec71m")]
position = Vector2(476, 253) position = Vector2(432, 186)
collision_layer = 1 collision_layer = 1
ui_actions = NodePath("../UILayer/UI") ui_actions = NodePath("../UILayer/UI")
[node name="BoxPushable1" parent="." index="11" instance=ExtResource("8_urw3p")] [node name="EnemyMover" parent="." index="10" instance=ExtResource("8_16072")]
position = Vector2(-84, 326) position = Vector2(-132, 311)
[node name="BreakableBlock" parent="." index="12" instance=ExtResource("9_m0qjy")] [node name="Block3" parent="." index="11" node_paths=PackedStringArray("ui_actions") instance=ExtResource("8_ec71m")]
position = Vector2(271, 210) position = Vector2(162, 124)
collision_layer = 1
[node name="BreakableBlock2" parent="." index="13" instance=ExtResource("9_m0qjy")] ui_actions = NodePath("../UILayer/UI")
position = Vector2(240, 210)

View file

@ -0,0 +1,194 @@
[gd_scene load_steps=12 format=4 uid="uid://cxsstkfcffdch"]
[ext_resource type="PackedScene" uid="uid://ba6afuig8bqrg" path="res://levels/LevelBase.tscn" id="1_8kfuv"]
[ext_resource type="Texture2D" uid="uid://c3m4os8kteaix" path="res://textures/level01-spritesheet.png" id="2_4iioo"]
[ext_resource type="Shader" path="res://shaders/scrolling.gdshader" id="3_ys3sa"]
[ext_resource type="Texture2D" uid="uid://c61y0181w3sq2" path="res://textures/Level 01.png" id="4_n40i2"]
[ext_resource type="PackedScene" path="res://objects/Goal.tscn" id="5_1tu7t"]
[ext_resource type="PackedScene" path="res://objects/MirrorOrb.tscn" id="6_87gst"]
[ext_resource type="PackedScene" uid="uid://br6fngf5208j0" path="res://objects/ResizableBlockBig.tscn" id="7_l2s1x"]
[ext_resource type="PackedScene" uid="uid://vtwswrkfkgas" path="res://objects/EnemyMover.tscn" id="8_3s3ae"]
[sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_e817v"]
texture = ExtResource("2_4iioo")
texture_region_size = Vector2i(32, 32)
0:0/0 = 0
0:0/0/physics_layer_0/polygon_0/points = PackedVector2Array(-16, -16, 16, -16, 16, 16, -16, 16)
1:0/0 = 0
1:0/0/physics_layer_0/polygon_0/points = PackedVector2Array(-16, -16, 16, -16, 16, 16, -16, 16)
2:0/0 = 0
2:0/0/physics_layer_0/polygon_0/points = PackedVector2Array(-16, -16, 16, -16, 16, 16, -16, 16)
3:0/0 = 0
3:0/0/physics_layer_0/polygon_0/points = PackedVector2Array(-16, -16, 16, -16, 16, 16, -16, 16)
4:0/0 = 0
4:0/0/physics_layer_0/polygon_0/points = PackedVector2Array(-16, -16, 16, -16, 16, 16, -16, 16)
5:0/0 = 0
5:0/0/physics_layer_0/polygon_0/points = PackedVector2Array(-16, -16, 16, -16, 16, 16, -16, 16)
6:0/0 = 0
6:0/0/physics_layer_0/polygon_0/points = PackedVector2Array(-16, -16, 16, -16, 16, 16, -16, 16)
7:0/0 = 0
7:0/0/physics_layer_0/polygon_0/points = PackedVector2Array(-16, -16, 16, -16, 16, 16, -16, 16)
8:0/next_alternative_id = 4
8:0/0 = 0
8:0/0/physics_layer_0/polygon_0/points = PackedVector2Array(-16, -16, 16, -16, 16, 16, -16, 16)
8:0/1 = 1
8:0/1/flip_v = true
8:0/1/physics_layer_0/polygon_0/points = PackedVector2Array(-16, -16, 16, -16, 16, 16, -16, 16)
8:0/2 = 2
8:0/2/transpose = true
8:0/2/physics_layer_0/polygon_0/points = PackedVector2Array(-16, -16, 16, -16, 16, 16, -16, 16)
8:0/3 = 3
8:0/3/flip_h = true
8:0/3/transpose = true
8:0/3/physics_layer_0/polygon_0/points = PackedVector2Array(-16, -16, 16, -16, 16, 16, -16, 16)
9:0/0 = 0
10:0/0 = 0
11:0/0 = 0
0:1/0 = 0
0:1/0/physics_layer_0/polygon_0/points = PackedVector2Array(-16, -16, 16, -16, 16, 16, -16, 16)
1:1/0 = 0
1:1/0/physics_layer_0/polygon_0/points = PackedVector2Array(-16, -16, 16, -16, 16, 16, -16, 16)
2:1/0 = 0
2:1/0/physics_layer_0/polygon_0/points = PackedVector2Array(-16, -16, 16, -16, 16, 16, -16, 16)
3:1/0 = 0
3:1/0/physics_layer_0/polygon_0/points = PackedVector2Array(-16, -16, 16, -16, 16, 16, -16, 16)
4:1/0 = 0
5:1/0 = 0
5:1/0/physics_layer_0/polygon_0/points = PackedVector2Array(-16, -16, 16, -16, 16, 16, -16, 16)
6:1/0 = 0
6:1/0/physics_layer_0/polygon_0/points = PackedVector2Array(-16, -16, 16, -16, 16, 16, -16, 16)
7:1/0 = 0
7:1/0/physics_layer_0/polygon_0/points = PackedVector2Array(-16, -16, 16, -16, 16, 16, -16, 16)
8:1/0 = 0
8:1/0/physics_layer_0/polygon_0/points = PackedVector2Array(-16, -16, 16, -16, 16, 16, -16, 16)
9:1/0 = 0
10:1/0 = 0
11:1/0 = 0
0:2/0 = 0
0:2/0/physics_layer_0/polygon_0/points = PackedVector2Array(-16, -16, 16, -16, 16, 16, -16, 16)
1:2/0 = 0
1:2/0/physics_layer_0/polygon_0/points = PackedVector2Array(-16, -16, 16, -16, 16, 16, -16, 16)
2:2/0 = 0
2:2/0/physics_layer_0/polygon_0/points = PackedVector2Array(-16, -16, 16, -16, 16, 16, -16, 16)
3:2/0 = 0
3:2/0/physics_layer_0/polygon_0/points = PackedVector2Array(-16, -16, 16, -16, 16, 16, -16, 16)
4:2/0 = 0
4:2/0/physics_layer_0/polygon_0/points = PackedVector2Array(-16, -16, 16, -16, 16, 16, -16, 16)
5:2/0 = 0
5:2/0/physics_layer_0/polygon_0/points = PackedVector2Array(-16, -16, 16, -16, 16, 16, -16, 16)
6:2/0 = 0
7:2/0 = 0
10:2/0 = 0
11:2/0 = 0
0:3/0 = 0
1:3/0 = 0
2:3/0 = 0
3:3/0 = 0
4:3/0 = 0
5:3/0 = 0
6:3/0 = 0
7:3/0 = 0
10:3/0 = 0
11:3/0 = 0
0:4/0 = 0
1:4/0 = 0
2:4/0 = 0
3:4/0 = 0
4:4/0 = 0
5:4/0 = 0
6:4/0 = 0
7:4/0 = 0
8:4/0 = 0
9:4/0 = 0
10:4/0 = 0
11:4/0 = 0
0:5/0 = 0
1:5/0 = 0
2:5/0 = 0
3:5/0 = 0
4:5/0 = 0
5:5/0 = 0
6:5/0 = 0
7:5/0 = 0
8:5/0 = 0
9:5/0 = 0
10:5/0 = 0
11:5/0 = 0
[sub_resource type="TileSet" id="TileSet_n3khe"]
tile_size = Vector2i(32, 32)
physics_layer_0/collision_layer = 1
sources/0 = SubResource("TileSetAtlasSource_e817v")
[sub_resource type="ShaderMaterial" id="ShaderMaterial_mvq46"]
shader = ExtResource("3_ys3sa")
shader_parameter/scroll_speed = 0.02
[node name="LevelBase" instance=ExtResource("1_8kfuv")]
[node name="Player" parent="." index="0"]
position = Vector2(-254, 99)
input_pickable = true
[node name="UI" parent="UILayer" index="0" node_paths=PackedStringArray("player")]
visible = false
mouse_filter = 2
player = NodePath("../../Player")
[node name="HBoxContainer" parent="UILayer/UI" index="0"]
offset_right = 296.0
offset_bottom = 96.0
mouse_filter = 0
[node name="Walls" parent="." index="4"]
collision_mask = 22
[node name="Ground" parent="Walls" index="0"]
position = Vector2(-7, 167)
[node name="Ceiling" parent="Walls" index="1"]
position = Vector2(57, -171)
[node name="LeftWall" parent="Walls" index="2"]
position = Vector2(-320, 26)
[node name="RightWall" parent="Walls" index="3"]
position = Vector2(338, 15)
[node name="Layer0" type="TileMapLayer" parent="." index="5"]
use_parent_material = true
tile_map_data = PackedByteArray("AAD2//v/AAADAAAAAAD2//z/AAACAAEAAAD2//3/AAACAAEAAAD2//7/AAACAAEAAAD2////AAACAAEAAAD2/wAAAAACAAEAAAD2/wEAAAACAAEAAAD2/wIAAAACAAEAAAD2/wMAAAACAAEAAAD2/wQAAAADAAIAAAAJAPv/AAAFAAAAAAAJAPz/AAAAAAEAAAAJAP3/AAAAAAEAAAAJAP7/AAAAAAEAAAAJAP//AAAAAAEAAAAJAAAAAAAAAAEAAAAJAAEAAAAAAAEAAAAJAAIAAAAAAAEAAAAJAAMAAAAAAAEAAAAJAAQAAAAFAAIAAAD3//v/AAABAAIAAAD4//v/AAABAAIAAAD5//v/AAABAAIAAAD6//v/AAABAAIAAAD7//v/AAABAAIAAAD8//v/AAABAAIAAAD9//v/AAABAAIAAAD+//v/AAABAAIAAAD///v/AAABAAIAAAAAAPv/AAABAAIAAAABAPv/AAABAAIAAAACAPv/AAABAAIAAAADAPv/AAABAAIAAAAEAPv/AAABAAIAAAAFAPv/AAABAAIAAAAGAPv/AAABAAIAAAAHAPv/AAABAAIAAAAIAPv/AAABAAIAAAD3/wQAAAABAAAAAAD4/wQAAAABAAAAAAD5/wQAAAABAAAAAAD6/wQAAAABAAAAAAD7/wQAAAAFAAIAAAD8/wQAAAABAAEAAAD9/wQAAAABAAEAAAD+/wQAAAABAAEAAAD//wQAAAABAAEAAAAAAAQAAAABAAEAAAABAAQAAAADAAIAAAACAAQAAAABAAAAAAADAAQAAAABAAAAAAAEAAQAAAABAAAAAAAFAAQAAAABAAAAAAAGAAQAAAABAAAAAAAHAAQAAAABAAAAAAAIAAQAAAABAAAAAAD7/wMAAAAAAAAAAAD8/wMAAAABAAAAAAD9/wMAAAABAAAAAAD+/wMAAAABAAAAAAD//wIAAAAAAAEAAAD//wEAAAAAAAAAAAAAAAEAAAAEAAIAAAABAAEAAAACAAAAAAABAAIAAAACAAEAAAABAAMAAAACAAEAAAD//wMAAAAFAAIAAAAAAAIAAAABAAEAAAAAAAMAAAABAAEAAAD3/wAAAAAIAAEAAGD4/wAAAAAIAAEAAGD5/wAAAAAIAAEAAGD6/wAAAAAIAAEAAGD7/wAAAAAIAAAAAVD3//3/AAAIAAEAAFD4//3/AAAIAAEAAFD5//3/AAAIAAEAAFD6//3/AAAIAAEAAFD7//3/AAAIAAEAAFD8//3/AAAIAAEAAFD9//3/AAAIAAEAAFD+//3/AAACAAAAAAAAAAAAAAAGAAIAAAAAAP//AAABAAIAAAD/////AAAAAAIAAAD///7/AAAHAAAAAAAAAP7/AAACAAAAAAABAP//AAAIAAAAAVD+//7/AAAAAAIAAAAFAAEAAAAIAAAAAAAFAAIAAAAIAAAAAQA=")
tile_set = SubResource("TileSet_n3khe")
[node name="TextureRect" type="TextureRect" parent="." index="6"]
z_index = -100
material = SubResource("ShaderMaterial_mvq46")
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
offset_left = -320.0
offset_top = -158.0
offset_right = -320.0
offset_bottom = -158.0
grow_horizontal = 2
grow_vertical = 2
texture = ExtResource("4_n40i2")
stretch_mode = 1
[node name="Goal" parent="." index="7" instance=ExtResource("5_1tu7t")]
position = Vector2(582, -317)
[node name="MirrorOrb" parent="." index="8" instance=ExtResource("6_87gst")]
position = Vector2(-431, -212)
[node name="EnemyMover" parent="." index="9" instance=ExtResource("8_3s3ae")]
position = Vector2(-132, 311)
[node name="Block" parent="." index="10" node_paths=PackedStringArray("ui_actions") instance=ExtResource("7_l2s1x")]
position = Vector2(-65, 63)
ui_actions = NodePath("../UILayer/UI")
[node name="Block2" parent="." index="11" node_paths=PackedStringArray("ui_actions") instance=ExtResource("7_l2s1x")]
position = Vector2(-255, -32)
scale = Vector2(0.5, 0.5)
ui_actions = NodePath("../UILayer/UI")

View file

@ -1,7 +1,8 @@
[gd_scene load_steps=5 format=3 uid="uid://snxpqx0ony7s"] [gd_scene load_steps=6 format=3 uid="uid://snxpqx0ony7s"]
[ext_resource type="Script" path="res://scripts/player_movement.gd" id="1_a6lhy"] [ext_resource type="Script" path="res://scripts/player_movement.gd" id="1_a6lhy"]
[ext_resource type="Texture2D" uid="uid://qcx482jc7pqr" path="res://textures/player.png" id="2_sscjv"] [ext_resource type="Texture2D" uid="uid://qcx482jc7pqr" path="res://textures/player.png" id="2_sscjv"]
[ext_resource type="Texture2D" uid="uid://dfvxk0e8taj1d" path="res://textures/Eye Lase.png" id="3_yg3ur"]
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_jqi2f"] [sub_resource type="CapsuleShape2D" id="CapsuleShape2D_jqi2f"]
radius = 9.0 radius = 9.0
@ -29,4 +30,12 @@ collision_mask = 2
[node name="CollisionShape2D" type="CollisionShape2D" parent="Hurtbox"] [node name="CollisionShape2D" type="CollisionShape2D" parent="Hurtbox"]
shape = SubResource("CircleShape2D_vxfel") shape = SubResource("CircleShape2D_vxfel")
[node name="data_link" type="Line2D" parent="."]
visible = false
texture_repeat = 2
points = PackedVector2Array(0, 0, 0, 0)
default_color = Color(0.298039, 1, 0.141176, 1)
texture = ExtResource("3_yg3ur")
texture_mode = 1
[connection signal="body_entered" from="Hurtbox" to="." method="_on_hurtbox_body_entered"] [connection signal="body_entered" from="Hurtbox" to="." method="_on_hurtbox_body_entered"]

View file

@ -1,10 +1,10 @@
[gd_scene load_steps=4 format=3 uid="uid://br6fngf5208j0"] [gd_scene load_steps=4 format=3 uid="uid://br6fngf5208j0"]
[ext_resource type="Texture2D" uid="uid://bplkveclkwuk" path="res://textures/block-big.png" id="1_ejp7j"] [ext_resource type="Texture2D" uid="uid://bplkveclkwuk" path="res://textures/block-blue.png" id="1_ejp7j"]
[ext_resource type="Script" path="res://scripts/resizable_block.gd" id="1_j40bu"] [ext_resource type="Script" path="res://scripts/resizable_block.gd" id="1_j40bu"]
[sub_resource type="CircleShape2D" id="CircleShape2D_h0307"] [sub_resource type="RectangleShape2D" id="RectangleShape2D_sgemy"]
radius = 35.0143 size = Vector2(59, 59)
[node name="Block" type="StaticBody2D"] [node name="Block" type="StaticBody2D"]
collision_layer = 17 collision_layer = 17
@ -16,6 +16,6 @@ script = ExtResource("1_j40bu")
texture = ExtResource("1_ejp7j") texture = ExtResource("1_ejp7j")
[node name="CollisionShape2D" type="CollisionShape2D" parent="."] [node name="CollisionShape2D" type="CollisionShape2D" parent="."]
shape = SubResource("CircleShape2D_h0307") shape = SubResource("RectangleShape2D_sgemy")
[connection signal="input_event" from="." to="." method="_on_input_event"] [connection signal="input_event" from="." to="." method="_on_input_event"]

View file

@ -0,0 +1,21 @@
[gd_scene load_steps=4 format=3 uid="uid://0jn86aogkcne"]
[ext_resource type="Script" path="res://scripts/resizable_block.gd" id="1_bulc3"]
[ext_resource type="Texture2D" uid="uid://dyl3dsoub6pmu" path="res://textures/block-small.png" id="2_42gyy"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_vlk61"]
size = Vector2(30, 30)
[node name="Block" type="StaticBody2D"]
collision_layer = 17
collision_mask = 22
input_pickable = true
script = ExtResource("1_bulc3")
[node name="Sprite2D" type="Sprite2D" parent="."]
texture = ExtResource("2_42gyy")
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
shape = SubResource("RectangleShape2D_vlk61")
[connection signal="input_event" from="." to="." method="_on_input_event"]

View file

@ -17,8 +17,8 @@ config/icon="res://icon.svg"
[display] [display]
window/size/viewport_width=1280 window/size/viewport_width=640
window/size/viewport_height=720 window/size/viewport_height=320
window/size/mode=2 window/size/mode=2
window/stretch/mode="viewport" window/stretch/mode="viewport"

View file

@ -4,17 +4,38 @@ extends CharacterBody2D
@export var gravity = 50 @export var gravity = 50
var jump_count = 1 var jump_count = 1
@export var jump_strength = 100 @export var jump_strength = 100
@export var jump_strength_max = 300
var is_touching_floor : bool = true var is_touching_floor : bool = true
var jump_buffer_timer : float var jump_buffer_timer : float
var coyote_timer : float = 0.2 # 200 millisecond buffer var coyote_timer : float = 0.2
var input_direction = 0 #To keep track of which direction we where moving in last frame var input_direction = 0
@export var max_link_distance: float = 70.0
var data_link: Line2D
var target_scale
@export var scale_duration: float = 0.5
var current_selected = "none"
var target_scale_player: Vector2 = Vector2(1, 1)
func _ready():
data_link = $data_link
func _unhandled_input(event):
if event.is_action_pressed("click"):
var nearest_block = find_nearest_block()
if nearest_block:
if nearest_block.scale == Vector2(0.5, 0.5) and self.scale == Vector2(2.0, 2.0):
nearest_block.scale_up()
scale_down_player()
elif nearest_block.scale == Vector2(1.0, 1.0) and self.scale == Vector2(1.0, 1.0):
nearest_block.scale_down()
scale_up_player()
func get_input(delta): func get_input(delta):
var left = Input.is_action_pressed("player_left") var left = Input.is_action_pressed("player_left")
var right = Input.is_action_pressed("player_right") var right = Input.is_action_pressed("player_right")
if left and right: if left and right:
input_direction = 0 input_direction = 0
elif left: elif left:
@ -23,18 +44,16 @@ func get_input(delta):
input_direction = 1 input_direction = 1
else: else:
input_direction = 0 input_direction = 0
# This line updates the player's velocity
velocity.x = input_direction * speed velocity.x = input_direction * speed
if is_on_floor(): if is_on_floor():
# reset the jump count
is_touching_floor = true is_touching_floor = true
jump_count = 1 jump_count = 1
coyote_timer = 0.2 coyote_timer = 0.2
if jump_buffer_timer > 0: if jump_buffer_timer > 0:
Jump() Jump()
if not is_on_floor(): if not is_on_floor():
if jump_buffer_timer > 0: if jump_buffer_timer > 0:
jump_buffer_timer -= delta jump_buffer_timer -= delta
@ -42,43 +61,56 @@ func get_input(delta):
coyote_timer -= delta coyote_timer -= delta
else: else:
jump_count = 0 jump_count = 0
if Input.is_action_just_pressed("player_jump"): if Input.is_action_just_pressed("player_jump"):
if jump_count > 0: if jump_count > 0:
Jump() Jump()
else: else:
jump_buffer_timer = 0.2 # set a timer to jump again once the player has reached the ground, provided the jump is is still being held down jump_buffer_timer = 0.2
elif Input.is_action_pressed("player_jump"): #Fall less fast if we keep holding the button elif Input.is_action_pressed("player_jump"):
velocity.y += -1 * 25 velocity.y += -1 * 25
func _physics_process(delta): func _physics_process(delta):
get_input(delta) get_input(delta)
velocity.y += gravity velocity.y += gravity
move_and_slide() move_and_slide()
update_data_link()
if(get_slide_collision_count() > 0):
for i in get_slide_collision_count():
var box = get_slide_collision(i).get_collider() as Box
if scale.x == 2:
if box and velocity.y >= 0:
box.velocity.x = velocity.x*0.8
else:
if box and velocity.y >= 0 and box.scale.x < 2:
box.velocity.x = velocity.x*0.8
# print(jump_count) # Uncomment for debugging
func Jump(): func Jump():
if scale.x == 1: velocity.y = -1 * jump_strength
velocity.y = -1 * jump_strength
elif scale.x == 2:
velocity.y = -1 * jump_strength_max
jump_count = 0 jump_count = 0
is_touching_floor = false is_touching_floor = false
func _on_hurtbox_body_entered(body: Node2D) -> void: func _on_hurtbox_body_entered(body: Node2D) -> void:
get_tree().reload_current_scene() get_tree().reload_current_scene()
func update_data_link():
var nearest_block = find_nearest_block()
if nearest_block:
data_link.visible = true
data_link.set_point_position(0, Vector2.ZERO)
data_link.set_point_position(1, get_transform().affine_inverse() * nearest_block.position)
else:
data_link.visible = false
func _on_area_2d_body_entered(body): func find_nearest_block() -> Node2D:
print("Body entered") var closest_distance = max_link_distance
var closest_block: Node2D = null
for block in get_tree().get_nodes_in_group("scalable_blocks"):
var distance = global_position.distance_to(block.global_position)
if distance <= closest_distance:
closest_distance = distance
closest_block = block
return closest_block
func start_scaling(target_node: Node2D, scale_value: Vector2):
var tween = create_tween()
tween.tween_property(target_node, "scale", scale_value, scale_duration)
func scale_up_player():
target_scale_player = Vector2(2.0, 2.0)
start_scaling(self, target_scale_player)
func scale_down_player():
target_scale_player = Vector2(1.0, 1.0)
start_scaling(self, target_scale_player)

View file

@ -1,28 +1,32 @@
extends StaticBody2D extends StaticBody2D
@export var scale_up_target: Vector2 = Vector2(3.0, 3.0) @export var scale_up_target: Vector2 = Vector2(1.0, 1.0)
@export var scale_down_target: Vector2 = Vector2(0.5, 0.5) @export var scale_down_target: Vector2 = Vector2(0.5, 0.5)
@export var scale_duration: float = 0.5 @export var scale_duration: float = 0.5
@export var ui_actions: Node @export var ui_actions: Node
@export var small_sprite = preload("res://textures/block-orange.png")
@export var large_sprite = preload("res://textures/block-blue.png")
func _ready(): func _ready():
if ui_actions == null: add_to_group("scalable_blocks")
ui_actions = get_parent().get_node("Path/To/UiActionsNode")
func _on_input_event(viewport, event, shape_idx): func _process(delta):
if event is InputEventMouseButton and event.pressed: change_sprite_based_on_scale()
if event.is_action_pressed("click"):
if ui_actions.current_selected == "scale_up":
scale_up()
ui_actions.scale_up_player()
elif ui_actions.current_selected == "scale_down":
scale_down()
ui_actions.scale_down_player()
func scale_up(): func scale_up():
var tween = create_tween() var tween = create_tween()
tween.tween_property(self, "scale", scale_up_target, scale_duration) tween.tween_property(self, "scale", scale_up_target, scale_duration)
change_sprite_based_on_scale()
func scale_down(): func scale_down():
var tween = create_tween() var tween = create_tween()
tween.tween_property(self, "scale", scale_down_target, scale_duration) tween.tween_property(self, "scale", scale_down_target, scale_duration)
change_sprite_based_on_scale()
func change_sprite_based_on_scale():
var sprite = $Sprite2D
if scale == Vector2(0.5, 0.5):
sprite.texture = small_sprite
elif scale == Vector2(1.0, 1.0):
sprite.texture = large_sprite

View file

@ -1,20 +1,19 @@
extends Node extends Node
@export var player: CharacterBody2D @export var player : CharacterBody2D
@export var scale_duration: float = 0.5
var current_selected = "none" var current_selected = "none"
@export var scale_duration: float = 0.5
var target_scale_player: Vector2 = Vector2(1, 1) var target_scale_player: Vector2 = Vector2(1, 1)
var target_scale_block: Vector2 = Vector2(1, 1)
func _unhandled_input(event: InputEvent) -> void: func _on_input_event(viewport, event, shape_idx):
if event.is_action_pressed("click"): if event.is_action_pressed("click"):
if current_selected == "scale_up": var nearest_block = player.find_nearest_block()
current_selected = "scale_up" if nearest_block and current_selected == "scale_up":
elif current_selected == "scale_down": nearest_block.scale_up()
current_selected = "scale_down" scale_up_player()
elif current_selected == "mirror": elif nearest_block:
mirror() nearest_block.scale_down()
scale_down_player()
func select_up(): func select_up():
current_selected = "scale_up" current_selected = "scale_up"
@ -30,11 +29,11 @@ func start_scaling(target_node: Node2D, scale_value: Vector2):
tween.tween_property(target_node, "scale", scale_value, scale_duration) tween.tween_property(target_node, "scale", scale_value, scale_duration)
func scale_up_player(): func scale_up_player():
target_scale_player = Vector2(0.5, 0.5) target_scale_player = Vector2(3.0, 3.0)
start_scaling(player, target_scale_player) start_scaling(player, target_scale_player)
func scale_down_player(): func scale_down_player():
target_scale_player = Vector2(2.0, 2.0) target_scale_player = Vector2(1.0, 1.0)
start_scaling(player, target_scale_player) start_scaling(player, target_scale_player)
func mirror(): func mirror():

Binary file not shown.

After

Width:  |  Height:  |  Size: 122 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.7 KiB

After

Width:  |  Height:  |  Size: 7.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1,012 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

View file

Before

Width:  |  Height:  |  Size: 410 B

After

Width:  |  Height:  |  Size: 410 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 412 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3 KiB

After

Width:  |  Height:  |  Size: 4 KiB