@@ -6,10 +6,13 @@ use std::f32::consts::PI;
66
77use rusty_engine:: prelude:: * ;
88
9+ #[ derive( Resource ) ]
10+ struct GameState { }
11+
912fn main ( ) {
1013 let mut game = Game :: new ( ) ;
1114
12- let mut race_car = game. add_sprite ( "Race Car" , SpritePreset :: RacingCarGreen ) ;
15+ let race_car = game. add_sprite ( "Race Car" , SpritePreset :: RacingCarGreen ) ;
1316 race_car. translation = Vec2 :: new ( 0.0 , 0.0 ) ;
1417 race_car. rotation = UP ;
1518 race_car. scale = 1.0 ;
@@ -19,20 +22,20 @@ fn main() {
1922 text. translation . y = 250.0 ;
2023
2124 game. add_logic ( logic) ;
22- game. run ( ( ) ) ;
25+ game. run ( GameState { } ) ;
2326}
2427
25- fn logic ( game_state : & mut Engine , _: & mut ( ) ) {
28+ fn logic ( engine : & mut Engine , _: & mut GameState ) {
2629 // Compute how fast we should move, rotate, and scale
27- let move_amount = 200.0 * game_state . delta_f32 ;
28- let rotation_amount = PI * game_state . delta_f32 ;
29- let scale_amount = 1.0 * game_state . delta_f32 ;
30+ let move_amount = 200.0 * engine . delta_f32 ;
31+ let rotation_amount = PI * engine . delta_f32 ;
32+ let scale_amount = 1.0 * engine . delta_f32 ;
3033
3134 // Get the race car sprite
32- let race_car = game_state . sprites . get_mut ( "Race Car" ) . unwrap ( ) ;
35+ let race_car = engine . sprites . get_mut ( "Race Car" ) . unwrap ( ) ;
3336
3437 // Handle keyboard input
35- let ks = & mut game_state . keyboard_state ;
38+ let ks = & mut engine . keyboard_state ;
3639 if ks. pressed_any ( & [ KeyCode :: W , KeyCode :: Up , KeyCode :: Comma ] ) {
3740 race_car. translation . y += move_amount;
3841 }
@@ -67,7 +70,7 @@ fn logic(game_state: &mut Engine, _: &mut ()) {
6770
6871 // Clamp the translation so that the car stays on the screen
6972 race_car. translation = race_car. translation . clamp (
70- -game_state . window_dimensions * 0.5 ,
71- game_state . window_dimensions * 0.5 ,
73+ -engine . window_dimensions * 0.5 ,
74+ engine . window_dimensions * 0.5 ,
7275 ) ;
7376}
0 commit comments