Code: Select all
#include <nds.h>
//include sprites
#include "sprite.h"
void init()
{
int i;
//point our video buffer to the start of bitmap background video
u16* video_buffer_main = (u16*)BG_BMP_RAM(0);
//set video mode to mode 5 with background 3 enabled
//map vram a to start of main background graphics memory
//initialize the background
BACKGROUND.control[3] = BG_BMP16_256x256 | BG_BMP_BASE(0);
BACKGROUND.bg3_rotation.hdy = 0;
BACKGROUND.bg3_rotation.hdx = 1 << 8;
BACKGROUND.bg3_rotation.vdx = 0;
BACKGROUND.bg3_rotation.vdy = 1 << 8;
for(i = 0;i < 256*256;i++)
video_buffer_main[i] = RGB15(31,31,31) | BIT(15);
}
int main() {
// Setup the video modes.
int x = 0; int y = 0; int held = 0;
videoSetMode( MODE_5_2D | DISPLAY_BG3_ACTIVE);
vramSetPrimaryBanks(VRAM_A_MAIN_SPRITE,VRAM_B_LCD,VRAM_C_MAIN_BG_0x06000000,VRAM_D_LCD);
init();
//setup sprites
oamInit(&oamMain, SpriteMapping_1D_128 , false); //initialize the oam
u16* gfx = oamAllocateGfx(&oamMain, SpriteSize_32x32,SpriteColorFormat_256Color);//make room for the sprite
dmaCopy(spriteTiles,gfx, spriteTilesLen);//copy the sprite
dmaCopy(spritePal, SPRITE_PALETTE, spritePalLen); //copy the sprites palette
while (1) //infinite loop
{
scanKeys();
held = keysHeld();
if (held & KEY_UP)
y-=2;
if (held & KEY_DOWN)
y+=2;
if (held & KEY_LEFT)
x-=2;
if (held & KEY_RIGHT)
x+=2;
if (x<0)
x = 0;
else
if (x>224)
x = 224;
if (y<0)
y = 0;
else
if (y>160)
y = 160;
oamSet(&oamMain,0,x,y,0,0,SpriteSize_32x32,SpriteColorFormat_256Color,gfx,0,false,false,false,false,false);
swiWaitForVBlank();
oamUpdate(&oamMain);
}
return 0;
}