@@ -16,6 +16,12 @@ self.cobject_block_left = new ColObject(shape_block_left.shape, self, shape_bloc
1616var shape_block_right = col_shape_from_penguin(self.mesh_block_right.collision_shapes[0 ], ECollisionMasks.DEFAULT , ECollisionMasks.DEFAULT );
1717self.cobject_block_right = new ColObject(shape_block_right.shape, self, shape_block_right.shape_mask, shape_block_right.shape_group);
1818
19+ var shape_activation_left = col_shape_from_penguin(array_search_with_name(self.mesh_block_left.collision_shapes, " #Activation" ));
20+ self.cobject_activation_left = new ColObject(shape_activation_left.shape, self, shape_activation_left.shape_mask, shape_activation_left.shape_group);
21+
22+ var shape_activation_right = col_shape_from_penguin(array_search_with_name(self.mesh_block_right.collision_shapes, " #Activation" ));
23+ self.cobject_activation_right = new ColObject(shape_activation_right.shape, self, shape_activation_right.shape_mask, shape_activation_right.shape_group);
24+
1925self.seesaw_angle = 0 ;
2026
2127self.matrix_base = undefined;
@@ -49,6 +55,22 @@ self.CalculateAllPositions = function() {
4955 col_object_update_position (self.cobject_seesaw , self.matrix_seesaw );
5056 col_object_update_position (self.cobject_block_left , self.matrix_block_left );
5157 col_object_update_position (self.cobject_block_right , self.matrix_block_right );
58+
59+ col_object_update_position (self.cobject_activation_left , self.matrix_block_left );
60+ col_object_update_position (self.cobject_activation_right , self.matrix_block_right );
61+ };
62+
63+ self.HandleActivation = function() {
64+ var is_left = obj_game.collision .CheckObject (self.cobject_activation_left );
65+ var is_right = obj_game.collision .CheckObject (self.cobject_activation_right );
66+
67+ if (is_left && !is_right) {
68+ self.state .change (" tilt_left" );
69+ } else if (is_right && !is_left) {
70+ self.state .change (" tilt_right" )
71+ } else if (is_left && is_right) {
72+ self.state .change (" balanced" )
73+ }
5274};
5375
5476self.state = new SnowState(" balanced" )
@@ -57,19 +79,38 @@ self.state = new SnowState("balanced")
5779 static turn_rate = 120 ;
5880 self.seesaw_angle = approach (self.seesaw_angle , 0 , turn_rate * DT );
5981 self.CalculateAllPositions ();
82+ self.HandleActivation ();
6083 }
6184 })
6285 .add(" tilt_left" , {
6386 update: function () {
6487 static turn_rate = 120 ;
65- self.seesaw_angle = approach (self.seesaw_angle , -15 , turn_rate * DT );
88+ static target_angle = 15 ;
89+ self.seesaw_angle = approach (self.seesaw_angle , target_angle, turn_rate * DT );
6690 self.CalculateAllPositions ();
91+ if (self.seesaw_angle == target_angle) {
92+ self.state .change (" left" );
93+ }
6794 }
6895 })
6996 .add(" tilt_right" , {
7097 update: function () {
7198 static turn_rate = 120 ;
72- self.seesaw_angle = approach (self.seesaw_angle , 15 , turn_rate * DT );
99+ static target_angle = -15 ;
100+ self.seesaw_angle = approach (self.seesaw_angle , target_angle, turn_rate * DT );
73101 self.CalculateAllPositions ();
102+ if (self.seesaw_angle == target_angle) {
103+ self.state .change (" left" );
104+ }
105+ }
106+ })
107+ .add(" left" , {
108+ update: function () {
109+ self.HandleActivation ();
110+ }
111+ })
112+ .add(" right" , {
113+ update: function () {
114+ self.HandleActivation ();
74115 }
75- });
116+ });
0 commit comments