jump and run working

This commit is contained in:
OddlyTimbot 2024-07-22 19:38:31 -04:00
parent c813ce8f0c
commit 87ff9b7f7f
29 changed files with 337 additions and 28 deletions

View File

@ -172,4 +172,4 @@ Anim={
"zfar": 4000.01,
"znear": 0.05
}
selected_nodes=Array[NodePath]([NodePath("/root/@EditorNode@17140/@Panel@13/@VBoxContainer@14/@HSplitContainer@17/@HSplitContainer@25/@HSplitContainer@33/@VBoxContainer@34/@VSplitContainer@36/@VSplitContainer@62/@VBoxContainer@63/@PanelContainer@110/MainScreen/@CanvasItemEditor@9462/@VSplitContainer@9281/@HSplitContainer@9283/@HSplitContainer@9285/@Control@9286/@SubViewportContainer@9287/@SubViewport@9288/Area2D")])
selected_nodes=Array[NodePath]([])

View File

@ -172,4 +172,4 @@ Anim={
"zfar": 4000.01,
"znear": 0.05
}
selected_nodes=Array[NodePath]([NodePath("/root/@EditorNode@17140/@Panel@13/@VBoxContainer@14/@HSplitContainer@17/@HSplitContainer@25/@HSplitContainer@33/@VBoxContainer@34/@VSplitContainer@36/@VSplitContainer@62/@VBoxContainer@63/@PanelContainer@110/MainScreen/@CanvasItemEditor@9462/@VSplitContainer@9281/@HSplitContainer@9283/@HSplitContainer@9285/@Control@9286/@SubViewportContainer@9287/@SubViewport@9288/Area2D")])
selected_nodes=Array[NodePath]([])

View File

@ -1,5 +1,5 @@
[folding]
node_unfolds=[]
resource_unfolds=["res://scenes/character.tscn::CircleShape2D_ubfw4", PackedStringArray()]
node_unfolds=[NodePath("AnimatedSprite2D"), PackedStringArray("Animation", "sprite_frames", "Texture")]
resource_unfolds=["res://scenes/character.tscn::SpriteFrames_h7tsu", PackedStringArray("Resource"), "res://scenes/character.tscn::CircleShape2D_ubfw4", PackedStringArray()]
nodes_folded=[]

View File

@ -1,3 +1,4 @@
AnimatedSprite2D
Node2D
CollisionShape2D
Area2D

View File

@ -4,12 +4,12 @@ dock_1_selected_tab_idx=0
dock_2_selected_tab_idx=0
dock_3_selected_tab_idx=0
dock_4_selected_tab_idx=0
dock_5_selected_tab_idx=1
dock_5_selected_tab_idx=0
dock_6_selected_tab_idx=0
dock_7_selected_tab_idx=0
dock_8_selected_tab_idx=0
dock_floating={}
dock_split_2=0
dock_split_2=-77
dock_split_3=0
dock_hsplit_1=0
dock_hsplit_2=270
@ -19,8 +19,8 @@ dock_filesystem_split=0
dock_filesystem_display_mode=0
dock_filesystem_file_sort=0
dock_filesystem_file_list_display_mode=1
dock_filesystem_selected_paths=PackedStringArray("res://scenes/bullet.tscn")
dock_filesystem_uncollapsed_paths=PackedStringArray("Favorites", "res://", "res://scripts/", "res://scenes/")
dock_filesystem_selected_paths=PackedStringArray("res://graphics/Player Idle 48x48.png")
dock_filesystem_uncollapsed_paths=PackedStringArray("Favorites", "res://", "res://scripts/", "res://scenes/", "res://graphics/")
dock_3="Scene,Import"
dock_4="FileSystem"
dock_5="Inspector,Node,History"
@ -28,16 +28,16 @@ dock_5="Inspector,Node,History"
[EditorNode]
open_scenes=PackedStringArray("res://scenes/game.tscn", "res://scenes/character.tscn", "res://scenes/bullet.tscn")
current_scene="res://scenes/bullet.tscn"
current_scene="res://scenes/character.tscn"
center_split_offset=0
selected_default_debugger_tab_idx=0
selected_main_editor_idx=2
selected_bottom_panel_item=0
selected_bottom_panel_item=9
[ScriptEditor]
open_scripts=["res://scripts/bullet.gd", "res://scripts/CharacterBody2D.gd", "res://scripts/gamecontroller.gd"]
selected_script="res://scripts/bullet.gd"
selected_script="res://scripts/CharacterBody2D.gd"
open_help=[]
script_split_offset=70
list_split_offset=0

