Collisions Tron DS

by Yotsu on February 8th, 2010

Vala ma gestion des collisions… pour l’instant… je te filerai le .NDS sur emesene

Syntax: C
Show lines - Hide lines - Show in textbox - Download
// Includes
#include <PA9.h>       // Include sur PAlib
#include "moto.h"
#include "arene.h"
#include "utile.h"
//#include "types.h"
 
int rouge= PA_RGB(31, 0, 0);
int vert= PA_RGB(0, 31, 0);
int bleu= PA_RGB(0, 0, 31);
 
void crash(moto *mt)
{
  PA_OutputSimpleText(1, 12, 10, "CRASH!!");
  mt->crash= true;
}
 
// Fonction: main()
int main(int argc, char **argv)
{
  arene colise;
  moto motoT;
 
  initMoto(&motoT);
  initA(&colise);
 
  PA_Init();    // Initialise PA_Lib
  PA_InitVBL(); // Initialise le VBL standard 
 
  PA_InitText(1, 1);
  PA_SetTextCol(1, 31, 0, 0);
  PA_Init16cBg(0, 1);
 
  colise.grille[motoT.pos_x][motoT.pos_y]= 1;
 
  // Boucle infinie pour laisser le programme tourner
  while(!motoT.crash)
    {     
      if(Pad.Newpress.Right)		
	{
	  if(!motoT.dir_x && motoT.dir_y)
	    {
	      motoT.dir_x= 1;
	      motoT.dir_y= 0;
	    }
	}
      else if(Pad.Newpress.Left)
	{
	  if(!motoT.dir_x && motoT.dir_y)
	    {
	      motoT.dir_x= -1;
	      motoT.dir_y= 0;
	    }
	}
      else if(Pad.Newpress.Up)
	{
	  if(motoT.dir_x && !motoT.dir_y)
	    {
	      motoT.dir_x= 0;
	      motoT.dir_y= -1;
	    }
	}
      else if(Pad.Newpress.Down)
	{
	  if(motoT.dir_x && !motoT.dir_y)
	    {
	      motoT.dir_x= 0;
	      motoT.dir_y= 1;
	    }
	}	
 
      if(colise.grille[motoT.pos_x+ motoT.dir_x*motoT.vitesse][motoT.pos_y+ motoT.dir_y*motoT.vitesse])
	crash(&motoT);
 
      else if(motoT.dir_x== 1 && motoT.pos_x== LARGEUR)
	  crash(&motoT);
 
      else if(motoT.dir_x== -1 && motoT.pos_x== 0)
	crash(&motoT);
 
      else if(motoT.dir_y== 1 && motoT.pos_y== HAUTEUR)
	crash(&motoT);
 
      else if(motoT.dir_y== -1 && motoT.pos_y== 0)
	crash(&motoT);
 
      else	  
	{
	  PA_16cPutPixel(0, motoT.pos_x, motoT.pos_y, 9);	  
	  colise.grille[motoT.pos_x][motoT.pos_y]= 1;
	  rouler(&motoT);
	  PA_WaitForVBL();
	}
    }	
  return 0;
} //main()
 

Leave a Reply

Note: XHTML is allowed. Your email address will never be published.

Subscribe to this comment feed via RSS