int main() { /* Turn on the 2D graphics core. */ powerOn(POWER_ALL_2D); /* * Configure the VRAM and background control registers. * * Place the main screen on the bottom physical screen. Then arrange the * VRAM banks. Next, confiure the background control registers. */ lcdMainOnBottom(); initVideo(); initBackgrounds(); /* Set up a few sprites. */ SpriteInfo spriteInfo[SPRITE_COUNT]; OAMTable *oam = new OAMTable(); initOAM(oam); initSprites(oam, spriteInfo); /* Display the backgrounds. */ displayStarField(); displayPlanet(); displaySplash(); /* Make the ship object. */ static const int SHUTTLE_OAM_ID = 0; SpriteEntry * shipEntry = &oam->oamBuffer[SHUTTLE_OAM_ID]; SpriteRotation * shipRotation = &oam->matrixBuffer[SHUTTLE_OAM_ID]; Ship * ship = new Ship(&spriteInfo[SHUTTLE_OAM_ID]); /* Accelerate the ship for a little while to make it move. */ for (int i = 0; i < 10; i++) { ship->accelerate(); } for (;;) { /* Update the game state. */ ship->moveShip(); /* Update sprite attributes. */ MathVector2D<float> position = ship->getPosition(); shipEntry->x = (int)position.x; shipEntry->y = (int)position.y; rotateSprite(shipRotation, -ship->getAngleDeg()); /* * Update the OAM. * * We have to copy our copy of OAM data into the actual OAM during * VBlank (writes to it are locked during other times). */ swiWaitForVBlank(); updateOAM(oam); } return 0; }
void ScreenEngine::ClearSprites() { _sprite_gfx_next_address = 0; _spriteObject.clear(); Sprite::_next_address = 0; initOAM(); updateOAM(); }
ScreenEngine::ScreenEngine(int pId) : Screen() { _id = pId; if (pId == 0) { _oam = OAM; _bg_gfx = BG_GFX; _bg_pal = BG_PALETTE; _sprite_pal = SPRITE_PALETTE; _sprite_gfx = SPRITE_GFX; _reg_cr = &DISPLAY_CR; _reg_mosaic_cr = &MOSAIC_CR; _reg_blend_cr = &BLEND_CR; _reg_blend_y = &BLEND_Y; _reg_blend_ab = &BLEND_AB; } else { _oam = OAM_SUB; _bg_gfx = BG_GFX_SUB; _bg_pal = BG_PALETTE_SUB; _sprite_pal = SPRITE_PALETTE_SUB; _sprite_gfx = SPRITE_GFX_SUB; _reg_cr = &SUB_DISPLAY_CR; _reg_mosaic_cr = &SUB_MOSAIC_CR; _reg_blend_cr = &SUB_BLEND_CR; _reg_blend_y = &SUB_BLEND_Y; _reg_blend_ab = &SUB_BLEND_AB; } _sprites = new SpriteEntry[128]; _sprite_rotations = (SpriteRotation *)_sprites; initOAM(); updateOAM(); _sprite_gfx_next_address = 0; }
//--------------------------------------------------------------------------------- int main(void) { //--------------------------------------------------------------------------------- int min_x = 4096 , min_y = 4096, max_x = 0, max_y = 0; int min_px = 4096 , min_py = 4096, max_px = 0 , max_py = 0; touchPosition touch; // put the main screen on the bottom lcd lcdMainOnBottom(); initOAM(); //enable vram and map it to the right places vramSetMainBanks( VRAM_A_MAIN_SPRITE, //A and B maped consecutively as sprite memory VRAM_B_MAIN_SPRITE, //this gives us 256KB which is the max VRAM_C_MAIN_BG_0x06000000, //map C to background memory VRAM_D_LCD //not using D ); //set the video mode videoSetMode( MODE_0_2D | DISPLAY_SPR_ACTIVE | //turn on sprites DISPLAY_BG0_ACTIVE | //turn on background 0 DISPLAY_SPR_1D //this is used when in tile mode ); int i; // Sprite initialisation for(i = 0; i < 256; i++) SPRITE_PALETTE[i] = ((u16*)ballpalette_bin)[i]; for(i = 0; i< 32*16; i++) SPRITE_GFX[i] = ((u16*)balldata_bin)[i]; consoleInit(0, 0,BgType_Text4bpp, BgSize_T_256x256, 31,0, true, true); iprintf("\x1b[4;8HTouch Screen Test"); iprintf("\x1b[15;4HRight Shoulder toggles"); while(1) { swiWaitForVBlank(); updateOAM(); // read the button states scanKeys(); // read the touchscreen coordinates touchRead(&touch); int pressed = keysDown(); // buttons pressed this loop int held = keysHeld(); // buttons currently held // Right Shoulder button toggles the mode if ( pressed & KEY_R) TouchType ^= SINGLE; iprintf("\x1b[14;4HTouch mode: %s",TouchType==CONTINUOUS?"CONTINUOUS ":"SINGLE SHOT"); iprintf("\x1b[6;5HTouch x = %04X, %04X\n", touch.rawx, touch.px); iprintf("\x1b[7;5HTouch y = %04X, %04X\n", touch.rawy, touch.py); iprintf("\x1b[0;18Hkeys: %08X\n", keysHeld()); iprintf("\x1b[9;10HFrame %d\n", frame); if ( TouchType == SINGLE && !(pressed & KEY_TOUCH) ) continue; if ( !(held & KEY_TOUCH) || touch.rawx == 0 || touch.rawy == 0) continue; iprintf("\x1b[12;12H(%d,%d) ",touch.px,touch.py); if ( touch.rawx > max_x) max_x = touch.rawx; if ( touch.rawy > max_y) max_y = touch.rawy; if ( touch.px > max_px) max_px = touch.px; if ( touch.py > max_py) max_py = touch.py; if ( touch.rawx < min_x) min_x = touch.rawx; if ( touch.rawy < min_y) min_y = touch.rawy; if ( touch.px < min_px) min_px = touch.px; if ( touch.py < min_py) min_py = touch.py; iprintf("\x1b[0;0H(%d,%d) ",min_px,min_py); iprintf("\x1b[1;0H(%d,%d) ",min_x,min_y); iprintf("\x1b[22;21H(%d,%d)",max_x,max_y); iprintf("\x1b[23;23H(%d,%d)",max_px,max_py); OAMCopy[0].attribute[2] = 0; OAMCopy[0].attribute[1] = ATTR1_SIZE_32 |((touch.px - 16) & 0x01FF); OAMCopy[0].attribute[0] = ATTR0_COLOR_256 | ATTR0_SQUARE | ((touch.py -16) & 0x00FF); } return 0; }
int main() { /* Turn on the 2D graphics core. */ powerOn(POWER_ALL_2D); /* * Configure the VRAM and background control registers. * * Place the main screen on the bottom physical screen. Then arrange the * VRAM banks. Next, confiure the background control registers. */ lcdMainOnBottom(); initVideo(); initBackgrounds(); consoleDemoInit(); /* Set up a few sprites. */ SpriteInfo spriteInfo[SPRITE_COUNT]; oam = new OAMTable(); initOAM(oam); //initSprites(oam, spriteInfo); OAM_Manager oam_manager (spriteInfo,oam); Jogador jogador (spriteInfo, &oam_manager); jogador.initGfx (); NPC npc (spriteInfo, &oam_manager); npc.initGfx (); /* * Update the OAM. * * We have to copy our copy of OAM data into the actual OAM during VBlank * (writes to it are locked during other times). */ swiWaitForVBlank(); updateOAM(oam); /* Loop forever so that the Nintendo DS doesn't reboot upon program * completion. */ controle.reset (); for (;;) { consoleClear (); /* Update the game state. */ updateInput(); handleInput(); jogador.update (&controle); npc.update (NULL); /* * Update the OAM. * * We have to copy our copy of OAM data into the actual OAM during * VBlank (writes to it are locked during other times). */ swiWaitForVBlank(); updateOAM(oam); } return 0; }
int main() { /* Turn on the 2D graphics core. */ powerOn(POWER_ALL_2D); /* * Configure the VRAM and background control registers. * * Place the main screen on the bottom physical screen. Then arrange the * VRAM banks. Next, confiure the background control registers. */ lcdMainOnBottom(); initVideo(); initBackgrounds(); /* Initialize maxmod using the memory based soundbank set up. */ mmInitDefaultMem((mm_addr)soundbank_bin); /* Set up a few sprites. */ SpriteInfo spriteInfo[SPRITE_COUNT]; OAMTable *oam = new OAMTable(); initOAM(oam); initSprites(oam, spriteInfo); /* Display the backgrounds. */ displayStarField(); displayPlanet(); displaySplash(); /*************************************************************************/ /* Keep track of the touch screen coordinates. */ touchPosition touch; /* Make the ship object. */ static const int SHUTTLE_OAM_ID = 0; SpriteEntry * shipEntry = &oam->oamBuffer[SHUTTLE_OAM_ID]; SpriteRotation * shipRotation = &oam->matrixBuffer[SHUTTLE_OAM_ID]; Ship * ship = new Ship(&spriteInfo[SHUTTLE_OAM_ID]); /* Make the moon. */ static const int MOON_OAM_ID = 1; SpriteEntry * moonEntry = &oam->oamBuffer[MOON_OAM_ID]; SpriteInfo * moonInfo = &spriteInfo[MOON_OAM_ID]; MathVector2D<int> * moonPos = new MathVector2D<int>(); moonPos->x = moonEntry->x; moonPos->y = moonEntry->y; /* Set up sound data. */ mmLoadEffect(SFX_THRUST); for (;;) { /* Update the game state. */ updateInput(&touch); handleInput(ship, moonPos, moonInfo, &touch); ship->moveShip(); /* Update ship sprite attributes. */ MathVector2D<float> position = ship->getPosition(); shipEntry->x = (int)position.x; shipEntry->y = (int)position.y; rotateSprite(shipRotation, -ship->getAngleDeg()); /* Update moon sprite attributes. */ moonEntry->x = (int)moonPos->x; moonEntry->y = (int)moonPos->y; /* * Update the OAM. * * We have to copy our copy of OAM data into the actual OAM during * VBlank (writes to it are locked during other times). */ swiWaitForVBlank(); updateOAM(oam); } return 0; }