home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 2 / DATAFILE_PDCD2.iso / utilities / codemaker / CodeMaker / Exemples / !Exemple0 / c / !RunImage next >
Text File  |  1992-12-19  |  5KB  |  159 lines

  1. /* 
  2.         CodeMaker !Exemple0 : Main
  3.         Frank Lyonnet 1992 
  4.  
  5.         You can contact me on internet : lyonnet@ufrima.imag.fr .
  6.                                          lyonnet@imag.fr .
  7.                         on french RTEL : bal ARCHETYPE .
  8.                                by mail : Frank Lyonnet
  9.                                          420 , Chemin de la Cassine
  10.                                          73000 Chambéry
  11.                                          France 
  12. */
  13.  
  14. #include <stdio.h>
  15. #include <stdlib.h>
  16. #include <time.h>
  17. #include "bbc.h"
  18. #include "kernel.h"
  19. #include "MyUtils.h"
  20. #include "ScreUtils.h"
  21.  
  22. #define SCREEN_WIDTH 320
  23. #define SCREEN_HEIGHT 256
  24. #define OFFSET1 0
  25. #define OFFSET2 SCREEN_WIDTH*SCREEN_HEIGHT
  26.                                                              
  27. #define MAX_SPEED 5
  28.  
  29. #define SPRITE_N_MAX 400
  30.  
  31. typedef struct SPRITE
  32.         {
  33.         int XCoords;
  34.         int YCoords;
  35.         int XSpeed;
  36.         int YSpeed;
  37.         int Width;
  38.         int Height;
  39.         void (*Display_routine)(int Adr);
  40.         } sprite;
  41.  
  42. static sprite Sprite[SPRITE_N_MAX];
  43. static int SpriteNumber;
  44.  
  45. extern void display_bleu0(int Adr);
  46.  
  47. static void update_sprites()
  48.         {
  49.         int i;
  50.  
  51.         for(i=0;i<SpriteNumber;i++)
  52.                 {
  53.                 Sprite[i].XCoords+=Sprite[i].XSpeed;
  54.                 Sprite[i].YCoords+=Sprite[i].YSpeed;
  55.                 if(Sprite[i].XCoords<0)
  56.                         {
  57.                         Sprite[i].XSpeed=-Sprite[i].XSpeed;
  58.                         Sprite[i].XCoords=0;
  59.                         };
  60.                 if(Sprite[i].XCoords>SCREEN_WIDTH-Sprite[i].Width)
  61.                         {
  62.                         Sprite[i].XSpeed=-Sprite[i].XSpeed;
  63.                         Sprite[i].XCoords=SCREEN_WIDTH-Sprite[i].Width;
  64.                         };
  65.                 if(Sprite[i].YCoords<Sprite[i].Height)
  66.                         {
  67.                         Sprite[i].YSpeed=-Sprite[i].YSpeed;
  68.                         Sprite[i].YCoords=Sprite[i].Height;
  69.                         };
  70.                 if(Sprite[i].YCoords>=SCREEN_HEIGHT)
  71.                         {
  72.                         Sprite[i].YSpeed=-Sprite[i].YSpeed;
  73.                         Sprite[i].YCoords=SCREEN_HEIGHT-1;
  74.                         };
  75.                 }
  76.         }
  77.  
  78. static void init_sprites()
  79.         {
  80.         int i;
  81.  
  82.         for(i=0;i<SpriteNumber;i++)
  83.                 {
  84.                 Sprite[i].Width=29;
  85.                 Sprite[i].Height=29;
  86.                 Sprite[i].Display_routine=&display_bleu0;
  87.                 Sprite[i].XCoords=(int)((double)rand()/(double)RAND_MAX*(double)(SCREEN_WIDTH-Sprite[i].Width));
  88.                 Sprite[i].YCoords=(int)((double)rand()/(double)RAND_MAX*(double)(SCREEN_HEIGHT-Sprite[i].Height))+Sprite[i].Height;
  89.                 Sprite[i].XSpeed=0;
  90.                 while(Sprite[i].XSpeed==0)
  91.                         Sprite[i].XSpeed=(int)((double)rand()/(double)RAND_MAX*(double)(MAX_SPEED+MAX_SPEED/2))-MAX_SPEED/2;
  92.                 Sprite[i].YSpeed=0;
  93.                 while(Sprite[i].YSpeed==0)
  94.                         Sprite[i].YSpeed=(int)((double)rand()/(double)RAND_MAX*(double)(MAX_SPEED+MAX_SPEED/2))-MAX_SPEED/2;
  95.                 };
  96.         }
  97.  
  98. int main()
  99.         {
  100.         int i,SAdr1,SAdr2;
  101.  
  102.         bbc_mode(15);
  103.         bbc_mode(13);
  104.  
  105.         bbc_vdu(23); 
  106.         bbc_vdu(1); 
  107.         bbc_vdu(0); 
  108.         bbc_vdu(0); 
  109.         bbc_vdu(0); 
  110.         bbc_vdu(0); 
  111.         bbc_vdu(0); 
  112.         bbc_vdu(0); 
  113.         bbc_vdu(0); 
  114.         bbc_vdu(0); 
  115.  
  116.         set_screen(OFFSET1);
  117.         SAdr1=get_screen_adr();
  118.         set_screen(OFFSET2);
  119.         SAdr2=get_screen_adr(); 
  120.  
  121.         srand((unsigned int)time(NULL));
  122.  
  123.         if (is_ram8())
  124.                 SpriteNumber=80;
  125.         else
  126.                 SpriteNumber=130;
  127.  
  128.         init_sprites();
  129.  
  130.         cache_off(); 
  131.  
  132.         while(mouse_buttons()==0)
  133.                 {
  134.                 set_screen(OFFSET1);
  135.                 clear_screen13(SAdr2); 
  136.                 update_sprites();
  137.                 for(i=0;i<SpriteNumber;i++)
  138.                         (*Sprite[i].Display_routine)(SAdr2+SCREEN_WIDTH*SCREEN_HEIGHT-(Sprite[i].YCoords+1)*SCREEN_WIDTH+Sprite[i].XCoords);
  139.  
  140.                 _kernel_osbyte(19,0,0);
  141.  
  142.                 set_screen(OFFSET2);
  143.                 clear_screen13(SAdr1); 
  144.                 update_sprites();
  145.                 for(i=0;i<SpriteNumber;i++)
  146.                         (*Sprite[i].Display_routine)(SAdr1+SCREEN_WIDTH*SCREEN_HEIGHT-(Sprite[i].YCoords+1)*SCREEN_WIDTH+Sprite[i].XCoords);
  147.  
  148.                 _kernel_osbyte(19,0,0);  
  149.                 };  
  150.  
  151.         cache_on();
  152.  
  153.         }
  154.  
  155.  
  156.  
  157.  
  158.  
  159.