File tree Expand file tree Collapse file tree 2 files changed +16
-12
lines changed Expand file tree Collapse file tree 2 files changed +16
-12
lines changed Original file line number Diff line number Diff line change @@ -15,8 +15,8 @@ pub struct GameState {
1515}
1616
1717impl GameState {
18- pub fn new ( ctx : & mut Context ) -> GameResult < GameState > {
19- let bird_image = Image :: new ( ctx, "/bird.png" ) ?;
18+ pub fn new ( ctx : & mut Context , bird_image_bytes : & ' static [ u8 ] ) -> GameResult < GameState > {
19+ let bird_image = Image :: from_bytes ( ctx, bird_image_bytes ) ?;
2020 Ok ( GameState {
2121 state : Game :: Menu ,
2222 bird_image,
Original file line number Diff line number Diff line change 11mod game;
2+ use crate :: game:: GameState ;
23use ggez:: event:: { self } ;
34use ggez:: { ContextBuilder , GameResult } ;
5+ use std:: path:: PathBuf ;
6+ const BIRD_IMAGE_BYTES : & ' static [ u8 ] = include_bytes ! ( "../resources/bird.png" ) ;
47
58fn main ( ) -> GameResult {
6- let resource_dir = if let Ok ( manifest_dir ) = std:: env:: var ( "CARGO_MANIFEST_DIR" ) {
7- let mut path = std :: path :: PathBuf :: from ( manifest_dir) ;
8- path. push ( "resources" ) ;
9- Some ( path)
10- } else {
11- None
12- } ;
9+ let resource_dir = std:: env:: var ( "CARGO_MANIFEST_DIR" )
10+ . map ( | manifest_dir| {
11+ let mut path = PathBuf :: from ( manifest_dir ) ;
12+ path. push ( "resources" ) ;
13+ path
14+ } )
15+ . unwrap_or_else ( |_| PathBuf :: from ( "." ) ) ;
1316
1417 let ( mut ctx, event_loop) = ContextBuilder :: new ( "flappy_bird" , "Carol" )
15- . add_resource_path ( resource_dir. unwrap ( ) )
18+ . add_resource_path ( resource_dir)
1619 . window_setup ( ggez:: conf:: WindowSetup :: default ( ) . title ( "Flappy Bird!" ) )
1720 . window_mode ( ggez:: conf:: WindowMode :: default ( ) . dimensions ( 800.0 , 600.0 ) )
1821 . build ( ) ?;
1922
20- let state = game:: GameState :: new ( & mut ctx) ?;
21- event:: run ( ctx, event_loop, state)
23+ let game_state = GameState :: new ( & mut ctx, BIRD_IMAGE_BYTES ) ?;
24+
25+ event:: run ( ctx, event_loop, game_state)
2226}
You can’t perform that action at this time.
0 commit comments