mirror of
https://github.com/Steffo99/looping-for-loops.git
synced 2024-11-25 17:44:22 +00:00
⚙️ Implement conveyor belt animation
This commit is contained in:
parent
9272e7bcbb
commit
8a9a48d46c
10 changed files with 215 additions and 85 deletions
|
@ -1,10 +1,12 @@
|
||||||
[gd_scene load_steps=4 format=2]
|
[gd_scene load_steps=6 format=2]
|
||||||
|
|
||||||
[ext_resource path="res://Tilesets/ConveyorBelt.tres" type="TileSet" id=1]
|
[ext_resource path="res://Tilesets/ConveyorBelt.tres" type="TileSet" id=1]
|
||||||
[ext_resource path="res://Scripts/ConveyorBelt.gd" type="Script" id=2]
|
[ext_resource path="res://Scripts/ConveyorBelt.gd" type="Script" id=2]
|
||||||
|
[ext_resource path="res://Scenes/Gear.tscn" type="PackedScene" id=3]
|
||||||
|
[ext_resource path="res://Scenes/Gears.gd" type="Script" id=5]
|
||||||
|
|
||||||
[sub_resource type="RectangleShape2D" id=1]
|
[sub_resource type="RectangleShape2D" id=1]
|
||||||
extents = Vector2( 680, 20 )
|
extents = Vector2( 640, 20 )
|
||||||
|
|
||||||
[node name="ConveyorBelt" type="StaticBody2D"]
|
[node name="ConveyorBelt" type="StaticBody2D"]
|
||||||
collision_layer = 4
|
collision_layer = 4
|
||||||
|
@ -22,4 +24,103 @@ cell_quadrant_size = 40
|
||||||
cell_tile_origin = 1
|
cell_tile_origin = 1
|
||||||
centered_textures = true
|
centered_textures = true
|
||||||
format = 1
|
format = 1
|
||||||
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 )
|
tile_data = PoolIntArray( 65520, 0, 0, 65521, 0, 0, 65522, 0, 0, 65523, 0, 0, 65524, 0, 0, 65525, 0, 0, 65526, 0, 0, 65527, 0, 0, 65528, 0, 0, 65529, 0, 0, 65530, 0, 0, 65531, 0, 0, 65532, 0, 0, 65533, 0, 0, 65534, 0, 0, 65535, 0, 0, 0, 0, 0, 1, 0, 0, 2, 0, 0, 3, 0, 0, 4, 0, 0, 5, 0, 0, 6, 0, 0, 7, 0, 0, 8, 0, 0, 9, 0, 0, 10, 0, 0, 11, 0, 0, 12, 0, 0, 13, 0, 0, 14, 0, 0, 15, 0, 0 )
|
||||||
|
|
||||||
|
[node name="Gears" type="Node2D" parent="."]
|
||||||
|
position = Vector2( -220, 0 )
|
||||||
|
script = ExtResource( 5 )
|
||||||
|
|
||||||
|
[node name="Gear" parent="Gears" instance=ExtResource( 3 )]
|
||||||
|
|
||||||
|
[node name="Gear2" parent="Gears" instance=ExtResource( 3 )]
|
||||||
|
position = Vector2( -360, 0 )
|
||||||
|
|
||||||
|
[node name="Gear3" parent="Gears" instance=ExtResource( 3 )]
|
||||||
|
position = Vector2( -320, 0 )
|
||||||
|
|
||||||
|
[node name="Gear4" parent="Gears" instance=ExtResource( 3 )]
|
||||||
|
position = Vector2( -280, 0 )
|
||||||
|
|
||||||
|
[node name="Gear5" parent="Gears" instance=ExtResource( 3 )]
|
||||||
|
position = Vector2( -240, 0 )
|
||||||
|
|
||||||
|
[node name="Gear6" parent="Gears" instance=ExtResource( 3 )]
|
||||||
|
position = Vector2( -200, 0 )
|
||||||
|
|
||||||
|
[node name="Gear7" parent="Gears" instance=ExtResource( 3 )]
|
||||||
|
position = Vector2( -160, 0 )
|
||||||
|
|
||||||
|
[node name="Gear8" parent="Gears" instance=ExtResource( 3 )]
|
||||||
|
position = Vector2( -120, 0 )
|
||||||
|
|
||||||
|
[node name="Gear9" parent="Gears" instance=ExtResource( 3 )]
|
||||||
|
position = Vector2( -80, 0 )
|
||||||
|
|
||||||
|
[node name="Gear10" parent="Gears" instance=ExtResource( 3 )]
|
||||||
|
position = Vector2( -40, 0 )
|
||||||
|
|
||||||
|
[node name="Gear11" parent="Gears" instance=ExtResource( 3 )]
|
||||||
|
position = Vector2( 0, 0 )
|
||||||
|
|
||||||
|
[node name="Gear12" parent="Gears" instance=ExtResource( 3 )]
|
||||||
|
position = Vector2( 40, 0 )
|
||||||
|
|
||||||
|
[node name="Gear13" parent="Gears" instance=ExtResource( 3 )]
|
||||||
|
position = Vector2( 80, 0 )
|
||||||
|
|
||||||
|
[node name="Gear14" parent="Gears" instance=ExtResource( 3 )]
|
||||||
|
position = Vector2( 120, 0 )
|
||||||
|
|
||||||
|
[node name="Gear15" parent="Gears" instance=ExtResource( 3 )]
|
||||||
|
position = Vector2( 160, 0 )
|
||||||
|
|
||||||
|
[node name="Gear16" parent="Gears" instance=ExtResource( 3 )]
|
||||||
|
position = Vector2( 200, 0 )
|
||||||
|
|
||||||
|
[node name="Gear17" parent="Gears" instance=ExtResource( 3 )]
|
||||||
|
position = Vector2( 240, 0 )
|
||||||
|
|
||||||
|
[node name="Gear18" parent="Gears" instance=ExtResource( 3 )]
|
||||||
|
position = Vector2( 280, 0 )
|
||||||
|
|
||||||
|
[node name="Gear19" parent="Gears" instance=ExtResource( 3 )]
|
||||||
|
position = Vector2( 320, 0 )
|
||||||
|
|
||||||
|
[node name="Gear20" parent="Gears" instance=ExtResource( 3 )]
|
||||||
|
position = Vector2( 360, 0 )
|
||||||
|
|
||||||
|
[node name="Gear21" parent="Gears" instance=ExtResource( 3 )]
|
||||||
|
position = Vector2( 400, 0 )
|
||||||
|
|
||||||
|
[node name="Gear22" parent="Gears" instance=ExtResource( 3 )]
|
||||||
|
position = Vector2( 440, 0 )
|
||||||
|
|
||||||
|
[node name="Gear23" parent="Gears" instance=ExtResource( 3 )]
|
||||||
|
position = Vector2( 480, 0 )
|
||||||
|
|
||||||
|
[node name="Gear24" parent="Gears" instance=ExtResource( 3 )]
|
||||||
|
position = Vector2( 520, 0 )
|
||||||
|
|
||||||
|
[node name="Gear25" parent="Gears" instance=ExtResource( 3 )]
|
||||||
|
position = Vector2( 560, 0 )
|
||||||
|
|
||||||
|
[node name="Gear26" parent="Gears" instance=ExtResource( 3 )]
|
||||||
|
position = Vector2( 600, 0 )
|
||||||
|
|
||||||
|
[node name="Gear27" parent="Gears" instance=ExtResource( 3 )]
|
||||||
|
position = Vector2( 640, 0 )
|
||||||
|
|
||||||
|
[node name="Gear28" parent="Gears" instance=ExtResource( 3 )]
|
||||||
|
position = Vector2( 680, 0 )
|
||||||
|
|
||||||
|
[node name="Gear29" parent="Gears" instance=ExtResource( 3 )]
|
||||||
|
position = Vector2( 720, 0 )
|
||||||
|
|
||||||
|
[node name="Gear30" parent="Gears" instance=ExtResource( 3 )]
|
||||||
|
position = Vector2( 760, 0 )
|
||||||
|
|
||||||
|
[node name="Gear31" parent="Gears" instance=ExtResource( 3 )]
|
||||||
|
position = Vector2( 800, 0 )
|
||||||
|
|
||||||
|
[node name="Gear32" parent="Gears" instance=ExtResource( 3 )]
|
||||||
|
position = Vector2( 840, 0 )
|
||||||
|
|
21
Scenes/Gear.gd
Normal file
21
Scenes/Gear.gd
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
extends Node2D
|
||||||
|
|
||||||
|
|
||||||
|
var rng = RandomNumberGenerator.new()
|
||||||
|
|
||||||
|
var cb_speed: float setget set_cb_speed, get_cb_speed
|
||||||
|
var randomize_start_position: bool = false
|
||||||
|
|
||||||
|
func set_cb_speed(value):
|
||||||
|
cb_speed = value
|
||||||
|
$AnimationPlayer.playback_speed = -value / 80
|
||||||
|
$AnimationPlayer.play("SpinClockwise")
|
||||||
|
if randomize_start_position:
|
||||||
|
rng.randomize()
|
||||||
|
var offset = rng.randf_range(0.0, 1.0)
|
||||||
|
$AnimationPlayer.seek(offset, true)
|
||||||
|
randomize_start_position = false
|
||||||
|
|
||||||
|
func get_cb_speed():
|
||||||
|
return cb_speed
|
||||||
|
|
30
Scenes/Gear.tscn
Normal file
30
Scenes/Gear.tscn
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
[gd_scene load_steps=4 format=2]
|
||||||
|
|
||||||
|
[ext_resource path="res://Sprites/conveyor_gear.png" type="Texture" id=1]
|
||||||
|
[ext_resource path="res://Scenes/Gear.gd" type="Script" id=2]
|
||||||
|
|
||||||
|
[sub_resource type="Animation" id=2]
|
||||||
|
resource_name = "SpinClockwise"
|
||||||
|
loop = true
|
||||||
|
tracks/0/type = "value"
|
||||||
|
tracks/0/path = NodePath("Gear1:rotation_degrees")
|
||||||
|
tracks/0/interp = 1
|
||||||
|
tracks/0/loop_wrap = true
|
||||||
|
tracks/0/imported = false
|
||||||
|
tracks/0/enabled = true
|
||||||
|
tracks/0/keys = {
|
||||||
|
"times": PoolRealArray( 0, 1 ),
|
||||||
|
"transitions": PoolRealArray( 1, 1 ),
|
||||||
|
"update": 0,
|
||||||
|
"values": [ 0.0, 360.0 ]
|
||||||
|
}
|
||||||
|
|
||||||
|
[node name="Gear" type="Node2D"]
|
||||||
|
position = Vector2( -400, 0 )
|
||||||
|
script = ExtResource( 2 )
|
||||||
|
|
||||||
|
[node name="Gear1" type="Sprite" parent="."]
|
||||||
|
texture = ExtResource( 1 )
|
||||||
|
|
||||||
|
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
|
||||||
|
anims/SpinClockwise = SubResource( 2 )
|
18
Scenes/Gears.gd
Normal file
18
Scenes/Gears.gd
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
extends Node2D
|
||||||
|
|
||||||
|
|
||||||
|
var cb_speed: float setget set_cb_speed, get_cb_speed
|
||||||
|
|
||||||
|
func set_cb_speed(value):
|
||||||
|
for children in get_children():
|
||||||
|
children.set_cb_speed(value)
|
||||||
|
|
||||||
|
func get_cb_speed():
|
||||||
|
return cb_speed
|
||||||
|
|
||||||
|
|
||||||
|
var randomize_start_position: bool setget set_randomize_start_position
|
||||||
|
|
||||||
|
func set_randomize_start_position(value):
|
||||||
|
for children in get_children():
|
||||||
|
children.randomize_start_position = value
|
|
@ -1,11 +1,9 @@
|
||||||
[gd_scene load_steps=7 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/Player.tscn" type="PackedScene" id=1]
|
||||||
[ext_resource path="res://Scenes/Conductor.tscn" type="PackedScene" id=2]
|
[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/ConveyorBelt.tscn" type="PackedScene" id=3]
|
||||||
[ext_resource path="res://Scenes/SingleScreenWalls.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="Main" type="Node2D"]
|
||||||
__meta__ = {
|
__meta__ = {
|
||||||
|
@ -17,80 +15,8 @@ position = Vector2( 622.258, 379.938 )
|
||||||
|
|
||||||
[node name="ConveyorBelt" parent="." instance=ExtResource( 3 )]
|
[node name="ConveyorBelt" parent="." instance=ExtResource( 3 )]
|
||||||
position = Vector2( 640, 700 )
|
position = Vector2( 640, 700 )
|
||||||
conveyor_speed = 100.0
|
cb_speed = 100.0
|
||||||
|
|
||||||
[node name="SingleScreenWalls" parent="." instance=ExtResource( 4 )]
|
[node name="SingleScreenWalls" parent="." instance=ExtResource( 4 )]
|
||||||
|
|
||||||
[node name="Conductor" parent="." instance=ExtResource( 2 )]
|
[node name="Conductor" parent="." instance=ExtResource( 2 )]
|
||||||
song_bpm = 120.0
|
|
||||||
|
|
||||||
[node name="ScrollingBlock" parent="." instance=ExtResource( 6 )]
|
|
||||||
position = Vector2( 800, 660 )
|
|
||||||
|
|
||||||
[node name="ScrollingBlock2" parent="." instance=ExtResource( 6 )]
|
|
||||||
position = Vector2( 880, 580 )
|
|
||||||
|
|
||||||
[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 )
|
|
||||||
|
|
||||||
[node name="ScrollingBlock14" parent="." instance=ExtResource( 6 )]
|
|
||||||
position = Vector2( 2240, 360 )
|
|
||||||
scale = Vector2( 5, 1 )
|
|
||||||
|
|
||||||
[node name="ScrollingBlock15" parent="." instance=ExtResource( 6 )]
|
|
||||||
position = Vector2( 2540, 280 )
|
|
||||||
scale = Vector2( 5, 1 )
|
|
||||||
|
|
||||||
[node name="ScrollingBlock16" parent="." instance=ExtResource( 6 )]
|
|
||||||
position = Vector2( 2820, 400 )
|
|
||||||
scale = Vector2( 5, 1 )
|
|
||||||
|
|
||||||
[node name="Press" parent="." instance=ExtResource( 5 )]
|
|
||||||
position = Vector2( 160, 0 )
|
|
||||||
scroll_velocity = Vector2( 0, 0 )
|
|
||||||
|
|
||||||
[node name="Press2" parent="." instance=ExtResource( 5 )]
|
|
||||||
position = Vector2( 3120, 0 )
|
|
||||||
|
|
||||||
[node name="Press3" parent="." instance=ExtResource( 5 )]
|
|
||||||
position = Vector2( 3280, 0 )
|
|
||||||
subbeat_offset = 3
|
|
||||||
|
|
||||||
[node name="Press4" parent="." instance=ExtResource( 5 )]
|
|
||||||
position = Vector2( 3440, 0 )
|
|
||||||
subbeat_offset = 6
|
|
||||||
|
|
||||||
[node name="Press5" parent="." instance=ExtResource( 5 )]
|
|
||||||
position = Vector2( 3600, 0 )
|
|
||||||
subbeat_offset = 9
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[gd_scene load_steps=4 format=2]
|
[gd_scene load_steps=4 format=2]
|
||||||
|
|
||||||
[ext_resource path="res://Sprites/scrolling_block.png" type="Texture" id=1]
|
[ext_resource path="res://Sprites/crate.png" type="Texture" id=1]
|
||||||
[ext_resource path="res://Scripts/Obstacles/ScrollingBlock.gd" type="Script" id=2]
|
[ext_resource path="res://Scripts/Obstacles/ScrollingBlock.gd" type="Script" id=2]
|
||||||
|
|
||||||
[sub_resource type="RectangleShape2D" id=1]
|
[sub_resource type="RectangleShape2D" id=1]
|
||||||
|
|
9
Scenes/Obstacles/ScrollingPipe.tscn
Normal file
9
Scenes/Obstacles/ScrollingPipe.tscn
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
[gd_scene load_steps=2 format=2]
|
||||||
|
|
||||||
|
[ext_resource path="res://Scripts/Obstacles/ScrollingBlock.gd" type="Script" id=2]
|
||||||
|
|
||||||
|
[node name="ScrollingPipe" type="KinematicBody2D"]
|
||||||
|
collision_layer = 8
|
||||||
|
collision_mask = 2
|
||||||
|
motion/sync_to_physics = true
|
||||||
|
script = ExtResource( 2 )
|
12
Scenes/Obstacles/ScrollingPipesTileMap.tscn
Normal file
12
Scenes/Obstacles/ScrollingPipesTileMap.tscn
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
[gd_scene load_steps=2 format=2]
|
||||||
|
|
||||||
|
[ext_resource path="res://Tilesets/Pipes.tres" type="TileSet" id=1]
|
||||||
|
|
||||||
|
[node name="TileMap" type="TileMap"]
|
||||||
|
tile_set = ExtResource( 1 )
|
||||||
|
cell_size = Vector2( 40, 40 )
|
||||||
|
cell_quadrant_size = 40
|
||||||
|
collision_use_kinematic = true
|
||||||
|
collision_layer = 8
|
||||||
|
collision_mask = 2
|
||||||
|
format = 1
|
|
@ -3,10 +3,23 @@ class_name ConveyorBelt
|
||||||
|
|
||||||
|
|
||||||
# Speed (and direction) of the conveyor belt
|
# Speed (and direction) of the conveyor belt
|
||||||
export(float) var conveyor_speed = 0
|
export(float) var cb_speed = 100 setget set_cb_speed, get_cb_speed
|
||||||
|
export(bool) var randomize_gear_starting_position = false
|
||||||
|
|
||||||
|
func set_cb_speed(value):
|
||||||
|
cb_speed = value
|
||||||
|
$Gears.set_cb_speed(value)
|
||||||
|
|
||||||
|
func get_cb_speed():
|
||||||
|
return cb_speed
|
||||||
|
|
||||||
|
|
||||||
func get_conveyor_speed(other_pos: Vector2):
|
func _ready():
|
||||||
|
$Gears.set_randomize_start_position(randomize_gear_starting_position)
|
||||||
|
$Gears.set_cb_speed(cb_speed)
|
||||||
|
|
||||||
|
|
||||||
|
func get_relative_cb_speed(other_pos: Vector2):
|
||||||
var relative_position = other_pos - position
|
var relative_position = other_pos - position
|
||||||
var speed_sign = sign(relative_position.dot(Vector2.UP.rotated(rotation)))
|
var speed_sign = sign(relative_position.dot(Vector2.UP.rotated(rotation)))
|
||||||
return speed_sign * conveyor_speed
|
return speed_sign * cb_speed
|
||||||
|
|
|
@ -56,8 +56,8 @@ func _physics_process(delta):
|
||||||
|
|
||||||
if is_on_floor():
|
if is_on_floor():
|
||||||
var current_floor = get_floor()
|
var current_floor = get_floor()
|
||||||
if current_floor.has_method("get_conveyor_speed"):
|
if current_floor.has_method("get_relative_cb_speed"):
|
||||||
movement += floor_normal.rotated(- PI / 2) * current_floor.get_conveyor_speed(position)
|
movement += floor_normal.rotated(- PI / 2) * current_floor.get_relative_cb_speed(position)
|
||||||
|
|
||||||
if Input.is_action_pressed("plr_left"):
|
if Input.is_action_pressed("plr_left"):
|
||||||
movement += Vector2.LEFT * move_speed
|
movement += Vector2.LEFT * move_speed
|
||||||
|
|
Loading…
Reference in a new issue