si pb , ya pas de pb je peux détailler...
#include <lynx.h>
#include <lynxlib.h>
#include <stdlib.h>
#define JOY_RIGHT 0x10
#define JOY_LEFT 0x20
#define JOY_DOWN 0x40
#define JOY_UP 0x80
#define BUTTON_OPTION1 0x08
#define BUTTON_OPTION2 0x04
#define BUTTON_INNER 0x02
#define BUTTON_OUTER 0x01
#define BUTTON_PAUSE 0x01
// il nous faut (TILES_X * TILE_WIDTH) * (TILES_Y * TILE_HEIGHT) pixels
// pour recouvrir tout l'écran:
#define TILE_WIDTH 16
#define TILE_HEIGHT 16
// Dans chaque direction, il nous faut uns sprite de plsu que SCREEN_WIDTH/TILE_WIDTH
// soit à l'horizontal : 160/16 + 1 = 10 + 1 = 11
#define TILES_X 11
// Pour 102/16 + 1 = 6.375 + 1 = 7.375 on va devoir arrondir à l'entier supérieur : 8!
// Si on se cantonne à 7, on aura des bugs d'afficahge sur les 6 dernières lignes...
#define TILES_Y 8
// the colour palette:(je traduis pas c pas la peine...)
#include ".\sprites\bg.pal"
//toute la définition des sprites est faite en exterieur, vous me direz c normal vu qu'il fait bô :)
extern uchar spr[TILES_Y][TILES_X][11];
extern uchar init_scb[23];
extern uchar spr0[11];
extern char* Sprites[];
#asm
xref _bg000000, _bg000001, _bg000002, _bg000003, _bg000004
xref _bg001000, _bg001001, _bg001002, _bg001003, _bg001004
xref _bg002000, _bg002001, _bg002002, _bg002003, _bg002004
;bon là c'est une inclusion assembleur, je rentre pas trop dans les détails
; il s'agit juste des définitions de tableau de sprite et du sprite pour la
;gpu mais vu que c'est limite bidouille...
; Address of the array for the 8*11 daisychained sprites:
; It's below the first screen which starts at $a000.
; We need 8*11*11 = 968 (0x03c8) bytes
; Always be carefull when doing such things!
_spr = $9c00 ; $a000 - 0x03c8 ~= $9c00
; We use init_scb to set up the SpriteEngine registers with the global
; Size- and Pen-values.
; Using this trick, the 8*11 spr[]-SCBs only need 11 Bytes each!
_init_scb:
dc.b $c1, $10, $20
dc.w _spr ; PTR_NEXT points to the first visible sprite
dc.w dummy ; PTR_DATA points to a NULL-sprite
dc.w 200, 200 ; x,y outside the visible screen area
dc.w $100, $100 ; all sprites will be scaled to normal size
; all sprites will use these pen-index-table:
dc.b $01, $23, $45, $67, $89, $ab, $cd, $ef
dummy: dc.b 0,0,0 ; No real sprite :)
; spr0 is used as a template for the 8*11 chained sprites
_spr0: dc.b $c1, $08, $00 ; CTL0, CTL1 = reuse existing palette, COLL
dc.w 0, _bg000001 ; pDataNext, pData
dc.w 0, 0 ; x, y
; the table with pointers to the 15 created tile-sprites:
_Sprites: dc.w _bg000000, _bg000001, _bg000002, _bg000003, _bg000004
dc.w _bg001000, _bg001001, _bg001002, _bg001003, _bg001004
dc.w _bg002000, _bg002001, _bg002002, _bg002003, _bg002004
#endasm
// ça c'est l'univers de notre affichage : 20*20 cases
SpriteMap[20][20] =
{
{14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14},
{14, 0,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13, 1,14},
{14,10, 2,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12, 6,14},
{14,10,11, 4, 0,13,13,13,13, 1,14,14,14,14,14,14,14,14,14,14},
{14,10,11, 4,10, 2,12,12, 3,11,14, 4, 4, 4, 4, 4, 4, 4, 4, 4},
{14,10, 7,13, 8,11,14,14,10,11,14, 4, 4, 4, 4, 4, 4, 4, 4, 4},
{14, 5,12,12,12, 6,14,14,10,11,14, 4, 4, 4, 4, 4, 4, 4, 4, 4},
{14,14,14,14,14,14,14,14,10,11,14, 4, 4, 4, 4, 4, 4, 4, 4, 4},
{ 4, 4, 4, 4, 4, 4, 4,14,10,11,14, 4, 4, 4, 4, 4, 4, 4, 4, 4},
{ 4, 4, 4, 4, 4, 4, 4,14,10,11,14, 4, 4, 4, 4, 4, 4, 4, 4, 4},
{ 4, 4, 4, 4, 4, 4, 4,14,10,11,14, 4, 4, 4, 4, 4, 4, 4, 4, 4},
{ 4, 4, 4, 4, 4, 4, 4,14,10,11,14, 4, 4, 4, 4, 4, 4, 4, 4, 4},
{ 4, 4, 4, 4, 4, 4, 4,14,10,11,14, 4, 4, 4, 4, 4, 4, 4, 4, 4},
{ 4, 4, 4, 4, 4, 4, 4,14,10,11,14, 4, 4, 4, 4, 4, 4, 4, 4, 4},
{ 4, 4, 4, 4, 4, 4, 4,14,10,11,14, 4, 4, 4, 4, 4, 4, 4, 4, 4},
{ 4, 4, 4, 4, 4, 4, 4,14,10,11,14, 4, 4, 4, 4, 4, 4, 4, 4, 4},
{ 4, 4, 4, 4, 4, 4, 4,14,10,11,14, 4, 4, 4, 4, 4, 4, 4, 4, 4},
{ 4, 4, 4, 4, 4, 4, 4,14,10,11,14, 4, 4, 4, 4, 4, 4, 4, 4, 4},
{14, 4, 4, 4, 4, 4, 4,14, 5, 6,14, 4, 4, 4, 4, 4, 4, 4, 4,14},
{14,14, 4, 4, 4, 4, 4,14,14,14,14, 4, 4, 4, 4, 4, 4, 4,14,14}
};
register uchar tile_col, tile_row;
register uchar tile_x, tile_y;
//on retrouve ici la définition des IT HBL et VBL qui se déclenchent à chaque raffraichissement de ligne / écran
/*****************************************************/
extern uchar VBLflag;
#asm
_VBLflag = $a0
#endasm
#define VSYNC {++VBLflag;while( VBLflag );}
VBL() interrupt
{
VBLflag = 0; /* indicates that a VBL has ocurred */
}
HBL() interrupt
{
}
/*****************************************************/
ShowScreen()
{
register uchar row,col;
// on affiche sur tout l'écran, donc l'effacer au préalable est inutile...
// DrawFBox(hoff,voff,160,102, 1);
// init des sprites
for (row = 0; row < TILES_Y; ++row)//8 lignes
for (col = 0; col < TILES_X; ++col)//11 colonnes
SCBDATA(&spr[row][col][0]) = Sprites[SpriteMap[tile_row+row][tile_col+col]];
// affiche l'écran:
DrawSprite(init_scb);
}
main()
{
register uchar x,y,c;
register uchar joy;
InitIRQ();
InstallIRQ(2,VBL);
EnableIRQ(2);
CLI;
SetBuffers(0xa000, 0xc000, 0);//double buffering pour l'affichage
_SetRGB(pal);
// init des sprites a afficher (on fait ici la chaine des sprites à afficher par la gpu)
for (y = 0; y < TILES_Y; ++y)
for (x = 0; x < TILES_X; ++x)
{
bcopy(&spr0[0], &spr[y][x][0], 11); // src, dest, count
SCBX(&spr[y][x][0]) = 16*x;
SCBY(&spr[y][x][0]) = 16*y;
SCBNEXT(&spr[y][x][0]) = &spr[y][x][0] + 11;
}
SCBNEXT(&spr[TILES_Y-1][TILES_X-1][0]) = 0; // indispensable pour ne pas planter la GPU!!!
tile_x = tile_y = 0;
tile_col = tile_row = 0;
//on affiche le premier écran
ShowScreen();
// main loop
for(;;)
{
VSYNC;
SwapBuffers();
voff = tile_y; // Set scroll offsets
hoff = tile_x; // Set scroll offsets
ShowScreen();
while (!(joy = joystick)) // on attends une touche
;
if (joy & JOY_LEFT)
{
// nouvelle position toujours dans la même case ?
if (tile_x > 0) // mouais!
{
--tile_x;
}
else // Non!
{
// mais peuton aller dans cette direction ?
if (tile_col > 0) // ah bon bah ok!
{
tile_x = TILE_WIDTH-1;
--tile_col;//bah c bon on décale
}
}
}
if (joy & JOY_RIGHT)//même principe mais à droite...
{
if (tile_x < TILE_WIDTH-1)
{
++tile_x;
}
else
{
if (tile_col < 20-TILES_X)
{
tile_x = 0;
++tile_col;
}
}
}
if (joy & JOY_UP)//en haut...
{
if (tile_y > 0)
{
--tile_y;
}
else
{
if (tile_row > 0)
{
tile_y = TILE_HEIGHT-1;
--tile_row;
}
}
}
if (joy & JOY_DOWN)//en bas... ces soirées là, on drague ... je m'égarre moi...
{
if (tile_y < TILE_HEIGHT-1)
{
++tile_y;
}
else
{
if (tile_row < 20-TILES_Y)
{
tile_y = 0;
++tile_row;
}
}
}
} // jusqu'à ce que le rap soit éradiqué de la planète...
} // main
//on notera que l'affichage est fait en début de boucle, en double buffering,
//sinon avec autant de sprites à l'écran, on pourrait avoir un piti problème de
//gros clignotage