void TrashCanEntity::Update()
{
	transformContext = 0;

	u8 derp = (u8)(updateCount % 30);
	float32 periodic = 0.5*sin(3.14159*(float32)derp/30.0);
	float32 derp2 = periodic + 1.0;

	oamRotateScale(&oamSub,
		0,
		degreesToAngle(periodic*10-30),
		floatToFixed(derp2, 8),
		floatToFixed(derp2, 8)	
	);

	if (shouldBeRemoved)
		return;

	if (IsTouchedByNearbyPlayer())
	{
		LivingEntity::Damage(gpPlayerEntity->mStats->attack);
		printf("Trashcan Ouch %d!\n", mStats->health);
	}

	Sprite::Update();
}
Esempio n. 2
0
// makes this sprite a RotateScale sprite
void object::makeRotateScale(int MatrixId, int Angle, int ScaleX, int ScaleY)
{
	// set variables
	matrixId = MatrixId;
	angle = Angle;
	scale.x = ScaleX < 0 ? scale.x : ScaleX;
	scale.y = ScaleY < 0 ? scale.y: ScaleY;

	// make rotateScale
	isRotateScale = true;

	// do rotation
	oamRotateScale(oam, matrixId, angle, scale.x, scale.y);
}
Esempio n. 3
0
void DSGM_SetRotset(u8 screen, int rotset, int angle, int scaleX, int scaleY) {
	oamRotateScale(screen == DSGM_TOP ? &oamMain : &oamSub, rotset, angle, scaleX, scaleY);
}
Esempio n. 4
0
//---------------------------------------------------------------------------------
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;
}
Esempio n. 5
0
int main(int argc, char** argv) {
	
   //three sprites of differing color format
   MySprite sprites[] = {
      {0, SpriteSize_32x32, SpriteColorFormat_Bmp, 0, 15, 20, 15},
      {0, SpriteSize_32x32, SpriteColorFormat_256Color, -1, 0, 20, 80},
      {0, SpriteSize_32x32, SpriteColorFormat_16Color, -1, 1, 20, 136}
   };

   videoSetModeSub(MODE_0_2D);

   consoleDemoInit();
   
   //initialize the sub sprite engine with 1D mapping 128 byte boundary
   //and no external palette support
   oamInit(&oamSub, SpriteMapping_Bmp_1D_128, false);

  
   vramSetBankD(VRAM_D_SUB_SPRITE);
   
   //allocate some space for the sprite graphics
   for(int i = 0; i < 3; i++)
      sprites[i].gfx = oamAllocateGfx(&oamSub, sprites[i].size, sprites[i].format);
   
   //ugly positional printf
   iprintf("\x1b[1;1HDirect Bitmap:");
   iprintf("\x1b[9;1H256 color:");
   iprintf("\x1b[16;1H16 color:");
   
   //fill bmp sprite with the color red
   dmaFillHalfWords(ARGB16(1,31,0,0), sprites[0].gfx, 32*32*2);
   //fill the 256 color sprite with index 1 (2 pixels at a time)
   dmaFillHalfWords((1<<8)|1, sprites[1].gfx, 32*32);
   //fill the 16 color sprite with index 1 (4 pixels at a time)
   dmaFillHalfWords((1<<12)|(1<<8)|(1<<4)|1, sprites[2].gfx, 32*32 / 2);

   //set index 1 to blue...this will be the 256 color sprite
   SPRITE_PALETTE_SUB[1] = RGB15(0,31,0);
   //set index 17 to green...this will be the 16 color sprite
   SPRITE_PALETTE_SUB[16 + 1] = RGB15(0,0,31);

   int angle = 0;

   while(1) {
      for(int i = 0; i < 3; i++) {
         oamSet(
         &oamSub, //sub display 
         i,       //oam entry to set
         sprites[i].x, sprites[i].y, //position 
         0, //priority
		 sprites[i].paletteAlpha, //palette for 16 color sprite or alpha for bmp sprite
         sprites[i].size, 
		 sprites[i].format, 
		 sprites[i].gfx, 
		 sprites[i].rotationIndex, 
         true, //double the size of rotated sprites
         false, //don't hide the sprite
		 false, false, //vflip, hflip
		 false //apply mosaic
         );
      }

      oamRotateScale(&oamSub, 0, angle, (1 << 8), (1<<8));

	  angle += 64;

      swiWaitForVBlank();

      //send the updates to the hardware
      oamUpdate(&oamSub);
   }
   return 0;
}