Oh yes is one limit, I have an idea how to solve the problem, thanks :D
Cette section vous permet de consulter les contributions (messages, sujets et fichiers joints) d'un utilisateur. Vous ne pourrez voir que les contributions des zones auxquelles vous avez accès.
Voir les contributions Menu
//Oh yes is big array, but is only for tests, in the future i go reduce this :)
unsigned short sprTiles16px[300] = {0,2,4,6,8,10,12,14,32,34,36,38,40,42,44,46,64,66,68,70,72,74,76,78,96,98,100,102,104,106,108,110,128,130,132,134,136,138,140,142,160,162,164,166,168,170,172,174,192,194,196,198,200,202,204,206,224,226,228,230,232,234,236,238,256,258,260,262,264,266,268,270,288,290,292,294,296,298,300,302,320,322,324,326,328,330,332,334,352,354,356,358,360,362,364,366,384,386,388,390,392,394,396,398,416,418,420,422,424,426,428,430,448,450,452,454,456,458,460,462,480,482,484,486,488,490,492,494,512,514,516,518,520,522,524,526,544,546,548,550,552,554,556,558,576,578,580,582,584,586,588,590,608,610,612,614,616,618,620,622,640,642,644,646,648,650,652,654,672,674,676,678,680,682,684,686,704,706,708,710,712,714,716,718,736,738,740,742,744,746,748,750,768,770,772,774,776,778,780,782,800,802,804,806,808,810,812,814,832,834,836,838,840,842,844,846,864,866,868,870,872,874,876,878,896,898,900,902,904,906,908,910,928,930,932,934,936,938,940,942,960,962,964,966,968,970,972,974,992,994,996,998,1000,1002,1004,1006,1024,1026,1028,1030,1032,1034,1036,1038,1056,1058,1060,1062,1064,1066,1068,1070,1088,1090,1092,1094,1096,1098,1100,1102,1120,1122,1124,1126,1128,1130,1132,1134,1152,1154,1156,1158,1160,1162,1164,1166,1184,1186,1188,1190};
//Custom oamInitGfxAttr, my sprites having 16X32 (see Val 6 in table Sprite sizes http://www.portabledev.com/wiki/doku.php?id=sprites_en)
REG_OBSEL = (6<<5) | (0x0000 >> 13);
//Copy the heros graphics for vram with dma, this point using 0x0000 to 0xC000
WaitForVBlank(); dmaCopyVram(&tileSourceHeros, 0x0000, &tileSourceHerosEnd-&tileSourceHeros);
//Copy the heros palette for vram with dma
dmaCopyCGram(&paletteEntryHeros, (128+0*16), 32);
//Copy the civis graphics for vram with dma, this point using 0xC000 to 0x2000
WaitForVBlank(); dmaCopyVram(&tileSourceCivis, 0xC000 , &tileSourceCivisEnd - &tileSourceCivis);
//Copy the civis palette for vram with dma
dmaCopyCGram(&paletteEntryCivis, (128+1*16), 32);
//Copy the objs graphics for vram with dma, this point using 0x2000 to 0x3000
WaitForVBlank(); dmaCopyVram(&tileSourceObjs, 0x2000, &tileSourceObjsEnd - &tileSourceObjs);
//Copy the objs palette for vram with dma
dmaCopyCGram(&paletteEntryObjs, (128+2*16), 32);
/*Table offset
Offset Sprite Addres Real
0 Hero 0x0000
16 Friend1 0x0400
32 Friend2 0x0800
48 Civil1 0x0C00
64 Civil2 0x1000
80 Civil3 0x1400
96 Civil4 0x1800
112 Civil5 0x1C00
128 OBJ1 0x2000 //Dont working
144 OBJ2 0x2400 //Dont working
160 OBJ3 0x2800 //Dont working
176 OBJ4 0x2C00 //Dont working
*/
//0x0000
oamSetEx(0, OBJ_SMALL, OBJ_SHOW);
oamSet(0, hero.x, hero.y, 0, 0, 0, sprTiles16px[0], 0);
//0x0400
oamSetEx(4, OBJ_SMALL, OBJ_SHOW);
oamSet(4, friend1.x, friend1.y, 0, 0, 0, sprTiles16px[16], 0);
//0x0800
oamSetEx(8, OBJ_SMALL, OBJ_SHOW);
oamSet(8, friend2.x, friend2.y, 0, 0, 0, sprTiles16px[32], 0);
//0x0C00
oamSetEx(12, OBJ_SMALL, OBJ_SHOW);
oamSet(12, civil1.x, civil1.y, 0, 0, 0, sprTiles16px[48], 1);
//0x1000
oamSetEx(16, OBJ_SMALL, OBJ_SHOW);
oamSet(16, civil2.x, civil2.y, 0, 0, 0, sprTiles16px[64], 1);
//0x1400
oamSetEx(20, OBJ_SMALL, OBJ_SHOW);
oamSet(20, civil3.x, civil3.y, 0, 0, 0, sprTiles16px[80], 1);
//0x1800
oamSetEx(24, OBJ_SMALL, OBJ_SHOW);
oamSet(24, civil4.x, civil4.y, 0, 0, 0, sprTiles16px[96], 1);
//0x1C00
oamSetEx(28, OBJ_SMALL, OBJ_SHOW);
oamSet(28, civil5.x, civil5.y, 0, 0, 0, sprTiles16px[112], 1);
//0x2000 - Dont working
oamSetEx(32, OBJ_SMALL, OBJ_SHOW);
oamSet(32, obj1.x, obj1.y, 0, 0, 0, sprTiles16px[128], 2);
//0x2400 - Dont working
oamSetEx(36, OBJ_SMALL, OBJ_SHOW);
oamSet(36, obj2.x, obj2.y, 0, 0, 0, sprTiles16px[144], 2);
//0x2800 - Dont working
oamSetEx(40, OBJ_SMALL, OBJ_SHOW);
oamSet(40, obj3.x, obj3.y, 0, 0, 0, sprTiles16px[160], 2);
//0x2C00 - Dont working
oamSetEx(44, OBJ_SMALL, OBJ_SHOW);
oamSet(44, obj4.x, obj4.y, 0, 0, 0, sprTiles16px[176], 2);
void oamInitGfxAttr(0x0000, OBJ_SIZE8);
u16 checkMapCol(short OBJX, short OBJY, u8 *mapCol){
//512 pixel width 512/8 = 64
//768 pixel height -> 768/8 = 96
u16 *ptrMap = (u16 *) &mapCol + (OBJY>>3)*64 + (OBJX>>3)*96;
return (*ptrMap);
}
Citation
shot valueOfTile;
valueOfTile = &mapcol / (13); //13st tile, return 1 or 1st Tile
valueOfTile = &mapcol / (14); //14st tile, Return 1 or 1st Tile
valueOfTile = &mapcol / (15); //15st tile, Return 2 or 2st Tile
valueOfTile = &mapcol / (16); //16st tile, Return 2 or 2st Tile
valueOfTile = &mapcol / (17); //17st tile, Return 1 or 1st Tile
valueOfTile = &mapcol / (18); //18st tile, Return 2 or 2st Tile
...
"Front" < BG3, BG2, SPRITES, BG1 > "Behind"
<Front Screen>
BG3 -> Here Dialog texts (I need set bit priority for 1, default is 0)
BG2 -> Here will be for example, leaf of trees, to create depth effect for the sprite (I need set bit priority for 1, default is 0)
OBJ -> Are all sprites (The priority i set in 2 and working becouse is native in function OamSet)
BG1 -> Here all background for my map (the bit priority default is 0, so no need to do anything)
<Behind>
BG3 -> priority 1
BG2 -> priority 1
OBJ -> priority 2
BG1 -> priority 0
CitationThis is how you get that type of arrangement (if I interpreted http://nocash.emubase.de/fullsnes.htm#snespictureprocessingunitppu 's background priority chart correctly)
/*---------------------------------------------------------------------------------
Animated Sprite demo
-- alekmaul
Sprite from Stephen "Redshrike" Challener), http://opengameart.org
---------------------------------------------------------------------------------*/
#include <snes.h>
extern char gfxpsrite, gfxpsrite_end;
extern char palsprite, palsprite_end;
extern char patterns, patterns_end;
extern char palette, palette_end;
extern char map, map_end;
extern char col, col_e;
#define FRAMES_PER_ANIMATION 3 // 3 sprites per direction
//---------------------------------------------------------------------
// The Monster sprite
//---------------------------------------------------------------------
typedef struct
{
short x, y;
int gfx_frame;
int state;
int anim_frame;
int flipx;
} Monster;
//---------------------------------------------------------------------
// The state of the sprite (which way it is walking)
//---------------------------------------------------------------------
enum SpriteState {W_DOWN = 0, W_UP = 1, W_RIGHT = 2, W_LEFT = 2};
//---------------------------------------------------------------------
// Screen dimentions
//---------------------------------------------------------------------
enum {SCREEN_TOP = 0, SCREEN_BOTTOM = 224, SCREEN_LEFT = 0, SCREEN_RIGHT = 256};
char sprTiles[9]={0,2,4, 6,8,10, 12,14,32}; // Remeber that sprites are interleave with 128 pix width,
//---------------------------------------------------------------------
// The magic function for collision
//---------------------------------------------------------------------
u16 getCollisionTile(u16 x, u16 y) {
u16 *ptrMap = (u16 *) &col + (y) + (x);
return (*ptrMap);
}
//---------------------------------------------------------------------------------
int main(void) {
unsigned short pad0,i;
Monster monster = {10,10};
// Initialize SNES
consoleInit();
// Init Sprites gfx and palette with default size of 16x16
oamInitGfxSet(&gfxpsrite, (&gfxpsrite_end-&gfxpsrite), &palsprite, (&palsprite_end-&palsprite), 0, 0x0000, OBJ_SIZE16);
// Copy tiles to VRAM
bgInitTileSet(0, &patterns, &palette, 0, (&patterns_end - &patterns), (&palette_end - &palette), BG_16COLORS, 0x4000);
// Copy Map to VRAM
bgInitMapSet(0, &map, (&map_end - &map),SC_32x32, 0x1000);
// Define sprites parameters
oamSet(0, monster.x, monster.y, 0, 0, 0, 0, 0);
oamSetEx(0, OBJ_SMALL, OBJ_SHOW);
// Now Put in 16 color mode and disable all backgrounds
setMode(BG_MODE1,0); bgSetDisable(1); bgSetDisable(2);
// Wait VBL 'and update sprites too ;-)
WaitForVBlank();
// Wait for nothing :P
while(1) {
// Refresh pad values
scanPads();
// Get current #0 pad
pad0 = padsCurrent(0);
if (pad0) {
// Update sprite with current pad
if(pad0 & KEY_UP) {
if (getCollisionTile((monster.x), ((monster.y) - 1)) == 0) {
if(monster.y >= SCREEN_TOP) monster.y--;
}
monster.state = W_UP;
monster.flipx = 0;
}
if(pad0 & KEY_LEFT) {
if (getCollisionTile(((monster.x) - 1), (monster.y)) == 0) {
if(monster.x >= SCREEN_LEFT) monster.x--;
}
monster.state = W_LEFT;
monster.flipx = 1;
}
if(pad0 & KEY_RIGHT) {
if (getCollisionTile(((monster.x) + 1), (monster.y)) == 0) {
if(monster.x <= SCREEN_RIGHT) monster.x++;
}
monster.state = W_LEFT;
monster.flipx = 0;
}
if(pad0 & KEY_DOWN) {
if (getCollisionTile((monster.x), ((monster.y) + 1)) == 0) {
if(monster.y <= SCREEN_BOTTOM) monster.y++;
}
monster.state = W_DOWN;
monster.flipx = 0;
}
monster.anim_frame++;
if(monster.anim_frame >= FRAMES_PER_ANIMATION){
monster.anim_frame = 0;
}
}
// Now, get current sprite in current animation
monster.gfx_frame = sprTiles[monster.anim_frame + monster.state*FRAMES_PER_ANIMATION ];
oamSet(0, monster.x, monster.y, 3, monster.flipx, 0, monster.gfx_frame, 0);
// Wait VBL 'and update sprites too ;-) )
WaitForVBlank();
}
return 0;
}
Citation de: RonaldCoLtd le 14 Juillet 2013 à 18:31:09Citation de: faeldaniel le 14 Juillet 2013 à 05:33:40
alekmaul not yet started their studies this point however how to adapt this function that you used in the LikeMario for bg collision of 512px X 512px?u16 getCollisionTile(u16 x, u16 y) {
u16 *ptrMap = (u16 *) &mapcol + (y>>3)*300 + (x>>3);
return (*ptrMap);
}
( Sorry I wasn't very descriptive ) I meant sprite by sprite. I.e., Sprite 1 touches Sprite 2 and Sprite 1 disappears.
if((oamGetX(ID_SPRITE_1) == oamGetX(ID_SPRITE_2)) & oamGetY(ID_SPRITE_1) == oamGetY(ID_SPRITE_2) ){
oamSetEx(ID_SPRITE_1, OBJ_SMALL, OBJ_HIDE);
}
u16 getCollisionTile(u16 x, u16 y) {
u16 *ptrMap = (u16 *) &mapcol + (y>>3)*300 + (x>>3);
return (*ptrMap);
}