home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 Mobile / Chip_Mobile_2001.iso / palm / spiele / teslabal / teslabal.exe / TeBaSource.c < prev    next >
C/C++ Source or Header  |  1999-05-22  |  4KB  |  188 lines

  1. // TeslaBalls
  2. // Version 1.0
  3. int ix,iy; // Impulse
  4.  
  5. near(int a, int b, int a1, int b1)
  6. {
  7.  
  8.  int ret,r;
  9. // return 1;
  10. // r=10;
  11. r=13; // para s=10
  12. r=16; // para s=16
  13.  if(a>a1-r && a<a1+r && b>b1-r && b<b1+r) ret=1; else ret=0;
  14.  return ret;
  15. }
  16.  
  17. evento(int f)
  18. { int ev; ev=event(f);
  19.    text(150,150,ev); return ev;
  20. }
  21.  
  22. pause(int s)
  23. {
  24.  int t;
  25.  t=ticks();
  26.  while(t+s<ticks());
  27. }
  28.  
  29. //delta(int ev)
  30. delta()
  31. { int tx,ty,c,e; c=8;
  32.    tx = penx();
  33.    ty = peny();
  34. //   beep(1);
  35.  
  36.    e=0;
  37. //  while(e!=3 && e!=4) {e=event(0); }
  38. while(e!=3 && e!=4 && c!=0) 
  39.      {e=event(0); c--; }
  40.    ix=penx()-tx;  iy=peny()-ty; 
  41. //   text(0,150,"["+ix+"|"+iy+"]");
  42. }
  43.  
  44. main()
  45. {
  46.   float x,y,xd,yd,ox,oy,r;
  47.   float bx,by,obx,oby,bxd,byd;
  48.   float rx,ry;
  49.   string b1,b2;
  50.   int s,e,sco,tim,top;
  51.   int lo,olo;
  52.  
  53.  
  54.  b1 = "0a1e03f06f8dfcffcffcffc7f83f01e0" ; s=10;
  55. //b2="0a1e03f07f8ffcffcffcfec7d83f01e0";
  56. b2="0a1e03f0618cccdecdecccc6183f01e0";
  57. s=16;
  58. b1="1003c00ff01ff839fc73fe77feffffffffffffffff7ffe7ffe3ffc1ff80ff003c0";
  59. b2="1003c00ff03ffc3ffc7ffe7dbef99ffffffffff99f7dbe7ffe3ffc3ffc0ff003c0";
  60. b2="10c18382410000000003c007e04ff28ff18ff14ff207e003c0000000008241c183";
  61. b2="0a1e03f06f8dfcffcffcffc7f83f01e0";
  62. b1="0c0f03fc67e6fedfffffffffff7fe7fc3fc0f0"; s=12;
  63.  
  64. if(dbopen("TeslaBallsS")==0) 
  65. { dbcreate("TeslaBallsS"); top=0; dbwrite(0); } else top=dbread('i');
  66. dbclose();
  67. graph_on(); rect(0,0,0,160,160,0);
  68. frame(1,2,2,158,158,0);
  69. text(80,144,"by Carlos Baquero");
  70. textattr(2,1,0);
  71. text(54,10,"TeslaBalls");
  72. text(50,50,"Top: "+(top));
  73. bitmap(63,100,b1);
  74. bitmap(83,105,b2);
  75. sleep(2000);
  76. while(event(0)!=0); waitp();
  77. //while(bstate()==0);
  78.  
  79. while(1) {  
  80.   x=ox=2; y=oy=30; xd=3; yd=3;
  81.   bx=obx=10; by=oby=80; bxd=0.5; byd=2.5;
  82.   r=5;sco=20; tim=0;
  83.  
  84.   rect(0,0,0,160,160,0);
  85.   textattr(1,2,0);
  86.   line(1,0,13,159,13);
  87.   line(1,0,14,159,14);
  88.   
  89.   line(1,0,20,1,20);
  90.   line(1,0,30,1,30);
  91.   line(1,0,40,1,40);
  92.   line(1,158,20,159,20);
  93.   line(1,158,30,159,30);
  94.   line(1,158,40,159,40);
  95.  
  96.   line(1,0,50,0,159);
  97.   line(1,1,51,1,158);
  98.   line(1,159,50,159,159);
  99.   line(1,158,51,158,158);
  100.   line(1,0,159,159,159);
  101.   line(1,1,158,158,158);
  102. //  line(1,0,68,108,68);
  103. //  lo=olo=((float) 16*log(sco));
  104.   lo=olo=sco/15;
  105.   rect(1,2,2,lo,11,0);
  106.   rect(1,130,1,158,12,0); // clean dig.
  107.   while(sco>0)
  108.   {
  109.     rect(0,ox,oy,ox+s,oy+s,0);
  110.     rect(0,obx,oby,obx+s,oby+s,0);
  111.     bitmap(x,y,b1);
  112.     bitmap(bx,by,b2);
  113.  
  114.     text(132,1,tim); 
  115. //    lo=((float) 16*log(sco));
  116.     lo=sco/15;
  117.     if(lo!=olo) 
  118.     { rect(0,2,2,129,11,0);
  119.      rect(1,2,2,lo,11,0); beep(7); }
  120.  
  121.     olo=lo;
  122.  
  123. //   pause(50);
  124.     ox=x; oy=y;
  125.     obx=bx; oby=by;
  126.     if(near(x,y,bx,by)) 
  127.    { tone(8000,10);
  128. //   beep(1); 
  129.     sco=sco+6;  
  130. //    rx=rand()*r-r/2;
  131.     rx=rand()*r-r/2;
  132. //   xd=xd+rx*-1.1; bxd=bxd+rx;
  133. //  xd=xd+rx; bxd=bxd+rx*-1.3;
  134. // xd=xd+rx; 
  135. bxd=bxd+rx;
  136. // xd=xd-rx;
  137.    }
  138.  
  139.   e=event(0); 
  140.   if(e==2 || e==4) 
  141. // if(e==4)
  142.  { 
  143. //    delta(e); 
  144.     delta(); 
  145. //    xd=xd+(ix/1);   yd=yd+(iy/1);
  146.     xd=xd+ix;   yd=yd+iy;
  147. //  if(ix!=0 || iy!=0) { xd=ix/3; yd=iy/3; }
  148.   }
  149.  
  150. xd=xd*0.97; yd=yd*0.97; // slowit
  151. if(bxd>1.5 || bxd<-1.5) bxd=bxd*0.96;
  152.  
  153.   x=x+xd; y=y+yd;
  154.   bx=bx+bxd; by=by+byd;
  155.   // 150=160-s
  156.   if (bx>146 && by<40) {bx=2;}
  157.   if (bx<2 && by<40) {bx=146;}
  158.   if (x>146) {xd=xd*-1; x=146;}
  159.   if (bx>146) {bxd=bxd*-1; bx=146;}
  160.   if (x<2) {xd=xd*-1; x=2;}
  161.   if (bx<2) {bxd=bxd*-1; bx=2;}
  162. //  if (bx<0) {bx=150;}
  163.   if (y>146) {yd=yd*-1; y=146;}
  164.   if (by>146) {byd=byd*-1; by=146;}
  165.   if (y<15) {yd=yd*-1; y=15;}
  166.   if (by<15) {byd=byd*-1; by=15;}
  167. //  sco=sco-(tim/300); tim=tim+1;
  168.   sco=sco-(tim/200); tim=tim+1;
  169.   }
  170.   clearg(); rect(0,0,0,160,160,0);
  171.   frame(1,2,2,158,158,0);
  172.   textattr(2,1,0);
  173.   text(47,70,"Score: "+(tim));
  174.   bitmap(63,100,b1);
  175.   bitmap(83,105,b2);
  176.    if(tim>top)
  177.    {
  178.       dbcreate("TeslaBalls");
  179.       dbwrite(tim); 
  180.       top=tim;
  181.       dbclose();
  182.     }
  183.   text(50,50,"Top: "+(top));
  184.    sleep(1000);
  185.    while(event(0)!=0); waitp();
  186. //  while(bstate()==0);
  187.  
  188. } }