diff --git a/Godot/Code/Character.gd b/Godot/Code/Character.gd index 1fd11a4..c05b2ee 100644 --- a/Godot/Code/Character.gd +++ b/Godot/Code/Character.gd @@ -1,18 +1,61 @@ extends CharacterBody2D -var gravity = 15 +var gravity = 800 +const SPEED = 60.0 +const JUMP_VELOCITY = -400.0 +@onready var sprite = $Sprites + +var land_time = 0 +var jumping = false +var side = 1 func _physics_process(delta): - if !is_on_floor(): - velocity.y += 15 + if not is_on_floor(): + velocity.y += gravity * delta + elif jumping: + jumping = false + sprite.play("Land") + land_time = 0.33 + + if Input.is_action_just_pressed("ui_accept") and is_on_floor(): + velocity.y = JUMP_VELOCITY + sprite.play("Jump") + jumping = true + sprite.pause() + sprite.set_frame_and_progress(0, 0) + + if jumping: + if velocity.y > 50: + sprite.set_frame_and_progress(2,0) + elif velocity.y > -150: + sprite.set_frame_and_progress(1, 0) + + var speed = SPEED + if Input.is_key_pressed(KEY_SHIFT): + speed *= 3 + var direction = Input.get_axis("ui_left", "ui_right") + if direction: + velocity.x = direction * speed + else: + velocity.x = move_toward(velocity.x, 0, speed) + if direction != 0: + sprite.flip_h = direction == -1 + + + + if land_time >= 0: + land_time -= delta + + # If shift left/right then 2 * speed, play run + if land_time <= 0 and not jumping: + if velocity.x != 0: + if Input.is_key_pressed(KEY_SHIFT): + sprite.play("Run") + else: + sprite.play("Walk") + else: + sprite.play("Idle") + + + move_and_slide() - $AnimationPlayer.play('Idle') - -# 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/Godot/Scenes/Main.tscn b/Godot/Scenes/Main.tscn index 82ae48e..ebdf85b 100644 --- a/Godot/Scenes/Main.tscn +++ b/Godot/Scenes/Main.tscn @@ -1,6 +1,6 @@ [gd_scene load_steps=4 format=3 uid="uid://dr8vg4b1eh6i"] -[ext_resource type="PackedScene" uid="uid://dv08bvquqpc8d" path="res://Scenes/Player.tscn" id="1_ibeo8"] +[ext_resource type="PackedScene" uid="uid://bjc6dwxaakqdg" path="res://Scenes/Player.tscn" id="1_ibeo8"] [sub_resource type="QuadMesh" id="QuadMesh_n5vip"] @@ -10,7 +10,7 @@ size = Vector2(300, 20) [node name="Node2D" type="Node2D"] [node name="Player" parent="." instance=ExtResource("1_ibeo8")] -position = Vector2(80, 82) +position = Vector2(163, 99) [node name="StaticBody2D" type="StaticBody2D" parent="."] position = Vector2(198, 184) diff --git a/Godot/Scenes/Player.tscn b/Godot/Scenes/Player.tscn index 4e3ee85..4ed252a 100644 --- a/Godot/Scenes/Player.tscn +++ b/Godot/Scenes/Player.tscn @@ -1,236 +1,296 @@ -[gd_scene load_steps=13 format=3 uid="uid://dv08bvquqpc8d"] +[gd_scene load_steps=44 format=3 uid="uid://bjc6dwxaakqdg"] -[ext_resource type="Texture2D" uid="uid://wfwjlevruveu" path="res://Import/Sprites/Character Idle 48x48.png" id="1_7u4sn"] -[ext_resource type="Texture2D" uid="uid://bge22c82umdui" path="res://Import/Sprites/PlayerWalk 48x48.png" id="1_h6xei"] -[ext_resource type="Script" path="res://Code/Character.gd" id="1_v1ece"] -[ext_resource type="Texture2D" uid="uid://8ikuchoh7pyd" path="res://Import/Sprites/player jump 48x48.png" id="3_ye2je"] -[ext_resource type="Texture2D" uid="uid://y8syonuki304" path="res://Import/Sprites/run cycle 48x48.png" id="4_2cq86"] +[ext_resource type="Script" path="res://Code/Character.gd" id="1_23c20"] +[ext_resource type="Texture2D" uid="uid://wfwjlevruveu" path="res://Import/Sprites/Character Idle 48x48.png" id="2_8h572"] +[ext_resource type="Texture2D" uid="uid://bge22c82umdui" path="res://Import/Sprites/PlayerWalk 48x48.png" id="3_xxdqr"] +[ext_resource type="Texture2D" uid="uid://y8syonuki304" path="res://Import/Sprites/run cycle 48x48.png" id="4_rqcgh"] +[ext_resource type="Texture2D" uid="uid://8ikuchoh7pyd" path="res://Import/Sprites/player jump 48x48.png" id="5_f2sni"] +[ext_resource type="Texture2D" uid="uid://diiqvgeqnmn1c" path="res://Import/Sprites/player land 48x48.png" id="6_ba2s3"] -[sub_resource type="Animation" id="Animation_vrt4p"] -resource_name = "Idle" -length = 1.3 -step = 0.05 -tracks/0/type = "value" -tracks/0/imported = false -tracks/0/enabled = true -tracks/0/path = NodePath(".:texture") -tracks/0/interp = 1 -tracks/0/loop_wrap = true -tracks/0/keys = { -"times": PackedFloat32Array(0), -"transitions": PackedFloat32Array(1), -"update": 1, -"values": [ExtResource("1_7u4sn")] -} -tracks/1/type = "value" -tracks/1/imported = false -tracks/1/enabled = true -tracks/1/path = NodePath(".:hframes") -tracks/1/interp = 1 -tracks/1/loop_wrap = true -tracks/1/keys = { -"times": PackedFloat32Array(0), -"transitions": PackedFloat32Array(1), -"update": 1, -"values": [10] -} -tracks/2/type = "value" -tracks/2/imported = false -tracks/2/enabled = true -tracks/2/path = NodePath(".:frame") -tracks/2/interp = 1 -tracks/2/loop_wrap = true -tracks/2/keys = { -"times": PackedFloat32Array(0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8), -"transitions": PackedFloat32Array(1, 1, 1, 1, 1, 1, 1, 1, 1), -"update": 1, -"values": [0, 1, 2, 3, 4, 5, 5, 6, 7] -} +[sub_resource type="AtlasTexture" id="AtlasTexture_t3ih3"] +atlas = ExtResource("2_8h572") +region = Rect2(0, 0, 48, 48) -[sub_resource type="Animation" id="Animation_2yfkp"] -resource_name = "Jump" -tracks/0/type = "value" -tracks/0/imported = false -tracks/0/enabled = true -tracks/0/path = NodePath(".:texture") -tracks/0/interp = 1 -tracks/0/loop_wrap = true -tracks/0/keys = { -"times": PackedFloat32Array(0), -"transitions": PackedFloat32Array(1), -"update": 1, -"values": [ExtResource("3_ye2je")] -} -tracks/1/type = "value" -tracks/1/imported = false -tracks/1/enabled = true -tracks/1/path = NodePath(".:hframes") -tracks/1/interp = 1 -tracks/1/loop_wrap = true -tracks/1/keys = { -"times": PackedFloat32Array(0), -"transitions": PackedFloat32Array(1), -"update": 1, -"values": [3] -} -tracks/2/type = "value" -tracks/2/imported = false -tracks/2/enabled = true -tracks/2/path = NodePath(".:frame") -tracks/2/interp = 1 -tracks/2/loop_wrap = true -tracks/2/keys = { -"times": PackedFloat32Array(0, 0.1, 0.2), -"transitions": PackedFloat32Array(1, 1, 1), -"update": 1, -"values": [0, 1, 2] -} +[sub_resource type="AtlasTexture" id="AtlasTexture_s5g6o"] +atlas = ExtResource("2_8h572") +region = Rect2(48, 0, 48, 48) -[sub_resource type="Animation" id="Animation_1l7dh"] -length = 0.001 -tracks/0/type = "value" -tracks/0/imported = false -tracks/0/enabled = true -tracks/0/path = NodePath(".:frame") -tracks/0/interp = 1 -tracks/0/loop_wrap = true -tracks/0/keys = { -"times": PackedFloat32Array(0), -"transitions": PackedFloat32Array(1), -"update": 1, -"values": [0] -} -tracks/1/type = "value" -tracks/1/imported = false -tracks/1/enabled = true -tracks/1/path = NodePath(".:texture") -tracks/1/interp = 1 -tracks/1/loop_wrap = true -tracks/1/keys = { -"times": PackedFloat32Array(0), -"transitions": PackedFloat32Array(1), -"update": 1, -"values": [ExtResource("1_h6xei")] -} -tracks/2/type = "value" -tracks/2/imported = false -tracks/2/enabled = true -tracks/2/path = NodePath(".:hframes") -tracks/2/interp = 1 -tracks/2/loop_wrap = true -tracks/2/keys = { -"times": PackedFloat32Array(0), -"transitions": PackedFloat32Array(1), -"update": 1, -"values": [10] -} +[sub_resource type="AtlasTexture" id="AtlasTexture_b6frn"] +atlas = ExtResource("2_8h572") +region = Rect2(96, 0, 48, 48) -[sub_resource type="Animation" id="Animation_oejr4"] -resource_name = "Run" -length = 0.75 -tracks/0/type = "value" -tracks/0/imported = false -tracks/0/enabled = true -tracks/0/path = NodePath(".:texture") -tracks/0/interp = 1 -tracks/0/loop_wrap = true -tracks/0/keys = { -"times": PackedFloat32Array(0), -"transitions": PackedFloat32Array(1), -"update": 1, -"values": [ExtResource("4_2cq86")] -} -tracks/1/type = "value" -tracks/1/imported = false -tracks/1/enabled = true -tracks/1/path = NodePath(".:hframes") -tracks/1/interp = 1 -tracks/1/loop_wrap = true -tracks/1/keys = { -"times": PackedFloat32Array(0), -"transitions": PackedFloat32Array(1), -"update": 1, -"values": [8] -} -tracks/2/type = "value" -tracks/2/imported = false -tracks/2/enabled = true -tracks/2/path = NodePath(".:frame") -tracks/2/interp = 1 -tracks/2/loop_wrap = true -tracks/2/keys = { -"times": PackedFloat32Array(0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7), -"transitions": PackedFloat32Array(1, 1, 1, 1, 1, 1, 1, 1), -"update": 1, -"values": [0, 1, 2, 3, 4, 5, 6, 7] -} +[sub_resource type="AtlasTexture" id="AtlasTexture_kmcgv"] +atlas = ExtResource("2_8h572") +region = Rect2(144, 0, 48, 48) -[sub_resource type="Animation" id="Animation_dl063"] -resource_name = "Walk" -tracks/0/type = "value" -tracks/0/imported = false -tracks/0/enabled = true -tracks/0/path = NodePath(".:texture") -tracks/0/interp = 1 -tracks/0/loop_wrap = true -tracks/0/keys = { -"times": PackedFloat32Array(0), -"transitions": PackedFloat32Array(1), -"update": 1, -"values": [ExtResource("1_h6xei")] -} -tracks/1/type = "value" -tracks/1/imported = false -tracks/1/enabled = true -tracks/1/path = NodePath(".:hframes") -tracks/1/interp = 1 -tracks/1/loop_wrap = true -tracks/1/keys = { -"times": PackedFloat32Array(0), -"transitions": PackedFloat32Array(1), -"update": 1, -"values": [8] -} -tracks/2/type = "value" -tracks/2/imported = false -tracks/2/enabled = true -tracks/2/path = NodePath(".:frame") -tracks/2/interp = 1 -tracks/2/loop_wrap = true -tracks/2/keys = { -"times": PackedFloat32Array(0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6), -"transitions": PackedFloat32Array(1, 1, 1, 1, 1, 1, 1), -"update": 1, -"values": [0, 1, 2, 3, 4, 5, 6] -} +[sub_resource type="AtlasTexture" id="AtlasTexture_ms05f"] +atlas = ExtResource("2_8h572") +region = Rect2(192, 0, 48, 48) -[sub_resource type="AnimationLibrary" id="AnimationLibrary_6srtp"] -_data = { -"Idle": SubResource("Animation_vrt4p"), -"Land": SubResource("Animation_2yfkp"), -"RESET": SubResource("Animation_1l7dh"), -"Run": SubResource("Animation_oejr4"), -"Walk": SubResource("Animation_dl063") -} +[sub_resource type="AtlasTexture" id="AtlasTexture_t3rvs"] +atlas = ExtResource("2_8h572") +region = Rect2(240, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_n46sx"] +atlas = ExtResource("2_8h572") +region = Rect2(288, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_48smm"] +atlas = ExtResource("2_8h572") +region = Rect2(336, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_tjhup"] +atlas = ExtResource("2_8h572") +region = Rect2(384, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_c84of"] +atlas = ExtResource("2_8h572") +region = Rect2(432, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_i67oc"] +atlas = ExtResource("5_f2sni") +region = Rect2(0, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_x3ooa"] +atlas = ExtResource("5_f2sni") +region = Rect2(48, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_7bpxf"] +atlas = ExtResource("5_f2sni") +region = Rect2(96, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_fexn1"] +atlas = ExtResource("6_ba2s3") +region = Rect2(0, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_3uk3c"] +atlas = ExtResource("6_ba2s3") +region = Rect2(48, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_iiovw"] +atlas = ExtResource("6_ba2s3") +region = Rect2(96, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_sx58l"] +atlas = ExtResource("6_ba2s3") +region = Rect2(144, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_6l2e7"] +atlas = ExtResource("6_ba2s3") +region = Rect2(240, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_acowd"] +atlas = ExtResource("6_ba2s3") +region = Rect2(336, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_3u4f5"] +atlas = ExtResource("4_rqcgh") +region = Rect2(0, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_dpm2p"] +atlas = ExtResource("4_rqcgh") +region = Rect2(48, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_qh1us"] +atlas = ExtResource("4_rqcgh") +region = Rect2(96, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_7kb6t"] +atlas = ExtResource("4_rqcgh") +region = Rect2(144, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_p5dlr"] +atlas = ExtResource("4_rqcgh") +region = Rect2(192, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_g7jsr"] +atlas = ExtResource("4_rqcgh") +region = Rect2(240, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_aq6al"] +atlas = ExtResource("4_rqcgh") +region = Rect2(288, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_ftoh7"] +atlas = ExtResource("4_rqcgh") +region = Rect2(336, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_a247p"] +atlas = ExtResource("3_xxdqr") +region = Rect2(0, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_24aks"] +atlas = ExtResource("3_xxdqr") +region = Rect2(48, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_hs577"] +atlas = ExtResource("3_xxdqr") +region = Rect2(96, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_1sf80"] +atlas = ExtResource("3_xxdqr") +region = Rect2(144, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_h515b"] +atlas = ExtResource("3_xxdqr") +region = Rect2(192, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_nx0f0"] +atlas = ExtResource("3_xxdqr") +region = Rect2(240, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_6ow76"] +atlas = ExtResource("3_xxdqr") +region = Rect2(288, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_ygn7k"] +atlas = ExtResource("3_xxdqr") +region = Rect2(336, 0, 48, 48) + +[sub_resource type="SpriteFrames" id="SpriteFrames_gvqqb"] +animations = [{ +"frames": [{ +"duration": 1.0, +"texture": SubResource("AtlasTexture_t3ih3") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_s5g6o") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_b6frn") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_kmcgv") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_ms05f") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_t3rvs") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_n46sx") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_48smm") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_tjhup") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_c84of") +}], +"loop": true, +"name": &"Idle", +"speed": 5.0 +}, { +"frames": [{ +"duration": 1.0, +"texture": SubResource("AtlasTexture_i67oc") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_x3ooa") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_7bpxf") +}], +"loop": true, +"name": &"Jump", +"speed": 5.0 +}, { +"frames": [{ +"duration": 1.0, +"texture": SubResource("AtlasTexture_fexn1") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_3uk3c") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_iiovw") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_sx58l") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_6l2e7") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_acowd") +}], +"loop": true, +"name": &"Land", +"speed": 15.0 +}, { +"frames": [{ +"duration": 1.0, +"texture": SubResource("AtlasTexture_3u4f5") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_dpm2p") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_qh1us") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_7kb6t") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_p5dlr") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_g7jsr") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_aq6al") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_ftoh7") +}], +"loop": true, +"name": &"Run", +"speed": 15.0 +}, { +"frames": [{ +"duration": 1.0, +"texture": SubResource("AtlasTexture_a247p") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_24aks") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_hs577") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_1sf80") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_h515b") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_nx0f0") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_6ow76") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_ygn7k") +}], +"loop": true, +"name": &"Walk", +"speed": 10.0 +}] [sub_resource type="RectangleShape2D" id="RectangleShape2D_wc2sw"] size = Vector2(16, 29) [node name="Player" type="CharacterBody2D"] -script = ExtResource("1_v1ece") +script = ExtResource("1_23c20") -[node name="AnimationPlayer" type="AnimationPlayer" parent="."] -root_node = NodePath("../Sprites") -autoplay = "Idle" -libraries = { -"": SubResource("AnimationLibrary_6srtp") -} - -[node name="Sprites" type="Sprite2D" parent="."] +[node name="Sprites" type="AnimatedSprite2D" parent="."] texture_filter = 1 position = Vector2(0, -16) -texture = ExtResource("1_h6xei") -hframes = 10 +sprite_frames = SubResource("SpriteFrames_gvqqb") +animation = &"Run" [node name="CollisionShape2D" type="CollisionShape2D" parent="."] position = Vector2(0, -14.5) diff --git a/Godot/project.godot b/Godot/project.godot index b15442f..94e4d4d 100644 --- a/Godot/project.godot +++ b/Godot/project.godot @@ -19,4 +19,6 @@ config/icon="res://icon.svg" window/size/viewport_width=500 window/size/viewport_height=300 -window/stretch/scale=2.0 +window/size/window_width_override=1600 +window/size/window_height_override=1050 +window/stretch/scale=3.0