[comp.binaries.ibm.pc.d] Making balls move with TC 2.0 graphics, a tough problem HELP

viggo@freja.diku.dk (Allan Kim Schougaard) (01/09/89)

Hello, I have been trying to make a Breakout game for the EGA with TC 2.0
(just for the fun of it and to find out the if's and the how's of the TC
graphics).  Anyhow it turns out that it isn't very simple making things move
with TC.
First I tried just using circle and floodfill to make the ball, but
that was to slow.  Then I tried getimage/putimage with XOR_PUT option but
that made the ball flicker. So I tried 

		putimage(newx,newy,ball,AND_PUT);
		putimage(oldx,oldy,ball,XOR_PUT);
		putimage(newx,newy,ball,COPY_PUT);

but this made the ball seem "long" in the moving direction, and it took an
extra color for the color that appered after the AND_PUT.
Then I got a new idea: let's capture a window around the old ball, big
enough to hold both the old ball and the new ball, then put the new ball in
the captured buffer and XOR_PUT the buffer on the screen. That would be
fast, efficient and flicker less. But the way TC stores graphics internaly i
awfull: The to first words (int's) in a capture is width and hight,
according to the manual, but how they are messured isn't revealt. Then the
graphics are stored in a strange way: byte no. 4 is the gray bits in the
beginning of the first line of the picture, byte no. 5 is gray bits after
the first bits... byte x is red in the beginning of the first line... byte y
is green in... byte zzz is gray in the second line of the picture... and so
on.

So I haven't found a way to get my ball moving both fast and flickerless.
Will someone PLEASE HELP me: HOW IS IT DONE ? Isn't there an easy way ?

	Please E-mail or post any solutions you might think possible,
	I am ready to try anything. (This is really geting on my nervs.)

		Viggo at DIKU
		Viggo@freja.dk

teittinen@cc.helsinki.fi (01/10/89)

In article <4343@freja.diku.dk>, 
    viggo@freja.diku.dk (Allan Kim Schougaard) writes:

> Hello, I have been trying to make a Breakout game for the EGA with TC 2.0

Lot's of stuff deleted...

> 
> So I haven't found a way to get my ball moving both fast and flickerless.
> Will someone PLEASE HELP me: HOW IS IT DONE ? Isn't there an easy way ?
> 

You can try taking advantage of the 2 display pages EGA offers.
Draw the same background on both of the pages (you can change active
page using setactivepage-function). Then move the ball so that you draw
the ball to the page that is "hidden" i.e. not visual (use
setvisualpage). When the ball is drawn, you change the visual page and
draw the ball again to the other page which is now hidden, and so on.

Now your ball shouldn't flicker. To increase speed, increase the amount
of pixels to move the ball between page change.

-- 
-----------------------------------+-------------------------------------------
    EARN: teittinen@finuh          I "Studying is the only way to do nothing
Internet: teittinen@cc.helsinki.fi I  without anyone complaining about it." 
-----------------------------------+-------------------------------------------
             Marko Teittinen, student of computer science
-------------------------------------------------------------------------------

boba@hpwala.wal.hp.com (Bob Alexander) (01/11/89)

The EGA, VGA and Hercules graphics boards support 2 graphics pages.  You
can swap between these using the setactivepage and setvisualpage functions.
Graphics functions always write to the active page.  The user sees only
the visual page.

So here's what to do: set the active page to 0 and the visual page to 1.
Draw the ball on the active page.  Switch the visual page to 0 and active
to 1.  Now you can see the ball on the screen.  Draw the ball's new position
on the active page and swap again.  Now, you have to erase the ball from
its old position (since you're swapping pages, you have to remember where
the ball is *on each page* to erase it.)  I recommend that you use putimage
with COPY_PUT.  At initialization time, draw a ball on the screen, then
save it with a getimage.  Also, save an area of blank screen.  Erase the
ball by doing a putimage of the blank screen area.

I'm currently writing a game, too, and I've found that this animation
technique works very well.  You won't see any flicker.  Alas, it's still
too slow for my taste, but it will be fast enough for a breakout game.

Have fun,


  Bob Alexander      | *Controversial remark deleted* 
  boba@hpwala.hp.com |
  -------------------+---------------------------------------------------
  Organizations don't have opinions: individuals do.  The opinions expressed
  above do not necessarily reflect those of the stockholders, employees, or
  directors of Hewlett-Packard.

dgr0093@ultb.UUCP (D.G. Rutherford ) (01/13/89)

> (stuff about moving a ball using two EGA pages)

Page-flipping is a good technique that all the best Apple games have
used since about 1983. And with machines which, like the EGA IBM, have
two graphics pages, it is a very simple and elegant solution. But
perhaps a more general solution would be useful; what if you were
writing a program for a CGA (yes, blecch, but..) or some other unipage
adaptor? Is there a simple way to do flickerless animation, or
minor-flicker animation, using only one display page?

Jones.