1
Fork 0
mirror of https://github.com/Steffo99/looping-for-loops.git synced 2024-11-21 15:44:24 +00:00

❇️ Add working hydraulic press

https://www.youtube.com/watch?v=w6khmhtsPHY
This commit is contained in:
Steffo 2020-10-04 00:33:54 +02:00
parent e705b6e95c
commit c3bca3ce7c
24 changed files with 296 additions and 78 deletions

View file

@ -4,7 +4,7 @@
[ext_resource path="res://Scripts/ConveyorBelt.gd" type="Script" id=2]
[sub_resource type="RectangleShape2D" id=1]
extents = Vector2( 640, 20 )
extents = Vector2( 680, 20 )
[node name="ConveyorBelt" type="StaticBody2D"]
collision_layer = 4
@ -22,4 +22,4 @@ cell_quadrant_size = 40
cell_tile_origin = 1
centered_textures = true
format = 1
tile_data = PoolIntArray( 65520, 0, 0, 65521, 1, 0, 65522, 1, 0, 65523, 1, 0, 65524, 1, 0, 65525, 1, 0, 65526, 1, 0, 65527, 1, 0, 65528, 1, 0, 65529, 1, 0, 65530, 1, 0, 65531, 1, 0, 65532, 1, 0, 65533, 1, 0, 65534, 1, 0, 65535, 1, 0, 0, 1, 0, 1, 1, 0, 2, 1, 0, 3, 1, 0, 4, 1, 0, 5, 1, 0, 6, 1, 0, 7, 1, 0, 8, 1, 0, 9, 1, 0, 10, 1, 0, 11, 1, 0, 12, 1, 0, 13, 1, 0, 14, 1, 0, 15, 2, 0 )
tile_data = PoolIntArray( 65519, 0, 0, 65520, 1, 0, 65521, 1, 0, 65522, 1, 0, 65523, 1, 0, 65524, 1, 0, 65525, 1, 0, 65526, 1, 0, 65527, 1, 0, 65528, 1, 0, 65529, 1, 0, 65530, 1, 0, 65531, 1, 0, 65532, 1, 0, 65533, 1, 0, 65534, 1, 0, 65535, 1, 0, 0, 1, 0, 1, 1, 0, 2, 1, 0, 3, 1, 0, 4, 1, 0, 5, 1, 0, 6, 1, 0, 7, 1, 0, 8, 1, 0, 9, 1, 0, 10, 1, 0, 11, 1, 0, 12, 1, 0, 13, 1, 0, 14, 1, 0, 15, 1, 0, 16, 2, 0 )

View file

@ -1,53 +1,71 @@
[gd_scene load_steps=5 format=2]
[gd_scene load_steps=7 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]
[ext_resource path="res://Scenes/SingleScreenWalls.tscn" type="PackedScene" id=4]
[ext_resource path="res://Scenes/Obstacles/Press.tscn" type="PackedScene" id=5]
[ext_resource path="res://Scenes/Obstacles/ScrollingBlock.tscn" type="PackedScene" id=6]
[node name="Main" type="Node2D"]
[node name="Conductor" parent="." instance=ExtResource( 2 )]
song_offset = 200000.0
__meta__ = {
"_edit_horizontal_guides_": [ ]
}
[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 )
conveyor_speed = 100.0
[node name="ConveyorBelt2" parent="." instance=ExtResource( 3 )]
position = Vector2( 640, 20 )
conveyor_speed = -100.0
[node name="SingleScreenWalls" parent="." instance=ExtResource( 4 )]
[node name="ScrollingBlock" parent="." instance=ExtResource( 4 )]
position = Vector2( 980, 660 )
collision_mask = 2147483650
scroll_velocity = Vector2( -100, 0 )
[node name="Press" parent="." instance=ExtResource( 5 )]
position = Vector2( 420, 0 )
[node name="ScrollingBlock3" parent="." instance=ExtResource( 4 )]
position = Vector2( 980, 620 )
collision_mask = 2147483650
scroll_velocity = Vector2( -100, 0 )
[node name="Conductor" parent="." instance=ExtResource( 2 )]
song_bpm = 30.0
[node name="ScrollingBlock4" parent="." instance=ExtResource( 4 )]
position = Vector2( 1020, 620 )
collision_mask = 2147483650
scroll_velocity = Vector2( -100, 0 )
[node name="Conductor2" parent="." instance=ExtResource( 2 )]
song_bpm = 30.0
[node name="ScrollingBlock6" parent="." instance=ExtResource( 4 )]
position = Vector2( 1020, 580 )
collision_mask = 2147483650
scroll_velocity = Vector2( -100, 0 )
[node name="ScrollingBlock" parent="." instance=ExtResource( 6 )]
position = Vector2( 800, 660 )
[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( 6 )]
position = Vector2( 880, 580 )
[node name="ScrollingBlock2" parent="." instance=ExtResource( 4 )]
position = Vector2( 940, 660 )
collision_mask = 2147483650
scroll_velocity = Vector2( -100, 0 )
[node name="ScrollingBlock3" parent="." instance=ExtResource( 6 )]
position = Vector2( 920, 540 )
[node name="ScrollingBlock4" parent="." instance=ExtResource( 6 )]
position = Vector2( 840, 620 )
[node name="ScrollingBlock5" parent="." instance=ExtResource( 6 )]
position = Vector2( 960, 500 )
[node name="ScrollingBlock6" parent="." instance=ExtResource( 6 )]
position = Vector2( 1000, 460 )
[node name="ScrollingBlock7" parent="." instance=ExtResource( 6 )]
position = Vector2( 1080, 380 )
[node name="ScrollingBlock8" parent="." instance=ExtResource( 6 )]
position = Vector2( 1120, 340 )
[node name="ScrollingBlock9" parent="." instance=ExtResource( 6 )]
position = Vector2( 1040, 420 )
[node name="ScrollingBlock10" parent="." instance=ExtResource( 6 )]
position = Vector2( 1160, 300 )
[node name="ScrollingBlock11" parent="." instance=ExtResource( 6 )]
position = Vector2( 1200, 260 )
[node name="ScrollingBlock12" parent="." instance=ExtResource( 6 )]
position = Vector2( 1240, 220 )
[node name="ScrollingBlock13" parent="." instance=ExtResource( 6 )]
position = Vector2( 1660, 220 )
scale = Vector2( 20, 1 )

