File: test.c - Tab length: 1 2 4 8 - Lines: on off - No wrap: on off

/*
 collision ordon�e et abscice - LYNX - kit BLL (newcc65)
 beauregard - philippe H.
 28/01/2011
 LYNX-image */

#include <stdlib.h>
#include <lynx.h>
#include <lynxlib.h>

uchar pal[]={
 0x00,0x0F,0x0A,0x00,0x03,0x05,0x08,0x0A,0x0C,0x0E,0x0D,0x00,0x04,0x03,0x02,0x00,
 0x00,0xFF,0xF0,0x0F,0x3F,0x5F,0x8F,0xAF,0xCF,0xEF,0x28,0xF8,0x53,0x63,0x52,0x21};

/* LYNX-specific #defines: */
#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_LEFT  0x02
#define BUTTON_RIGHT 0x01

#define BUTTON_PAUSE 0x01


char SCREEN[8160]       at (MEMTOP-16320);
char RENDER[8160]       at (MEMTOP-8160);

// ------------------------------------
extern char arene[]; // image du fond
char SCB[];
#asm        
_SCB      dc.b $c0,$10,$20
          dc.w 0,0
          dc.w 0,0,$100,$100
          dc.b $01,$23,$45,$67,$89,$ab,$cd,$ef
#endasm
// ------------------------------------

// ------------------------------------
/**

set image01=rouge.bmp

SPRPCK -t6 -S009009 -r001001 -o000000 -a004004 -p0 %image01% ro
cmd

**  Le point d'action de l'image rouge.bmp est mis au centre de celle-ci,  **
**  (-a004004). Le but de la manoeuvre est de r�aliser un zoom si besoin.  **
** 10 --> de 0 � 9 en fait.
*****************************************************************************/

extern uchar ro[]; // carre rouge, d'une taille de 9*9;
uchar SCBro[];
#asm        
_SCBro      dc.b $c7,$10,$20
          dc.w 0,0
          dc.w 0,0,$100,$100
          dc.b $01,$23,$45,$67,$89,$ab,$cd,$ef
#endasm
// ------------------------------------

// ------------------------------------
/**

set image01=blanc.bmp

SPRPCK -t6 -S032032 -p0 %image01% bl
cmd

*****************************************************************************/

extern uchar bl[]; // carre blanc, d'une taille de 32*32;
uchar SCBbl[];
#asm        
_SCBbl      dc.b $c7,$10,$20
          dc.w 0,0
          dc.w 0,0,$100,$100
          dc.b $01,$23,$45,$67,$89,$ab,$cd,$ef
#endasm
// ------------------------------------





int etape,posx,posy,blancx,blancy;
int tempa, drapa;

// assembler vertical retrace syncronisation routine
void Vsync()
{
#asm
vretrace:
 lda $fd0a
 bne vretrace
#endasm
}

/**************************************************************************
**                                                                       **
**                                                                       **
**************************************************************************/

