@@ -4,6 +4,59 @@ self.target = undefined;
44
55self.state = new SnowState(" idle" )
66 .add(" idle" , {
7+ update: function () {
8+ if (!self.IsGrounded ()) {
9+ self.state .change (" falling" );
10+ }
11+ }
12+ })
13+ .add(" falling" , {
14+ enter: function () {
15+ show_debug_message (" block is now falling" )
16+ },
17+ leave: function () {
18+ show_debug_message (" block has landed" )
19+ },
20+ update: function () {
21+ // properly do this later
22+ static grav = 9 ;
23+ static block_size = 32 ;
24+ self.yspeed -= grav * PDT ;
25+
26+ var step = abs (self.yspeed );
27+ var dir = sign (self.yspeed );
28+ repeat (step div block_size) {
29+ self.y += dir * block_size;
30+ self.cshapes [0 ].position .y += dir * block_size;
31+
32+ if (obj_game.collision .CheckObject (self.cobjects [0 ])) {
33+ self.y -= dir * block_size;
34+ self.cshapes [0 ].position .y -= dir * block_size;
35+ break ;
36+ }
37+
38+ step -= block_size;
39+ }
40+
41+ repeat (step) {
42+ self.y += dir;
43+ self.cshapes [0 ].position .y += dir;
44+
45+ if (obj_game.collision .CheckObject (self.cobjects [0 ])) {
46+ self.y -= dir;
47+ self.cshapes [0 ].position .y -= dir;
48+ break ;
49+ }
50+
51+ // step -= 1;
52+ }
53+
54+ if (self.IsGrounded ()) {
55+ self.state .change (" idle" );
56+ }
57+
58+ self.UpdateCollisionPositions ();
59+ }
760 })
861 .add(" moving" , {
962 update: function () {
@@ -40,4 +93,13 @@ self.OnSpellHit = function(spell) {
4093
4194 self.target = new Vector3 (self.x + dist * dcos (dir), self.y , self.z - dist * dsin (dir));
4295 self.state .change (" moving" );
96+ };
97+
98+ self.IsGrounded = function() {
99+ if (self.y <= 0 ) return true ;
100+
101+ self.cshapes [0 ].position .y -= 1 ;
102+ var grounded = obj_game.collision .CheckObject (self.cobjects [0 ]);
103+ self.cshapes [0 ].position .y += 1 ;
104+ return grounded;
43105};
0 commit comments