delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/06/10/22:46:52

From: Michael Ellerman <e3159858 AT student DOT anu DOT edu DOT au>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: How to get the Area of a square...
Date: Thu, 11 Jun 1998 12:33:06 +1000
Organization: Australian National University
Lines: 31
Message-ID: <357F41E2.640@student.anu.edu.au>
References: <357F3B82 DOT D761E6FD AT netrover DOT com>
NNTP-Posting-Host: 150.203.21.88
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Nicolas Blais wrote:
> 
> Hi, let's say I have a 40 by 40 pixels square (at 0,0) on the screen.  I
> use Allegro for my mouse routines and I currently use a do/while loop to
> see if the mouse is over this square, but it's very slow and
> inefficient.  Can someone suggest me a better way with example?
> 
> Here's way I do:
> 
> do
>     {
>     for (int x = 0; x = 40; x++)
>        {
>         for (int y = 0; y = 40; y++)
>             {
>              if (mouse_x == x && mouse_y = y)
>             outtext(screen,font,"Bla",1,1,COLOR);
>              }
>         }
>     } while (keypressed() != 0);
> 
> Sorry for my coding habits...  Nicolas Blais

Try:

if (mouse_x >= 0 && mouse_x <= 40)
	if (mouse_y >= 0 && mouse_y <= 40)
		outtext(...);

I think that works, I haven't been programming much lately though so my
brain may have gone gooey.

- Raw text -


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