diff --git a/project.godot b/project.godot index dbfeacb..8632594 100644 --- a/project.godot +++ b/project.godot @@ -11,11 +11,28 @@ config_version=5 [application] config/name="pDash v0.2" -run/main_scene="res://scenes/Main.tscn" +run/main_scene="res://scenes/ui/Splash.tscn" config/features=PackedStringArray("4.2", "Forward Plus") config/icon="res://icon.svg" +[autoload] + +PDash="*res://scripts/PDash.gd" + [editor] version_control/plugin_name="GitPlugin" version_control/autoload_on_startup=true + +[input] + +jump={ +"deadzone": 0.5, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":32,"key_label":0,"unicode":0,"echo":false,"script":null) +] +} +debug={ +"deadzone": 0.5, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":126,"key_label":0,"unicode":0,"echo":false,"script":null) +] +} diff --git a/scenes/Main.tscn b/scenes/Main.tscn index dbb1a4e..4b7d9ab 100644 --- a/scenes/Main.tscn +++ b/scenes/Main.tscn @@ -1,11 +1,16 @@ -[gd_scene format=3 uid="uid://bc3i3udumnh3r"] +[gd_scene load_steps=2 format=3 uid="uid://bc3i3udumnh3r"] -[node name="Main" type="Node"] +[ext_resource type="Script" path="res://scripts/Main.gd" id="1_wd8h7"] -[node name="Game" type="CanvasLayer" parent="."] +[node name="Main" type="Node2D"] +script = ExtResource("1_wd8h7") + +[node name="Game" type="Node2D" parent="."] [node name="UI" type="CanvasLayer" parent="."] +[node name="Splash" type="CanvasLayer" parent="."] + [node name="Curtains" type="CanvasLayer" parent="."] [node name="Post" type="CanvasLayer" parent="."] diff --git a/scenes/Player.tscn b/scenes/Player.tscn new file mode 100644 index 0000000..c66b47f --- /dev/null +++ b/scenes/Player.tscn @@ -0,0 +1,164 @@ +[gd_scene load_steps=14 format=3 uid="uid://cqa6qtn1lj53m"] + +[ext_resource type="Script" path="res://scripts/Player.gd" id="1_str71"] +[ext_resource type="AudioStream" uid="uid://cuyel4kvgrcov" path="res://audio/jump.wav" id="2_w5kyr"] + +[sub_resource type="ShaderMaterial" id="ShaderMaterial_3db0b"] + +[sub_resource type="Animation" id="Animation_qv6th"] +length = 0.001 +tracks/0/type = "value" +tracks/0/imported = false +tracks/0/enabled = true +tracks/0/path = NodePath("CollisionShape2D:scale") +tracks/0/interp = 1 +tracks/0/loop_wrap = true +tracks/0/keys = { +"times": PackedFloat32Array(0), +"transitions": PackedFloat32Array(1), +"update": 0, +"values": [Vector2(1, 1)] +} +tracks/1/type = "value" +tracks/1/imported = false +tracks/1/enabled = true +tracks/1/path = NodePath("CollisionShape2D:position") +tracks/1/interp = 1 +tracks/1/loop_wrap = true +tracks/1/keys = { +"times": PackedFloat32Array(0), +"transitions": PackedFloat32Array(1), +"update": 0, +"values": [Vector2(0, 0)] +} + +[sub_resource type="Animation" id="Animation_37igj"] +resource_name = "jump" +length = 0.5 +step = 0.05 +tracks/0/type = "value" +tracks/0/imported = false +tracks/0/enabled = true +tracks/0/path = NodePath("CollisionShape2D:scale") +tracks/0/interp = 1 +tracks/0/loop_wrap = true +tracks/0/keys = { +"times": PackedFloat32Array(0, 0.05, 0.15), +"transitions": PackedFloat32Array(1, 1, 1), +"update": 0, +"values": [Vector2(1, 1), Vector2(1.5, 0.5), Vector2(0.6, 1.4)] +} +tracks/1/type = "value" +tracks/1/imported = false +tracks/1/enabled = true +tracks/1/path = NodePath("CollisionShape2D:position") +tracks/1/interp = 1 +tracks/1/loop_wrap = true +tracks/1/keys = { +"times": PackedFloat32Array(0, 0.05, 0.15), +"transitions": PackedFloat32Array(1, 1, 1), +"update": 0, +"values": [Vector2(0, 0), Vector2(0, 4), Vector2(0, -4)] +} + +[sub_resource type="Animation" id="Animation_caret"] +resource_name = "land" +length = 0.5 +step = 0.05 +tracks/0/type = "value" +tracks/0/imported = false +tracks/0/enabled = true +tracks/0/path = NodePath("CollisionShape2D:scale") +tracks/0/interp = 1 +tracks/0/loop_wrap = true +tracks/0/keys = { +"times": PackedFloat32Array(0, 0.1, 0.15), +"transitions": PackedFloat32Array(1, 1, 1), +"update": 0, +"values": [Vector2(0.6, 1.4), Vector2(1.5, 0.5), Vector2(1, 1)] +} +tracks/1/type = "value" +tracks/1/imported = false +tracks/1/enabled = true +tracks/1/path = NodePath("CollisionShape2D:position") +tracks/1/interp = 1 +tracks/1/loop_wrap = true +tracks/1/keys = { +"times": PackedFloat32Array(0, 0.1, 0.15), +"transitions": PackedFloat32Array(1, 1, 1), +"update": 0, +"values": [Vector2(0, -4), Vector2(0, 4), Vector2(0, 0)] +} + +[sub_resource type="AnimationLibrary" id="AnimationLibrary_x6ekt"] +_data = { +"RESET": SubResource("Animation_qv6th"), +"jump": SubResource("Animation_37igj"), +"land": SubResource("Animation_caret") +} + +[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_pnajy"] +radius = 4.0 +height = 16.0 + +[sub_resource type="CanvasItemMaterial" id="CanvasItemMaterial_oeovl"] + +[sub_resource type="Curve" id="Curve_v0kkc"] +_data = [Vector2(0, 0), 0.0, 0.0, 0, 0, Vector2(0.14486, 1), 0.0, 0.0, 0, 0, Vector2(1, 0), 0.0, 0.0, 0, 0] +point_count = 3 + +[sub_resource type="CurveTexture" id="CurveTexture_k65h6"] +curve = SubResource("Curve_v0kkc") + +[sub_resource type="ParticleProcessMaterial" id="ParticleProcessMaterial_fswit"] +particle_flag_disable_z = true +gravity = Vector3(0, 98, 0) +scale_min = 4.0 +scale_max = 4.0 +alpha_curve = SubResource("CurveTexture_k65h6") +turbulence_noise_strength = 10.49 +turbulence_noise_scale = 50.0 +sub_emitter_keep_velocity = true + +[sub_resource type="PrismMesh" id="PrismMesh_43iim"] +lightmap_size_hint = Vector2i(14, 21) +size = Vector3(2, 2, 0) + +[node name="Player" type="CharacterBody2D"] +material = SubResource("ShaderMaterial_3db0b") +collision_layer = 3 +collision_mask = 3 +script = ExtResource("1_str71") +metadata/_edit_group_ = true +metadata/_edit_horizontal_guides_ = [8.0] + +[node name="AnimationPlayer" type="AnimationPlayer" parent="."] +deterministic = true +libraries = { +"": SubResource("AnimationLibrary_x6ekt") +} + +[node name="AudioStreamPlayer" type="AudioStreamPlayer" parent="."] +stream = ExtResource("2_w5kyr") + +[node name="CollisionShape2D" type="CollisionShape2D" parent="."] +shape = SubResource("CapsuleShape2D_pnajy") + +[node name="GPUParticles2D" type="GPUParticles2D" parent="CollisionShape2D"] +material = SubResource("CanvasItemMaterial_oeovl") +position = Vector2(0, -4) +process_material = SubResource("ParticleProcessMaterial_fswit") +lifetime = 0.5 +trail_lifetime = 3.78 +trail_sections = 48 +trail_section_subdivisions = 1 + +[node name="MeshInstance2D" type="MeshInstance2D" parent="CollisionShape2D"] +rotation = -3.14159 +scale = Vector2(8, 8) +mesh = SubResource("PrismMesh_43iim") + +[node name="Camera2D" type="Camera2D" parent="."] +limit_smoothed = true +position_smoothing_enabled = true +rotation_smoothing_enabled = true diff --git a/scenes/levels/Level.gd b/scenes/levels/Level.gd new file mode 100644 index 0000000..e69fb94 --- /dev/null +++ b/scenes/levels/Level.gd @@ -0,0 +1,10 @@ +extends Node2D + +@export var dir: int + +# Called when the node enters the scene tree for the first time. +func _ready(): + pass # Replace with function body. +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta): + pass diff --git a/scenes/levels/level_0.tscn b/scenes/levels/level_0.tscn index 744e57a..d950340 100644 --- a/scenes/levels/level_0.tscn +++ b/scenes/levels/level_0.tscn @@ -1,8 +1,9 @@ -[gd_scene load_steps=6 format=3 uid="uid://bhoqj8b4oxyks"] +[gd_scene load_steps=7 format=3 uid="uid://bhoqj8b4oxyks"] -[ext_resource type="PackedScene" uid="uid://dn0lboldm331y" path="res://scenes/modules/platform_02.tscn" id="1_kka3y"] -[ext_resource type="Script" path="res://scripts/null.gd" id="2_0yetm"] -[ext_resource type="PackedScene" uid="uid://cuefds30ddne1" path="res://scenes/modules/platform_00.tscn" id="4_wje6l"] +[ext_resource type="PackedScene" uid="uid://dn0lboldm331y" path="res://scenes/modules/platform_02.tscn" id="1_cbvrq"] +[ext_resource type="Script" path="res://scenes/levels/Level.gd" id="1_qbkcb"] +[ext_resource type="PackedScene" uid="uid://cuefds30ddne1" path="res://scenes/modules/platform_00.tscn" id="2_jkfr1"] +[ext_resource type="Script" path="res://scripts/null.gd" id="3_m83jh"] [sub_resource type="RectangleShape2D" id="RectangleShape2D_7hfyn"] @@ -11,57 +12,62 @@ size = Vector2(7318, 557) [node name="Level" type="Node2D"] position = Vector2(0, 96) +script = ExtResource("1_qbkcb") +dir = 1 [node name="SpawnPoint" type="Node2D" parent="."] [node name="Platforms" type="CanvasGroup" parent="."] -[node name="Platform_26" parent="Platforms" instance=ExtResource("1_kka3y")] +[node name="Platform_26" parent="Platforms" instance=ExtResource("1_cbvrq")] position = Vector2(28, 60) -[node name="Platform_27" parent="Platforms" instance=ExtResource("1_kka3y")] +[node name="Platform_27" parent="Platforms" instance=ExtResource("1_cbvrq")] position = Vector2(328, 60) -[node name="Platform_28" parent="Platforms" instance=ExtResource("1_kka3y")] +[node name="Platform_28" parent="Platforms" instance=ExtResource("1_cbvrq")] position = Vector2(674, 60) -[node name="Platform_29" parent="Platforms" instance=ExtResource("1_kka3y")] +[node name="Platform_29" parent="Platforms" instance=ExtResource("1_cbvrq")] position = Vector2(1079, 139) -[node name="Platform_31" parent="Platforms" instance=ExtResource("1_kka3y")] +[node name="Platform_31" parent="Platforms" instance=ExtResource("1_cbvrq")] position = Vector2(1629, 139) -[node name="Platform_30" parent="Platforms" instance=ExtResource("1_kka3y")] +[node name="Platform_30" parent="Platforms" instance=ExtResource("1_cbvrq")] position = Vector2(2870, 59) -[node name="Platform_25" parent="Platforms" instance=ExtResource("1_kka3y")] +[node name="Platform_25" parent="Platforms" instance=ExtResource("1_cbvrq")] modulate = Color(0.00784314, 0.490196, 0, 1) position = Vector2(3755, 149) -[node name="Platform_00" parent="Platforms" instance=ExtResource("4_wje6l")] +[node name="Platform_00" parent="Platforms" instance=ExtResource("2_jkfr1")] position = Vector2(1079, 60) -[node name="Platform_09" parent="Platforms" instance=ExtResource("4_wje6l")] +[node name="Platform_09" parent="Platforms" instance=ExtResource("2_jkfr1")] position = Vector2(1629, 60) -[node name="Platform_10" parent="Platforms" instance=ExtResource("4_wje6l")] +[node name="Platform_10" parent="Platforms" instance=ExtResource("2_jkfr1")] position = Vector2(1904, 60) -[node name="Platform_01" parent="Platforms" instance=ExtResource("4_wje6l")] +[node name="Platform_01" parent="Platforms" instance=ExtResource("2_jkfr1")] position = Vector2(1354, 60) -[node name="Platform_06" parent="Platforms" instance=ExtResource("4_wje6l")] +[node name="Platform_06" parent="Platforms" instance=ExtResource("2_jkfr1")] position = Vector2(2217, 59) -[node name="Platform_07" parent="Platforms" instance=ExtResource("4_wje6l")] +[node name="Platform_07" parent="Platforms" instance=ExtResource("2_jkfr1")] position = Vector2(2492, 59) +[node name="Platform_32" parent="Platforms" instance=ExtResource("1_cbvrq")] +position = Vector2(3287, 59) + [node name="Checkpoints" type="CanvasGroup" parent="."] [node name="End" type="Area2D" parent="Checkpoints"] position = Vector2(3755, 128) scale = Vector2(16.672, 1) -script = ExtResource("2_0yetm") +script = ExtResource("3_m83jh") metadata/_edit_group_ = true [node name="CollisionShape2D" type="CollisionShape2D" parent="Checkpoints/End"] @@ -89,6 +95,3 @@ shape = SubResource("RectangleShape2D_0f50m") [node name="Direction" type="Node2D" parent="Switches"] [node name="Gravity" type="Node2D" parent="Switches"] - -[node name="Platform_30" parent="." instance=ExtResource("1_kka3y")] -position = Vector2(3287, 59) diff --git a/scenes/main.tscn b/scenes/main.tscn deleted file mode 100644 index dbb1a4e..0000000 --- a/scenes/main.tscn +++ /dev/null @@ -1,11 +0,0 @@ -[gd_scene format=3 uid="uid://bc3i3udumnh3r"] - -[node name="Main" type="Node"] - -[node name="Game" type="CanvasLayer" parent="."] - -[node name="UI" type="CanvasLayer" parent="."] - -[node name="Curtains" type="CanvasLayer" parent="."] - -[node name="Post" type="CanvasLayer" parent="."] diff --git a/scenes/ui/Splash.tscn b/scenes/ui/Splash.tscn new file mode 100644 index 0000000..e8455ee --- /dev/null +++ b/scenes/ui/Splash.tscn @@ -0,0 +1,116 @@ +[gd_scene load_steps=9 format=3 uid="uid://dvt585i7m0286"] + +[ext_resource type="Script" path="res://scripts/tools/between2.gd" id="1_o5ti7"] +[ext_resource type="Script" path="res://scripts/Splash.gd" id="1_tnoah"] +[ext_resource type="PackedScene" uid="uid://bc3i3udumnh3r" path="res://scenes/Main.tscn" id="2_dq85p"] +[ext_resource type="Texture2D" uid="uid://cihjayxr028j3" path="res://icon.svg" id="2_fpfqa"] +[ext_resource type="PackedScene" uid="uid://dfqspackuotur" path="res://scenes/ui/fade.tscn" id="4_hn3xu"] + +[sub_resource type="Animation" id="Animation_sdvqp"] +length = 0.001 +tracks/0/type = "bezier" +tracks/0/imported = false +tracks/0/enabled = true +tracks/0/path = NodePath("Logo:weight") +tracks/0/interp = 1 +tracks/0/loop_wrap = true +tracks/0/keys = { +"handle_modes": PackedInt32Array(0), +"points": PackedFloat32Array(0.5, -0.25, 0, 0.25, 0), +"times": PackedFloat32Array(0) +} +tracks/1/type = "value" +tracks/1/imported = false +tracks/1/enabled = true +tracks/1/path = NodePath("Black:color") +tracks/1/interp = 1 +tracks/1/loop_wrap = true +tracks/1/keys = { +"times": PackedFloat32Array(0), +"transitions": PackedFloat32Array(1), +"update": 0, +"values": [Color(0, 0, 0, 1)] +} + +[sub_resource type="Animation" id="Animation_2v5v3"] +resource_name = "animation" +length = 3.0 +tracks/0/type = "bezier" +tracks/0/imported = false +tracks/0/enabled = true +tracks/0/path = NodePath("Logo:weight") +tracks/0/interp = 1 +tracks/0/loop_wrap = true +tracks/0/keys = { +"handle_modes": PackedInt32Array(0, 0, 0, 0), +"points": PackedFloat32Array(0, -0.25, 0, 0.0947368, 0.323529, 0.5, -0.366629, 0.00130719, 0.25, 0, 0.5, -0.25, 0, 0.25, 0, 1, -0.105263, -0.344444, 0.25, 0), +"times": PackedFloat32Array(0.5, 1, 2, 2.5) +} +tracks/1/type = "value" +tracks/1/imported = false +tracks/1/enabled = true +tracks/1/path = NodePath("Black:color") +tracks/1/interp = 1 +tracks/1/loop_wrap = true +tracks/1/keys = { +"times": PackedFloat32Array(0, 0.5, 2.5, 3), +"transitions": PackedFloat32Array(1, 1, 1, 1), +"update": 0, +"values": [Color(0, 0, 0, 1), Color(0, 0, 0, 0), Color(0, 0, 0, 0), Color(0, 0, 0, 1)] +} + +[sub_resource type="AnimationLibrary" id="AnimationLibrary_sansa"] +_data = { +"RESET": SubResource("Animation_sdvqp"), +"animation": SubResource("Animation_2v5v3") +} + +[node name="Main" type="CanvasLayer"] +follow_viewport_enabled = true +script = ExtResource("1_tnoah") +res = ExtResource("2_dq85p") +metadata/_edit_use_anchors_ = true + +[node name="in" type="Control" parent="."] +layout_mode = 3 +anchors_preset = 4 +anchor_top = 0.5 +anchor_bottom = 0.5 +grow_vertical = 2 + +[node name="out" type="Control" parent="."] +layout_mode = 3 +anchors_preset = 6 +anchor_left = 1.0 +anchor_top = 0.5 +anchor_right = 1.0 +anchor_bottom = 0.5 +grow_horizontal = 0 +grow_vertical = 2 +metadata/_edit_use_anchors_ = true + +[node name="Logo" type="Control" parent="."] +layout_mode = 3 +anchors_preset = 0 +grow_horizontal = 2 +grow_vertical = 2 +rotation = -6.28318 +script = ExtResource("1_o5ti7") +weight = 0.5 + +[node name="TextureRect" type="TextureRect" parent="Logo"] +layout_mode = 0 +offset_left = -96.0 +offset_top = -96.0 +offset_right = 96.0 +offset_bottom = 96.0 +texture = ExtResource("2_fpfqa") + +[node name="Black" parent="." instance=ExtResource("4_hn3xu")] +script = null + +[node name="AnimationPlayer" type="AnimationPlayer" parent="."] +libraries = { +"": SubResource("AnimationLibrary_sansa") +} +autoplay = "animation" diff --git a/scenes/ui/fade.tscn b/scenes/ui/fade.tscn new file mode 100644 index 0000000..0941cac --- /dev/null +++ b/scenes/ui/fade.tscn @@ -0,0 +1,81 @@ +[gd_scene load_steps=6 format=3 uid="uid://dfqspackuotur"] + +[ext_resource type="Script" path="res://scripts/tools/fade.gd" id="1_i8eyl"] + +[sub_resource type="Animation" id="Animation_7acmb"] +length = 0.001 +tracks/0/type = "value" +tracks/0/imported = false +tracks/0/enabled = true +tracks/0/path = NodePath(".:modulate") +tracks/0/interp = 1 +tracks/0/loop_wrap = true +tracks/0/keys = { +"times": PackedFloat32Array(0), +"transitions": PackedFloat32Array(1), +"update": 0, +"values": [Color(1, 1, 1, 1)] +} + +[sub_resource type="Animation" id="Animation_iqj70"] +resource_name = "fade_in" +tracks/0/type = "value" +tracks/0/imported = false +tracks/0/enabled = true +tracks/0/path = NodePath(".:modulate") +tracks/0/interp = 1 +tracks/0/loop_wrap = true +tracks/0/keys = { +"times": PackedFloat32Array(0, 1), +"transitions": PackedFloat32Array(1, 1), +"update": 0, +"values": [Color(1, 1, 1, 1), Color(1, 1, 1, 0)] +} +tracks/1/type = "method" +tracks/1/imported = false +tracks/1/enabled = true +tracks/1/path = NodePath(".") +tracks/1/interp = 1 +tracks/1/loop_wrap = true +tracks/1/keys = { +"times": PackedFloat32Array(), +"transitions": PackedFloat32Array(), +"values": [] +} + +[sub_resource type="Animation" id="Animation_x5jw3"] +resource_name = "fade_out" +tracks/0/type = "value" +tracks/0/imported = false +tracks/0/enabled = true +tracks/0/path = NodePath(".:modulate") +tracks/0/interp = 1 +tracks/0/loop_wrap = true +tracks/0/keys = { +"times": PackedFloat32Array(0, 1), +"transitions": PackedFloat32Array(1, 1), +"update": 0, +"values": [Color(1, 1, 1, 0), Color(1, 1, 1, 1)] +} + +[sub_resource type="AnimationLibrary" id="AnimationLibrary_ejj8p"] +_data = { +"RESET": SubResource("Animation_7acmb"), +"fade_in": SubResource("Animation_iqj70"), +"fade_out": SubResource("Animation_x5jw3") +} + +[node name="Black" type="ColorRect"] +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +mouse_filter = 2 +color = Color(0, 0, 0, 1) +script = ExtResource("1_i8eyl") + +[node name="AnimationPlayer" type="AnimationPlayer" parent="."] +libraries = { +"": SubResource("AnimationLibrary_ejj8p") +} diff --git a/scripts/Main.gd b/scripts/Main.gd new file mode 100644 index 0000000..31987ee --- /dev/null +++ b/scripts/Main.gd @@ -0,0 +1,38 @@ +extends Node2D + +var G: Node2D +var L: Node2D +var P: CharacterBody2D + +var curr_lives: int = PDash.STARTING_LIVES +var curr_lvl: int = 1 + +func load_lvl( lvl_index: int ): + var lvl_path = PDash.lvl_paths[ lvl_index-1 ] + var lvl: Node = load( lvl_path ).instantiate() + G.add_child( lvl ) + L = $Game/Level + +func load_plyr(): + var plyr = load("res://scenes/Player.tscn").instantiate() + G.add_child( plyr ) + P = $Game/Player + +func init_plyr(): + P.set_gravity_vector( Vector2(0,1) ) + +# Called when the node enters the scene tree for the first time. +func _ready(): + G = $Game + + PDash.fade( "in" , 1 ) + + load_lvl(curr_lvl) + load_plyr() + init_plyr() + + + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta): + pass diff --git a/scripts/PDash.gd b/scripts/PDash.gd new file mode 100644 index 0000000..38c1b1c --- /dev/null +++ b/scripts/PDash.gd @@ -0,0 +1,30 @@ +extends Node + +var game_name: String = "pDash" +var game_version: float = 0.1 + +## Resources +var lvl_paths: Array[String] = [ + "res://scenes/levels/level_0.tscn", + "res://scenes/levels/level_1.tscn" +] + +## Variables +const STARTING_LIVES: int = 3 + +## Preferences +var show_splash: bool = false + +func fade( type: String , t: float ): + var fade = load("res://scenes/ui/fade.tscn").instantiate(); + if type == "in": + fade.type = 0 + elif type == "out": + fade.type = 1 + fade.speed = 1/t + get_node("/root/Main/Curtains").add_child( fade ) + +func splash(): + var splash = load("res://scenes/ui/Splash.tscn").instantiate(); + get_node("/root/Main/Splash").add_child( splash ) + await splash.get_node("AnimationPlayer").animation_finished diff --git a/scripts/Player.gd b/scripts/Player.gd new file mode 100644 index 0000000..dfc9cc1 --- /dev/null +++ b/scripts/Player.gd @@ -0,0 +1,89 @@ +extends CharacterBody2D + +const SPEED = 300 +const JUMP_VELOCITY = -400.0 +const ANGULAR_ACCELERATION = 7.5; + +var gravity = ProjectSettings.get_setting("physics/2d/default_gravity") +var gravity_vector: Vector2 +var direction: int = 1 +var World: Node2D +var ap: AnimationPlayer +var asp: AudioStreamPlayer +var cam: Camera2D + +var jumping: bool = false +var lives: int = 3 + +var jump_sound = preload("res://audio/jump.wav") +var land_sound = preload("res://audio/land.wav") +var fall_sound = preload("res://audio/fall.wav") +var switch_direction_sound = preload("res://audio/switch_direction.wav") + + +func switch_direction(): + velocity.x *= -1 + set_direction( direction * -1 ) + asp.stream = switch_direction_sound + asp.play() + +func _ready(): + ap = $AnimationPlayer; + asp = $AudioStreamPlayer; + + +## Setters +func set_direction( d: int ): + direction = d + +func set_gravity_vector( gv: Vector2 ): + gravity_vector = gv + +func _physics_process(delta): + + if Input.is_action_just_pressed("debug"): + switch_direction() + #if direction != World.direction: + #swap_direction() + + # Add the gravity. + self.up_direction = -gravity_vector; + $CollisionShape2D.skew = lerp( $CollisionShape2D.skew, (.001) * self.velocity.x * sin(gravity_vector.angle()) , delta * ANGULAR_ACCELERATION ) + self.rotation = lerp( self.rotation , -gravity_vector.angle() + (.5*PI) , delta * ANGULAR_ACCELERATION ) ; + + + if not is_on_floor(): + velocity.y += gravity * (sin(gravity_vector.angle())) * delta + velocity.x += gravity * (cos(gravity_vector.angle())) * delta + else: + # Handle jump. + + if jumping: + jumping = false + ap.play("land") + asp.stream = land_sound + asp.play() + + + if Input.is_action_just_pressed("jump") and is_on_floor(): + #velocity.x = JUMP_VELOCITY * cos(jump_vector.angle()) + jumping = true + ap.play("jump") + asp.stream = jump_sound + asp.play() + + velocity.y = JUMP_VELOCITY * sin(gravity_vector.angle()) + + if direction != 0: + velocity.x = direction * SPEED + else: + velocity.x = move_toward(velocity.x, 0, SPEED) + + move_and_slide() + +func _on_activate_camera(): + cam.make_current() + +func _on_fall(): + asp.stream = fall_sound + asp.play() diff --git a/scripts/Splash.gd b/scripts/Splash.gd new file mode 100644 index 0000000..fa19853 --- /dev/null +++ b/scripts/Splash.gd @@ -0,0 +1,12 @@ +extends CanvasLayer +@export var res: Resource + +func _ready(): + if PDash.show_splash: + await $AnimationPlayer.animation_finished + get_tree().change_scene_to_packed( res ) + #queue_free() + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta): + pass diff --git a/scripts/tools/between2.gd b/scripts/tools/between2.gd new file mode 100644 index 0000000..8c668a4 --- /dev/null +++ b/scripts/tools/between2.gd @@ -0,0 +1,17 @@ +extends Control +var in_p : Vector2 +var out_p : Vector2 +var width : float +@export var weight : float + +# Called when the node enters the scene tree for the first time. +func _ready(): + in_p = $"../in".position + out_p = $"../out".position + width = $TextureRect.texture.get_size().x + + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta): + position = lerp(in_p -Vector2( width ,0 ), out_p +Vector2( width ,0 ),weight) + pass diff --git a/scripts/tools/fade.gd b/scripts/tools/fade.gd new file mode 100644 index 0000000..060ae69 --- /dev/null +++ b/scripts/tools/fade.gd @@ -0,0 +1,19 @@ +extends ColorRect +@export var type: int = 0 +@export var speed: float = 1 + +# Called when the node enters the scene tree for the first time. + +func _ready(): + if type == 0: + $AnimationPlayer.play("fade_in") + elif type == 1: + $AnimationPlayer.play("fade_out") + + $AnimationPlayer.speed_scale = speed + await $AnimationPlayer.animation_finished + queue_free() + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta): + pass