new version

This commit is contained in:
artem 2024-03-05 22:09:52 +03:00
parent b534d5fbde
commit e061a1405a
6 changed files with 661 additions and 814 deletions

554
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -6,7 +6,6 @@ use platformer::GameConstructor;
fn main() { fn main() {
let event_loop = EventLoop::new().unwrap(); let event_loop = EventLoop::new().unwrap();
let mut editor = Editor::new( let mut editor = Editor::new(
&event_loop,
Some(StartupData { Some(StartupData {
working_directory: Default::default(), working_directory: Default::default(),
scenes: vec!["data/scene.rgs".into()], scenes: vec!["data/scene.rgs".into()],

View File

@ -187,29 +187,19 @@ impl Enemy {
if !self.fight { if !self.fight {
return; return;
} }
let index = ctx let player_script = ctx
.scene .scene
.graph .graph
.try_get_script_index_of::<Player>(self.player_handle) .try_get_script_of_mut::<Player>(self.player_handle)
.unwrap(); .unwrap();
match ctx if player_script.get_health() <= 0.0 {
.scene self.fight = false;
.graph self.block = false;
.try_get_mut(self.player_handle) self.win = true;
.and_then(|node| node.try_get_script_mut::<Player>(index)) return;
{
Some(script) => {
if script.get_health() <= 0.0 {
self.fight = false;
self.block = false;
self.win = true;
return;
}
self.block = false;
script.take_damage(&self.attack_damage);
}
None => {}
} }
self.block = false;
player_script.take_damage(&self.attack_damage);
} }
fn get_player_position(&self, context: &mut ScriptContext) -> Vector3<f32> { fn get_player_position(&self, context: &mut ScriptContext) -> Vector3<f32> {

View File

@ -195,7 +195,7 @@ impl EnemySpawn {
.with_name(format!("Sceleton ({x}, {y})",)) .with_name(format!("Sceleton ({x}, {y})",))
// Set position of tile // Set position of tile
.with_local_transform(rb_transform) .with_local_transform(rb_transform)
.with_script(Script::new(enemy)), .with_script(enemy),
) )
.with_mass(20.0) .with_mass(20.0)
// Turn off gravity for tile // Turn off gravity for tile

View File

@ -363,23 +363,12 @@ impl Player {
parent = Some(d.parent()); parent = Some(d.parent());
} }
if let Some(d) = parent { if let Some(d) = parent {
let index = context let enemy_script = context
.scene .scene
.graph .graph
.try_get_script_index_of::<Enemy>(d) .try_get_script_of_mut::<Enemy>(d)
.unwrap(); .unwrap();
match context enemy_script.take_damage(&self.damage);
.scene
.graph
.try_get_mut(d)
.and_then(|node| node.try_get_script_mut::<Enemy>(index))
{
Some(script) => {
script.take_damage(&self.damage);
break;
}
None => {}
}
} }
} }
} }

File diff suppressed because it is too large Load Diff