www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/11/16/13:04:36

Message-Id: <199811161803.SAA02771@remus.clara.net>
From: "Arthur" <arfa AT clara DOT net>
To: <djgpp AT delorie DOT com>
Subject: RE: Coding problems from an extreme C newbie...
Date: Mon, 16 Nov 1998 18:02:38 -0000
X-Priority: 3 (Normal)
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook 8.5, Build 4.71.2173.0
Importance: Normal
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3
In-Reply-To: <36504861.201569@news.flash.net>
Reply-To: djgpp AT delorie DOT com

> >if((x1 == 0) && (y1 == 0)) /* Red sprite at (0,0) - do stuff */
> >if((x2 == 20)&& (y2 == 20))/* Blue sprite at (20,20) - do stuff */
>
> I got to thinking about this, and now I have another question: What if
> I have TWO or more sprites at the same location...i.e. the sprites
> changes..
>
> Actually, maybe I should tell you about the code I want to write, so
> here goes... (deep breath)
>
> It's a puzzle game with a 9x9 sprite grid (sprite size unimportant)
> This grid is filled with colors of "orbs" or colored sprites.
> If the player clicks on a blue sprite, it changes to a red sprite (and
> the "orbs" horizontally and vertically change as well).  The player
> completes a level when all sprites have changed to a specific color.

So you want to know if the mouse clicks on a sprite in the grid. You need to
check where the mouse is up to 9x9=81 times per loop. First work out which
column the mouse pointer is in. This is easy - you know the position of the
mouse, and the width and height of each grid square. For instance,

if(mouse_x > col1x && mouse_x < col2_x) row=1;
if(mouse_x > col2x && mouse_x < col3_x) row=2;
... etc ...

Then you do the same for columns:

if(mouse_y > row1y && mouse_y < row2y) col=1;
... etc ...

So you now know which square you're in. I assume you're using a 2D array to
store the contents of the squares in...

> So I guess my first question (of many more to come) is how do I get
> the program to check when a level is all one color? (Also, there are
> "empty orbs" in each level which do not change at all.)

Check each row and column in your array to see if the sprite is red or blue.

> Next quick question: What if I have different bitmaps for the
> animations of sprites?  How do I incorporate them into my program?
> Like if the player clicks on an orb, it will "flip" over (play an
> animation).

He he he. Figure it out :-) After all, that's what programming's about.

Hint: you need to set a flag when the orb is clicked on. While the flag is
set, the sprite number needs to be changed to the next frame. The flag is
unset when the last frame is reached.

> And the last question: What's the best way to have a bitmap fade in?
> It's easy to get it to fade to black with an Allegro function, but I
> tried several things for fading in, and nothing worked.  Help!

Use the fade_in function. You need to know the palette of the bitmap,
returned by load_bitmap(), and how long you want it to take.

> That's all for now.

I've got nothing against newbies, and I'll help if I can, but it seems like
we're figuring your code out for you. :-) Experimentation is the name of the
game. Incidentally, have you read George Foot's Vivace tutorial? On the
Allegro Homepage (http://www.talula.demon.co.uk/allegro/) there are links to
loads of tutorials in the "documentation" section. Have a read of a few of
these, and memorise the Allegro manual (or at least learn what it can do).
Obviously I'll help if you get really stuck, but just think logically and
half of your problems will disappear (Ok, so it's not that simple...).

HTH

James Arthur
jaa AT arfa DOT clara DOT net
ICQ#15054819


- Raw text -


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