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; }
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() { touchPosition touch; PrintConsole mainScreen; mySprite sprites[128]; lcdMainOnBottom(); initVideo(); initBackgrounds(); initConsole(&mainScreen); initSprites(sprites); //leftButtonOff oamSet(&oamMain, sprites[0].id, sprites[0].x, sprites[0].y, 0, 0, SpriteSize_64x64, SpriteColorFormat_16Color, sprites[0].gfx, -1, false, false, false, false, false); //rightButtonOff oamSet(&oamMain, sprites[2].id, sprites[2].x, sprites[2].y, 0, 0, SpriteSize_64x64, SpriteColorFormat_16Color, sprites[2].gfx, -1, false, false, false, false, false); int keys = keysDown(); int currentSprite = 4; int moveLeft = 0; int moveRight = 0; int MOVE_SPEED = 21; while (true) { //consoleClear(); scanKeys(); touchRead(&touch); keys = keysHeld(); if (keys) { if (keys & KEY_TOUCH) { touchRead(&touch); if (within(&touch, sprites[0])) { // leftButton clicked // leftButtonOn oamClearSprite(&oamMain, 0); oamSet(&oamMain, sprites[1].id, sprites[1].x, sprites[1].y, 0, 1, SpriteSize_64x64, SpriteColorFormat_16Color, sprites[1].gfx, -1, false, false, false, false, false); swiWaitForVBlank(); oamUpdate(&oamMain); moveLeft = 1; } else if (within(&touch, sprites[2])) { // rightButton clicked // rightButtonOn oamClearSprite(&oamMain, 2); oamSet(&oamMain, sprites[3].id, sprites[3].x, sprites[3].y, 0, 1, SpriteSize_64x64, SpriteColorFormat_16Color, sprites[3].gfx, -1, false, false, false, false, false); swiWaitForVBlank(); oamUpdate(&oamMain); moveRight = 1; } else if(within(&touch, sprites[currentSprite])) { mmEffectEx(&sprites[currentSprite].sfx); } } } else { //leftButtonOff oamClearSprite(&oamMain, 1); oamSet(&oamMain, sprites[0].id, sprites[0].x, sprites[0].y, 0, 0, SpriteSize_64x64, SpriteColorFormat_16Color, sprites[0].gfx, -1, false, false, false, false, false); //rightButtonOff oamClearSprite(&oamMain, 3); oamSet(&oamMain, sprites[2].id, sprites[2].x, sprites[2].y, 0, 0, SpriteSize_64x64, SpriteColorFormat_16Color, sprites[2].gfx, -1, false, false, false, false, false); if (moveLeft) { if ((currentSprite - 1) >= 4) { // move current sprite to the right and new one in from left int x1 = sprites[currentSprite].x; int x2 = -64; while (x1 < 280 || x2 < 96) { oamSet(&oamMain, sprites[currentSprite].id, x1, sprites[currentSprite].y, 0, sprites[currentSprite].paletteAlpha, SpriteSize_64x64, SpriteColorFormat_16Color, sprites[currentSprite].gfx, -1, false, false, false, false, false); oamSet(&oamMain, sprites[currentSprite-1].id, x2, sprites[currentSprite-1].y, 0, sprites[currentSprite-1].paletteAlpha, SpriteSize_64x64, SpriteColorFormat_16Color, sprites[currentSprite-1].gfx, -1, false, false, false, false, false); swiWaitForVBlank(); oamUpdate(&oamMain); x1 += MOVE_SPEED; x2 += MOVE_SPEED; } currentSprite--; } moveLeft = 0; } else if (moveRight) { if ((currentSprite + 1) - SPRITECOUNT < 0) { // move current sprite to the left and new one from right int x1 = sprites[currentSprite].x; int x2 = 256; while (x1 > -80 || x2 > 96) { oamSet(&oamMain, sprites[currentSprite].id, x1, sprites[currentSprite].y, 0, sprites[currentSprite].paletteAlpha, SpriteSize_64x64, SpriteColorFormat_16Color, sprites[currentSprite].gfx, -1, false, false, false, false, false); oamSet(&oamMain, sprites[currentSprite+1].id, x2, sprites[currentSprite+1].y, 0, sprites[currentSprite+1].paletteAlpha, SpriteSize_64x64, SpriteColorFormat_16Color, sprites[currentSprite+1].gfx, -1, false, false, false, false, false); swiWaitForVBlank(); oamUpdate(&oamMain); x1 -= MOVE_SPEED; x2 -= MOVE_SPEED; } currentSprite++; } moveRight = 0; } } //oamSet(oam, id, x, y, priority, palette_alpha, size, colorformat, gfxOffset, affineIndex, //sizedouble, hide, hflip, vflip, mosaic); // //gong consoleClear(); printf("\x1b[3;3H%s", sprites[currentSprite].desc); oamSet(&oamMain, sprites[currentSprite].id, sprites[currentSprite].x, sprites[currentSprite].y, 0, sprites[currentSprite].paletteAlpha, SpriteSize_64x64, SpriteColorFormat_16Color, sprites[currentSprite].gfx, -1, false, false, false, false, false); swiWaitForVBlank(); oamUpdate(&oamMain); } }
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; }