MCPcopy Create free account
hub / github.com/CleanCut/rusty_engine / logic

Function logic

examples/collision.rs:47–90  ·  view source on GitHub ↗
(engine: &mut Engine, _: &mut GameState)

Source from the content-addressed store, hash-verified

45}
46
47fn logic(engine: &mut Engine, _: &mut GameState) {
48 // If a collision event happened last frame, print it out and play a sound
49 for collision_event in engine.collision_events.drain(..) {
50 let text = engine.texts.get_mut("collision text").unwrap();
51 match collision_event.state {
52 CollisionState::Begin => {
53 text.value = format!("{:?}", collision_event.pair);
54 engine.audio_manager.play_sfx(SfxPreset::Switch1, 1.0)
55 }
56 CollisionState::End => {
57 text.value = "".into();
58 engine.audio_manager.play_sfx(SfxPreset::Switch2, 1.0)
59 }
60 }
61 }
62
63 if let Some(sprite) = engine.sprites.get_mut("Player") {
64 // Use the latest state of the mouse buttons to rotate the sprite
65 let mut rotation_amount = 0.0;
66 if engine.mouse_state.pressed(MouseButton::Left) {
67 rotation_amount += ROTATION_SPEED * engine.delta_f32;
68 }
69 if engine.mouse_state.pressed(MouseButton::Right) {
70 rotation_amount -= ROTATION_SPEED * engine.delta_f32;
71 }
72 sprite.rotation += rotation_amount;
73
74 // Use the latest state of the mouse wheel to scale the sprite
75 if let Some(location) = engine.mouse_state.location() {
76 sprite.translation = location
77 }
78
79 // Mousewheel scales the car
80 for mouse_wheel in &engine.mouse_wheel_events {
81 sprite.scale *= 1.0 + (0.05 * mouse_wheel.y);
82 sprite.scale = sprite.scale.clamp(0.1, 4.0);
83 }
84 }
85
86 // Pressing C toggles sprite collider debug lines
87 if engine.keyboard_state.just_pressed(KeyCode::KeyC) {
88 engine.show_colliders = !engine.show_colliders;
89 }
90}

Callers

nothing calls this directly

Calls 4

play_sfxMethod · 0.80
locationMethod · 0.80
pressedMethod · 0.45
just_pressedMethod · 0.45

Tested by

no test coverage detected