Skip to content

Commit

Permalink
give "build your course then run it" a try
Browse files Browse the repository at this point in the history
  • Loading branch information
nolenroyalty committed Apr 30, 2023
1 parent 3e7fea0 commit 1e40391
Show file tree
Hide file tree
Showing 9 changed files with 184 additions and 11 deletions.
6 changes: 6 additions & 0 deletions Bucket/Bucket.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
extends KinematicBody2D

onready var string_location = $StringLocation

func get_string_location() -> Vector2:
return string_location.global_position
45 changes: 37 additions & 8 deletions Bucket/Bucket.tscn
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
[gd_scene load_steps=5 format=2]
[gd_scene load_steps=8 format=2]

[ext_resource path="res://Bucket/Sprites/bucket.png" type="Texture" id=1]
[ext_resource path="res://Bucket/Bucket.gd" type="Script" id=2]

[sub_resource type="CircleShape2D" id=1]
radius = 12.1655
[sub_resource type="CapsuleShape2D" id=4]
radius = 4.00002
height = 9.99997

[sub_resource type="CircleShape2D" id=2]
radius = 15.0
Expand All @@ -12,16 +14,26 @@ radius = 15.0
radius = 14.0
height = 14.0

[sub_resource type="CapsuleShape2D" id=5]
radius = 3.0
height = 8.0

[sub_resource type="CapsuleShape2D" id=6]
radius = 2.0
height = 22.0

[node name="KinematicBody2D" type="KinematicBody2D"]
collision_mask = 2
collision_mask = 6
script = ExtResource( 2 )

[node name="Bucket" type="Sprite" parent="."]
position = Vector2( 0, 3 )
position = Vector2( 0, 16 )
texture = ExtResource( 1 )

[node name="CollisionShape2D2" type="CollisionShape2D" parent="."]
position = Vector2( 1, -20 )
shape = SubResource( 1 )
position = Vector2( 0, -10 )
rotation = 1.57079
shape = SubResource( 4 )

[node name="CollisionShape2D3" type="CollisionShape2D" parent="."]
visible = false
Expand All @@ -30,6 +42,23 @@ shape = SubResource( 2 )
disabled = true

