dora_ssr/dora/platformer/
bullet_def.rs

1/* Copyright (c) 2016-2025 Li Jin <dragon-fly@qq.com>
2
3Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
5The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
7THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
8
9extern "C" {
10	fn platformer_bulletdef_type() -> i32;
11	fn platformer_bulletdef_set_tag(slf: i64, val: i64);
12	fn platformer_bulletdef_get_tag(slf: i64) -> i64;
13	fn platformer_bulletdef_set_end_effect(slf: i64, val: i64);
14	fn platformer_bulletdef_get_end_effect(slf: i64) -> i64;
15	fn platformer_bulletdef_set_life_time(slf: i64, val: f32);
16	fn platformer_bulletdef_get_life_time(slf: i64) -> f32;
17	fn platformer_bulletdef_set_damage_radius(slf: i64, val: f32);
18	fn platformer_bulletdef_get_damage_radius(slf: i64) -> f32;
19	fn platformer_bulletdef_set_high_speed_fix(slf: i64, val: i32);
20	fn platformer_bulletdef_is_high_speed_fix(slf: i64) -> i32;
21	fn platformer_bulletdef_set_gravity(slf: i64, val: i64);
22	fn platformer_bulletdef_get_gravity(slf: i64) -> i64;
23	fn platformer_bulletdef_set_face(slf: i64, val: i64);
24	fn platformer_bulletdef_get_face(slf: i64) -> i64;
25	fn platformer_bulletdef_get_body_def(slf: i64) -> i64;
26	fn platformer_bulletdef_get_velocity(slf: i64) -> i64;
27	fn platformer_bulletdef_set_as_circle(slf: i64, radius: f32);
28	fn platformer_bulletdef_set_velocity(slf: i64, angle: f32, speed: f32);
29	fn platformer_bulletdef_new() -> i64;
30}
31use crate::dora::IObject;
32/// A struct type that specifies the properties and behaviors of a bullet object in the game.
33pub struct BulletDef { raw: i64 }
34crate::dora_object!(BulletDef);
35impl BulletDef {
36	pub(crate) fn type_info() -> (i32, fn(i64) -> Option<Box<dyn IObject>>) {
37		(unsafe { platformer_bulletdef_type() }, |raw: i64| -> Option<Box<dyn IObject>> {
38			match raw {
39				0 => None,
40				_ => Some(Box::new(BulletDef { raw: raw }))
41			}
42		})
43	}
44	/// Sets the tag for the bullet object.
45	pub fn set_tag(&mut self, val: &str) {
46		unsafe { platformer_bulletdef_set_tag(self.raw(), crate::dora::from_string(val)) };
47	}
48	/// Gets the tag for the bullet object.
49	pub fn get_tag(&self) -> String {
50		return unsafe { crate::dora::to_string(platformer_bulletdef_get_tag(self.raw())) };
51	}
52	/// Sets the effect that occurs when the bullet object ends its life.
53	pub fn set_end_effect(&mut self, val: &str) {
54		unsafe { platformer_bulletdef_set_end_effect(self.raw(), crate::dora::from_string(val)) };
55	}
56	/// Gets the effect that occurs when the bullet object ends its life.
57	pub fn get_end_effect(&self) -> String {
58		return unsafe { crate::dora::to_string(platformer_bulletdef_get_end_effect(self.raw())) };
59	}
60	/// Sets the amount of time in seconds that the bullet object remains active.
61	pub fn set_life_time(&mut self, val: f32) {
62		unsafe { platformer_bulletdef_set_life_time(self.raw(), val) };
63	}
64	/// Gets the amount of time in seconds that the bullet object remains active.
65	pub fn get_life_time(&self) -> f32 {
66		return unsafe { platformer_bulletdef_get_life_time(self.raw()) };
67	}
68	/// Sets the radius of the bullet object's damage area.
69	pub fn set_damage_radius(&mut self, val: f32) {
70		unsafe { platformer_bulletdef_set_damage_radius(self.raw(), val) };
71	}
72	/// Gets the radius of the bullet object's damage area.
73	pub fn get_damage_radius(&self) -> f32 {
74		return unsafe { platformer_bulletdef_get_damage_radius(self.raw()) };
75	}
76	/// Sets whether the bullet object should be fixed for high speeds.
77	pub fn set_high_speed_fix(&mut self, val: bool) {
78		unsafe { platformer_bulletdef_set_high_speed_fix(self.raw(), if val { 1 } else { 0 }) };
79	}
80	/// Gets whether the bullet object should be fixed for high speeds.
81	pub fn is_high_speed_fix(&self) -> bool {
82		return unsafe { platformer_bulletdef_is_high_speed_fix(self.raw()) != 0 };
83	}
84	/// Sets the gravity vector that applies to the bullet object.
85	pub fn set_gravity(&mut self, val: &crate::dora::Vec2) {
86		unsafe { platformer_bulletdef_set_gravity(self.raw(), val.into_i64()) };
87	}
88	/// Gets the gravity vector that applies to the bullet object.
89	pub fn get_gravity(&self) -> crate::dora::Vec2 {
90		return unsafe { crate::dora::Vec2::from(platformer_bulletdef_get_gravity(self.raw())) };
91	}
92	/// Sets the visual item of the bullet object.
93	pub fn set_face(&mut self, val: &crate::dora::platformer::Face) {
94		unsafe { platformer_bulletdef_set_face(self.raw(), val.raw()) };
95	}
96	/// Gets the visual item of the bullet object.
97	pub fn get_face(&self) -> crate::dora::platformer::Face {
98		return unsafe { crate::dora::platformer::Face::from(platformer_bulletdef_get_face(self.raw())).unwrap() };
99	}
100	/// Gets the physics body definition for the bullet object.
101	pub fn get_body_def(&self) -> crate::dora::BodyDef {
102		return unsafe { crate::dora::BodyDef::from(platformer_bulletdef_get_body_def(self.raw())).unwrap() };
103	}
104	/// Gets the velocity vector of the bullet object.
105	pub fn get_velocity(&self) -> crate::dora::Vec2 {
106		return unsafe { crate::dora::Vec2::from(platformer_bulletdef_get_velocity(self.raw())) };
107	}
108	/// Sets the bullet object's physics body as a circle.
109	///
110	/// # Arguments
111	///
112	/// * `radius` - The radius of the circle.
113	pub fn set_as_circle(&mut self, radius: f32) {
114		unsafe { platformer_bulletdef_set_as_circle(self.raw(), radius); }
115	}
116	/// Sets the velocity of the bullet object.
117	///
118	/// # Arguments
119	///
120	/// * `angle` - The angle of the velocity in degrees.
121	/// * `speed` - The speed of the velocity.
122	pub fn set_velocity(&mut self, angle: f32, speed: f32) {
123		unsafe { platformer_bulletdef_set_velocity(self.raw(), angle, speed); }
124	}
125	/// Creates a new bullet object definition with default settings.
126	///
127	/// # Returns
128	///
129	/// * `BulletDef` - The new bullet object definition.
130	pub fn new() -> BulletDef {
131		unsafe { return BulletDef { raw: platformer_bulletdef_new() }; }
132	}
133}