mirror of
https://github.com/Steffo99/looping-for-loops.git
synced 2024-11-25 01:24:21 +00:00
💥 Change so much stuff I couldn't do separate commits
This commit is contained in:
parent
538d21f36d
commit
9bfc81748c
10 changed files with 237 additions and 5 deletions
65
Scenes/ConveyorBelt.tscn
Normal file
65
Scenes/ConveyorBelt.tscn
Normal file
|
@ -0,0 +1,65 @@
|
|||
[gd_scene load_steps=5 format=2]
|
||||
|
||||
[ext_resource path="res://Sprites/conveyor_belt.png" type="Texture" id=1]
|
||||
[ext_resource path="res://Scripts/ConveyorBelt.gd" type="Script" id=2]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id=1]
|
||||
extents = Vector2( 640, 40 )
|
||||
|
||||
[sub_resource type="TileSet" id=2]
|
||||
0/name = "conveyor_belt.png 0"
|
||||
0/texture = ExtResource( 1 )
|
||||
0/tex_offset = Vector2( 0, 0 )
|
||||
0/modulate = Color( 1, 1, 1, 1 )
|
||||
0/region = Rect2( 0, 0, 80, 80 )
|
||||
0/tile_mode = 0
|
||||
0/occluder_offset = Vector2( 0, 0 )
|
||||
0/navigation_offset = Vector2( 0, 0 )
|
||||
0/shape_offset = Vector2( 0, 0 )
|
||||
0/shape_transform = Transform2D( 1, 0, 0, 1, 0, 0 )
|
||||
0/shape_one_way = false
|
||||
0/shape_one_way_margin = 0.0
|
||||
0/shapes = [ ]
|
||||
0/z_index = 0
|
||||
1/name = "conveyor_belt.png 1"
|
||||
1/texture = ExtResource( 1 )
|
||||
1/tex_offset = Vector2( 0, 0 )
|
||||
1/modulate = Color( 1, 1, 1, 1 )
|
||||
1/region = Rect2( 80, 0, 80, 80 )
|
||||
1/tile_mode = 0
|
||||
1/occluder_offset = Vector2( 0, 0 )
|
||||
1/navigation_offset = Vector2( 0, 0 )
|
||||
1/shape_offset = Vector2( 0, 0 )
|
||||
1/shape_transform = Transform2D( 1, 0, 0, 1, 0, 0 )
|
||||
1/shape_one_way = false
|
||||
1/shape_one_way_margin = 0.0
|
||||
1/shapes = [ ]
|
||||
1/z_index = 0
|
||||
2/name = "conveyor_belt.png 2"
|
||||
2/texture = ExtResource( 1 )
|
||||
2/tex_offset = Vector2( 0, 0 )
|
||||
2/modulate = Color( 1, 1, 1, 1 )
|
||||
2/region = Rect2( 160, 0, 80, 80 )
|
||||
2/tile_mode = 0
|
||||
2/occluder_offset = Vector2( 0, 0 )
|
||||
2/navigation_offset = Vector2( 0, 0 )
|
||||
2/shape_offset = Vector2( 0, 0 )
|
||||
2/shape_transform = Transform2D( 1, 0, 0, 1, 0, 0 )
|
||||
2/shape_one_way = false
|
||||
2/shape_one_way_margin = 0.0
|
||||
2/shapes = [ ]
|
||||
2/z_index = 0
|
||||
|
||||
[node name="ConveyorBelt" type="StaticBody2D"]
|
||||
collision_layer = 4
|
||||
collision_mask = 3
|
||||
script = ExtResource( 2 )
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
shape = SubResource( 1 )
|
||||
|
||||
[node name="TileMap" type="TileMap" parent="."]
|
||||
tile_set = SubResource( 2 )
|
||||
cell_size = Vector2( 40, 40 )
|
||||
format = 1
|
||||
tile_data = PoolIntArray( -16, 0, 0, -14, 1, 0, -12, 1, 0, -10, 1, 0, -8, 1, 0, -6, 1, 0, -4, 1, 0, -2, 1, 0, -65536, 1, 0, -65534, 1, 0, -65532, 1, 0, -65530, 1, 0, -65528, 1, 0, -65526, 1, 0, -65524, 1, 0, -65522, 2, 0 )
|
|
@ -1,12 +1,17 @@
|
|||
[gd_scene load_steps=3 format=2]
|
||||
[gd_scene load_steps=4 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]
|
||||
|
||||
[node name="Main" type="Node2D"]
|
||||
|
||||
[node name="Conductor" parent="." instance=ExtResource( 2 )]
|
||||
song_offset = 200000.0
|
||||
|
||||
[node name="ConveyorBelt" parent="." instance=ExtResource( 3 )]
|
||||
position = Vector2( 662.439, 610.32 )
|
||||
conveyor_speed = 100.0
|
||||
|
||||
[node name="Player" parent="." instance=ExtResource( 1 )]
|
||||
position = Vector2( 293.919, 200.506 )
|
||||
position = Vector2( 918.923, 436.874 )
|
||||
|
|
3
Scenes/Obstacles/ScrollingBlock.tscn
Normal file
3
Scenes/Obstacles/ScrollingBlock.tscn
Normal file
|
@ -0,0 +1,3 @@
|
|||
[gd_scene format=2]
|
||||
|
||||
[node name="Node2D" type="Node2D"]
|
|
@ -1,12 +1,18 @@
|
|||
[gd_scene load_steps=3 format=2]
|
||||
[gd_scene load_steps=4 format=2]
|
||||
|
||||
[ext_resource path="res://Sprites/placeholder_cat.jpg" type="Texture" id=1]
|
||||
[ext_resource path="res://Scripts/Player.gd" type="Script" id=2]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id=1]
|
||||
extents = Vector2( 22.5, 22.5 )
|
||||
|
||||
[node name="Player" type="KinematicBody2D"]
|
||||
collision_layer = 2
|
||||
script = ExtResource( 2 )
|
||||
gravity = Vector2( 0, 10 )
|
||||
move_speed = 300.0
|
||||
jump_speed = 500.0
|
||||
jump_buffer_msec = 64.0
|
||||
|
||||
[node name="Sprite" type="Sprite" parent="."]
|
||||
scale = Vector2( 0.25, 0.25 )
|
||||
|
|
12
Scripts/ConveyorBelt.gd
Normal file
12
Scripts/ConveyorBelt.gd
Normal file
|
@ -0,0 +1,12 @@
|
|||
extends StaticBody2D
|
||||
class_name ConveyorBelt
|
||||
|
||||
|
||||
# Speed (and direction) of the conveyor belt
|
||||
export(float) var conveyor_speed = 0
|
||||
|
||||
|
||||
func get_conveyor_speed(other_pos: Vector2):
|
||||
var relative_position = other_pos - position
|
||||
var speed_sign = sign(relative_position.dot(Vector2.UP.rotated(rotation)))
|
||||
return speed_sign * conveyor_speed
|
10
Scripts/ExtendedKinematicBody2D.gd
Normal file
10
Scripts/ExtendedKinematicBody2D.gd
Normal file
|
@ -0,0 +1,10 @@
|
|||
extends KinematicBody2D
|
||||
class_name ExtendedKinematicBody2D
|
||||
|
||||
|
||||
func get_floor():
|
||||
for slide in get_slide_count():
|
||||
var collision = get_slide_collision(slide)
|
||||
if collision.normal != get_floor_normal():
|
||||
continue
|
||||
return collision.collider
|
47
Scripts/Player.gd
Normal file
47
Scripts/Player.gd
Normal file
|
@ -0,0 +1,47 @@
|
|||
extends ExtendedKinematicBody2D
|
||||
class_name Player
|
||||
|
||||
export(Vector2) var gravity: Vector2
|
||||
var speed: Vector2 = Vector2.ZERO
|
||||
|
||||
export(float) var move_speed: float
|
||||
export(float) var jump_speed: float
|
||||
export(float) var jump_buffer_msec: float
|
||||
|
||||
var can_jump = false
|
||||
var jump_buffer = 0
|
||||
|
||||
|
||||
func _physics_process(delta):
|
||||
var up_normal = -gravity.normalized()
|
||||
var floor_normal = get_floor_normal()
|
||||
|
||||
if is_on_floor():
|
||||
var gravity_speed = speed * up_normal
|
||||
speed -= gravity_speed * floor_normal
|
||||
can_jump = true
|
||||
|
||||
speed += gravity
|
||||
|
||||
var current_time = OS.get_ticks_msec()
|
||||
|
||||
if Input.is_action_just_pressed("plr_up"):
|
||||
jump_buffer = current_time
|
||||
|
||||
if can_jump and current_time - jump_buffer <= jump_buffer_msec:
|
||||
speed += up_normal * jump_speed
|
||||
can_jump = false
|
||||
|
||||
var movement = speed
|
||||
|
||||
if is_on_floor():
|
||||
var current_floor = get_floor()
|
||||
if current_floor.has_method("get_conveyor_speed"):
|
||||
movement += floor_normal.rotated(- PI / 2) * current_floor.get_conveyor_speed(position)
|
||||
|
||||
if Input.is_action_pressed("plr_left"):
|
||||
movement += Vector2.LEFT * move_speed
|
||||
if Input.is_action_pressed("plr_right"):
|
||||
movement += Vector2.RIGHT * move_speed
|
||||
|
||||
move_and_slide(movement, up_normal)
|
BIN
Sprites/conveyor_belt.png
(Stored with Git LFS)
Normal file
BIN
Sprites/conveyor_belt.png
(Stored with Git LFS)
Normal file
Binary file not shown.
34
Sprites/conveyor_belt.png.import
Normal file
34
Sprites/conveyor_belt.png.import
Normal file
|
@ -0,0 +1,34 @@
|
|||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="StreamTexture"
|
||||
path="res://.import/conveyor_belt.png-340c8423b3408a1af8fff4bf7141849d.stex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://Sprites/conveyor_belt.png"
|
||||
dest_files=[ "res://.import/conveyor_belt.png-340c8423b3408a1af8fff4bf7141849d.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
|
|
@ -13,9 +13,27 @@ _global_script_classes=[ {
|
|||
"class": "Conductor",
|
||||
"language": "GDScript",
|
||||
"path": "res://Scripts/Conductor.gd"
|
||||
}, {
|
||||
"base": "StaticBody2D",
|
||||
"class": "ConveyorBelt",
|
||||
"language": "GDScript",
|
||||
"path": "res://Scripts/ConveyorBelt.gd"
|
||||
}, {
|
||||
"base": "KinematicBody2D",
|
||||
"class": "ExtendedKinematicBody2D",
|
||||
"language": "GDScript",
|
||||
"path": "res://Scripts/ExtendedKinematicBody2D.gd"
|
||||
}, {
|
||||
"base": "ExtendedKinematicBody2D",
|
||||
"class": "Player",
|
||||
"language": "GDScript",
|
||||
"path": "res://Scripts/Player.gd"
|
||||
} ]
|
||||
_global_script_class_icons={
|
||||
"Conductor": ""
|
||||
"Conductor": "",
|
||||
"ConveyorBelt": "",
|
||||
"ExtendedKinematicBody2D": "",
|
||||
"Player": ""
|
||||
}
|
||||
|
||||
[application]
|
||||
|
@ -25,13 +43,42 @@ run/main_scene="res://Scenes/Main.tscn"
|
|||
|
||||
[display]
|
||||
|
||||
window/size/height=576
|
||||
window/size/width=1280
|
||||
window/size/height=720
|
||||
|
||||
[input]
|
||||
|
||||
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)
|
||||
]
|
||||
}
|
||||
plr_left={
|
||||
"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":16777231,"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":65,"unicode":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
plr_right={
|
||||
"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":16777233,"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":68,"unicode":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
|
||||
[layer_names]
|
||||
|
||||
2d_render/layer_1="Default"
|
||||
2d_physics/layer_1="Default"
|
||||
2d_physics/layer_2="Player"
|
||||
2d_physics/layer_3="ConveyorBelt"
|
||||
|
||||
[rendering]
|
||||
|
||||
|
|
Loading…
Reference in a new issue