blob: e64508e1359fd6018d804b8f0a3a15794b947ca9 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
use gdnative::api::*;
use gdnative::prelude::*;
use crate::buff_trait::Buff;
struct BuffPhase {
name: String,
description: String,
rigid_body: Option<Ref<RigidBody>>,
wall_layer_bit: i64,
}
impl BuffPhase {
fn new(rigid_body: Option<Ref<RigidBody>>) -> Self {
// calculate the bit for the mask to enable/ disable collision detection
let mask_layer = 2;
let mask_bit = 2_i64.pow(mask_layer - 1);
BuffPhase {
name: String::from("Phase"),
description: String::from("Phases through thin fences"),
rigid_body,
wall_layer_bit: mask_bit,
}
}
}
impl Buff for BuffPhase {
unsafe fn execute_buff(&mut self) {
match &self.rigid_body {
Some(body) => {
// actually disable the collision to the fences
let save_body = body.assume_safe();
save_body.set_collision_mask_bit(self.wall_layer_bit, false);
},
None => godot_warn!("Rigid body not found")
}
}
unsafe fn revert_buff(& mut self) {
// make sure the rigid body exists
match &self.rigid_body {
Some(body) => {
// actually enable the collision again
let save_body = body.assume_safe();
save_body.set_collision_mask_bit(self.wall_layer_bit, false);
},
None => godot_warn!("Rigid body not found")
}
}
fn get_name(self) -> GodotString {
GodotString::from_str(self.name)
}
fn get_description(self) -> GodotString {
GodotString::from_str(self.description)
}
}
|