// Games made using `agb` are no_std which means you don't have access to the standard // rust library. This is because the game boy advance doesn't have an operating // system, so most of the content of the standard library doesn't apply. #![no_std] // `agb` defines its own `main` function, so you must declare your game's main function // using the #[agb::entry] proc macro. Failing to do so will cause failure in linking // which won't be a particularly clear error message. #![no_main] // This is required to allow writing tests #![cfg_attr(test, feature(custom_test_frameworks))] #![cfg_attr(test, reexport_test_harness_main = "test_main")] #![cfg_attr(test, test_runner(agb::test_runner::test_runner))] mod game; // By default no_std crates don't get alloc, so you won't be able to use things like Vec // until you declare the extern crate. `agb` provides an allocator so it will all work extern crate alloc; use crate::game::{GameLoop, GameState}; use agb::display::font::{AlignmentKind, Font, Layout, RegularBackgroundTextRenderer}; use agb::display::tiled::{RegularBackground, RegularBackgroundSize, TileFormat, VRAM_MANAGER}; use agb::display::{Priority, Rgb15}; use agb::fixnum::Num; use agb::input::Button; use agb::{include_aseprite, include_font}; include_aseprite!( mod goose_sprites, "gfx/flap_animated.aseprite" ); static FONT: Font = include_font!("fnt/Born2bSportyV2.ttf", 24); type Fixed = Num; #[agb::entry] fn main(mut gba: agb::Gba) -> ! { let mut game = GameLoop::new(); VRAM_MANAGER.set_background_palette_colour(0, 1, Rgb15::WHITE); let mut bg = RegularBackground::new( Priority::P0, RegularBackgroundSize::Background32x32, TileFormat::FourBpp, ); let mut text_layout = Layout::new( "HonkBird\nPress Start to play", &FONT, AlignmentKind::Left, 32, 200, ); let mut text_renderer = RegularBackgroundTextRenderer::new((4, 50)); let mut button_controller = agb::input::ButtonController::new(); loop { match game.game_state { GameState::Start => { button_controller.update(); if let Some(letter) = text_layout.next() { text_renderer.show(&mut bg, &letter); } if button_controller.is_just_pressed(Button::START) { game.game_state = GameState::Playing; } let mut gfx = gba.graphics.get(); let mut frame = gfx.frame(); bg.show(&mut frame); frame.commit(); } GameState::Playing => { game.run(&mut gba); } GameState::GameOver => {} } } }