Skip to content

Instantly share code, notes, and snippets.

@felixjones
Last active March 9, 2019 16:16
Show Gist options
  • Save felixjones/72362ac20a3690708b4d9167775290aa to your computer and use it in GitHub Desktop.
Save felixjones/72362ac20a3690708b4d9167775290aa to your computer and use it in GitHub Desktop.
C++ clone of rust gba-console's hello_world.rs example
#include <gba.hpp>
#define EVER ;;
using namespace gba;
int main( int argc, char * argv[] ) {
display::control = display::mode( 3 ).enable_layers( { 2 } );
uint8 px = gba::mode3.width / 2;
uint8 py = gba::mode3.height / 2;
auto color = gba::color( 31, 0, 0 );
for ( EVER ) {
// read our keys for this frame
auto this_frame_keys = keys.read_keys();
// adjust game state and wait for vblank
px += 2 * this_frame_keys.pad.axis_x();
py += 2 * this_frame_keys.pad.axis_y();
if ( this_frame_keys.button.L ) {
color <<= 5;
}
if ( this_frame_keys.button.R ) {
color >>= 5;
}
// now we wait
display::wait_vblank();
// draw the new game and wait until the next frame starts.
if ( px >= 240 || py >= 160 ) {
// out of bounds, reset the screen and position.
gba::mode3.fill( gba::color() );
px = gba::mode3.width / 2;
py = gba::mode3.height / 2;
} else {
// draw the new part of the line
gba::mode3.fill( color, { px, py, 2, 2 } );
}
// now we wait again
display::wait_vdraw();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment