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

001: /*
002:  collision ordon�e et abscice - LYNX - kit BLL (newcc65)
003:  beauregard - philippe H.
004:  28/01/2011
005:  LYNX-image */
006: #include <stdlib.h>
007: #include <lynx.h>
008: #include <lynxlib.h>
009: 
010: uchar pal[]={
011:         0x00,0x0F,0x0A,0x00,0x03,0x05,0x08,0x0A,0x0C,0x0E,0x0D,0x00,0x04,0x03,0x02,0x00,
012:         0x00,0xFF,0xF0,0x0F,0x3F,0x5F,0x8F,0xAF,0xCF,0xEF,0x28,0xF8,0x53,0x63,0x52,0x21};
013: 
014: /* LYNX-specific #defines: */
015: #define JOY_RIGHT               0x10
016: #define JOY_LEFT                0x20
017: #define JOY_DOWN                0x40
018: #define JOY_UP                  0x80
019: 
020: #define BUTTON_OPTION1  0x08
021: #define BUTTON_OPTION2  0x04
022: #define BUTTON_LEFT             0x02
023: #define BUTTON_RIGHT    0x01
024: 
025: #define BUTTON_PAUSE    0x01
026: 
027: 
028: char SCREEN[8160]       at (MEMTOP-16320);
029: char RENDER[8160]       at (MEMTOP-8160);
030: 
031: // ------------------------------------
032: extern char arene[]; // image du fond
033: char SCB[];
034: #asm        
035: _SCB      dc.b $c0,$10,$20
036:           dc.w 0,0
037:           dc.w 0,0,$100,$100
038:           dc.b $01,$23,$45,$67,$89,$ab,$cd,$ef
039: #endasm
040: // ------------------------------------
041: 
042: // ------------------------------------
043: /**
044: 
045: set image01=rouge.bmp
046: 
047: SPRPCK -t6 -S009009 -r001001 -o000000 -a004004 -p0 %image01% ro
048: cmd
049: 
050: **  Le point d'action de l'image rouge.bmp est mis au centre de celle-ci,  **
051: **  (-a004004). Le but de la manoeuvre est de r�aliser un zoom si besoin.  **
052: ** 10 --> de 0 � 9 en fait.
053: *****************************************************************************/
054: extern uchar ro[]; // carre rouge, d'une taille de 9*9;
055: uchar SCBro[];
056: #asm        
057: _SCBro      dc.b $c7,$10,$20
058:           dc.w 0,0
059:           dc.w 0,0,$100,$100
060:           dc.b $01,$23,$45,$67,$89,$ab,$cd,$ef
061: #endasm
062: // ------------------------------------
063: 
064: // ------------------------------------
065: /**
066: 
067: set image01=blanc.bmp
068: 
069: SPRPCK -t6 -S032032 -p0 %image01% bl
070: cmd
071: 
072: *****************************************************************************/
073: extern uchar bl[]; // carre blanc, d'une taille de 32*32;
074: uchar SCBbl[];
075: #asm        
076: _SCBbl      dc.b $c7,$10,$20
077:           dc.w 0,0
078:           dc.w 0,0,$100,$100
079:           dc.b $01,$23,$45,$67,$89,$ab,$cd,$ef
080: #endasm
081: // ------------------------------------
082: 
083: 
084: 
085: 
086: 
087: int etape,posx,posy,blancx,blancy;
088: int tempa, drapa;
089: 
090: // assembler vertical retrace syncronisation routine
091: void Vsync()
092: {
093: #asm
094: vretrace:
095:         lda $fd0a
096:         bne vretrace
097: #endasm
098: }
099: 
100: /**************************************************************************
101: **                                                                       **
102: **                                                                       **
103: **************************************************************************/
104: char main()
105: {
106:   InitIRQ();
107:   CLI;
108: 
109:   SetBuffers(SCREEN, RENDER ,0);
110: 
111:   /* set the palette */
112:   SetRGB(pal); //  Ceci sert � changer la palette de la Lynx.
113: 
114:   DrawFBox(0,0,160,102,0);
115:  
116:   etape=10; // on zappe l'�cran d'intro ect... pour ce concentrer sur le vif du sujet, � savoir la d�tection des collisions.
117:  
118:   posx=80;posy=70; // abscice et ordonn�e du carr� rouge int�ractif
119:  
120:   blancx=64;blancy=30; // abscice et ordonn�e du carr� blanc
121:  
122: 
123: 
124: 
125:   SCBX(SCB) = 0;
126:   SCBY(SCB) = 0;
127:   SCBDATA(SCB) = arene; // l'image du fond;
128: 
129:   SCBNEXT(SCB) = SCBro; // chainage de sprite (du carr� rouge int�ractif � l'image de fond)
130:   SCBX(SCBro) = posx;
131:   SCBY(SCBro) = posy;
132:   SCBDATA(SCBro) = ro; // l'image du carr� rouge int�ractif.
133: 
134:   SCBNEXT(SCBro) = SCBbl; // chainage de sprite (du carr� blanc au carr� rouge int�ractif)
135:   SCBX(SCBbl) = blancx;
136:   SCBY(SCBbl) = blancy;
137:   SCBDATA(SCBbl) = bl; // l'image du carr� rouge blanc.
138: 
139: 
140: 
141: 
142: 
143: /**************************************************************************
144: **                       BOUCLE PRINCIPALE                               **
145: **************************************************************************/    
146:  
147:   for( ; ; )
148: {
149: 
150: 
151: 
152: 
153: // *********************************************************************************************
154: 
155:  if (etape==10)  // �cran test collision
156:         {
157: 
158:        
159:         if (joystick & (BUTTON_RIGHT)) // remettre le carr� rouge int�ractif au centre de l'�cran (facultatif pour ce cours, mais bon)
160:                 {
161:                 etape=10;
162:                 posx=80;posy=70;SCBX(SCBro) = posx;SCBY(SCBro) = posy;
163:                 blancx=64;blancy=30;SCBX(SCBbl) = blancx;SCBY(SCBbl) = blancy;
164:                 tempa=0;drapa=0;
165:                 }
166:        
167:         // sollicitation du joueur via la croix directionnelle:
168:         if (joystick & JOY_RIGHT) // direction Droite
169:                 {posx++;SCBX(SCBro) = posx;}
170:                
171:         if (joystick & JOY_LEFT) // direction Gauche
172:                 {posx--;SCBX(SCBro) = posx;}
173:                
174:         if (joystick & JOY_UP) // direction Haut
175:                 {posy--;SCBY(SCBro) = posy;}
176:                
177:         if (joystick & JOY_DOWN) // direction Bas
178:                 {posy++;SCBY(SCBro) = posy;}
179:        
180:        
181:        
182:         // Collision 1
183:         // limite bord de l'arene:
184:         // X
185:         if (posx<12)            {posx=12;SCBX(SCBro) = posx;}
186:         if (posx>147)           {posx=147;SCBX(SCBro) = posx;}
187:         // Y
188:         if (posy<12)            {posy=12;SCBY(SCBro) = posy;}
189:         if (posy>89)            {posy=89;SCBY(SCBro) = posy;}
190:        
191:        
192:        
193:         // Collision 2
194:         // carr� rouge int�ractif avec carr� blanc (taille 32*32):
195:         // X
196:         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
197:                 {
198:                 if (posx+5>blancx & posx+5<blancx+10)           {posx=blancx-5;SCBX(SCBro) = posx;} // teste le bord droite du carr� rouge
199:                 if (posx-5>blancx+22 & posx-5<blancx+32)                {posx=blancx+36;SCBX(SCBro) = posx;} // teste le bord gauche du carr� rouge
200:                 }
201:         // Y
202:         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
203:                 {
204:                 if (posy+5>blancy & posy+5<blancy+10)           {posy=blancy-5;SCBY(SCBro) = posy;} // teste le bord bas du carr� rouge
205:                 if (posy-5>blancy+22 & posy-5<blancy+32)                {posy=blancy+36;SCBY(SCBro) = posy;} // teste le bord haut du carr� rouge
206:                 }
207:        
208:        
209:        
210:        
211:        
212:        
213:         ++tempa; // tempo pour la vitesse de d�placement du carr� blanc
214:         if (tempa>3)
215:                 {
216:                 tempa=0;
217:                 if (drapa==0) // Si drapa = 0 alors ordre de d�placer la carr� blanc � droite
218:                         {
219:                         ++blancx;SCBX(SCBbl) = blancx;
220:                         if (blancx>84)          {drapa=1;} // changement de direction
221:                         }
222:                 if (drapa==1) // Si drapa = 1 alors ordre de d�placer la carr� blanc � gauche
223:                         {
224:                         --blancx;SCBX(SCBbl) = blancx;
225:                         if (blancx<44)          {drapa=0;} // changement de direction
226:                         }
227:                 }
228:        
229:         }
230: 
231: 
232:  
233:  
234:   DrawSprite(SCB); // Affichage de tous les objets chain�s (fond, carr� rouge int�ractif et carr� blanc)
235:  
236:   Vsync();
237:   SwapBuffers();
238: }
239:  
240: /**************************************************************************
241: **                     FIN de la BOUCLE PRINCIPALE                       **
242: **************************************************************************/
243:  
244:  }