char main()
{
  InitIRQ();
  CLI;

  SetBuffers(SCREEN, RENDER ,0);

  /* set the palette */
  SetRGB(pal); //  Ceci sert � changer la palette de la Lynx.

  DrawFBox(0,0,160,102,0);
 
  etape=10; // on zappe l'�cran d'intro ect... pour ce concentrer sur le vif du sujet, � savoir la d�tection des collisions.
 
  posx=80;posy=70; // abscice et ordonn�e du carr� rouge int�ractif
 
  blancx=64;blancy=30; // abscice et ordonn�e du carr� blanc
 



  SCBX(SCB) = 0;
  SCBY(SCB) = 0;
  SCBDATA(SCB) = arene; // l'image du fond;

  SCBNEXT(SCB) = SCBro; // chainage de sprite (du carr� rouge int�ractif � l'image de fond)
  SCBX(SCBro) = posx;
  SCBY(SCBro) = posy;
  SCBDATA(SCBro) = ro; // l'image du carr� rouge int�ractif.

  SCBNEXT(SCBro) = SCBbl; // chainage de sprite (du carr� blanc au carr� rouge int�ractif)
  SCBX(SCBbl) = blancx;
  SCBY(SCBbl) = blancy;
  SCBDATA(SCBbl) = bl; // l'image du carr� rouge blanc.





/**************************************************************************
**                       BOUCLE PRINCIPALE                               **
**************************************************************************/
   
 
  for( ; ; )
{




// *********************************************************************************************

 if (etape==10)  // �cran test collision
 {

 
 if (joystick & (BUTTON_RIGHT)) // remettre le carr� rouge int�ractif au centre de l'�cran (facultatif pour ce cours, mais bon)
  {
  etape=10;
  posx=80;posy=70;SCBX(SCBro) = posx;SCBY(SCBro) = posy;
  blancx=64;blancy=30;SCBX(SCBbl) = blancx;SCBY(SCBbl) = blancy;
  tempa=0;drapa=0;
  }
 
 // sollicitation du joueur via la croix directionnelle:
 if (joystick & JOY_RIGHT) // direction Droite
  {posx++;SCBX(SCBro) = posx;}
 
 if (joystick & JOY_LEFT) // direction Gauche
  {posx--;SCBX(SCBro) = posx;}
 
 if (joystick & JOY_UP) // direction Haut
  {posy--;SCBY(SCBro) = posy;}
 
 if (joystick & JOY_DOWN) // direction Bas
  {posy++;SCBY(SCBro) = posy;}
 
 
 
 // Collision 1
 // limite bord de l'arene:
 // X
 if (posx<12)  {posx=12;SCBX(SCBro) = posx;}
 if (posx>147)  {posx=147;SCBX(SCBro) = posx;}
 // Y
 if (posy<12)  {posy=12;SCBY(SCBro) = posy;}
 if (posy>89)  {posy=89;SCBY(SCBro) = posy;}
 
 
 
 // Collision 2
 // carr� rouge int�ractif avec carr� blanc (taille 32*32):
 // X
 if (posy+5>blancy & posy-5<blancy+32) // posy+5 correspond au bord Bas du carr� rouge // posy-5 correspond au bord Haut du carr� rouge
  {
  if (posx+5>blancx & posx+5<blancx+10)  {posx=blancx-5;SCBX(SCBro) = posx;} // teste le bord droite du carr� rouge
  if (posx-5>blancx+22 & posx-5<blancx+32)  {posx=blancx+36;SCBX(SCBro) = posx;} // teste le bord gauche du carr� rouge
  }
 // Y
 if (posx+5>blancx & posx-5<blancx+32) // posx+5 correspond au bord Droite du carr� rouge // posx-5 correspond au bord Gauche du carr� rouge
  {
  if (posy+5>blancy & posy+5<blancy+10)  {posy=blancy-5;SCBY(SCBro) = posy;} // teste le bord bas du carr� rouge
  if (posy-5>blancy+22 & posy-5<blancy+32)  {posy=blancy+36;SCBY(SCBro) = posy;} // teste le bord haut du carr� rouge
  }
 
 
 
 
 
 
 ++tempa; // tempo pour la vitesse de d�placement du carr� blanc
 if (tempa>3)
  {
  tempa=0;
  if (drapa==0) // Si drapa = 0 alors ordre de d�placer la carr� blanc � droite
   {
   ++blancx;SCBX(SCBbl) = blancx;
   if (blancx>84)  {drapa=1;} // changement de direction
   }
  if (drapa==1) // Si drapa = 1 alors ordre de d�placer la carr� blanc � gauche
   {
   --blancx;SCBX(SCBbl) = blancx;
   if (blancx<44)  {drapa=0;} // changement de direction
   }
  }
 
 }


 
 
  DrawSprite(SCB); // Affichage de tous les objets chain�s (fond, carr� rouge int�ractif et carr� blanc)
 
  Vsync();
  SwapBuffers();
}
 
/**************************************************************************
**                     FIN de la BOUCLE PRINCIPALE                       **
**************************************************************************/

 
 }