0
.godot/editor/favorites Normal file
View File

View File

@ -1,9 +1,17 @@
ea4bc82a6ad023ab7ee23ee620429895
::res://::1721083613
icon.svg::CompressedTexture2D::9114977118871582245::1721083376::1721083376::1::::<><>::
::res://scenes/::1721083376
game.tscn::PackedScene::1738196330916037717::1721083376::0::1::::<><>::res://scripts/gamecontroller.gd<>res://scripts/CharacterBody2D.gd<>res://scripts/Trigger.gd
::res://scripts/::1721083376
CharacterBody2D.gd::GDScript::-1::1721083376::0::1::::<>CharacterBody2D<>::
gamecontroller.gd::GDScript::-1::1721083376::0::1::::<>Node2D<>::
Trigger.gd::GDScript::-1::1721083376::0::1::::<>Area2D<>::
::res://::1721688521
icon.svg::CompressedTexture2D::9114977118871582245::1721682499::1721682499::1::::<><>::
README.md::TextFile::-1::1721686814::0::1::::<><>::
::res://graphics/::1721690749
Player Idle 48x48.png::CompressedTexture2D::3034784150585975320::1721688486::1721688521::1::::<><>::
player jump 48x48.png::CompressedTexture2D::5342238035347045068::1721690749::1721690749::1::::<><>::
player run 48x48.png::CompressedTexture2D::3468292145757083245::1721689940::1721689940::1::::<><>::
::res://scenes/::1721690574
bullet.tscn::PackedScene::6880909734590904373::1721690574::0::1::::<><>::res://scripts/bullet.gd
character.tscn::PackedScene::451838158579532324::1721690574::0::1::::<><>::res://scripts/CharacterBody2D.gd<>uid://bjicpmau1iy7y::::res://graphics/Player Idle 48x48.png<>uid://bpocjaij352uj::::res://graphics/player run 48x48.png
game.tscn::PackedScene::1738196330916037717::1721690574::0::1::::<><>::res://scripts/gamecontroller.gd<>uid://go4yc8hfo1gq::::res://scenes/character.tscn<>res://scripts/Trigger.gd
::res://scripts/::1721690574
bullet.gd::GDScript::-1::1721682499::0::1::::<>Area2D<>::
CharacterBody2D.gd::GDScript::-1::1721690574::0::1::::<>CharacterBody2D<>::
gamecontroller.gd::GDScript::-1::1721682499::0::1::::<>Node2D<>::
Trigger.gd::GDScript::-1::1721682499::0::1::::<>Area2D<>::

View File

@ -1,5 +1,4 @@
res://scenes/game.tscn
res://scripts/CharacterBody2D.gd
res://scenes/character.tscn
res://scripts/bullet.gd
res://scenes/bullet.tscn
res://scripts/CharacterBody2D.gd

View File

@ -172,4 +172,4 @@ Anim={
"zfar": 4000.01,
"znear": 0.05
}
selected_nodes=Array[NodePath]([NodePath("/root/@EditorNode@17140/@Panel@13/@VBoxContainer@14/@HSplitContainer@17/@HSplitContainer@25/@HSplitContainer@33/@VBoxContainer@34/@VSplitContainer@36/@VSplitContainer@62/@VBoxContainer@63/@PanelContainer@110/MainScreen/@CanvasItemEditor@9462/@VSplitContainer@9281/@HSplitContainer@9283/@HSplitContainer@9285/@Control@9286/@SubViewportContainer@9287/@SubViewport@9288/Area2D")])
selected_nodes=Array[NodePath]([])