102
Scenes/Obstacles/Press.tscn Normal file
View file

@ -0,0 +1,102 @@
[gd_scene load_steps=7 format=2]
[ext_resource path="res://Sprites/press_bottom.png" type="Texture" id=1]
[ext_resource path="res://Scripts/Obstacles/Press.gd" type="Script" id=2]
[ext_resource path="res://Sprites/press_pipes.png" type="Texture" id=3]
[sub_resource type="Animation" id=3]
resource_name = "Stomp"
tracks/0/type = "bezier"
tracks/0/path = NodePath("Bottom:position:y")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/keys = {
"points": PoolRealArray( 40, -0.25, 0, 0.25, 0, 567, 0, -303.5, 0.25, 0 ),
"times": PoolRealArray( 0, 1 )
}
tracks/1/type = "bezier"
tracks/1/path = NodePath("Pipes:scale:y")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/keys = {
"points": PoolRealArray( 1, -0.25, 0, 0.25, 0, 14.2, 0, -7.1, 0.25, 0 ),
"times": PoolRealArray( 0, 1 )
}
tracks/2/type = "bezier"
tracks/2/path = NodePath("CollisionShape2D:shape:extents:y")
tracks/2/interp = 1
tracks/2/loop_wrap = true
tracks/2/imported = false
tracks/2/enabled = true
tracks/2/keys = {
"points": PoolRealArray( 76.5, -0.25, 0, 0.25, 0, 340, 0, -170, 0.25, 0 ),
"times": PoolRealArray( 0, 1 )
}
tracks/3/type = "bezier"
tracks/3/path = NodePath("CollisionShape2D:position:y")
tracks/3/interp = 1
tracks/3/loop_wrap = true
tracks/3/imported = false
tracks/3/enabled = true
tracks/3/keys = {
"points": PoolRealArray( 76.5, -0.25, 0, 0.25, 0, 340, 0, -170, 0.25, 0 ),
"times": PoolRealArray( 0, 1 )
}
tracks/4/type = "value"
tracks/4/path = NodePath("Bottom/StompArea/CollisionShape2D:disabled")
tracks/4/interp = 1
tracks/4/loop_wrap = true
tracks/4/imported = false
tracks/4/enabled = true
tracks/4/keys = {
"times": PoolRealArray( 0, 0.2 ),
"transitions": PoolRealArray( 1, 1 ),
"update": 1,
"values": [ true, false ]
}
[sub_resource type="RectangleShape2D" id=4]
extents = Vector2( 78, 4 )
[sub_resource type="RectangleShape2D" id=5]
extents = Vector2( 80, 76.5 )
[node name="Press" type="StaticBody2D"]
script = ExtResource( 2 )
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
playback_process_mode = 0
playback_speed = 3.5
anims/Stomp = SubResource( 3 )
[node name="Pipes" type="Node2D" parent="."]
[node name="Sprite" type="Sprite" parent="Pipes"]
texture = ExtResource( 3 )
offset = Vector2( 0, 20 )
[node name="Bottom" type="Node2D" parent="."]
position = Vector2( 0, 40 )
[node name="Sprite" type="Sprite" parent="Bottom"]
texture = ExtResource( 1 )
offset = Vector2( 0, 56.5 )
[node name="StompArea" type="Area2D" parent="Bottom"]
position = Vector2( 0, -40 )
collision_layer = 8
collision_mask = 2
[node name="CollisionShape2D" type="CollisionShape2D" parent="Bottom/StompArea"]
position = Vector2( 0, 157 )
shape = SubResource( 4 )
disabled = true
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
position = Vector2( 0, 76.5 )
shape = SubResource( 5 )
[connection signal="body_entered" from="Bottom/StompArea" to="." method="_on_StompArea_body_entered"]

