diff --git a/Assets/Graphics/Environment/Terrain/Terrain (32x32).png b/Assets/Graphics/Environment/Terrain/Terrain (32x32).png new file mode 100644 index 0000000..ddf1eaf Binary files /dev/null and b/Assets/Graphics/Environment/Terrain/Terrain (32x32).png differ diff --git a/Assets/Graphics/Environment/Terrain/Terrain (32x32).png.import b/Assets/Graphics/Environment/Terrain/Terrain (32x32).png.import new file mode 100644 index 0000000..c9ea446 --- /dev/null +++ b/Assets/Graphics/Environment/Terrain/Terrain (32x32).png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://binxtl7gl8psd" +path="res://.godot/imported/Terrain (32x32).png-baaca909196f48992c283812cbf3423f.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://Assets/Graphics/Environment/Terrain/Terrain (32x32).png" +dest_files=["res://.godot/imported/Terrain (32x32).png-baaca909196f48992c283812cbf3423f.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/Assets/Graphics/Player/IDLE/Player Idle 48x48.png b/Assets/Graphics/Player/IDLE/Player Idle 48x48.png new file mode 100644 index 0000000..b618511 Binary files /dev/null and b/Assets/Graphics/Player/IDLE/Player Idle 48x48.png differ diff --git a/Assets/Graphics/Player/IDLE/Player Idle 48x48.png.import b/Assets/Graphics/Player/IDLE/Player Idle 48x48.png.import new file mode 100644 index 0000000..0fb5bf5 --- /dev/null +++ b/Assets/Graphics/Player/IDLE/Player Idle 48x48.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://3jfrk0kpmfdg" +path="res://.godot/imported/Player Idle 48x48.png-624a4b2724cfe306a5e07b163b6a705b.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://Assets/Graphics/Player/IDLE/Player Idle 48x48.png" +dest_files=["res://.godot/imported/Player Idle 48x48.png-624a4b2724cfe306a5e07b163b6a705b.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/Assets/Graphics/Player/JUMP_FALL/player jump 48x48.png b/Assets/Graphics/Player/JUMP_FALL/player jump 48x48.png new file mode 100644 index 0000000..dff105c Binary files /dev/null and b/Assets/Graphics/Player/JUMP_FALL/player jump 48x48.png differ diff --git a/Assets/Graphics/Player/JUMP_FALL/player jump 48x48.png.import b/Assets/Graphics/Player/JUMP_FALL/player jump 48x48.png.import new file mode 100644 index 0000000..2bab132 --- /dev/null +++ b/Assets/Graphics/Player/JUMP_FALL/player jump 48x48.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://wp3aoodpllgs" +path="res://.godot/imported/player jump 48x48.png-085202161e3eba05d97d7ca845f691c9.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://Assets/Graphics/Player/JUMP_FALL/player jump 48x48.png" +dest_files=["res://.godot/imported/player jump 48x48.png-085202161e3eba05d97d7ca845f691c9.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/Assets/Graphics/Player/RUN/player run 48x48.png b/Assets/Graphics/Player/RUN/player run 48x48.png new file mode 100644 index 0000000..aca5b55 Binary files /dev/null and b/Assets/Graphics/Player/RUN/player run 48x48.png differ diff --git a/Assets/Graphics/Player/RUN/player run 48x48.png.import b/Assets/Graphics/Player/RUN/player run 48x48.png.import new file mode 100644 index 0000000..9954142 --- /dev/null +++ b/Assets/Graphics/Player/RUN/player run 48x48.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://dkkt184lbbiys" +path="res://.godot/imported/player run 48x48.png-20ae840a9789b4f9d7e549f30bad543b.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://Assets/Graphics/Player/RUN/player run 48x48.png" +dest_files=["res://.godot/imported/player run 48x48.png-20ae840a9789b4f9d7e549f30bad543b.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/Scenes/player.tscn b/Scenes/player.tscn index 3295495..867e501 100644 --- a/Scenes/player.tscn +++ b/Scenes/player.tscn @@ -1,11 +1,185 @@ -[gd_scene load_steps=3 format=3 uid="uid://c5uf1o0s4syv7"] +[gd_scene load_steps=28 format=3 uid="uid://c5uf1o0s4syv7"] [ext_resource type="Script" uid="uid://bxlrsqltut2xn" path="res://scripts/Player.gd" id="1_v0iea"] +[ext_resource type="Texture2D" uid="uid://3jfrk0kpmfdg" path="res://Assets/Graphics/Player/IDLE/Player Idle 48x48.png" id="2_cvnsp"] +[ext_resource type="Texture2D" uid="uid://wp3aoodpllgs" path="res://Assets/Graphics/Player/JUMP_FALL/player jump 48x48.png" id="2_vgqql"] +[ext_resource type="Texture2D" uid="uid://dkkt184lbbiys" path="res://Assets/Graphics/Player/RUN/player run 48x48.png" id="3_6t5aa"] [sub_resource type="CircleShape2D" id="CircleShape2D_ag0er"] +[sub_resource type="AtlasTexture" id="AtlasTexture_olqyp"] +atlas = ExtResource("2_vgqql") +region = Rect2(96, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_6t5aa"] +atlas = ExtResource("2_cvnsp") +region = Rect2(0, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_vgqql"] +atlas = ExtResource("2_cvnsp") +region = Rect2(48, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_fkybt"] +atlas = ExtResource("2_cvnsp") +region = Rect2(96, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_x3wgy"] +atlas = ExtResource("2_cvnsp") +region = Rect2(144, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_3smsa"] +atlas = ExtResource("2_cvnsp") +region = Rect2(192, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_8erm5"] +atlas = ExtResource("2_cvnsp") +region = Rect2(240, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_f1ek2"] +atlas = ExtResource("2_cvnsp") +region = Rect2(288, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_tx1dd"] +atlas = ExtResource("2_cvnsp") +region = Rect2(336, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_gymyn"] +atlas = ExtResource("2_cvnsp") +region = Rect2(384, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_pu2lt"] +atlas = ExtResource("2_cvnsp") +region = Rect2(432, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_wpjfl"] +atlas = ExtResource("2_vgqql") +region = Rect2(0, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_bi64h"] +atlas = ExtResource("2_vgqql") +region = Rect2(48, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_ukyrk"] +atlas = ExtResource("3_6t5aa") +region = Rect2(0, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_7dp3o"] +atlas = ExtResource("3_6t5aa") +region = Rect2(48, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_h4iuc"] +atlas = ExtResource("3_6t5aa") +region = Rect2(96, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_fd4e3"] +atlas = ExtResource("3_6t5aa") +region = Rect2(144, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_qqcod"] +atlas = ExtResource("3_6t5aa") +region = Rect2(192, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_igrcy"] +atlas = ExtResource("3_6t5aa") +region = Rect2(240, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_fs7ks"] +atlas = ExtResource("3_6t5aa") +region = Rect2(288, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_l6n3p"] +atlas = ExtResource("3_6t5aa") +region = Rect2(336, 0, 48, 48) + +[sub_resource type="SpriteFrames" id="SpriteFrames_ukyrk"] +animations = [{ +"frames": [{ +"duration": 1.0, +"texture": SubResource("AtlasTexture_olqyp") +}], +"loop": true, +"name": &"FALL", +"speed": 5.0 +}, { +"frames": [{ +"duration": 1.0, +"texture": SubResource("AtlasTexture_6t5aa") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_vgqql") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_fkybt") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_x3wgy") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_3smsa") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_8erm5") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_f1ek2") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_tx1dd") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_gymyn") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_pu2lt") +}], +"loop": true, +"name": &"IDLE", +"speed": 8.0 +}, { +"frames": [{ +"duration": 1.0, +"texture": SubResource("AtlasTexture_wpjfl") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_bi64h") +}], +"loop": false, +"name": &"JUMP", +"speed": 10.0 +}, { +"frames": [{ +"duration": 1.0, +"texture": SubResource("AtlasTexture_ukyrk") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_7dp3o") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_h4iuc") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_fd4e3") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_qqcod") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_igrcy") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_fs7ks") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_l6n3p") +}], +"loop": true, +"name": &"RUN", +"speed": 10.0 +}] + [node name="Player" type="CharacterBody2D"] script = ExtResource("1_v0iea") +acceleration = 10 metadata/_edit_group_ = true [node name="CollisionShape2D" type="CollisionShape2D" parent="."] @@ -23,3 +197,18 @@ position = Vector2(16, -5) [node name="BulletSpawnPointLeft" type="Node2D" parent="."] position = Vector2(-16, -5) + +[node name="jumpbuffertimer" type="Timer" parent="."] +wait_time = 0.5 +one_shot = true + +[node name="PlayerGraphic" type="AnimatedSprite2D" parent="."] +texture_filter = 1 +position = Vector2(1, -6) +sprite_frames = SubResource("SpriteFrames_ukyrk") +animation = &"JUMP" +autoplay = "IDLE" +frame = 1 +frame_progress = 1.0 + +[connection signal="animation_finished" from="PlayerGraphic" to="." method="_on_animation_finished"] diff --git a/Scenes/reallygoodgame.tscn b/Scenes/reallygoodgame.tscn index c605797..493d74e 100644 --- a/Scenes/reallygoodgame.tscn +++ b/Scenes/reallygoodgame.tscn @@ -1,13 +1,67 @@ -[gd_scene load_steps=8 format=3 uid="uid://ibkufgrwjwro"] +[gd_scene load_steps=11 format=4 uid="uid://ibkufgrwjwro"] [ext_resource type="Script" uid="uid://buhkldpol3slp" path="res://scripts/gamecontroller.gd" id="1_3d84a"] [ext_resource type="PackedScene" uid="uid://4a4u47173cyb" path="res://Scenes/trigger.tscn" id="2_lptsb"] [ext_resource type="Script" uid="uid://bo0opwq3l73ec" path="res://scripts/scene_manager.gd" id="2_t43dh"] +[ext_resource type="Texture2D" uid="uid://binxtl7gl8psd" path="res://Assets/Graphics/Environment/Terrain/Terrain (32x32).png" id="3_f0he5"] [ext_resource type="PackedScene" uid="uid://lwju71dirkcy" path="res://Scenes/Crate.tscn" id="3_u2cf2"] [ext_resource type="PackedScene" uid="uid://c5uf1o0s4syv7" path="res://Scenes/player.tscn" id="4_f0he5"] +[ext_resource type="PackedScene" uid="uid://bex5lhiuhhnq6" path="res://Scenes/static_body_2d.tscn" id="4_xqt3w"] -[sub_resource type="RectangleShape2D" id="RectangleShape2D_ag0er"] -size = Vector2(82, 20) +[sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_xqt3w"] +texture = ExtResource("3_f0he5") +texture_region_size = Vector2i(32, 32) +0:0/0 = 0 +1:0/0 = 0 +2:0/0 = 0 +4:0/0 = 0 +6:0/0 = 0 +7:0/0 = 0 +9:0/0 = 0 +10:0/0 = 0 +12:0/0 = 0 +13:0/0 = 0 +15:0/0 = 0 +0:1/0 = 0 +1:1/0 = 0 +2:1/0 = 0 +4:1/0 = 0 +6:1/0 = 0 +7:1/0 = 0 +9:1/0 = 0 +10:1/0 = 0 +12:1/0 = 0 +13:1/0 = 0 +15:1/0 = 0 +16:1/0 = 0 +0:2/0 = 0 +1:2/0 = 0 +2:2/0 = 0 +4:2/0 = 0 +6:3/0 = 0 +7:3/0 = 0 +9:3/0 = 0 +10:3/0 = 0 +12:3/0 = 0 +13:3/0 = 0 +15:3/0 = 0 +16:3/0 = 0 +0:4/0 = 0 +1:4/0 = 0 +2:4/0 = 0 +4:4/0 = 0 +6:4/0 = 0 +7:4/0 = 0 +9:4/0 = 0 +10:4/0 = 0 +12:4/0 = 0 +13:4/0 = 0 +15:4/0 = 0 +16:4/0 = 0 + +[sub_resource type="TileSet" id="TileSet_g7vkj"] +tile_size = Vector2i(32, 32) +sources/0 = SubResource("TileSetAtlasSource_xqt3w") [sub_resource type="WorldBoundaryShape2D" id="WorldBoundaryShape2D_ag0er"] @@ -18,21 +72,33 @@ script = ExtResource("1_3d84a") unique_name_in_owner = true script = ExtResource("2_t43dh") -[node name="StaticBody2D" type="StaticBody2D" parent="."] -position = Vector2(113, 130) -metadata/_edit_group_ = true +[node name="TileMapLayer" type="TileMapLayer" parent="."] +texture_filter = 1 +scale = Vector2(1.00124, 0.995921) +tile_map_data = PackedByteArray("AAACAAQAAAAAAAAAAAADAAQAAAABAAAAAAAEAAQAAAACAAAAAAAGAAQAAAAAAAAAAAAIAAQAAAACAAAAAAAHAAQAAAABAAAAAAA=") +tile_set = SubResource("TileSet_g7vkj") -[node name="CollisionShape2D" type="CollisionShape2D" parent="StaticBody2D"] -shape = SubResource("RectangleShape2D_ag0er") +[node name="StaticBody2D" parent="." instance=ExtResource("4_xqt3w")] +position = Vector2(113, 143) +scale = Vector2(1.11201, 1.40772) + +[node name="StaticBody2D2" parent="." instance=ExtResource("4_xqt3w")] +position = Vector2(240, 143) [node name="Crate1" parent="." instance=ExtResource("3_u2cf2")] -position = Vector2(128, 41) +position = Vector2(90, 106) [node name="Crate2" parent="." instance=ExtResource("3_u2cf2")] -position = Vector2(171, 73) +position = Vector2(233, 107) + +[node name="Crate" parent="." instance=ExtResource("3_u2cf2")] +position = Vector2(265, 107) + +[node name="Crate3" parent="." instance=ExtResource("3_u2cf2")] +position = Vector2(250, 84) [node name="ground" type="StaticBody2D" parent="."] -position = Vector2(186, 270) +position = Vector2(175, 236) metadata/_edit_group_ = true [node name="CollisionShape2D" type="CollisionShape2D" parent="ground"] @@ -41,7 +107,9 @@ shape = SubResource("WorldBoundaryShape2D_ag0er") [node name="Player" parent="." instance=ExtResource("4_f0he5")] position = Vector2(127, 108) -[node name="Area2D" parent="." instance=ExtResource("2_lptsb")] -position = Vector2(82, 87) +[node name="Triggers" type="Node2D" parent="."] +position = Vector2(176, 113) -[connection signal="areaTriggerSignal" from="Area2D" to="." method="_on_trigger"] +[node name="player hurt" parent="Triggers" instance=ExtResource("2_lptsb")] + +[connection signal="areaTriggerSignal" from="Triggers/player hurt" to="." method="_on_trigger"] diff --git a/Scenes/static_body_2d.tscn b/Scenes/static_body_2d.tscn new file mode 100644 index 0000000..15cc3cd --- /dev/null +++ b/Scenes/static_body_2d.tscn @@ -0,0 +1,11 @@ +[gd_scene load_steps=2 format=3 uid="uid://bex5lhiuhhnq6"] + +[sub_resource type="RectangleShape2D" id="RectangleShape2D_ag0er"] +size = Vector2(82, 20) + +[node name="StaticBody2D" type="StaticBody2D"] +scale = Vector2(1.12, 1.36) +metadata/_edit_group_ = true + +[node name="CollisionShape2D" type="CollisionShape2D" parent="."] +shape = SubResource("RectangleShape2D_ag0er") diff --git a/scripts/Player.gd b/scripts/Player.gd index fc8bedf..f48808a 100644 --- a/scripts/Player.gd +++ b/scripts/Player.gd @@ -6,23 +6,60 @@ const bullet_scene = preload("res://Scenes/bullet.tscn") @onready var left_cast: RayCast2D = $LeftCast @onready var bullet_spawn_point_right: Node2D = $BulletSpawnPointRight @onready var bullet_spawn_point_left: Node2D = $BulletSpawnPointLeft +@onready var jump_buffer_timer: Timer = $jumpbuffertimer +@onready var player_graphic: AnimatedSprite2D = $PlayerGraphic const SPEED = 300.0 const JUMP_VELOCITY = -400.0 const PUSH_POWER = 2000 +var upJump:bool = false +@export var acceleration:int=5 var direction: float enum FaceDirection{LEFT, RIGHT} var facing: FaceDirection = FaceDirection.RIGHT var pushTarget: Object var pushEnabled: bool = false - +enum State{IDLE,RUN,JUMP,FALLING} +var current_state:State = State.IDLE func _physics_process(delta: float) -> void: handle_input(delta) handle_movement(delta) + handle_states() + handle_animation() handle_collisions(delta) +func handle_states() -> void: + match current_state: + State.IDLE when velocity.x !=0: + current_state = State.RUN + State.RUN: + if velocity.x == 0: + current_state = State.IDLE + #player steps off ledge + if not is_on_floor() && velocity.y >0: + current_state = State.FALLING + State.FALLING when is_on_floor(): + if velocity.x == 0: + current_state = State.IDLE + else: + current_state = State.RUN + State.JUMP when velocity.y >0: + current_state = State.FALLING + +func handle_animation() -> void: + match current_state: + State.IDLE: + player_graphic.play("IDLE") + State.RUN: + player_graphic.play("RUN") + State.FALLING: + player_graphic.play("FALL") + State.JUMP: + if upJump: + player_graphic.play("JUMP") + func handle_input(delta: float) -> void: var dir: int = 0 match facing: @@ -33,7 +70,7 @@ func handle_input(delta: float) -> void: # Handle jump. if Input.is_action_just_pressed("ui_accept") and is_on_floor(): - velocity.y = JUMP_VELOCITY + jump_buffer_timer.start() # Get the input direction and handle the movement/deceleration. # As good practice, you should replace UI actions with custom gameplay actions. @@ -41,8 +78,10 @@ func handle_input(delta: float) -> void: if direction < 0: facing = FaceDirection.LEFT + player_graphic.flip_h = true elif direction > 0: facing = FaceDirection.RIGHT + player_graphic.flip_h = false if Input.is_action_just_pressed("ForcePush") && pushEnabled: pushTarget.apply_central_impulse(Vector2(dir, 0) * PUSH_POWER) @@ -57,10 +96,18 @@ func handle_input(delta: float) -> void: func handle_movement(delta: float) -> void: handle_gravity(delta) - if direction: - velocity.x = direction * SPEED + if direction ==0: + velocity.x = move_toward(velocity.x,0, acceleration) else: - velocity.x = move_toward(velocity.x, 0, SPEED) + velocity.x = move_toward(velocity.x, SPEED * direction, acceleration) + if not is_on_floor(): + velocity += get_gravity() * delta + if is_on_floor() && jump_buffer_timer.time_left >0: + velocity.y = JUMP_VELOCITY + jump_buffer_timer.stop() + current_state = State.JUMP + upJump = true + move_and_slide() func handle_collisions(delta: float) -> void: @@ -90,3 +137,9 @@ func handle_gravity(delta: float) -> void: # Add the gravity. if not is_on_floor(): velocity += get_gravity() * delta + + +func _on_animation_finished() -> void: + match current_state: + State.JUMP: + upJump = false diff --git a/scripts/gamecontroller.gd b/scripts/gamecontroller.gd index 5334040..39fa027 100644 --- a/scripts/gamecontroller.gd +++ b/scripts/gamecontroller.gd @@ -1,6 +1,6 @@ extends Node2D - +signal playerDamage # Called when the node enters the scene tree for the first time. func _ready() -> void: pass # Replace with function body. @@ -13,6 +13,11 @@ func _process(delta: float) -> void: func _on_trigger(effect: Variant, body: Variant) -> void: print("GC see trigger " + effect) + match effect: + "player_hurt": + if body is Player: + print("hurt the player") + playerDamage.emit() if body.name == "world-boundary": return if not body is Player: diff --git a/scripts/scene_manager.gd b/scripts/scene_manager.gd index 25a2d30..4f3223b 100644 --- a/scripts/scene_manager.gd +++ b/scripts/scene_manager.gd @@ -2,7 +2,14 @@ class_name SCENEMANAGER extends Node2D const bulletscn = preload("res://Scenes/bullet.tscn") @onready var game: Node2D = $".." +@onready var triggers: Node2D = $"../Triggers" +func _ready() -> void: + if triggers: + for obj in triggers.get_children(): + if obj is Trigger: + obj.areaTriggerSignal.connect(game._on_trigger) + var bullets: Array[Bullet] = [] const MAX_BULLETS = 10 var current_bullet = 0 diff --git a/scripts/trigger.gd b/scripts/trigger.gd index 12e784b..833ebc8 100644 --- a/scripts/trigger.gd +++ b/scripts/trigger.gd @@ -1,4 +1,4 @@ -extends Area2D +class_name Trigger extends Area2D @export var effect := "destroy"