From fb70634b6674c48ece290500e828eefea04a9ac4 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Sat, 3 Oct 2020 20:27:59 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9D=87=EF=B8=8F=20Add=20tentative=20Scrollin?= =?UTF-8?q?gBlock?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Scenes/Main.tscn | 34 +++++++++++++++++++++++++++- Scenes/Obstacles/ScrollingBlock.tscn | 19 ++++++++++++++-- Scripts/Obstacles/ScrollingBlock.gd | 12 ++++++++++ Scripts/Player.gd | 10 ++++++-- Sprites/button.png.import | 34 ++++++++++++++++++++++++++++ Sprites/button_left.png.import | 34 ++++++++++++++++++++++++++++ Sprites/button_right.png.import | 34 ++++++++++++++++++++++++++++ Sprites/red_button.png.import | 34 ++++++++++++++++++++++++++++ Sprites/scrolling_block.png | 3 +++ Sprites/scrolling_block.png.import | 34 ++++++++++++++++++++++++++++ project.godot | 18 ++++++++------- 11 files changed, 253 insertions(+), 13 deletions(-) create mode 100644 Scripts/Obstacles/ScrollingBlock.gd create mode 100644 Sprites/button.png.import create mode 100644 Sprites/button_left.png.import create mode 100644 Sprites/button_right.png.import create mode 100644 Sprites/red_button.png.import create mode 100644 Sprites/scrolling_block.png create mode 100644 Sprites/scrolling_block.png.import diff --git a/Scenes/Main.tscn b/Scenes/Main.tscn index b958a48..c2c6a91 100644 --- a/Scenes/Main.tscn +++ b/Scenes/Main.tscn @@ -1,8 +1,9 @@ -[gd_scene load_steps=4 format=2] +[gd_scene load_steps=5 format=2] [ext_resource path="res://Scenes/Player.tscn" type="PackedScene" id=1] [ext_resource path="res://Scenes/Conductor.tscn" type="PackedScene" id=2] [ext_resource path="res://Scenes/ConveyorBelt.tscn" type="PackedScene" id=3] +[ext_resource path="res://Scenes/Obstacles/ScrollingBlock.tscn" type="PackedScene" id=4] [node name="Main" type="Node2D"] @@ -11,6 +12,7 @@ song_offset = 200000.0 [node name="Player" parent="." instance=ExtResource( 1 )] position = Vector2( 622.258, 379.938 ) +jump_buffer_msec = 80.0 [node name="ConveyorBelt" parent="." instance=ExtResource( 3 )] position = Vector2( 640, 700 ) @@ -19,3 +21,33 @@ conveyor_speed = 100.0 [node name="ConveyorBelt2" parent="." instance=ExtResource( 3 )] position = Vector2( 640, 20 ) conveyor_speed = -100.0 + +[node name="ScrollingBlock" parent="." instance=ExtResource( 4 )] +position = Vector2( 980, 660 ) +collision_mask = 2147483650 +scroll_velocity = Vector2( -100, 0 ) + +[node name="ScrollingBlock3" parent="." instance=ExtResource( 4 )] +position = Vector2( 980, 620 ) +collision_mask = 2147483650 +scroll_velocity = Vector2( -100, 0 ) + +[node name="ScrollingBlock4" parent="." instance=ExtResource( 4 )] +position = Vector2( 1020, 620 ) +collision_mask = 2147483650 +scroll_velocity = Vector2( -100, 0 ) + +[node name="ScrollingBlock6" parent="." instance=ExtResource( 4 )] +position = Vector2( 1020, 580 ) +collision_mask = 2147483650 +scroll_velocity = Vector2( -100, 0 ) + +[node name="ScrollingBlock5" parent="." instance=ExtResource( 4 )] +position = Vector2( 1020, 660 ) +collision_mask = 2147483650 +scroll_velocity = Vector2( -100, 0 ) + +[node name="ScrollingBlock2" parent="." instance=ExtResource( 4 )] +position = Vector2( 940, 660 ) +collision_mask = 2147483650 +scroll_velocity = Vector2( -100, 0 ) diff --git a/Scenes/Obstacles/ScrollingBlock.tscn b/Scenes/Obstacles/ScrollingBlock.tscn index b171e8d..0bd4b9b 100644 --- a/Scenes/Obstacles/ScrollingBlock.tscn +++ b/Scenes/Obstacles/ScrollingBlock.tscn @@ -1,3 +1,18 @@ -[gd_scene format=2] +[gd_scene load_steps=4 format=2] -[node name="Node2D" type="Node2D"] +[ext_resource path="res://Sprites/scrolling_block.png" type="Texture" id=1] +[ext_resource path="res://Scripts/Obstacles/ScrollingBlock.gd" type="Script" id=2] + +[sub_resource type="RectangleShape2D" id=1] +extents = Vector2( 20, 20 ) + +[node name="ScrollingBlock" type="KinematicBody2D"] +collision_layer = 8 +collision_mask = 2 +script = ExtResource( 2 ) + +[node name="Sprite" type="Sprite" parent="."] +texture = ExtResource( 1 ) + +[node name="CollisionShape2D" type="CollisionShape2D" parent="."] +shape = SubResource( 1 ) diff --git a/Scripts/Obstacles/ScrollingBlock.gd b/Scripts/Obstacles/ScrollingBlock.gd new file mode 100644 index 0000000..f70e04f --- /dev/null +++ b/Scripts/Obstacles/ScrollingBlock.gd @@ -0,0 +1,12 @@ +extends ExtendedKinematicBody2D +class_name ScrollingBlock + + +export(Vector2) var scroll_velocity: Vector2 = Vector2(-10, 0) + + +func _physics_process(delta): + # FIXME: This doesn't really work... Any other things we could try? + var collision = move_and_collide(scroll_velocity * delta) + if collision: + print(collision) diff --git a/Scripts/Player.gd b/Scripts/Player.gd index b46454d..5c4ec6d 100644 --- a/Scripts/Player.gd +++ b/Scripts/Player.gd @@ -15,9 +15,11 @@ var jump_buffer: int = 0 var is_quick_falling: bool = false var quick_fall_buffer: int = 0 +func up_normal(): + return -gravity.normalized() func _physics_process(delta): - var up_normal = -gravity.normalized() + var up_normal = up_normal() var floor_normal = get_floor_normal() if is_on_floor(): @@ -58,4 +60,8 @@ func _physics_process(delta): if Input.is_action_pressed("plr_right"): movement += Vector2.RIGHT * move_speed - move_and_slide(movement, up_normal) + player_move(movement) + + +func player_move(movement): + move_and_slide(movement, up_normal()) diff --git a/Sprites/button.png.import b/Sprites/button.png.import new file mode 100644 index 0000000..8616e76 --- /dev/null +++ b/Sprites/button.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/button.png-877ac5cd2b80fdc0cebdbf31a84881c2.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://Sprites/button.png" +dest_files=[ "res://.import/button.png-877ac5cd2b80fdc0cebdbf31a84881c2.stex" ] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=true +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=2 +process/fix_alpha_border=true +process/premult_alpha=false +process/HDR_as_SRGB=false +process/invert_color=false +stream=false +size_limit=0 +detect_3d=true +svg/scale=1.0 diff --git a/Sprites/button_left.png.import b/Sprites/button_left.png.import new file mode 100644 index 0000000..1e81f38 --- /dev/null +++ b/Sprites/button_left.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/button_left.png-206fbca05b2d52e70c9e97e1821d0246.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://Sprites/button_left.png" +dest_files=[ "res://.import/button_left.png-206fbca05b2d52e70c9e97e1821d0246.stex" ] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=true +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=2 +process/fix_alpha_border=true +process/premult_alpha=false +process/HDR_as_SRGB=false +process/invert_color=false +stream=false +size_limit=0 +detect_3d=true +svg/scale=1.0 diff --git a/Sprites/button_right.png.import b/Sprites/button_right.png.import new file mode 100644 index 0000000..fe2da9a --- /dev/null +++ b/Sprites/button_right.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/button_right.png-8030242b7555d3b0634c117bb992b3f8.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://Sprites/button_right.png" +dest_files=[ "res://.import/button_right.png-8030242b7555d3b0634c117bb992b3f8.stex" ] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=true +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=2 +process/fix_alpha_border=true +process/premult_alpha=false +process/HDR_as_SRGB=false +process/invert_color=false +stream=false +size_limit=0 +detect_3d=true +svg/scale=1.0 diff --git a/Sprites/red_button.png.import b/Sprites/red_button.png.import new file mode 100644 index 0000000..3f47ba0 --- /dev/null +++ b/Sprites/red_button.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/red_button.png-414b3db90d1cea22521067e11dd7d149.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://Sprites/red_button.png" +dest_files=[ "res://.import/red_button.png-414b3db90d1cea22521067e11dd7d149.stex" ] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=true +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=2 +process/fix_alpha_border=true +process/premult_alpha=false +process/HDR_as_SRGB=false +process/invert_color=false +stream=false +size_limit=0 +detect_3d=true +svg/scale=1.0 diff --git a/Sprites/scrolling_block.png b/Sprites/scrolling_block.png new file mode 100644 index 0000000..c6e5011 --- /dev/null +++ b/Sprites/scrolling_block.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:95957985ea1f7fcb3b1adf969aa3d289cc8e6e9663d00944013532a943a22a51 +size 610 diff --git a/Sprites/scrolling_block.png.import b/Sprites/scrolling_block.png.import new file mode 100644 index 0000000..c8c39ca --- /dev/null +++ b/Sprites/scrolling_block.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/scrolling_block.png-8ffa2a5bdae1a814eec757ce2af9b35f.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://Sprites/scrolling_block.png" +dest_files=[ "res://.import/scrolling_block.png-8ffa2a5bdae1a814eec757ce2af9b35f.stex" ] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=true +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=2 +process/fix_alpha_border=true +process/premult_alpha=false +process/HDR_as_SRGB=false +process/invert_color=false +stream=false +size_limit=0 +detect_3d=true +svg/scale=1.0 diff --git a/project.godot b/project.godot index 6ebbebf..74a6ba5 100644 --- a/project.godot +++ b/project.godot @@ -28,12 +28,18 @@ _global_script_classes=[ { "class": "Player", "language": "GDScript", "path": "res://Scripts/Player.gd" +}, { +"base": "ExtendedKinematicBody2D", +"class": "ScrollingBlock", +"language": "GDScript", +"path": "res://Scripts/Obstacles/ScrollingBlock.gd" } ] _global_script_class_icons={ "Conductor": "", "ConveyorBelt": "", "ExtendedKinematicBody2D": "", -"Player": "" +"Player": "", +"ScrollingBlock": "" } [application] @@ -53,12 +59,7 @@ plr_up={ "deadzone": 0.5, "events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777232,"unicode":0,"echo":false,"script":null) , Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":87,"unicode":0,"echo":false,"script":null) - ] -} -plr_down={ -"deadzone": 0.5, -"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777234,"unicode":0,"echo":false,"script":null) -, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":83,"unicode":0,"echo":false,"script":null) +, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":32,"unicode":0,"echo":false,"script":null) ] } plr_left={ @@ -79,7 +80,8 @@ plr_right={ 2d_render/layer_1="Default" 2d_physics/layer_1="Default" 2d_physics/layer_2="Player" -2d_physics/layer_3="ConveyorBelt" +2d_physics/layer_3="Conveyor Belt" +2d_physics/layer_4="Obstacles" [rendering]