delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/05/06/05:15:47

From: Unigni <unigni AT zaynar DOT demon DOT co DOT uk>
Newsgroups: comp.os.msdos.djgpp
Subject: Collision detection (Was: Simple timer question...)
Date: Wed, 5 May 1999 20:27:17 +0100
Organization: Zaynar Productions
Distribution: world
Message-ID: <mCtvWEAVuJM3EwRy@zaynar.demon.co.uk>
References: <8D53104ECD0CD211AF4000A0C9D60AE30136620B AT probe-2 DOT acclaim-euro DOT net>
NNTP-Posting-Host: zaynar.demon.co.uk
X-NNTP-Posting-Host: zaynar.demon.co.uk:158.152.90.16
X-Trace: news.demon.co.uk 925932767 nnrp-04:26181 NO-IDENT zaynar.demon.co.uk:158.152.90.16
X-Complaints-To: abuse AT demon DOT net
MIME-Version: 1.0
X-Newsreader: Turnpike Version 3.03a <iYfirxJDTC4cxpT9l8N57y$FY6>
Lines: 50
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

In article <8D53104ECD0CD211AF4000A0C9D60AE30136620B AT probe-2 DOT acclaim-
euro.net>, Shawn Hargreaves <ShawnH AT Probe DOT co DOT uk> writes
>SIowTalker writes:
>> unsigned long QueryTimer(void)
>> {
>>   unsigned long clock = _farpeekl(_dos_ds, 0x0046C);
>>   return(clock);
>> }
>>
>> then so each game loop takes at least 100 milliseconds, you save 
>> the time setting in the beggining of the game loop.
>
>A nice theory, but the default BIOS timer only increments 18.2 times
>a second, which is nowhere near enough to give a smooth animation
>in a computer game. For more accurate timing you must use something
>like the djgpp uclock() routine, or reprogram the timer interrupt
>to run at a faster rate (in which case you have to deal with some
>black magic to hook the interrupt and then make sure that you go
>on calling the original BIOS handler at 18.2 ticks per second).

 I've actually decided to use this method, as it's only a few lines and
looks the simplest :-)  (but thanks to everyone else who suggested
ideas, anyway!)
 I've got it taking 2 increments for each loop, making 9.1 every second
(about one every 110 milliseconds). I know this is quite slow, but it's
the first game I've every made with DJGPP/Allegro and so it's not going
to be very fast anyway...
 However, it does say:
   In function `long unsigned int QueryTimer()':
   18: warning: implicit declaration of function `int _farpeekl(...)'
when I compile it ('gxx ver11.cpp -o ver11.exe -lalleg') -- although it
still works fine.


 I now have another problem which I need help with: I have the spaceship
(a 32x32 bitmap object) moving about the playing area (a 200x400 bitmap
object, with colour 128 being solid land), and I want to know when the
spaceship has hit the land. The spaceship isn't square -- it can be lots
of different shapes.
 I have thought of making two 32x32 bitmap objects, and then putting the
land picture with the spaceship over it in one, and the spaceship with
the land over it in the other, compare the two, and if they're different
then the land and spaceship must be overlapping. However, I don't know
how to easily compare two bitmap objects...
 If you know how to do this, or know of any better/alternative way to
achieve collision detection, then I'd be grateful for any help!
-- 
Philip Taylor
philip @ zaynar . demon . co . uk
http://www.zaynar.demon.co.uk/atr - Programming robots!

- Raw text -


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