View File

@ -23,6 +23,7 @@ CollisionShape2D:scale=true
RigidBody2D:scale=true
RayCast2D:scale=true
Area2D:scale=true
AnimatedSprite2D:scale=true
[dialog_bounds]

View File

@ -1,2 +1,3 @@
res://graphics
res://scripts
res://scenes

View File

@ -17,11 +17,11 @@ state={
state={
"bookmarks": PackedInt32Array(),
"breakpoints": PackedInt32Array(),
"column": 52,
"column": 30,
"folded_lines": Array[int]([]),
"h_scroll_position": 0,
"row": 47,
"scroll_position": 30.0,
"row": 69,
"scroll_position": 56.0,
"selection": false,
"syntax_highlighter": "GDScript"
}

View File

@ -0,0 +1,3 @@
source_md5="25eca82a8943e0cb7df742fc2f8287eb"
dest_md5="40424c46e7e7da6cb6f8f38becacd5fa"

View File

@ -0,0 +1,3 @@
source_md5="25eca82a8943e0cb7df742fc2f8287eb"
dest_md5="40424c46e7e7da6cb6f8f38becacd5fa"

View File

@ -0,0 +1,3 @@
source_md5="32c25d5ee4a6233bebc766fa35137e71"
dest_md5="e2c6a646cfe3495563ee0fd7127f6784"

View File

@ -0,0 +1,3 @@
source_md5="01ad20affe3a719d2248d3eb59a0b3dd"
dest_md5="c7e49f2c0ac84ac6a6d941074f19bd68"

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

View File

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://bjicpmau1iy7y"
path="res://.godot/imported/Player Idle 48x48.png-b25968a287377bab7d6899f33fed0ec9.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://graphics/Player Idle 48x48.png"
dest_files=["res://.godot/imported/Player Idle 48x48.png-b25968a287377bab7d6899f33fed0ec9.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

Binary file not shown.

After

Width:  |  Height:  |  Size: 1021 B

View File

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://cid246g3bgt7a"
path="res://.godot/imported/player jump 48x48.png-44bab2151e6e1eb3cf69ed16e7a4f4ad.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://graphics/player jump 48x48.png"
dest_files=["res://.godot/imported/player jump 48x48.png-44bab2151e6e1eb3cf69ed16e7a4f4ad.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

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

View File

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://bpocjaij352uj"
path="res://.godot/imported/player run 48x48.png-626defb011aee5b3f5c54d9acb45d5f5.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://graphics/player run 48x48.png"
dest_files=["res://.godot/imported/player run 48x48.png-626defb011aee5b3f5c54d9acb45d5f5.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

View File

@ -1,18 +1,194 @@
[gd_scene load_steps=3 format=3 uid="uid://go4yc8hfo1gq"]
[gd_scene load_steps=28 format=3 uid="uid://go4yc8hfo1gq"]
[ext_resource type="Script" path="res://scripts/CharacterBody2D.gd" id="1_x87yo"]
[ext_resource type="Texture2D" uid="uid://bjicpmau1iy7y" path="res://graphics/Player Idle 48x48.png" id="2_re2it"]
[ext_resource type="Texture2D" uid="uid://bpocjaij352uj" path="res://graphics/player run 48x48.png" id="3_4gwja"]
[ext_resource type="Texture2D" uid="uid://cid246g3bgt7a" path="res://graphics/player jump 48x48.png" id="3_h032e"]
[sub_resource type="AtlasTexture" id="AtlasTexture_bkvw7"]
atlas = ExtResource("2_re2it")
region = Rect2(0, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_2oy63"]
atlas = ExtResource("2_re2it")
region = Rect2(48, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_q4cvr"]
atlas = ExtResource("2_re2it")
region = Rect2(96, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_ib3dq"]
atlas = ExtResource("2_re2it")
region = Rect2(144, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_kdna3"]
atlas = ExtResource("2_re2it")
region = Rect2(192, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_muups"]
atlas = ExtResource("2_re2it")
region = Rect2(240, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_nkvak"]
atlas = ExtResource("2_re2it")
region = Rect2(288, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_fxl5c"]
atlas = ExtResource("2_re2it")
region = Rect2(336, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_pnqri"]
atlas = ExtResource("2_re2it")
region = Rect2(384, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_i6dxl"]
atlas = ExtResource("2_re2it")
region = Rect2(432, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_fxixe"]
atlas = ExtResource("3_h032e")
region = Rect2(0, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_mvx11"]
atlas = ExtResource("3_h032e")
region = Rect2(48, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_a2bf2"]
atlas = ExtResource("3_h032e")
region = Rect2(96, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_7ad6o"]
atlas = ExtResource("3_4gwja")
region = Rect2(0, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_yoh57"]
atlas = ExtResource("3_4gwja")
region = Rect2(48, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_rtw0v"]
atlas = ExtResource("3_4gwja")
region = Rect2(96, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_abqek"]
atlas = ExtResource("3_4gwja")
region = Rect2(144, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_fqjri"]
atlas = ExtResource("3_4gwja")
region = Rect2(192, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_f8bsf"]
atlas = ExtResource("3_4gwja")
region = Rect2(240, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_xgued"]
atlas = ExtResource("3_4gwja")
region = Rect2(288, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_six34"]
atlas = ExtResource("3_4gwja")
region = Rect2(336, 0, 48, 48)
[sub_resource type="SpriteFrames" id="SpriteFrames_h7tsu"]
animations = [{
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_bkvw7")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_2oy63")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_q4cvr")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_ib3dq")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_kdna3")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_muups")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_nkvak")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_fxl5c")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_pnqri")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_i6dxl")
}],
"loop": true,
"name": &"idle",
"speed": 15.0
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_fxixe")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_mvx11")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_a2bf2")
}],
"loop": false,
"name": &"jump",
"speed": 5.0
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_7ad6o")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_yoh57")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_rtw0v")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_abqek")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_fqjri")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_f8bsf")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_xgued")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_six34")
}],
"loop": true,
"name": &"run",
"speed": 15.0
}]
[sub_resource type="CircleShape2D" id="CircleShape2D_ubfw4"]
radius = 13.0384
radius = 11.0
[node name="CharacterBody2D" type="CharacterBody2D"]
position = Vector2(-1, 0)
script = ExtResource("1_x87yo")
JUMP_VELOCITY = -500.0
PUSH_FORCE = 200
metadata/_edit_group_ = true
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
texture_filter = 1
sprite_frames = SubResource("SpriteFrames_h7tsu")
animation = &"jump"
autoplay = "idle"
frame = 2
frame_progress = 1.0
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
position = Vector2(0, 5)
shape = SubResource("CircleShape2D_ubfw4")
[node name="RightRay" type="RayCast2D" parent="."]

View File

@ -10,6 +10,7 @@ extends CharacterBody2D
@onready var left_ray = $LeftRay
@onready var marker_right = $MarkerRight
@onready var marker_left = $MarkerLeft
@onready var animated_sprite = $AnimatedSprite2D
var faceLeft = false
var pushLeftEnabled = false
@ -57,8 +58,16 @@ func _physics_process(delta):
if direction:
velocity.x = direction * SPEED
animated_sprite.flip_h = true if direction <0 else false
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
if is_on_floor():
if direction == 0:
animated_sprite.play("idle")
else:
animated_sprite.play("run")
else:
animated_sprite.play("jump")
move_and_slide()
if right_ray.is_colliding():