2022-01-02 10:38:13 +11:00
|
|
|
// 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 really have an operating
|
|
|
|
// system, so most of the content of the standard library doesn't apply.
|
|
|
|
//
|
|
|
|
// Provided you haven't disabled it, agb does provide an allocator, so it is possible
|
|
|
|
// to use both the `core` and the `alloc` built in crates.
|
2022-01-02 09:37:39 +11:00
|
|
|
#![no_std]
|
2022-01-02 10:38:13 +11:00
|
|
|
// `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.
|
2022-01-02 09:37:39 +11:00
|
|
|
#![no_main]
|
|
|
|
|
2022-03-08 09:04:02 +11:00
|
|
|
use agb::display::object::{Graphics, Tag};
|
2022-01-02 11:27:53 +11:00
|
|
|
use agb::Gba;
|
|
|
|
|
2022-03-08 09:04:02 +11:00
|
|
|
const GRAPHICS: &Graphics = agb::include_aseprite!("gfx/sprites.aseprite");
|
2022-01-02 11:21:59 +11:00
|
|
|
|
2022-01-02 10:38:13 +11:00
|
|
|
// The main function must take 0 arguments and never return. The agb::entry decorator
|
|
|
|
// ensures that everything is in order. `agb` will call this after setting up the stack
|
|
|
|
// and interrupt handlers correctly.
|
2022-01-02 09:37:39 +11:00
|
|
|
#[agb::entry]
|
2022-01-17 08:44:17 +11:00
|
|
|
fn main(mut gba: Gba) -> ! {
|
2022-03-08 09:04:02 +11:00
|
|
|
let object = gba.display.object.get();
|
2022-01-02 11:40:34 +11:00
|
|
|
|
2022-03-08 09:04:02 +11:00
|
|
|
const BALL: &Tag = GRAPHICS.tags().get("Ball");
|
2022-03-24 07:32:29 +11:00
|
|
|
let ball_sprite = object.sprite(BALL.sprite(0));
|
2022-03-24 07:34:55 +11:00
|
|
|
let mut ball = object.object(ball_sprite);
|
2022-01-02 11:40:34 +11:00
|
|
|
|
2022-03-08 09:04:02 +11:00
|
|
|
ball.set_x(50).set_y(50).show();
|
2022-01-02 22:27:26 +11:00
|
|
|
|
2022-01-03 05:46:00 +11:00
|
|
|
let mut ball_x = 50;
|
|
|
|
let mut ball_y = 50;
|
|
|
|
let mut x_velocity = 1;
|
|
|
|
let mut y_velocity = 1;
|
2022-01-02 11:21:59 +11:00
|
|
|
|
2022-01-03 05:46:00 +11:00
|
|
|
loop {
|
|
|
|
ball_x = (ball_x + x_velocity).clamp(0, agb::display::WIDTH - 16);
|
|
|
|
ball_y = (ball_y + y_velocity).clamp(0, agb::display::HEIGHT - 16);
|
|
|
|
|
|
|
|
if ball_x == 0 || ball_x == agb::display::WIDTH - 16 {
|
|
|
|
x_velocity = -x_velocity;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ball_y == 0 || ball_y == agb::display::HEIGHT - 16 {
|
|
|
|
y_velocity = -y_velocity;
|
|
|
|
}
|
|
|
|
|
|
|
|
ball.set_x(ball_x as u16).set_y(ball_y as u16);
|
|
|
|
|
|
|
|
agb::display::busy_wait_for_vblank();
|
2022-04-06 06:30:26 +10:00
|
|
|
object.commit();
|
2022-01-03 05:46:00 +11:00
|
|
|
}
|
2022-01-02 09:37:39 +11:00
|
|
|
}
|