Don't worry about it
1// Games made using `agb` are no_std which means you don't have access to the standard
2// rust library. This is because the game boy advance doesn't have an operating
3// system, so most of the content of the standard library doesn't apply.
4#![no_std]
5// `agb` defines its own `main` function, so you must declare your game's main function
6// using the #[agb::entry] proc macro. Failing to do so will cause failure in linking
7// which won't be a particularly clear error message.
8#![no_main]
9// This is required to allow writing tests
10#![cfg_attr(test, feature(custom_test_frameworks))]
11#![cfg_attr(test, reexport_test_harness_main = "test_main")]
12#![cfg_attr(test, test_runner(agb::test_runner::test_runner))]
13
14mod game;
15
16// By default no_std crates don't get alloc, so you won't be able to use things like Vec
17// until you declare the extern crate. `agb` provides an allocator so it will all work
18extern crate alloc;
19
20use crate::game::{GameLoop, GameState};
21use agb::display::font::{AlignmentKind, Font, Layout, RegularBackgroundTextRenderer};
22use agb::display::tiled::{RegularBackground, RegularBackgroundSize, TileFormat, VRAM_MANAGER};
23use agb::display::{Priority, Rgb15};
24use agb::fixnum::Num;
25use agb::input::Button;
26use agb::{include_aseprite, include_font};
27
28include_aseprite!(
29 mod goose_sprites,
30 "gfx/flap_animated.aseprite"
31);
32
33static FONT: Font = include_font!("fnt/Born2bSportyV2.ttf", 24);
34
35type Fixed = Num<i32, 8>;
36
37#[agb::entry]
38fn main(mut gba: agb::Gba) -> ! {
39 let mut game = GameLoop::new();
40 VRAM_MANAGER.set_background_palette_colour(0, 1, Rgb15::WHITE);
41
42 let mut bg = RegularBackground::new(
43 Priority::P0,
44 RegularBackgroundSize::Background32x32,
45 TileFormat::FourBpp,
46 );
47
48 let mut text_layout = Layout::new(
49 "HonkBird\nPress Start to play",
50 &FONT,
51 AlignmentKind::Left,
52 32,
53 200,
54 );
55
56 let mut text_renderer = RegularBackgroundTextRenderer::new((4, 50));
57 let mut button_controller = agb::input::ButtonController::new();
58 loop {
59 match game.game_state {
60 GameState::Start => {
61 button_controller.update();
62
63 if let Some(letter) = text_layout.next() {
64 text_renderer.show(&mut bg, &letter);
65 }
66 if button_controller.is_just_pressed(Button::START) {
67 game.game_state = GameState::Playing;
68 }
69 let mut gfx = gba.graphics.get();
70 let mut frame = gfx.frame();
71
72 bg.show(&mut frame);
73
74 frame.commit();
75 }
76 GameState::Playing => {
77 game.run(&mut gba);
78 }
79 GameState::GameOver => {}
80 }
81 }
82}