www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/11/21/11:19:47

Message-ID: <001501be1569$3dfa0f20$7dd1d8d4@tedi0117>
From: "Emiliano Baggiani" <eliobagg AT tin DOT it>
To: <djgpp AT delorie DOT com>
Subject: Re: colide
Date: Sat, 21 Nov 1998 17:01:16 +0100
MIME-Version: 1.0
X-Priority: 3
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook Express 4.72.2106.4
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.2106.4
Reply-To: djgpp AT delorie DOT com

Messaggio a pił sezioni in formato MIME.

------=_NextPart_000_000E_01BE1570.8DD32CA0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: 8bit

I've resolved your problem (it's a little thing).
I've attached the '.c' file to this message.


-----Original Message-----
Da: Lazer ---¤--- <lazer_hassing AT yahoo DOT com>
A: djgpp AT delorie DOT com <djgpp AT delorie DOT com>
Data: sabato 21 novembre 1998 15.10
Oggetto: colide


Hi

Im writing a game using djgpp,allegro and
Bounding-Box collision
detection(http://www.geocities.com/SiliconValley/Park/1077)

Could any-one take alot at my source (its a mess,but..)?

The error is in line 138,139 & 140, but i dont know what wrong!! (it
compiles,but won't run)

Thanks

         Lazer



------=_NextPart_000_000E_01BE1570.8DD32CA0
Content-Type: application/octet-stream;
	name="Sample.c"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="Sample.c"

#include <stdio.h>
#include "allegro.h"
#define MAX_SPRITES 10

struct spr_bb{=20
 int bb_height;
 int bb_width;
}
spr_bb[MAX_SPRITES];

int x1=3D20, y1=3D20;=20
int x2=3D150, y2=3D150;
int sp1=3D1, sp2=3D2;

void init_sp_bb()
{
 int l;

 for (l=3D0; l<(MAX_SPRITES+1); l++)
 {
  spr_bb[l].bb_height=3D0;
  spr_bb[l].bb_width=3D0;
 }
}

void mk_spr_bb(BITMAP *s3, int spr_no)
{
 int bb_height=3D0;
 int bb_width=3D0;=20
 int x1, y1;
 int p;=20

        =20
 for (y1=3D0; y1<128; y1++)   =20
 {
  for (x1=3D0; x1<128; x1++)  =20
  {
   p=3Dgetpixel(s3,x1,y1);    =20
   if ((p!=3D0) && (p!=3D-1))   =20
    {
     if (y1>bb_height) bb_height=3Dy1;
     if (x1>bb_width) bb_width=3Dx1; =20
    }
  }
 }
 spr_bb[spr_no].bb_height=3Dbb_height;=20
 spr_bb[spr_no].bb_width=3Dbb_width;
}

int check_collision(int spr1, int spr1x, int spr1y, int spr2, int spr2x, =
int spr2y)
 {
 if ((spr1x>spr2x+spr_bb[spr2].bb_width) || (spr2x > =
spr1x+spr_bb[spr1].bb_width) ||
     (spr1y>spr2y+spr_bb[spr2].bb_height) || (spr2y> =
spr1y+spr_bb[spr1].bb_height))
  {
     return 0;
  }
  else
  {
   return 1;
  }
}


int main()
{
   int qi =3D 3;
   int s =3D 0;
   int ways =3D 1;
   int b =3D 0;
   int w =3D 1;
   int a =3D 100;
   int i =3D 0;
   int q;

   BITMAP *the_ball;
   BITMAP *the_image;
   PALLETE the_pallete;
   the_image =3D load_bitmap("pix1.bmp", the_pallete);
   allegro_init();
   install_keyboard();=20
   install_timer();
   set_pallete(desktop_pallete);
   set_gfx_mode (GFX_AUTODETECT, 320,200, 4, 0);
   set_pallete(the_pallete);
   clear(the_image);


   the_ball =3D create_bitmap(8, 8);
   clear(the_ball);
   circle(the_ball, 2, 2, 2, 2);  =20
   the_image =3D load_bitmap("gra1.bmp", the_pallete);
   draw_sprite(screen, the_image, (SCREEN_W-the_image->w)/2, =
200-the_image->h);

   q =3D (SCREEN_W-the_image->w)/2;
   w =3D 170;
   b=3D3;
   s=3DSCREEN_W/2;
   ways=3D1;


   /*Lines added by Emiliano Baggiani BEGIN*/
   #define THEBALL  0
   #define THEIMAGE 1

   mk_spr_bb(the_ball,THEBALL);
   mk_spr_bb(the_image,THEIMAGE);

   /*Lines added by Emiliano Baggiani END*/


   while(!key[KEY_ESC])
   {

     if(b<2){
        w=3Dw-1;
        if(ways<2){
           s=3Ds-1;
        }
          if(s<2){
             ways=3D3;
          }
        if(ways>2){
           s=3Ds+1;
        }
          if(s>318){
             ways=3D1;
          }

        if(w<2){
           b=3D3;
        }
     }

     if(b>2){
        w=3Dw+1;
        if(ways>2){
           s=3Ds+1;
        }
          if(s>318){
             ways=3D1;
          }
        if(ways<2){
           s=3Ds-1;
        }
          if(s<2){
             ways=3D3;
          }

        if(w>(200-the_image->h)-2){
           b=3D1;
           if =
(check_collision(THEBALL,s,w,THEIMAGE,q,200-the_image->h)){// ERROR //
              rest(1000);// ERROR //
              /*You've passed a pointer to a bitmap, but It require an =
int!*/
           }// ERROR //
        }
     }

     clear (screen);
     draw_sprite(screen, the_image, q, 200-the_image->h);
     circle(screen, s, w, 2, 2);
     rest(10);

    if(key[KEY_LEFT])
    {
      clear(screen);
      q=3Dq-10;
        if (q<1)
          q=3D1;
     draw_sprite(screen, the_image, q, 200-the_image->h);
      circle(screen, s, w, 2, 2);
      clear_keybuf();
    }

    if(key[KEY_RIGHT])
    {
      clear(screen);
      q=3Dq+10;
        if (q>241)
          q=3D241;
      draw_sprite(screen, the_image, q, 200-the_image->h);
      circle(screen, s, w, 2, 2);
      clear_keybuf();
    }

   }

   fade_out(5);
}

/*
Hello from Leghorn (Tuscany - Italy)!

Contact me, I'm an italian c\c++ programmer
and i'm programming a game with DJGPP in c++.
If you want any help, don't esitate to contact me.

EMAIL : eliobagg AT tin DOT it
URL   : http://space.tin.it/computer/ebaggian

*/


------=_NextPart_000_000E_01BE1570.8DD32CA0--

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019