void TextButton::render_to( int& oam_entry, int _x, int _y ) { if( this->fg_vram && this->is_visible(_x, _y, this->width, this->height) ) { oamSet( this->get_oam(), oam_entry++, _x, _y, // position this->fg_prio, 1, this->sprite_size, SpriteColorFormat_Bmp, this->fg_vram, this->fg_rotation, 0, 0, 0, 0, 0 ); } if( this->text_vram && this->is_visible(_x+this->text_x_offset, _y+this->text_y_offset, this->text_width, this->text_height) ) { oamSet( this->get_oam(), oam_entry++, _x+this->text_x_offset, _y+this->text_y_offset, // position this->text_prio, 0, this->text_sprite_size, SpriteColorFormat_256Color, this->text_vram, this->text_rotation, 0, 0, 0, 0, 0 ); } u16* vram = this->bg_vram; if( this->active && this->bg_active_vram ) vram = this->bg_active_vram; if( this->disabled && this->bg_inactive_vram ) vram = this->bg_inactive_vram; if( vram && this->is_visible(_x, _y, this->width, this->height) ) { oamSet( this->get_oam(), oam_entry++, _x, _y, // position this->bg_prio, 1, this->sprite_size, SpriteColorFormat_Bmp, vram, this->bg_rotation, 0, 0, 0, 0, 0 ); } }
void ChangeCircle(u16 x, u16 y, u16 spriteIndex, u16 tileIndex, u16 pal) { oamSet(spriteIndex, x, y, 2, 0, 0, tileIndex, pal); oamSet(spriteIndex+32, x, y+32, 2, 0, 1, tileIndex, pal); oamSet(spriteIndex+64, x+32, y, 2, 1, 0, tileIndex, pal); oamSet(spriteIndex+96, x+32, y+32, 2, 1, 1, tileIndex, pal); }
void DrawNumber(u16 x, u16 y, u16 spriteIndex, u16 tileIndex, u16 pal) { oamSet(spriteIndex, x, y, 3, 0, 0, tileIndex, pal); oamSetEx(spriteIndex, OBJ_SMALL, OBJ_SHOW); oamSetVisible(spriteIndex, OBJ_SHOW); oamSet(spriteIndex+32, x, y+32, 3, 0, 0, tileIndex+4, pal); oamSetEx(spriteIndex+32, OBJ_SMALL, OBJ_SHOW); oamSetVisible(spriteIndex+32, OBJ_SHOW); }
void videoInit() { videoSetModeSub(MODE_0_2D); oamInit(&oamSub, SpriteMapping_Bmp_1D_128, false); int bgId = bgInitSub(3, BgType_Text8bpp, BgSize_T_256x256, 0, 1); bgSetPriority(bgId, 3); dmaCopy(background.gfxData, bgGetGfxPtr(bgId), MemChunk_GetSize(background.gfxData)); dmaCopy(background.mapData, bgGetMapPtr(bgId), MemChunk_GetSize(background.mapData)); dmaCopy(background.palData, BG_PALETTE_SUB, MemChunk_GetSize(background.palData)); videoSetMode(MODE_3_2D); int bgBmp = bgInit(3, BgType_Bmp16, BgSize_B16_256x256, 2, 0); bmpBuf = bgGetGfxPtr(bgBmp); clearBitmap(); int bgTop = bgInit(2, BgType_Text8bpp, BgSize_T_256x256, 0, 1); bgSetPriority(bgTop, 3); dmaCopy(topscr.gfxData, bgGetGfxPtr(bgTop), MemChunk_GetSize(topscr.gfxData)); dmaCopy(topscr.mapData, bgGetMapPtr(bgTop), MemChunk_GetSize(topscr.mapData)); dmaCopy(topscr.palData, BG_PALETTE, MemChunk_GetSize(topscr.palData)); u16* gfx = SPRITE_GFX_SUB; for (int i = 0; i < 6; i ++) { int xPos = 16 + (i % 3) * (64+16); int yPos = 48 + (i / 3) * (64+8); oamSet(&oamSub, i, xPos, yPos, 1, 15, SpriteSize_64x64, SpriteColorFormat_Bmp, gfx, -1, 0, false, false, false, false); gfx += 64*64; } { dmaCopy(selection.gfxData, gfx, MemChunk_GetSize(selection.gfxData)); oamSet(&oamSub, 6, 0, 0, 0, 15, SpriteSize_16x16, SpriteColorFormat_Bmp, gfx, -1, 0, false, false, false, false); gfx += 16*16; } for (int i = 0; i < MAX_RUNNING_APP_COUNT; i ++) { oamSet(&oamSub, 7+i, 64+(i*(16+8)), 16, 1, 15, SpriteSize_16x16, SpriteColorFormat_Bmp, gfx, -1, 0, false, false, false, false); oamSub_mem[7+i].isHidden = true; gfx += 16*16; } g_appListChanged = true; bump.init(BG_PALETTE_SUB); bump.SelectBump(page); updCursor(); loadPageIcons(); updAppList(); forceTopScrRefresh = true; }
//map our sprite to oam entries void updateSprites(void) { int i; //sort our sprites on z //a more efficient way would be to keep a sorted list of sprites qsort(sprites, SPRITE_MAX, sizeof(mySprite), zsort); //set oam to values required by my sprite for(i = 0; i < SPRITE_MAX; i++) { //an api function: void oamSet(OamState* oam, int id, int x, int y, int priority, int palette_alpha, SpriteSize size, SpriteColorFormat format, const void* gfxOffset, int affineIndex, bool sizeDouble, bool hide); oamSet(oam, i, sprites[i].x, sprites[i].y, 0, 0, sprites[i].size, sprites[i].format, sprites[i].gfx, -1, false, !sprites[i].alive, false, false, false); } }
void DrawCircle(u16 x, u16 y, u16 spriteIndex, u16 tileIndex, u16 pal) { oamSet(spriteIndex, x, y, 2, 0, 0, tileIndex, pal); oamSetEx(spriteIndex, OBJ_SMALL, OBJ_SHOW); oamSetVisible(spriteIndex, OBJ_SHOW); oamSet(spriteIndex+32, x, y+32, 2, 0, 1, tileIndex, pal); oamSetEx(spriteIndex+32, OBJ_SMALL, OBJ_SHOW); oamSetVisible(spriteIndex+32, OBJ_SHOW); oamSet(spriteIndex+64, x+32, y, 2, 1, 0, tileIndex, pal); oamSetEx(spriteIndex+64, OBJ_SMALL, OBJ_SHOW); oamSetVisible(spriteIndex+64, OBJ_SHOW); oamSet(spriteIndex+96, x+32, y+32, 2, 1, 1, tileIndex, pal); oamSetEx(spriteIndex+96, OBJ_SMALL, OBJ_SHOW); oamSetVisible(spriteIndex+96, OBJ_SHOW); }
void DSGM_CreateSprite(u8 screen, int spriteNumber, int x, int y, ObjPriority priority, int frame, bool hFlip, bool vFlip, DSGM_Sprite *sprite) { //oamSet(screen == DSGM_TOP ? &oamMain : &oamSub, spriteNumber, 255, 191, 0, sprite->palette->paletteNumber[screen], sprite->size, SpriteColorFormat_256Color, screen == DSGM_TOP ? sprite->topTiles[0] : sprite->bottomTiles[0], -1, false, false, false, false, false); //swiWaitForVBlank(); //oamUpdate(screen == DSGM_TOP ? &oamMain : &oamSub); //DSGM_SetSpriteXY(screen, spriteNumber, x, y); oamSet(screen == DSGM_TOP ? &oamMain : &oamSub, spriteNumber, x, y, priority, sprite->palette->paletteNumber[screen], sprite->size, SpriteColorFormat_256Color, screen == DSGM_TOP ? sprite->topTiles[frame] : sprite->bottomTiles[frame], -1, false, false, hFlip, vFlip, false); //oamUpdate(screen == DSGM_TOP ? &oamMain : &oamSub); }
void Enemy::draw() { if((s_x + 7 > 0) && (s_x < 256) && (s_y + 7 > 0) && (s_y < 192)) { // If the sprite is on the screen // Draw the sprite on the screen oamSet(&oamMain, s_i, s_x, s_y, 0, 15, s_size, s_format, s_gfx, -1, false, false, false, false, false); } else { oamClearSprite(&oamMain, s_i); // Clear the sprite } }
//Displaying a sprite void Sprite::display(u8 id, int x, int y, u8 priority, u8 frame){ oamSet(oam, id, x, y, priority, palNumber, spriteSize, SpriteColorFormat_256Color, gfxMem[frame], -1, false, false, false, false, false); }
void SpriteInstance::setOAM() { OamState *oam; oam = screen == Rage::MAIN ? &oamMain : &oamSub; oamSet(oam, spriteIndex, x, y, 0, 0, currAnim->size, SpriteColorFormat_256Color, animationFrames[currentFrameIndex], -1, false, !visible || emptyFrame /* hide */, false, false, false); }
void iconTitleInit (void) { // initialize video mode videoSetMode(MODE_4_2D); // initialize VRAM banks vramSetPrimaryBanks(VRAM_A_MAIN_BG, VRAM_B_MAIN_SPRITE, VRAM_C_LCD, VRAM_D_LCD); // initialize bg2 as a rotation background and bg3 as a bmp background // http://mtheall.com/vram.html#T2=3&RNT2=96&MB2=3&TB2=0&S2=2&T3=6&MB3=1&S3=1 bg2 = bgInit(2, BgType_Rotation, BgSize_R_512x512, 3, 0); bg3 = bgInit(3, BgType_Bmp16, BgSize_B16_256x256, 1, 0); // initialize rotate, scale, and scroll bgSetRotateScale(bg3, 0, 1<<8, 1<<8); bgSetScroll(bg3, 0, 0); bgSetRotateScale(bg2, 0, 8*(1<<8)/6, 1<<8); bgSetScroll(bg2, -TITLE_POS_X, -TITLE_POS_Y); // clear bg2's map: 512x512 pixels is 64x64 tiles is 4KB dmaFillHalfWords(0, bgGetMapPtr(bg2), 4096); // load compressed font into bg2's tile data decompress(font6x8Tiles, bgGetGfxPtr(bg2), LZ77Vram); // load compressed bitmap into bg3 decompress(hbmenu_bannerBitmap, bgGetGfxPtr(bg3), LZ77Vram); // load font palette dmaCopy(font6x8Pal, BG_PALETTE, font6x8PalLen); // apply the bg changes bgUpdate(); // initialize OAM oamInit(&oamMain, SpriteMapping_1D_128, false); sprite = oamAllocateGfx(&oamMain, SpriteSize_32x32, SpriteColorFormat_16Color); dmaFillHalfWords(0, sprite, sizeof(banner.icon)); oamSet(&oamMain, 0, ICON_POS_X, ICON_POS_Y, 0, 0, SpriteSize_32x32, SpriteColorFormat_16Color, sprite, -1, 0, 0, 0, 0, 0); // oam can only be updated during vblank swiWaitForVBlank(); oamUpdate(&oamMain); // everything's ready :) writeRow (0,"...initializing..."); writeRow (1,"===>>> HBMenu+ <<<==="); writeRow (2,"(this text should disappear..."); writeRow (3,"...otherwise, trouble!)"); }
//Set all of the objects to be displayed during the next redraw void menu_main_redraw(void) { //Let's redraw things! //all of the buttons int i, j; for (i = j = 0; i < sizeof(BUTTON) * NUM_BUTTONS; i += sizeof(BUTTON), j++) { //iprintf("%i\n", j); oamSet(&oamMain, j, menu_buttons[i]->x, menu_buttons[i]->y, 0, 0, SpriteSize_32x32, SpriteColorFormat_256Color, menu_buttons[i]->sprite_gfx_mem, -1, false, false, false, false, false); } //TODO: maybe other things? }
void Sprite2D::Draw() { oamSet(&oamSub, spid, x, y, 0, 0, size, format, gfx, -1, false, false, false, false, false); }
//--------------------------------------------------------------------------------- int main(void) { // Initialize SNES consoleInit(); // Put current handler to our function spr_queue = 0xff; spr_mutex = 0; __nmi_handler=myconsoleVblank; // Init Sprites gfx and palette with default size of 16x16 (and don't load sprite tiles) oamInitGfxSet(&gfxpsrite, 2, &palsprite, 16*2, 0, ADRGFXSPR, OBJ_SIZE16); // Define sprites parmaters oamSet(0, 100, 100, 3, 0, 0, 0, 0); // Put sprite in 100,100, with maximum priority 3 from tile entry 0, palette 0 oamSetEx(0, OBJ_SMALL, OBJ_SHOW); // Now Put in 16 color mode and disable all backgrounds setMode(BG_MODE1,0); bgSetDisable(0); bgSetDisable(1); bgSetDisable(2); // add new sprite to queue addSprite(&gfxpsrite, ADRGFXSPR); // Wait for nothing :P while(1) { // Refresh pad values in VBL and Get current #0 pad pad0 = padsCurrent(0); if (pad0) { // Key A pressed if(pad0 & KEY_A) { // if not yet pressed if (padkeya == 0) { padkeya=1; // avoid adding new sprite continuisly // add new sprite to queue addSprite((&gfxpsrite)+8*4*2, ADRGFXSPR); } } else padkeya=0; } // Wait VBL 'and update sprites too ;-) ) WaitForVBlank(); } return 0; }
void VisualElement::update_sprite(const unsigned int offset_bytes) { st_sprite& sprite = s_SpritePositions[m_SpritePosition]; u8 *data_offset = sprite.charset_data + offset_bytes; dmaCopy(data_offset, sprite.mem_addr, SPRITE_LENGHT_BYTES); oamSet(&oamMain, m_SpritePosition, s_SpritePositions[m_SpritePosition].offset->x, s_SpritePositions[m_SpritePosition].offset->y, 0, 0, SpriteSize_32x32, SpriteColorFormat_256Color, sprite.mem_addr, -1, false, sprite.hide, false, false, false); }
void DSGM_DeleteObjectInstanceFull(DSGM_Room *room, DSGM_ObjectInstance **meP, DSGM_ObjectInstance *objectInstance) { DSGM_ObjectInstanceRelation relation = { 0, 0 }; if(meP && *meP) relation = DSGM_GetObjectInstanceRelationFull(room, *meP); DSGM_ObjectGroup *group = DSGM_GetObjectGroupFull(room, objectInstance->screen, objectInstance->object); if(!group) { DSGM_Debug("PEBCAK! Supplied a bad object instance %p, object %p, no object group could be found\n", objectInstance, objectInstance->object); return; } bool spriteNumbersChange = 0; u8 screen = objectInstance->screen; if(objectInstance->object->sprite != DSGM_NO_SPRITE) { spriteNumbersChange = 1; } int ID = DSGM_GetObjectInstanceIDFull(room, objectInstance); DSGM_Debug("Deleting object instance with ID %d\n", ID); if(objectInstance->object->destroy) objectInstance->object->destroy(objectInstance); DSGM_DeinitObjectInstanceRotScale(objectInstance); DSGM_invalidObjectInstance = objectInstance; if(ID < group->objectInstanceCount - 1) { DSGM_Debug("Shifting %d object instances for deletion\n", (group->objectInstanceCount - ID - 1)); memcpy(&group->objectInstances[ID], &group->objectInstances[ID + 1], (group->objectInstanceCount - ID - 1) * sizeof(DSGM_ObjectInstance)); } group->objectInstances = realloc(group->objectInstances, --group->objectInstanceCount * sizeof(DSGM_ObjectInstance)); if(spriteNumbersChange) { int i; for(i = 0; i < 128; i++) { oamSet(screen == DSGM_TOP ? &oamMain : &oamSub, i, 0, 0, 0, 0, SpriteSize_32x32, SpriteColorFormat_256Color, NULL, -1, false, true, false, false, false); } DSGM_RedistributeSpriteNumbers(room, screen); } if(meP && *meP) *meP = DSGM_GetMeFromObjectInstanceRelationFull(room, &relation); }
void Statue::init() { init_timer(1, 30); counter = 0; oamClear(&oamMain, 0, 0); oamEnable(&oamMain); oamInit(&oamMain, SpriteMapping_1D_32, false); dmaCopy(statuePal, SPRITE_PALETTE, sizeof(statuePal)); oamSet( &oamMain, STATUE_SPRITE, 50, 50, /*priority*/1, /*palette*/0, SpriteSize_32x64, SpriteColorFormat_16Color, oamGetGfxPtr(&oamMain, STATUE_TILE), -1, false, false, false, false, false); Game::init(); writeTimed("\x1b[10;10HDetruis!", 1000); }
void VisualElement::update_position(void) { for (unsigned short i = 0; i < SPRITE_POSITIONS; ++i) { st_sprite& sprite = s_SpritePositions[i]; if (sprite.in_use == false) { continue; } int new_x = sprite.offset->x; int new_y = sprite.offset->y; /* Give extra offset to correctly place the other sprite. */ if (i != SPRITE_PIVOT_INDEX) { //debug("new: %d,%d", new_x, new_y); new_x += s_SpritePositions[SPRITE_PIVOT_INDEX].offset->x - TILE_8PX_TO_PX(VisualElement::s_PivotOffset_8px->x); new_y += s_SpritePositions[SPRITE_PIVOT_INDEX].offset->y - TILE_8PX_TO_PX(VisualElement::s_PivotOffset_8px->y); //debug("bef: %d,%d", new_x, new_y); /* Verify if the sprite is inside the showing bounds (otherwise, it will be appearing * every multiples of "screen size offset") */ if ( ((new_x + TILE_SIZE_32PX) < 0) || ((new_y + TILE_SIZE_32PX) < 0) || (new_x > SCREEN_WIDTH) || (new_y > SCREEN_HEIGHT)) { oamClearSprite(&oamMain, i); continue; } } oamSet(&oamMain, i, new_x, new_y, 0, 0, SpriteSize_32x32, SpriteColorFormat_256Color, sprite.mem_addr, -1, false, sprite.hide, false, false, false); } }
void EzabatuBeltza(int indizea, int x, int y) { oamSet(&oamMain, indizea, x, y, 0, 0, SpriteSize_16x16, SpriteColorFormat_256Color, gfx_beltza, -1, false, true, false, false, false ); oamUpdate(&oamMain); }
// Draw the object on screen void object::draw(int spriteId) { // Load up the gfx frame = animations[0][0]->gfx; paletteAsset *pal = animations[0][0]->pal; uint16 *frameMem = zbeAssets->getGfx(frame); uint8 paletteId = zbeAssets->getPalette(pal); // Flip horizontally? if (velocity.x < 0) hflip = true; else hflip = false; // Update the OAM // NOTE: If hidden doesn't work as expected on affine transformed sprites, then there needs to be a check here to see if // the object is hidden and if so, pass -1 for affineIndex. // void oamSet(OamState *oam, int id, int x, int y, int priority, int palette_id, SpriteSize size, SpriteColorFormat format, // const void * gfxOffset, int affineIndex, bool sizeDouble, bool hide, bool hflip, bool vflip, bool mosaic); oamSet(oam, spriteId, int (position.x - screenOffset.x), int (position.y - screenOffset.y), priority, paletteId, frame->size, format, frameMem, matrixId, true, hidden, hflip, vflip, mosaic); }
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); } }
void Sprite::draw() { // Draw the sprite on the screen oamSet(s_oam, s_i, s_x, s_y, 0, 15, s_size, s_format, s_gfx, -1, false, false, false, false, false); }
//--------------------------------------------------------------------------------- int main(void) { //--------------------------------------------------------------------------------- int i = 0; int angle = 0; videoSetMode(MODE_0_2D); vramSetBankA(VRAM_A_MAIN_SPRITE); oamInit(&oamMain, SpriteMapping_1D_32, false); u16* gfx = oamAllocateGfx(&oamMain, SpriteSize_32x32, SpriteColorFormat_256Color); /* This is where we load the image. * In this case we're doing a really simple striped pattern, * but we could also load a bitmap. */ for(i = 0; i < 32 * 32 / 2; i++) { //gfx[i] = 1 | (1 << 8); gfx[i] = 0x201; // alternating red and yellow } SPRITE_PALETTE[1] = RGB15(31,0,0); // full red SPRITE_PALETTE[2] = RGB15(28,28,0); // bright yellow while(1) { scanKeys(); /* Slow down the rotate if the left trigger is pressed * I'd like to do a fixed-point here, but I don't know how */ float inc = (keysHeld() & KEY_L)? 0.05 : 0.3; if(keysHeld() & KEY_LEFT) angle += degreesToAngle(inc); if(keysHeld() & KEY_RIGHT) angle -= degreesToAngle(inc); //------------------------------------------------------------------------- // Set the first rotation/scale matrix // // There are 32 rotation/scale matricies that can store sprite rotations // Any number of sprites can share a sprite rotation matrix or each sprite // (up to 32) can utilize a seperate rotation. Because this sprite is doubled // in size we have to adjust its position by subtracting half of its height and // width (20 - 16, 20 - 16, ) //------------------------------------------------------------------------- oamRotateScale(&oamMain, 0, angle, intToFixed(1, 8), intToFixed(1, 8)); oamSet(&oamMain, //main graphics engine context 0, //oam index (0 to 127) 20 - 16, 20 - 16, //x and y pixle location of the sprite 0, //priority, lower renders last (on top) 0, //this is the palette index if multiple palettes or the alpha value if bmp sprite SpriteSize_32x32, SpriteColorFormat_256Color, gfx, //pointer to the loaded graphics 0, //sprite rotation/scale matrix index true, //double the size when rotating? false, //hide the sprite? false, false, //vflip, hflip false //apply mosaic ); //------------------------------------------------------------------------- // Because the sprite below has size double set to false it can never be larger than // 32x32 causing it to clip as it rotates. //------------------------------------------------------------------------- oamSet(&oamMain, //main graphics engine context 1, //oam index (0 to 127) 204, 20, //x and y pixle location of the sprite 0, //priority, lower renders last (on top) 0, //this is the palette index if multiple palettes or the alpha value if bmp sprite SpriteSize_32x32, SpriteColorFormat_256Color, gfx, //pointer to the loaded graphics 0, //sprite rotation/scale matrix index false, //double the size when rotating? false, //hide the sprite? false, false, //vflip, hflip false //apply mosaic ); swiWaitForVBlank(); oamUpdate(&oamMain); } return 0; }
void zombieType::render(int i,camera &cam,bool unrender) { animate(); oamSet(&oamMain, i+10, x-cam.getX(), y-cam.getY(), 0, 0, SpriteSize_32x32, SpriteColorFormat_256Color, sprite_gfx_mem, -1, false, unrender, false, false, false); }
static void loadSpriteData(Sprite_s* spr) {//((spr->gfxId<<1)+((spr->gfxId<<7)&0x400)) oamSet((spr->gfxId<<2), spr->x, spr->y, spr->priority, spr->vFlip, spr->hFlip, SPRITE1_ADDR_OFFSET + (testFrames[spr->gfxId&0xF]), spr->palId);//last parameter here is spr->palId. old spr->gfxId<<7 oamSetEx((spr->gfxId<<2), spr->size, spr->visible); oamSetXYEx((spr->gfxId), spr->x, spr->y); }
//--------------------------------------------------------------------------------- int main(void) { //--------------------------------------------------------------------------------- int i = 0; videoSetMode(MODE_0_2D); videoSetModeSub(0); // not using subscreen lcdMainOnBottom(); //initialize the sprite engine with 1D mapping 128 byte boundary //and no external palette support oamInit(&oamMain, SpriteMapping_1D_32, false); vramSetBankA(VRAM_A_MAIN_SPRITE); for (i = 0; i < 5; i++) { //allocate some space for the sprite graphics sprites[i].gfx = oamAllocateGfx(&oamMain, sprites[i].size, sprites[i].format); //fill each sprite with a different index (2 pixels at a time) dmaFillHalfWords( ((i+1)<<8)|(i+1), sprites[i].gfx, 32*32); } //set indexes to different colours SPRITE_PALETTE[1] = RGB15(31,0,0); SPRITE_PALETTE[2] = RGB15(0,31,0); SPRITE_PALETTE[3] = RGB15(0,0,31); SPRITE_PALETTE[4] = RGB15(31,0,31); SPRITE_PALETTE[5] = RGB15(0,31,31); // initialise maxmod using default settings, and enable interface for soundbank that is loaded into memory mmInitDefaultMem( (mm_addr)mmsolution_bin ); // setup maxmod to use the song event handler mmSetEventHandler( myEventHandler ); // load song // values for this function are in the solution header mmLoad( MOD_EXAMPLE2 ); // start song playing mmStart( MOD_EXAMPLE2, MM_PLAY_LOOP ); while(1) { for (i=0; i < 5; i++) { // constantly increase the sprite's y velocity sprites[i].dy += 1; // update the sprite's y position with its y velocity sprites[i].y += sprites[i].dy; // clamp the sprite's y position if ( sprites[i].y<72 ) sprites[i].y = 72; if ( sprites[i].y>96 ) sprites[i].y = 96; oamSet( &oamMain, //main graphics engine context i, //oam index (0 to 127) sprites[i].x, //x and y pixel location of the sprite sprites[i].y, 0, //priority, lower renders last (on top) sprites[i].paletteAlpha, //palette index sprites[i].size, sprites[i].format, sprites[i].gfx, //pointer to the loaded graphics sprites[i].rotationIndex, //sprite rotation data false, //double the size when rotating? false, //hide the sprite? false, false, //vflip, hflip false //apply mosaic ); } swiWaitForVBlank(); //send the updates to the hardware oamUpdate(&oamMain); } return 0; }
void Aim::init() { init_timer(3, 0); counter = 0; oamClear(&oamMain, 0, 0); oamEnable(&oamMain); oamInit(&oamMain, SpriteMapping_1D_32, false); dmaCopy(capitalistTiles, oamGetGfxPtr(&oamMain, CAPITALIST_TILE), sizeof(capitalistTiles)); dmaCopy(capitalistPal, SPRITE_PALETTE, sizeof(capitalistPal)); dmaCopy(sovietTiles, oamGetGfxPtr(&oamMain, SOVIET_TILE), sizeof(sovietTiles)); dmaCopy(sovietPal, SPRITE_PALETTE + 16, sizeof(sovietPal)); for (int i = 0; i <= NUM_SOVIET; ++i) { frame[i] = rand() % 8; anim[i] = rand() % 2; oamSet( &oamMain, SOVIET_SPRITE + i, (rand() % 128) + 32, (rand() % 64) + 32, /*priority*/1, /*palette*/1, SpriteSize_64x64, SpriteColorFormat_16Color, NULL, -1, false, false, false, false, false); } for (int i = 0; i < NUM_SOVIET; ++i) { SpriteEntry* ii = oamMain.oamMemory + SOVIET_SPRITE + i; for (int j = i + 1; j <= NUM_SOVIET; ++j) { SpriteEntry* jj = oamMain.oamMemory + SOVIET_SPRITE + j; if (ii->y < jj->y) { int tmp = jj->y; jj->y = ii->y; ii->y = tmp; } } } capitalist_sprite = rand() % NUM_SOVIET; (oamMain.oamMemory + SOVIET_SPRITE + capitalist_sprite)->palette = 0; for (int i = 0; i <= NUM_SOVIET; ++i) { if (i == capitalist_sprite) { (oamMain.oamMemory + SOVIET_SPRITE + i)->gfxIndex = CAPITALIST_TILE + anim[i]*CAPITALIST_TILE_COUNT; } else { (oamMain.oamMemory + SOVIET_SPRITE + i)->gfxIndex = SOVIET_TILE + anim[i]*SOVIET_TILE_COUNT; } } Game::init(); writeTimed("\x1b[5;15HCamoufle le capitaliste!", 1000); bgHide(1); }
// Program entrypoint int main() { if (!mmIsARM7Loaded()) { printf("Couldn't load Maxmod!\n"); return 1; } // Init Maxmod with default settings (loading from FAR) mmInitDefaultFAR(hFar, "/soundbank.bin"); FeOS_DirectMode(); videoSetMode(MODE_0_2D); videoSetModeSub(0); vramSetBankA(VRAM_A_MAIN_SPRITE); // Initialize the sprite engine with 1D mapping 128 byte boundary // aand no external palette support oamInit(&oamMain, SpriteMapping_1D_32, false); int i; for (i = 0; i < 5; i ++) { // Allocate some space for the sprite graphics sprites[i].gfx = oamAllocateGfx(&oamMain, sprites[i].size, sprites[i].format); // Fill each sprite with a different index (2 pixels at a time) dmaFillHalfWords(((i+1) << 8) | (i+1), sprites[i].gfx, 32*32); } // Set indexes to different colours SPRITE_PALETTE[1] = RGB15(31,0,0); SPRITE_PALETTE[2] = RGB15(0,31,0); SPRITE_PALETTE[3] = RGB15(0,0,31); SPRITE_PALETTE[4] = RGB15(31,0,31); SPRITE_PALETTE[5] = RGB15(0,31,31); mmSetEventHandler(myEventHandler); mmLoad(MOD_EXAMPLE2); mmStart(MOD_EXAMPLE2, MM_PLAY_LOOP); for(;;) { swiWaitForVBlank(); if (keysDown() & KEY_START) break; for (i = 0; i < 5; i ++) { // Constantly increase the sprite's y velocity sprites[i].dy += 1; // Update the sprite's y position with its y velocity sprites[i].y += sprites[i].dy; // Clamp the sprite's y position if (sprites[i].y<72) sprites[i].y = 72; if (sprites[i].y>96) sprites[i].y = 96; oamSet(&oamMain, // Main graphics engine context i, // OAM index (0 to 127) sprites[i].x, // X and Y pixel location of the sprite sprites[i].y, 0, // Priority, lower renders last (on top) sprites[i].paletteAlpha, // Palette index sprites[i].size, sprites[i].format, sprites[i].gfx, // Pointer to the loaded graphics sprites[i].rotationIndex, // Sprite rotation data false, // Double the size when rotating? false, // Hide the sprite? false, false, // VFlip, HFlip false); // Apply mosaic } } mmStop(); mmUnload(MOD_EXAMPLE2); mmUnloadSoundbank(); FeOS_ConsoleMode(); return 0; }
void ChangeNumber(u16 x, u16 y, u16 spriteIndex, u16 tileIndex, u16 pal) { oamSet(spriteIndex, x, y, 3, 0, 0, tileIndex, pal); oamSet(spriteIndex+(4*8), x, y+32, 3, 0, 0, tileIndex+4, pal); }
//update this function first it's the ugliest and most unwieldly //maybe add bsprite param? void blu_impl::GFX_BltSpr(bluSprite* bsp){ oamSet(&oamMain,bsp->id,bsp->x,bsp->y,bsp->priority,0,bsp->sz,bsp->sfmt,bsp->gfx,0,false,false,false,false,false); oamUpdate(&oamMain); }