#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
#include ".\sprites\bg.pal"
extern char clsSCB[];
extern uchar cls_color;
extern char Sprite1[];
extern char Sprite2[];
extern char Sprite3[];
extern char Sprite4[];
extern uint Sprite1col;
extern uint Sprite2col;
extern uint Sprite3col;
extern uint Sprite4col;
#asm
xref _bg000000, _bg000001, _bg000002, _bg000003
; sprite used to clear the collision buffer
dc.w 0 ; lieu de collision
_clsSCB: dc.b $c0,$90,$00 ; collision number is 0!
dc.w 0,cls_data
dc.w 0,0 ; X,Y
dc.w 160*$100,102*$100 ; scaled to 160*102 pixels
_cls_color: dc.b $00
; data: 1*1 pixel
cls_data dc.b 2,$10,0
_Sprite1col:
dc.w 0 ; lieu de collision de Sprite1!
_Sprite1:
dc.b $c4, $10, $01 ; collision number is 1
dc.w 0 ; PTR_NEXT (sprite seul)
dc.w _bg000000 ; PTR_DATA
dc.w 0, 0 ; x,y outside the visible screen area
dc.w $100, $100 ;
; seul l'index 1 de la palette est utilisé!
dc.b $0b, $23, $45, $67, $89, $ab, $cd, $ef
_Sprite2col:
dc.w 0 ; lieu de collision de Sprite2!
_Sprite2:
dc.b $c4, $10, $02 ; collision number is 2
dc.w 0 ; PTR_NEXT
dc.w _bg000001 ; PTR_DATA
dc.w 32+8, 32+8 ; x,y
dc.w $100, $100 ;
dc.b $09, $23, $45, $67, $89, $ab, $cd, $ef
_Sprite3col:
dc.w 0 ; lieu de collision de Sprite3!
_Sprite3:
dc.b $c4, $10, $03 ; collision number is 3
dc.w 0 ; PTR_NEXT
dc.w _bg000002 ; PTR_DATA
dc.w 64+8, 64+8 ; x,y
dc.w $100, $100 ;
dc.b $0a, $23, $45, $67, $89, $ab, $cd, $ef
_Sprite4col:
dc.w 0 ; lieu de collision de Sprite4!
_Sprite4:
dc.b $c4, $10, $04 ; collision number is 4
dc.w 0 ; PTR_NEXT
dc.w _bg000003 ; PTR_DATA
dc.w 96+8, 32+8 ; x,y
dc.w $100, $100 ;
dc.b $0c, $23, $45, $67, $89, $ab, $cd, $ef
#endasm
uchar posx;
uchar posy;
char szTemp[20+1]; // for text messages
char szText1[] = "SPRDEMO5";
char szText2[] = "by M.Domin";
/*****************************************************/
extern uchar VBLflag;
#asm
_VBLflag = $a0
#endasm
#define VSYNC {++VBLflag;while( VBLflag );}
VBL() interrupt
{
VBLflag = 0; /* VBL a eu lieu */
}
HBL() interrupt
{
}
/****************************************/
/* Converts an uint into a ASCII-string */
/****************************************/
UintToASCII(uNr, pStr)
uint uNr;
char * pStr;
{
strcpy(pStr, "00000");
while(uNr >= 10000)
{
uNr -= 10000;
(*pStr)++;
}
pStr++;
while(uNr >= 1000)
{
uNr -= 1000;
(*pStr)++;
}
pStr++;
while(uNr >= 100)
{
uNr -= 100;
(*pStr)++;
}
pStr++;
while(uNr >= 10)
{
uNr -= 10;
(*pStr)++;
}
pStr++;
*pStr += (uint) uNr;
}
/***********************************************/
/* Clears the screen _and_ the collsion buffer */
/***********************************************/
CLS(nColor)
uchar nColor;
{
cls_color = nColor; // méthode un peu brutale...
DrawSprite(clsSCB);
}
/****************************************/
/* Paints the screen */
/****************************************/
ShowScreen()
{
//DrawFBox(0,0,160,102, 0); // BACKGRND-sprite, clears the screen
// but not the collision buffer!
CLS(0); // comment this line and uncomment the above DrawFBox-line to
// watch the affect of not initializing the collision buffer:
// The sprites will "collide" with themselves!
// Si un sprite est en collision, on double son volume
if (Sprite1col == 2)
{
SCBHS(Sprite2) = 0x200;
SCBVS(Sprite2) = 0x200;
}
else
{
SCBHS(Sprite2) = 0x100;
SCBVS(Sprite2) = 0x100;
}
if (Sprite1col == 3)
{
SCBHS(Sprite3) = 0x200;
SCBVS(Sprite3) = 0x200;
}
else
{
SCBHS(Sprite3) = 0x100;
SCBVS(Sprite3) = 0x100;
}
if (Sprite1col == 4)
{
SCBHS(Sprite4) = 0x200;
SCBVS(Sprite4) = 0x200;
}
else
{
SCBHS(Sprite4) = 0x100;
SCBVS(Sprite4) = 0x100;
}
// Affichage des sprites
DrawSprite(Sprite2);
DrawSprite(Sprite3);
DrawSprite(Sprite4);
// le notre en dernier de sorte que la collision puisse être détectée en une fois.
SCBX(Sprite1) = posx;
SCBY(Sprite1) = posy;
DrawSprite(Sprite1);
// On affiche les valeurs des registres de collision (après conversion)
UintToASCII(Sprite1col, szTemp);
TextOut2(0,102-4*8, 11, 0, szTemp);
UintToASCII(Sprite2col, szTemp);
TextOut2(0,102-3*8, 9, 0, szTemp);
UintToASCII(Sprite3col, szTemp);
TextOut2(0,102-2*8, 10, 0, szTemp);
UintToASCII(Sprite4col, szTemp);
TextOut2(0,102-1*8, 12, 0, szTemp);
// Un peu de pub :)
TextOut2(12*8,102-(16+6)+2, 14, 0, szText1);
TextOut2(10*8,102-(16+6)+2+8+2, 14, 0, szText2);
}
/*************************************************************/
main()
{
register uchar joy;
InitIRQ();
InstallIRQ(2,VBL);
EnableIRQ(2);
CLI;
// l'offset du registre de collision est fixé à -2 !!!(la conversion des uint utilise des valeurs sur 2 octets...)
#asm
lda #$fe ;on charge la valeur immédiate fe (en hexa)
sta $fc24 ;on la stocke à l'adresse mémoire fc24 (un registre, celui des collisions part 1)
lda #$ff ;idem (en fait on stock une valeur sur 16 bits donc faut le faire en 2 fois)
sta $fc25
#endasm
// Faut s'assurer que la détection de collision est activée:
sprsys = _sprsys = _sprsys & 0xdf;//(on agit par masque bit à bit)
SetBuffers(0xa000, 0xc000, 0x8000);
_SetRGB(pal);
// position initiale...:
posx = 64+8; // +8 pour calculer le centre (16*16)
posy = 0+8;
// On affiche le premier écran
ShowScreen();
// main loop => ratage fait main ? LOL
for(;;)
{
VSYNC;
SwapBuffers();
ShowScreen();
while (!(joy = joystick)) // on attends que qq chose se passe sur les touches de la console (en interdisant les sorties d'écran)
;
if (joy & JOY_LEFT)
{
if (posx > 0+8)
{
--posx;
}
}
if (joy & JOY_RIGHT)
{
if (posx < 160-8)
{
++posx;
}
}
if (joy & JOY_UP)
{
if (posy > 0+8)
{
--posy;
}
}
if (joy & JOY_DOWN)
{
if (posy < 102-8)
{
++posy;
}
}
} // jusqu'à la fin de ta mort, toute ta vie
} // main
et en n&b sans n° de lignes...
#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
#include ".\sprites\bg.pal"
extern char clsSCB[];
extern uchar cls_color;
extern char Sprite1[];
extern char Sprite2[];
extern char Sprite3[];
extern char Sprite4[];
extern uint Sprite1col;
extern uint Sprite2col;
extern uint Sprite3col;
extern uint Sprite4col;
#asm
xref _bg000000, _bg000001, _bg000002, _bg000003
; sprite used to clear the collision buffer
dc.w 0 ; lieu de collision
_clsSCB: dc.b $c0,$90,$00 ; collision number is 0!
dc.w 0,cls_data
dc.w 0,0 ; X,Y
dc.w 160*$100,102*$100 ; scaled to 160*102 pixels
_cls_color: dc.b $00
; data: 1*1 pixel
cls_data dc.b 2,$10,0
_Sprite1col:
dc.w 0 ; lieu de collision de Sprite1!
_Sprite1:
dc.b $c4, $10, $01 ; collision number is 1
dc.w 0 ; PTR_NEXT (sprite seul)
dc.w _bg000000 ; PTR_DATA
dc.w 0, 0 ; x,y outside the visible screen area
dc.w $100, $100 ;
; seul l'index 1 de la palette est utilisé!
dc.b $0b, $23, $45, $67, $89, $ab, $cd, $ef
_Sprite2col:
dc.w 0 ; lieu de collision de Sprite2!
_Sprite2:
dc.b $c4, $10, $02 ; collision number is 2
dc.w 0 ; PTR_NEXT
dc.w _bg000001 ; PTR_DATA
dc.w 32+8, 32+8 ; x,y
dc.w $100, $100 ;
dc.b $09, $23, $45, $67, $89, $ab, $cd, $ef
_Sprite3col:
dc.w 0 ; lieu de collision de Sprite3!
_Sprite3:
dc.b $c4, $10, $03 ; collision number is 3
dc.w 0 ; PTR_NEXT
dc.w _bg000002 ; PTR_DATA
dc.w 64+8, 64+8 ; x,y
dc.w $100, $100 ;
dc.b $0a, $23, $45, $67, $89, $ab, $cd, $ef
_Sprite4col:
dc.w 0 ; lieu de collision de Sprite4!
_Sprite4:
dc.b $c4, $10, $04 ; collision number is 4
dc.w 0 ; PTR_NEXT
dc.w _bg000003 ; PTR_DATA
dc.w 96+8, 32+8 ; x,y
dc.w $100, $100 ;
dc.b $0c, $23, $45, $67, $89, $ab, $cd, $ef
#endasm
uchar posx;
uchar posy;
char szTemp[20+1]; // for text messages
char szText1[] = "SPRDEMO5";
char szText2[] = "by M.Domin";
/*****************************************************/
extern uchar VBLflag;
#asm
_VBLflag = $a0
#endasm
#define VSYNC {++VBLflag;while( VBLflag );}
VBL() interrupt
{
VBLflag = 0; /* VBL a eu lieu */
}
HBL() interrupt
{
}
/****************************************/
/* Converts an uint into a ASCII-string */
/****************************************/
UintToASCII(uNr, pStr)
uint uNr;
char * pStr;
{
strcpy(pStr, "00000");
while(uNr >= 10000)
{
uNr -= 10000;
(*pStr)++;
}
pStr++;
while(uNr >= 1000)
{
uNr -= 1000;
(*pStr)++;
}
pStr++;
while(uNr >= 100)
{
uNr -= 100;
(*pStr)++;
}
pStr++;
while(uNr >= 10)
{
uNr -= 10;
(*pStr)++;
}
pStr++;
*pStr += (uint) uNr;
}
/***********************************************/
/* Clears the screen _and_ the collsion buffer */
/***********************************************/
CLS(nColor)
uchar nColor;
{
cls_color = nColor; // méthode un peu brutale...
DrawSprite(clsSCB);
}
/****************************************/
/* Paints the screen */
/****************************************/
ShowScreen()
{
//DrawFBox(0,0,160,102, 0); // BACKGRND-sprite, clears the screen
// but not the collision buffer!
CLS(0); // comment this line and uncomment the above DrawFBox-line to
// watch the affect of not initializing the collision buffer:
// The sprites will "collide" with themselves!
// Si un sprite est en collision, on double son volume
if (Sprite1col == 2)
{
SCBHS(Sprite2) = 0x200;
SCBVS(Sprite2) = 0x200;
}
else
{
SCBHS(Sprite2) = 0x100;
SCBVS(Sprite2) = 0x100;
}
if (Sprite1col == 3)
{
SCBHS(Sprite3) = 0x200;
SCBVS(Sprite3) = 0x200;
}
else
{
SCBHS(Sprite3) = 0x100;
SCBVS(Sprite3) = 0x100;
}
if (Sprite1col == 4)
{
SCBHS(Sprite4) = 0x200;
SCBVS(Sprite4) = 0x200;
}
else
{
SCBHS(Sprite4) = 0x100;
SCBVS(Sprite4) = 0x100;
}
// Affichage des sprites
DrawSprite(Sprite2);
DrawSprite(Sprite3);
DrawSprite(Sprite4);
// le notre en dernier de sorte que la collision puisse être détectée en une fois.
SCBX(Sprite1) = posx;
SCBY(Sprite1) = posy;
DrawSprite(Sprite1);
// On affiche les valeurs des registres de collision (après conversion)
UintToASCII(Sprite1col, szTemp);
TextOut2(0,102-4*8, 11, 0, szTemp);
UintToASCII(Sprite2col, szTemp);
TextOut2(0,102-3*8, 9, 0, szTemp);
UintToASCII(Sprite3col, szTemp);
TextOut2(0,102-2*8, 10, 0, szTemp);
UintToASCII(Sprite4col, szTemp);
TextOut2(0,102-1*8, 12, 0, szTemp);
// Un peu de pub :)
TextOut2(12*8,102-(16+6)+2, 14, 0, szText1);
TextOut2(10*8,102-(16+6)+2+8+2, 14, 0, szText2);
}
/*************************************************************/
main()
{
register uchar joy;
InitIRQ();
InstallIRQ(2,VBL);
EnableIRQ(2);
CLI;
// l'offset du registre de collision est fixé à -2 !!!(la conversion des uint utilise des valeurs sur 2 octets...)
#asm
lda #$fe ;on charge la valeur immédiate fe (en hexa)
sta $fc24 ;on la stocke à l'adresse mémoire fc24 (un registre, celui des collisions part 1)
lda #$ff ;idem (en fait on stock une valeur sur 16 bits donc faut le faire en 2 fois)
sta $fc25
#endasm
// Faut s'assurer que la détection de collision est activée:
sprsys = _sprsys = _sprsys & 0xdf;//(on agit par masque bit à bit)
SetBuffers(0xa000, 0xc000, 0x8000);
_SetRGB(pal);
// position initiale...:
posx = 64+8; // +8 pour calculer le centre (16*16)
posy = 0+8;
// On affiche le premier écran
ShowScreen();
// main loop => ratage fait main ? LOL
for(;;)
{
VSYNC;
SwapBuffers();
ShowScreen();
while (!(joy = joystick)) // on attends que qq chose se passe sur les touches de la console (en interdisant les sorties d'écran)
;
if (joy & JOY_LEFT)
{
if (posx > 0+8)
{
--posx;
}
}
if (joy & JOY_RIGHT)
{
if (posx < 160-8)
{
++posx;
}
}
if (joy & JOY_UP)
{
if (posy > 0+8)
{
--posy;
}
}
if (joy & JOY_DOWN)
{
if (posy < 102-8)
{
++posy;
}
}
} // jusqu'à la fin de ta mort, toute ta vie
} // main
Vala
c la fin d'un tite série bien sympathique...

