www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/12/05/20:11:05

From: mert0407 AT sable DOT ox DOT ac DOT uk (George Foot)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Allegro Mouse Problem: Allegro: Code
Date: Fri, 06 Dec 1996 00:17:14 GMT
Organization: Oxford University
Lines: 83
Message-ID: <32a76032.9708569@news.ox.ac.uk>
References: <01bbe16a$1b67efc0$LocalHost AT miller>
NNTP-Posting-Host: mc31.merton.ox.ac.uk
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Apparently-To: djgpp AT delorie DOT com

On 5 Dec 1996 02:37:09 GMT, "Neil Miller" <miller AT citilink DOT com> wrote:

>This message has my code for a simple Allegro program.

In future it would be better to post the code itself, rather than an
encoded version.

> I am testing
>whether there is a "hit", and then drawing a circle.  I can drag this dot
>and it is no longer a dot.  Is there a way to fix this?? Also sometimes, if
>you click twice close together, there are two dots, but one is distorted.

Decoded attachment follows, with comments...

|#include "allegro.h"
|
|extern volatile int mouse_x; //mouse x coord
|extern volatile int mouse_y; //mouse y coord
|extern volatile int mouse_b; //mouse button state 
|			     //&1=Left &2=Right 	

These externs are already declared in allegro.h - there's no need to
repeat them.

|int HitStatus = 0; //hit or miss 1=hit 0=miss
|int mx, my;   //mouse coord = mouse_y & mouse_x
|
|main()
|{
|	allegro_init();
|	install_keyboard();
|	install_timer();
|	install_mouse();
|	set_gfx_mode(GFX_MODEX, 320, 240, 0, 0);
|	set_pallete(desktop_pallete);
|	mouse_action();	
|}
|
|mouse_action(){
|	show_mouse(screen);
|	HitStatus = 0;
|	do{	
|	if(mouse_b & 1)
|		hit_check();
|	} while(!keypressed());
|}
|
|hit_check(){
|	mx = mouse_x;
|	my = mouse_y;
|	ClrScr();
|	show_mouse(NULL);
|	if(mx > 50 && mx < 75)
|		if(my > 50 && my <75)
|			HitStatus = 1;
|	if(HitStatus == 1)
|		drawBlood();
|	show_mouse(screen);
|}

You need to hide the mouse before all screen updates. This includes
your ClrScr() function... move the show_mouse(NULL) call up one line.

|ClrScr(){
|	rectfill(screen, 0, 0, 320, 240, 0);
|}

There are special commands to clear bitmaps... try clear(screen) or
clear(screen,colour) if you want it a different colour.

|drawBlood(){
|	circlefill(screen,  mx-1, my-1, 2, 1);		
|
|	HitStatus = 0;
|}

Your use of HitStatus is slightly round-about... I assume there's a
reason for it, which doesn't show up in this simplified version of the
code.

In short, move the show_mouse(NULL) command up a line.

George Foot.

- Raw text -


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