SpriteRotate.pp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. program SpriteRotate;
  2. {$mode objfpc}
  3. uses
  4. ctypes, nds9;
  5. var
  6. i: integer;
  7. angle: integer = 0;
  8. gfx: pcuint16;
  9. begin
  10. videoSetMode(MODE_0_2D);
  11. vramSetBankA(VRAM_A_MAIN_SPRITE);
  12. oamInit(oamMain, SpriteMapping_1D_32, false);
  13. gfx := oamAllocateGfx(oamMain, SpriteSize_32x32, SpriteColorFormat_256Color);
  14. for i := 0 to (32 * 32 div 2) -1 do
  15. gfx[i] := 1 or (1 shl 8);
  16. SPRITE_PALETTE[1] := RGB15(31,0,0);
  17. while true do
  18. begin
  19. scanKeys();
  20. if (keysHeld() and KEY_LEFT) <> 0 then
  21. angle := angle + degreesToAngle(2);
  22. if (keysHeld() and KEY_RIGHT) <> 0 then
  23. angle := angle - degreesToAngle(2);
  24. //-------------------------------------------------------------------------
  25. // Set the first rotation/scale matrix
  26. //
  27. // There are 32 rotation/scale matricies that can store sprite rotations
  28. // Any number of sprites can share a sprite rotation matrix or each sprite
  29. // (up to 32) can utilize a seperate rotation. Because this sprite is doubled
  30. // in size we have to adjust its position by subtracting half of its height and
  31. // width (20 - 16, 20 - 16, )
  32. //-------------------------------------------------------------------------
  33. oamRotateScale(oamMain, 0, angle, intToFixed(1, 8), intToFixed(1, 8));
  34. oamSet(oamMain, //main graphics engine context
  35. 0, //oam index (0 to 127)
  36. 20 - 16, 20 - 16, //x and y pixle location of the sprite
  37. 0, //priority, lower renders last (on top)
  38. 0, //this is the palette index if multiple palettes or the alpha value if bmp sprite
  39. SpriteSize_32x32,
  40. SpriteColorFormat_256Color,
  41. gfx, //pointer to the loaded graphics
  42. 0, //sprite rotation/scale matrix index
  43. true, //double the size when rotating?
  44. false, //hide the sprite?
  45. false, false, //vflip, hflip
  46. false //apply mosaic
  47. );
  48. //-------------------------------------------------------------------------
  49. // Because the sprite below has size double set to false it can never be larger than
  50. // 32x32 causing it to clip as it rotates.
  51. //-------------------------------------------------------------------------
  52. oamSet(oamMain, //main graphics engine context
  53. 1, //oam index (0 to 127)
  54. 204, 20, //x and y pixle location of the sprite
  55. 0, //priority, lower renders last (on top)
  56. 0, //this is the palette index if multiple palettes or the alpha value if bmp sprite
  57. SpriteSize_32x32,
  58. SpriteColorFormat_256Color,
  59. gfx, //pointer to the loaded graphics
  60. 0, //sprite rotation/scale matrix index
  61. false, //double the size when rotating?
  62. false, //hide the sprite?
  63. false, false, //vflip, hflip
  64. false //apply mosaic
  65. );
  66. swiWaitForVBlank();
  67. oamUpdate(oamMain);
  68. end;
  69. end.