Skip to content

Commit 1192e97

Browse files
committed
blocks can fall
1 parent 55ecb23 commit 1192e97

1 file changed

Lines changed: 62 additions & 0 deletions

File tree

objects/obj_3d_spell_block/Create_0.gml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,59 @@ self.target = undefined;
44

55
self.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

Comments
 (0)