View file

@ -4,12 +4,12 @@
[ext_resource path="res://Scripts/Player.gd" type="Script" id=2]
[sub_resource type="RectangleShape2D" id=1]
extents = Vector2( 20, 20 )
extents = Vector2( 19.8, 19.8 )
[node name="Player" type="KinematicBody2D"]
collision_layer = 2
collision_mask = 2147483677
script = ExtResource( 2 )
jump_buffer_msec = 500.0
[node name="Sprite" type="Sprite" parent="."]
texture = ExtResource( 1 )

View file

@ -0,0 +1,35 @@
[gd_scene load_steps=4 format=2]
[ext_resource path="res://Scenes/Wall.tscn" type="PackedScene" id=1]
[sub_resource type="RectangleShape2D" id=1]
extents = Vector2( 20, 360 )
[sub_resource type="RectangleShape2D" id=2]
extents = Vector2( 680, 20 )
[node name="SingleScreenWalls" type="Node2D"]
[node name="WallLeft" type="StaticBody2D" parent="." instance=ExtResource( 1 )]
collision_layer = 16
collision_mask = 2
[node name="CollisionShape2D" type="CollisionShape2D" parent="WallLeft"]
position = Vector2( -20, 360 )
shape = SubResource( 1 )
[node name="WallRight" type="StaticBody2D" parent="." instance=ExtResource( 1 )]
collision_layer = 16
collision_mask = 2
[node name="CollisionShape2D" type="CollisionShape2D" parent="WallRight"]
position = Vector2( 1300, 360 )
shape = SubResource( 1 )
[node name="WallTop" type="StaticBody2D" parent="." instance=ExtResource( 1 )]
collision_layer = 16
collision_mask = 2
[node name="CollisionShape2D" type="CollisionShape2D" parent="WallTop"]
position = Vector2( 640, -20 )
shape = SubResource( 2 )

5
Scenes/Wall.tscn Normal file
View file

@ -0,0 +1,5 @@
[gd_scene format=2]
[node name="Wall" type="StaticBody2D"]
collision_layer = 16
collision_mask = 2

View file

@ -11,23 +11,19 @@ export(float, 0, 1000000) var song_offset: float = 0
# The time the song started playing at
var start_time: int
# Song beats signals
signal quarter_beat
signal half_beat
signal beat
signal four_beats
signal two_beats
# Beat signal
signal subbeat(subbeat_num)
# The time of the last quarter_beat
var last_qb: int
var last_subbeat: int
# The count of quarter_beats so far
var count_qb: int = 0
var subbeat_count: int = 0
# Calculate the microseconds per beat
func usec_per_quarter_beat():
return 60000000 / (song_bpm * 4)
# Calculate the microseconds per 1/12 beat
func subbeat_usec():
return 60000000 / (song_bpm * 12)
# Returns microseconds since the song start
@ -44,7 +40,7 @@ func corrected_time():
# Start playing the song
func play():
start_time = OS.get_ticks_usec()
count_qb = 0
subbeat_count = 0
$Music.play()
@ -54,15 +50,7 @@ func _ready():
func _process(delta):
var time = corrected_time()
if time - last_qb >= usec_per_quarter_beat():
emit_signal("quarter_beat")
if count_qb % 2 == 0:
emit_signal("half_beat")
if count_qb % 4 == 0:
emit_signal("beat")
if count_qb % 8 == 0:
emit_signal("two_beats")
if count_qb % 16 == 0:
emit_signal("four_beats")
last_qb = time
count_qb += 1
if time - last_subbeat >= subbeat_usec():
emit_signal("subbeat", subbeat_count)
last_subbeat = time
subbeat_count += 1

