Skip to content

Commit ce1da95

Browse files
committed
speed up connect gameplay
1 parent c4cb790 commit ce1da95

File tree

5 files changed

+40
-15
lines changed

5 files changed

+40
-15
lines changed

game/games/asecondguy_connect/ai.gd

+14-6
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ onready var _chips_node := $"../Chips"
1414
onready var _grid := $"../Grid"
1515
onready var _game: CONNECTSCRIPT = $".."
1616
onready var _timer := $Timer
17+
onready var _pickup_timer := $PickupTimer
1718

1819

1920
func _ready():
@@ -22,7 +23,7 @@ func _ready():
2223

2324

2425
func _process(_delta):
25-
if chip.sleeping and !_picked:
26+
if _is_chip_stopped() and !_picked:
2627
_start_pickup()
2728
if _picked:
2829
var pos = (
@@ -41,13 +42,14 @@ func _on_chip_spawn(new_chip: CHIPSCRIPT):
4142
chip.set_mouse_control(false)
4243
_choose_goal()
4344
set_process(true)
45+
_pickup_timer.start()
4446

4547

4648
# drawing the path for debugging
47-
#func _draw():
48-
# var points := _curve.get_baked_points()
49-
# for i in range(points.size() - 1):
50-
# draw_line(points[i], points[i + 1], Color.red)
49+
func _draw():
50+
var points := _curve.get_baked_points()
51+
for i in range(points.size() - 1):
52+
draw_line(points[i], points[i + 1], Color.red)
5153

5254

5355
func _choose_goal():
@@ -93,7 +95,7 @@ func _start_pickup():
9395
_curve.add_point(
9496
Vector2(chip.position.x, _grid.global_position.y),
9597
Vector2(),
96-
Vector2(0, -_grid.tile_size.y * _grid.grid_size.y),
98+
Vector2(0, -2 * _grid.tile_size.y),
9799
0
98100
)
99101
_curve.add_point(chip.position, Vector2(), Vector2(), 0)
@@ -110,3 +112,9 @@ func _unpick():
110112
set_process(false)
111113
_curve.clear_points()
112114
update()
115+
116+
117+
func _is_chip_stopped():
118+
if !_pickup_timer.time_left == 0:
119+
return false
120+
return chip.linear_velocity.length() < 5 or chip.sleeping

game/games/asecondguy_connect/ai.tscn

+3
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@ script = ExtResource( 1 )
77

88
[node name="Timer" type="Timer" parent="."]
99
one_shot = true
10+
11+
[node name="PickupTimer" type="Timer" parent="."]
12+
one_shot = true

game/games/asecondguy_connect/chip.gd

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ var target_position: Vector2
77
var _picked := false
88

99

10+
func _ready():
11+
apply_central_impulse(Vector2.DOWN * 500)
12+
13+
1014
func _integrate_forces(state):
1115
if _picked:
1216
var move: Vector2 = target_position - global_position

game/games/asecondguy_connect/connect.gd

+5-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ onready var _info_label := $UI/PanelContainer/InfoLabel
2222

2323

2424
func _ready():
25+
randomize()
2526
# setup the code representation of all played chips
2627
for _x in range(_grid.grid_size.x):
2728
var tmp := []
@@ -82,7 +83,10 @@ func _spawn_chip(player_id := 0):
8283
var chip: RigidBody2D = preload("res://games/asecondguy_connect/chip.tscn").instance()
8384
chip.player_id = player_id
8485
chip.color = player_colors[player_id]
85-
chip.global_position = _spawners[player_id].global_position
86+
chip.global_position = (
87+
_spawners[player_id].global_position
88+
+ Vector2(rand_range(-10, 10), rand_range(-10, 10))
89+
)
8690
if chip.connect("sleeping_state_changed", self, "_on_chip_sleep", [chip]) != OK:
8791
GameManager.end_game("A fatal error occured.")
8892
_chips.call_deferred("add_child", chip)

game/games/asecondguy_connect/connect.tscn

+14-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[gd_scene load_steps=17 format=2]
1+
[gd_scene load_steps=18 format=2]
22

33
[ext_resource path="res://games/asecondguy_connect/slow_label.gd" type="Script" id=1]
44
[ext_resource path="res://games/asecondguy_connect/connect.gd" type="Script" id=2]
@@ -14,6 +14,9 @@ extents = Vector2( 1124, 155 )
1414
[sub_resource type="RectangleShape2D" id=2]
1515
extents = Vector2( 1745, 497.5 )
1616

17+
[sub_resource type="PhysicsMaterial" id=14]
18+
bounce = 100.0
19+
1720
[sub_resource type="RectangleShape2D" id=4]
1821
extents = Vector2( 404.5, 39 )
1922

@@ -85,23 +88,26 @@ shape = SubResource( 2 )
8588
position = Vector2( 504, -890 )
8689
shape = SubResource( 2 )
8790

88-
[node name="RampLeft" type="CollisionShape2D" parent="Bounds"]
91+
[node name="Ramps" type="StaticBody2D" parent="."]
92+
physics_material_override = SubResource( 14 )
93+
94+
[node name="RampLeft" type="CollisionShape2D" parent="Ramps"]
8995
position = Vector2( -323, 433 )
90-
rotation = 0.626923
96+
rotation = 0.698132
9197
shape = SubResource( 4 )
9298

93-
[node name="RampRight" type="CollisionShape2D" parent="Bounds"]
94-
position = Vector2( 1318, 399 )
95-
rotation = -0.735762
99+
[node name="RampRight" type="CollisionShape2D" parent="Ramps"]
100+
position = Vector2( 1318, 433 )
101+
rotation = -0.698132
96102
shape = SubResource( 4 )
97103

98104
[node name="Chips" type="Node" parent="."]
99105

100106
[node name="Spawner1" type="Position2D" parent="."]
101-
position = Vector2( -432, 56 )
107+
position = Vector2( -398, 178 )
102108

103109
[node name="Spawner2" type="Position2D" parent="."]
104-
position = Vector2( 1255, 160 )
110+
position = Vector2( 1398, 178 )
105111

106112
[node name="Grid" type="StaticBody2D" parent="."]
107113
position = Vector2( 250, 133 )

0 commit comments

Comments
 (0)