delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/12/16/16:18:27

From: locke AT mcs DOT net (Peter Johnson)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Allegro mouse routines... Code probs
Date: Thu, 16 Dec 1999 15:07:08 -0600
Organization: BiLogic Productions
Lines: 30
Message-ID: <MPG.12c3107b3dc38e0b9896dd@news.cso.uiuc.edu>
References: <cPb64.12704$uj2 DOT 348729 AT newscontent-01 DOT sprint DOT ca>
NNTP-Posting-Host: isr4186.urh.uiuc.edu
X-Newsreader: MicroPlanet Gravity v2.12
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

In article <cPb64.12704$uj2 DOT 348729 AT newscontent-01 DOT sprint DOT ca>, 
max133 AT chalktv DOT com says...
>  for (mx==x1; mx<x2; mx++)
>  {
>   for (my==y1; my<y2; my++)
>   {
>    if ((mouse_x==mx) && (mouse_y==my) )&& (mouse_b & 1))
>    {
>     newgame();
>   }
>   }
>  }

Instead of this, why not the following:

if ((mouse_x < x2) && (mouse_x > x1) &&
    (mouse_y < y2) && (mouse_y > y1) &&
    (mouse_b & 1))
        newgame();

Looping through the entire coordinate range is wasteful.

Also, a better way to do this test would be in a mouse callback instead 
of polling, but that's another topic entirely.. :)

-- 
Peter Johnson             locke AT mcs DOT net
:Windows: Where do you want to go today?
:Linux:   Where do you want to go tomorrow?
:FreeBSD: Are you guys coming or what?

- Raw text -


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