[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
position = Vector2( 1, 19 )
position = Vector2( 0, 32 )
rotation = 1.5708
shape = SubResource( 3 )

[node name="StringLocation" type="Node2D" parent="."]
position = Vector2( 0, -3 )

[node name="HandleUpRight" type="CollisionShape2D" parent="."]
position = Vector2( 6, -2 )
shape = SubResource( 5 )
disabled = true

[node name="HandleTop" type="CollisionShape2D" parent="."]
position = Vector2( 0, -10 )
rotation = 1.57079
shape = SubResource( 4 )

[node name="HandleStalk" type="CollisionShape2D" parent="."]
position = Vector2( -6, 6 )
shape = SubResource( 6 )
80 changes: 80 additions & 0 deletions Levels/BuilderGeneric.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
extends Node2D

var fixed_latch_points = []
onready var static_body = $StaticBody2D
onready var line = $StaticBody2D/Line2D

func _ready():
init_fixed_latchpoints()

func init_fixed_latchpoints():
for child in get_children():
if child.is_in_group("fixed_latchpoint"):
fixed_latch_points.append(child.position)

render_line(fixed_latch_points)

func render_line(points):
points.sort_custom(SortByX, "sort")

# Maybe this could be smart about keeping most of the polygons?
for child in static_body.get_children():
if child is CollisionPolygon2D:
child.call_deferred("queue_free")
# child.queue_free()

line.points = points
# Store the line's global position so we can reset its position after moving its parent
var line_global_position = line.global_position
# Generate collision polygons from the Line2D node
var line_poly = Geometry.offset_polyline_2d(line.points, line.width / 2, Geometry.JOIN_ROUND, Geometry.END_ROUND)
# Move the rigidbody to the center of the line, taking into account
# any offset the Polygon2D node may have relative to the rigidbody
var line_center = get_line_center()
# static_line.set_deferred("global_position", static_line.global_position + line_center + line_points.position)
static_body.global_position += line_center + line.position
# Move the line node to its original position
# line_points.set_deferred("global_position", line_global_position)
line.global_position = line_global_position

# line_poly may contain multiple polygons, so iterate over it
for poly in line_poly:
var collision_shape = CollisionPolygon2D.new()
collision_shape.polygon = offset_line_points(line_center, poly)
# static_line.call_deferred("add_child", collision_shape)
static_body.add_child(collision_shape)

# A simple weighted average of all points of the Line2D to find the center
func get_line_center() -> Vector2:
var center_weight = line.points.size()
var center = Vector2(0, 0)

for point in line.points:
center.x += point.x / center_weight
center.y += point.y / center_weight

return center

# Offset the points of the polygon by the center of the line
func offset_line_points(center: Vector2, poly: Array) -> Array:
var adjusted_points = []
for point in poly:
# Moving the collision shape itself doesn't seem to work as well as offsetting the polygon points
# for putting the collision shape in the right position after moving the rigidbody.
# Therefore, to have the collision shape appear where drawn, subtract the polygon center from each point
# to move the point by the amount the rigidbody was moved relative to the original Line2D's position.
adjusted_points.append(point - center)
return adjusted_points

func line_length(points) -> int:
var initial_point = points[0]
var length = 0
for idx in range(1, points.size()):
var point = points[idx]
length += initial_point.distance_to(point)
initial_point = point
return length

class SortByX:
static func sort(a, b):
return a.x < b.x
35 changes: 35 additions & 0 deletions Levels/LevelBuilder1.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
[gd_scene load_steps=5 format=2]

[ext_resource path="res://Terrain/Landscape.tscn" type="PackedScene" id=1]
[ext_resource path="res://Terrain/FixedLatchPoint.tscn" type="PackedScene" id=2]
[ext_resource path="res://Levels/BuilderGeneric.gd" type="Script" id=3]

[sub_resource type="Curve" id=1]
_data = [ Vector2( 0, 1 ), 0.0, 0.0, 0, 0 ]

[node name="Level1Builder" type="Node2D"]
script = ExtResource( 3 )

[node name="TileMap" parent="." instance=ExtResource( 1 )]
tile_data = PoolIntArray( 262146, 2, 0, 327682, 2, 65536, 393218, 2, 65536, 458754, 2, 65536, 524290, 2, 65536, 589826, 2, 65536, 720894, 1, 1, 720895, 1, 2, 655360, 1, 2, 655361, 1, 3, 655362, 2, 131072, 786430, 1, 65537, 786431, 1, 65538, 720896, 1, 65538, 720897, 1, 65538, 720898, 1, 2, 720899, 1, 2, 720900, 1, 3, 720913, 1, 1, 720914, 1, 2, 720915, 1, 3, 851966, 1, 65537, 851967, 1, 65538, 786432, 1, 65538, 786433, 1, 65538, 786434, 1, 65538, 786435, 1, 65538, 786436, 1, 65538, 786437, 1, 2, 786438, 1, 2, 786439, 1, 2, 786440, 1, 3, 786449, 1, 65537, 786450, 1, 65538, 786451, 1, 65539, 917502, 1, 65537, 917503, 1, 65538, 851968, 1, 65538, 851969, 1, 65538, 851970, 1, 65538, 851971, 1, 65538, 851972, 1, 65538, 851973, 1, 65538, 851974, 1, 65538, 851975, 1, 65538, 851976, 1, 65538, 851977, 1, 2, 851978, 1, 3, 851985, 1, 65537, 851986, 1, 65538, 851987, 1, 65539, 983038, 1, 65537, 983039, 1, 65538, 917504, 1, 65538, 917505, 1, 65538, 917506, 1, 65538, 917507, 1, 65538, 917508, 1, 65538, 917509, 1, 65538, 917510, 1, 65538, 917511, 1, 65538, 917512, 1, 65538, 917513, 1, 65538, 917514, 1, 65538, 917515, 1, 2, 917516, 1, 2, 917517, 1, 2, 917518, 1, 2, 917519, 1, 3, 917521, 1, 65537, 917522, 1, 65538, 917523, 1, 65538, 917524, 1, 3, 1048574, 1, 131073, 1048575, 1, 65538, 983040, 1, 65538, 983041, 1, 65538, 983042, 1, 65538, 983043, 1, 65538, 983044, 1, 65538, 983045, 1, 65538, 983046, 1, 65538, 983047, 1, 65538, 983048, 1, 65538, 983049, 1, 65538, 983050, 1, 65538, 983051, 1, 65538, 983052, 1, 65538, 983053, 1, 65538, 983054, 1, 65538, 983055, 1, 65538, 983056, 1, 2, 983057, 1, 65538, 983058, 1, 65538, 983059, 1, 65538, 983060, 1, 65538, 983061, 1, 3, 1114111, 1, 65537, 1048576, 1, 65538, 1048577, 1, 65538, 1048578, 1, 65538, 1048579, 1, 65538, 1048580, 1, 65538, 1048581, 1, 65538, 1048582, 1, 65538, 1048583, 1, 65538, 1048584, 1, 65538, 1048585, 1, 65538, 1048586, 1, 65538, 1048587, 1, 65538, 1048588, 1, 65538, 1048589, 1, 65538, 1048590, 1, 65538, 1048591, 1, 65538, 1048592, 1, 65538, 1048593, 1, 65538, 1048594, 1, 65538, 1048595, 1, 65538, 1048596, 1, 65538, 1048597, 1, 65538, 1048598, 1, 3, 1179647, 1, 65537, 1114112, 1, 65538, 1114113, 1, 65538, 1114114, 1, 65538, 1114115, 1, 65538, 1114116, 1, 65538, 1114117, 1, 65538, 1114118, 1, 65538, 1114119, 1, 65538, 1114120, 1, 65538, 1114121, 1, 65538, 1114122, 1, 65538, 1114123, 1, 65538, 1114124, 1, 65538, 1114125, 1, 65538, 1114126, 1, 65538, 1114127, 1, 65538, 1114128, 1, 65538, 1114129, 1, 65538, 1114130, 1, 65538, 1114131, 1, 65538, 1114132, 1, 65538, 1114133, 1, 65538, 1114134, 1, 65538, 1114135, 1, 2, 1114136, 1, 3, 1114146, 2, 0, 1245183, 1, 65537, 1179648, 1, 65538, 1179649, 1, 65538, 1179650, 1, 65538, 1179651, 1, 65538, 1179652, 1, 65538, 1179653, 1, 65538, 1179654, 1, 65538, 1179655, 1, 65538, 1179656, 1, 65538, 1179657, 1, 65538, 1179658, 1, 65538, 1179659, 1, 65538, 1179660, 1, 65538, 1179661, 1, 65538, 1179662, 1, 65538, 1179663, 1, 65538, 1179664, 1, 65538, 1179665, 1, 65538, 1179666, 1, 65538, 1179667, 1, 65538, 1179668, 1, 65538, 1179669, 1, 65538, 1179670, 1, 65538, 1179671, 1, 65538, 1179672, 1, 65538, 1179673, 1, 2, 1179674, 1, 2, 1179675, 1, 2, 1179676, 1, 3, 1179682, 2, 65536, 1310719, 1, 65537, 1245184, 1, 65538, 1245185, 1, 65538, 1245186, 1, 65538, 1245187, 1, 65538, 1245188, 1, 65538, 1245189, 1, 65538, 1245190, 1, 65538, 1245191, 1, 65538, 1245192, 1, 65538, 1245193, 1, 65538, 1245194, 1, 65538, 1245195, 1, 65538, 1245196, 1, 65538, 1245197, 1, 65538, 1245198, 1, 65538, 1245199, 1, 65538, 1245200, 1, 65538, 1245201, 1, 65538, 1245202, 1, 65538, 1245203, 1, 65538, 1245204, 1, 65538, 1245205, 1, 65538, 1245206, 1, 65538, 1245207, 1, 65538, 1245208, 1, 65538, 1245209, 1, 65538, 1245210, 1, 65538, 1245211, 1, 65538, 1245212, 1, 65538, 1245213, 1, 3, 1245218, 2, 65536, 1376255, 1, 65537, 1310720, 1, 65538, 1310721, 1, 65538, 1310722, 1, 65538, 1310723, 1, 65538, 1310724, 1, 65538, 1310725, 1, 65538, 1310726, 1, 65538, 1310727, 1, 65538, 1310728, 1, 65538, 1310729, 1, 65538, 1310730, 1, 65538, 1310731, 1, 65538, 1310732, 1, 65538, 1310733, 1, 65538, 1310734, 1, 65538, 1310735, 1, 65538, 1310736, 1, 65538, 1310737, 1, 65538, 1310738, 1, 65538, 1310739, 1, 65538, 1310740, 1, 65538, 1310741, 1, 65538, 1310742, 1, 65538, 1310743, 1, 65538, 1310744, 1, 65538, 1310745, 1, 65538, 1310746, 1, 65538, 1310747, 1, 65538, 1310748, 1, 65538, 1310749, 1, 65538, 1310750, 1, 2, 1310751, 1, 3, 1310754, 2, 131072, 1441791, 1, 65537, 1376256, 1, 65538, 1376257, 1, 65538, 1376258, 1, 65538, 1376259, 1, 65538, 1376260, 1, 65538, 1376261, 1, 65538, 1376262, 1, 65538, 1376263, 1, 65538, 1376264, 1, 65538, 1376265, 1, 65538, 1376266, 1, 65538, 1376267, 1, 65538, 1376268, 1, 65538, 1376269, 1, 65538, 1376270, 1, 65538, 1376271, 1, 65538, 1376272, 1, 65538, 1376273, 1, 65538, 1376274, 1, 65538, 1376275, 1, 65538, 1376276, 1, 65538, 1376277, 1, 65538, 1376278, 1, 65538, 1376279, 1, 65538, 1376280, 1, 65538, 1376281, 1, 65538, 1376282, 1, 65538, 1376283, 1, 65538, 1376284, 1, 65538, 1376285, 1, 65538, 1376286, 1, 65538, 1376287, 1, 65538, 1376288, 1, 2, 1376289, 1, 2, 1376290, 1, 2, 1376291, 1, 2, 1376292, 1, 3, 1507327, 1, 65537, 1441792, 1, 65538, 1441793, 1, 65538, 1441794, 1, 65538, 1441795, 1, 65538, 1441796, 1, 65538, 1441797, 1, 65538, 1441798, 1, 65538, 1441799, 1, 65538, 1441800, 1, 65538, 1441801, 1, 65538, 1441802, 1, 65538, 1441803, 1, 65538, 1441804, 1, 65538, 1441805, 1, 65538, 1441806, 1, 65538, 1441807, 1, 65538, 1441808, 1, 65538, 1441809, 1, 65538, 1441810, 1, 65538, 1441811, 1, 65538, 1441812, 1, 65538, 1441813, 1, 65538, 1441814, 1, 65538, 1441815, 1, 65538, 1441816, 1, 65538, 1441817, 1, 65538, 1441818, 1, 65538, 1441819, 1, 65538, 1441820, 1, 65538, 1441821, 1, 65538, 1441822, 1, 65538, 1441823, 1, 65538, 1441824, 1, 65538, 1441825, 1, 65538, 1441826, 1, 65538, 1441827, 1, 65538, 1441828, 1, 65538, 1441829, 1, 3, 1572863, 1, 65537, 1507328, 1, 65538, 1507329, 1, 65538, 1507330, 1, 65538, 1507331, 1, 65538, 1507332, 1, 65538, 1507333, 1, 65538, 1507334, 1, 65538, 1507335, 1, 65538, 1507336, 1, 65538, 1507337, 1, 65538, 1507338, 1, 65538, 1507339, 1, 65538, 1507340, 1, 65538, 1507341, 1, 65538, 1507342, 1, 65538, 1507343, 1, 65538, 1507344, 1, 65538, 1507345, 1, 65538, 1507346, 1, 65538, 1507347, 1, 65538, 1507348, 1, 65538, 1507349, 1, 65538, 1507350, 1, 65538, 1507351, 1, 65538, 1507352, 1, 65538, 1507353, 1, 65538, 1507354, 1, 65538, 1507355, 1, 65538, 1507356, 1, 65538, 1507357, 1, 65538, 1507358, 1, 65538, 1507359, 1, 65538, 1507360, 1, 65538, 1507361, 1, 65538, 1507362, 1, 65538, 1507363, 1, 65538, 1507364, 1, 65538, 1507365, 1, 65539, 1638399, 1, 131073, 1572864, 1, 131074, 1572865, 1, 131074, 1572866, 1, 131074, 1572867, 1, 131074, 1572868, 1, 131074, 1572869, 1, 131074, 1572870, 1, 131074, 1572871, 1, 131074, 1572872, 1, 131074, 1572873, 1, 131074, 1572874, 1, 131074, 1572875, 1, 131074, 1572876, 1, 131074, 1572877, 1, 131074, 1572878, 1, 131074, 1572879, 1, 131074, 1572880, 1, 131074, 1572881, 1, 131074, 1572882, 1, 131074, 1572883, 1, 131074, 1572884, 1, 131074, 1572885, 1, 131074, 1572886, 1, 131074, 1572887, 1, 131074, 1572888, 1, 131074, 1572889, 1, 131074, 1572890, 1, 131074, 1572891, 1, 131074, 1572892, 1, 131074, 1572893, 1, 131074, 1572894, 1, 131074, 1572895, 1, 131074, 1572896, 1, 131074, 1572897, 1, 131074, 1572898, 1, 131074, 1572899, 1, 131074, 1572900, 1, 131074, 1572901, 1, 131075 )

[node name="FixedLatchPoint" parent="." instance=ExtResource( 2 )]
position = Vector2( 40, 64 )

[node name="FixedLatchPoint2" parent="." instance=ExtResource( 2 )]
position = Vector2( -24, 24 )

[node name="FixedLatchPoint3" parent="." instance=ExtResource( 2 )]
position = Vector2( 552, 272 )

[node name="FixedLatchPoint4" parent="." instance=ExtResource( 2 )]
position = Vector2( 632, 312 )

[node name="StaticBody2D" type="StaticBody2D" parent="."]
collision_layer = 4

[node name="Line2D" type="Line2D" parent="StaticBody2D"]
points = PoolVector2Array( 640, -48 )
width = 2.0
width_curve = SubResource( 1 )
default_color = Color( 0, 0, 0, 1 )
4 changes: 2 additions & 2 deletions Main.gd
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ enum S { STATIC, DRAGGING, WON, LOST, LOADING }
const STRETCH_FACTOR = 1.2
const MAXIMUM_BUCKET_WEIGHT = 80
const MINIMUM_BUCKET_WEIGHT = 0
const GRAVITY_MAX = 20
const GRAVITY_DELTA = 2
const GRAVITY_MAX = 40
const GRAVITY_DELTA = 5
const MAX_EXPECTED_DISTANCE = 400
const STICK_TO_MOUSE_WITHIN = 30
const MAXIMUM_SINGLE_FRAME_Y_MOVE = 1
Expand Down
4 changes: 3 additions & 1 deletion Main.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
script = ExtResource( 1 )

[node name="StaticLine" type="StaticBody2D" parent="."]
collision_layer = 2
collision_layer = 4
collision_mask = 0
input_pickable = true

[node name="LinePoints" type="Line2D" parent="StaticLine"]
width = 4.0
default_color = Color( 0.611765, 0.470588, 0.160784, 1 )

[node name="IceBarHud" parent="StaticLine" instance=ExtResource( 2 )]
6 changes: 6 additions & 0 deletions Terrain/FixedLatchPoint.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
extends Node2D

onready var planning_site = $PlanningSite

func _ready():
planning_site.hide()
13 changes: 13 additions & 0 deletions Terrain/FixedLatchPoint.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[gd_scene load_steps=2 format=2]

[ext_resource path="res://Terrain/FixedLatchPoint.gd" type="Script" id=1]

[node name="FixedLatchPoint" type="Node2D" groups=["fixed_latchpoint"]]
script = ExtResource( 1 )

[node name="PlanningSite" type="ColorRect" parent="."]
margin_left = -8.0
margin_top = -8.0
margin_right = 8.0
margin_bottom = 8.0
color = Color( 0.764706, 0.0588235, 0.0588235, 0.466667 )
2 changes: 2 additions & 0 deletions project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ window/stretch/aspect="keep"
[global]

font=false
layer=false

[gui]

Expand Down Expand Up @@ -72,6 +73,7 @@ click={

2d_physics/layer_1="bucket"
2d_physics/layer_2="static_obstacle"
2d_physics/layer_3="string"

[mono]

Expand Down

0 comments on commit 1e40391

Please sign in to comment.