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

Function game_logic

examples/collider.rs:115–221  ·  view source on GitHub ↗
(engine: &mut Engine, game_state: &mut GameState)

Source from the content-addressed store, hash-verified

113}
114
115fn game_logic(engine: &mut Engine, game_state: &mut GameState) {
116 // Zoom levels
117 if engine.keyboard_state.just_pressed(KeyCode::Digit1) {
118 game_state.scale = 1.0;
119 }
120 if engine.keyboard_state.just_pressed(KeyCode::Digit2) {
121 game_state.scale = 2.0;
122 }
123 if engine.keyboard_state.just_pressed(KeyCode::Digit3) {
124 game_state.scale = 3.0;
125 }
126 if engine.keyboard_state.just_pressed(KeyCode::Digit4) {
127 game_state.scale = 4.0;
128 }
129 if engine.keyboard_state.just_pressed(KeyCode::Digit5) {
130 game_state.scale = 5.0;
131 }
132 if engine.keyboard_state.just_pressed(KeyCode::Digit6) {
133 game_state.scale = 6.0;
134 }
135 if engine.keyboard_state.just_pressed(KeyCode::Digit7) {
136 game_state.scale = 7.0;
137 }
138 if engine.keyboard_state.just_pressed(KeyCode::Digit8) {
139 game_state.scale = 8.0;
140 }
141 if engine.keyboard_state.just_pressed(KeyCode::Digit9) {
142 game_state.scale = 9.0;
143 }
144 // Update scale
145 let sprite = engine.sprites.get_mut("sprite").unwrap();
146 sprite.scale = game_state.scale;
147
148 // Rotate
149 if engine.mouse_state.pressed(MouseButton::Right) {
150 sprite.rotation += engine.delta_f32 * 6.0;
151 }
152 // Delete collider
153 if engine.keyboard_state.just_pressed(KeyCode::Delete)
154 || engine.keyboard_state.just_pressed(KeyCode::Backspace)
155 {
156 sprite.collider = Collider::NoCollider;
157 sprite.collider_dirty = true;
158 }
159 // Modify a collider point
160 if engine.mouse_state.just_pressed(MouseButton::Left) {
161 if let Some(location) = engine.mouse_state.location() {
162 let location = (((location / game_state.scale) * 2.0).round() * 0.5) * game_state.scale;
163 if engine
164 .keyboard_state
165 .pressed_any(&[KeyCode::ShiftLeft, KeyCode::ShiftRight])
166 {
167 sprite.change_last_collider_point(location);
168 } else {
169 sprite.add_collider_point(location);
170 }
171 }
172 }

Callers

nothing calls this directly

Calls 9

locationMethod · 0.80
add_collider_pointMethod · 0.80
is_convexMethod · 0.80
write_colliderMethod · 0.80
just_pressedMethod · 0.45
pressedMethod · 0.45
pressed_anyMethod · 0.45
just_pressed_anyMethod · 0.45

Tested by

no test coverage detected