View file

@ -0,0 +1,22 @@
extends StaticBody2D
class_name Press
var root_node: Node = null
var conductor: Conductor = null
func _subbeat(subbeat_num):
if subbeat_num % 24 == 0:
$AnimationPlayer.play("Stomp")
elif subbeat_num % 24 == 12:
$AnimationPlayer.play_backwards("Stomp")
func _enter_tree():
root_node = get_tree().current_scene
conductor = root_node.get_node("Conductor")
conductor.connect("subbeat", self, "_subbeat")
func _on_StompArea_body_entered(body):
print(body)

View file

@ -2,7 +2,7 @@ extends ExtendedKinematicBody2D
class_name ScrollingBlock
export(Vector2) var scroll_velocity: Vector2 = Vector2(-10, 0)
export(Vector2) var scroll_velocity: Vector2 = Vector2(-100, 0)
func _physics_process(delta):

View file

@ -5,9 +5,10 @@ export(Vector2) var gravity: Vector2 = Vector2(0, 10)
var speed: Vector2 = Vector2.ZERO
export(float) var move_speed: float = 300
export(float) var jump_speed: float = 500
export(float) var jump_buffer_msec: float = 64
export(float) var jump_speed: float = 425
export(float) var jump_buffer_msec: float = 80
export(float) var quick_fall_gravity_multiplier: float = 4
export(bool) var stop_jump_on_bonk: bool = true
var can_jump: bool = false
var jump_buffer: int = 0
@ -28,6 +29,9 @@ func _physics_process(delta):
can_jump = true
is_quick_falling = false
if stop_jump_on_bonk and is_on_ceiling():
speed.y = 0
if is_quick_falling:
speed += gravity * quick_fall_gravity_multiplier
else:

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

View file

@ -20,7 +20,7 @@ compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/filter=false
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2

View file

@ -20,7 +20,7 @@ compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/filter=false
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2

View file

@ -20,7 +20,7 @@ compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/filter=false
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2

View file

@ -20,7 +20,7 @@ compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/filter=false
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2

View file

@ -20,7 +20,7 @@ compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/filter=false
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2

View file

@ -20,7 +20,7 @@ compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/filter=false
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2

BIN
Sprites/press_bottom.png (Stored with Git LFS) Normal file

Binary file not shown.

View file

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/press_bottom.png-334fad476d2fb2f7e1f033f4eecb9564.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://Sprites/press_bottom.png"
dest_files=[ "res://.import/press_bottom.png-334fad476d2fb2f7e1f033f4eecb9564.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=false
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

BIN
Sprites/press_pipes.png (Stored with Git LFS) Normal file

Binary file not shown.

View file

@ -2,15 +2,15 @@
importer="texture"
type="StreamTexture"
path="res://.import/pressa.png-de3cbaeb993efaee29fad4d460691535.stex"
path="res://.import/press_pipes.png-a7b3ec50f427100b50342d18a41d9393.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://Sprites/pressa.png"
dest_files=[ "res://.import/pressa.png-de3cbaeb993efaee29fad4d460691535.stex" ]
source_file="res://Sprites/press_pipes.png"
dest_files=[ "res://.import/press_pipes.png-a7b3ec50f427100b50342d18a41d9393.stex" ]
[params]
@ -20,7 +20,7 @@ compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/filter=false
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2

BIN
Sprites/pressa.png (Stored with Git LFS)

Binary file not shown.

View file

@ -20,7 +20,7 @@ compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/filter=false
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2

View file

@ -29,6 +29,11 @@ _global_script_classes=[ {
"language": "GDScript",
"path": "res://Scripts/Player.gd"
}, {
"base": "StaticBody2D",
"class": "Press",
"language": "GDScript",
"path": "res://Scripts/Obstacles/Press.gd"
}, {
"base": "ExtendedKinematicBody2D",
"class": "ScrollingBlock",
"language": "GDScript",
@ -39,6 +44,7 @@ _global_script_class_icons={
"ConveyorBelt": "",
"ExtendedKinematicBody2D": "",
"Player": "",
"Press": "",
"ScrollingBlock": ""
}
@ -82,6 +88,7 @@ plr_right={
2d_physics/layer_2="Player"
2d_physics/layer_3="Conveyor Belt"
2d_physics/layer_4="Obstacles"
2d_physics/layer_5="Screen Walls"
[rendering]