Ultimate Amiga

Network Boards => AMOS Language Discussion => AMOS Factory => AMOS Forum => Topic started by: wojt_gl on February 20, 2013, 12:20:15 AM

Title: AMOS - Collision detection with background
Post by: wojt_gl on February 20, 2013, 12:20:15 AM
Hello anybody!
I am looking for good example or solution for my problem.
I am trying to write a game with ship traveling across some corridors.
I need to detect collision with corridors walls - those are irregular.

What I need is to find out if there is an existing function for detect bob/sprite collision with background.
My background has some walls graphics and corridors with color zero. I want to allow to move ship only on corridor and hitting the wall should finish with explosion.

I was trying almost everything (with big bob as mask also) and no result :/
I was trying with set hardcol and hardcol (but those are not well documented and dont know how to use that, and if those are proper for this feature).
Anybody has an idea how to achieve?

Thanks!
Title: Re: AMOS - Collision detection with background
Post by: bruceuncle on February 20, 2013, 09:17:55 PM
I haven't done anything in this area myself.  BUT, if you have a look at the Planet_Zybex program on the Productivity1 disk, the programmer uses a novel technique for detecting collision with an irregularly-shaped background.
This is mentioned in the AMOS Pro Application Supplement (in Downloads here http://www.ultimateamiga.co.uk/index.php?action=tpmod;dl=item417 (http://www.ultimateamiga.co.uk/index.php?action=tpmod;dl=item417)) on page 03.02.

And if you can get hold of a copy, Amiga Game Makers Manual - With AMOS Basic should give you plenty of info on game design in general.

If your backgroud is made up of rectangular shapes, try using zone definitions and detecting zone collision.  Look at page 07.04.06 in the AMOS Pro User Manual (in Downloads here http://www.ultimateamiga.co.uk/index.php?action=tpmod;dl=item451 (http://www.ultimateamiga.co.uk/index.php?action=tpmod;dl=item451)) for more info.

Hope this helps.  ;)
Title: Re: AMOS - Collision detection with background
Post by: wojt_gl on February 21, 2013, 07:23:34 AM
Thank You for Your quick reply.
I will take a look on book positions You mentioned.
And my background is not rectangular shapes - its totaly irregular.
Title: Re: AMOS - Collision detection with background
Post by: wojt_gl on February 21, 2013, 07:26:07 PM
LOL - i just noticed that my object which i want to detect colission are not so much irregular. They are possible wrapped by rectangle... so it would be easy to detect the collission.
Anyway i checked the PlanetZybex sources, and found out that they are doing it the same (checking the color of screen by point() method - as there is NO way in AMOS to check collision with background).

Anyway - why they didnt provide a method for that? Its easy to do it this way (checking the background color against an object rectangle...)?
Title: Re: AMOS - Collision detection with background
Post by: bruceuncle on February 21, 2013, 10:26:55 PM
Pleased to hear you found a way around the problem.

AMOS does provide a way to check background collision but it's a bit convoluted.  Either you define zones and check bob/zone collision.  Or you define static bobs and check bob/bob collision.

There's probably other ways to do it using assembler and the hardcol register but I haven't explored that side of the Amiga hardware yet.  So I'm probably wrong!  ;D
Title: Re: AMOS - Collision detection with background
Post by: Lonewolf10 on February 28, 2013, 05:37:29 PM
There's probably other ways to do it using assembler and the hardcol register but I haven't explored that side of the Amiga hardware yet.  So I'm probably wrong!  ;D

From a quick look at the Amiga HRM (Hardware Reference Manual) I have you are correct. It is possible to detect collisions between sprites and the background. Registers CLXCON (address $DFF098) and CLXDAT (address $DFF00E) are used for sprite collision detection (both with other sprites and the screen). In assembler you can only write to CLXCON (collision control - it set's up what type/s of collision you want) and read CLXDAT (collision data - it's bits are set appropriately when certain collisions are detected). Doing so via AMOS' peek and poke command may crash your Amiga.
I don't understand why AMOS doesn't take advantage of this feature.
Title: Re: AMOS - Collision detection with background
Post by: bruceuncle on March 01, 2013, 10:30:23 PM
From a quick look at the Amiga HRM (Hardware Reference Manual) I have you are correct. It is possible to detect collisions between sprites and the background.
Thanks Lonewolf10.  Had a quick look at my manuals (a bit out of date - A1000 - but that's a long story) and it looks very promising.  Particularly like the way you can limit it to specific bitplanes.  That makes it possible to have a full colour background, but collisions only detected with certain bits of the 'landscape'.   8)

I also came across one of those docs files from way back.  The ones that people typed in by hand.  I've attached the archive it came from, plus the individual file to save hunting around for it.

The file amigaocs_hardware.doc (nothing to do with being a Messysoft Word document! - it's just plain text) has one of the best talk-throughs of the original hardware that I've come across so far.  It's pre-ECS but covers all the hardware basics from the assembler programmers angle.  I read the whole thing the other night and now have a far better understanding of how the Amiga hardware really works.  If anyone knows who the author was (there's no author or acknowledgments in the doc) I'd love to find out.  Or any other docs he/she wrote.  This sort of quality doc is just what I need.  It may be well known to seasoned Amiga programmers but it's gold dust to us novices!

The attached archive is a real grab bag of assorted docs.  Quality is very variable!  But worth spending some time wading through it.  There's a useful AGA section too.   ;)

I don't understand why AMOS doesn't take advantage of this feature.
I suspect it was maybe considered a bit too complex to inflict on AMOS programmers at the time.  I had a think about how it could be put into AMOS Basic instruction format and it's not easy to come up with something workable.  BUT, it should definitely be considered for the AMOS Pro Re-development project.

Just thinking out loud - maybe it could be implemented as:
Title: Re: AMOS - Collision detection with background
Post by: Hungry Horace on March 02, 2013, 12:19:10 PM
interesting reading.

I saw something about a technique used for Indy Heat...

http://www.codetapper.com/amiga/interviews/john-croudy/

.... where there is a mask for items on the track pictures, such as buildings / bridges etc, and that mask is used to stop the sprite being drawn at those points (ie. driving under a bridge etc) ... .any idea how that oculd presently be implemented, or if functions for this could be added to AMOS?
Title: Re: AMOS - Collision detection with background
Post by: bruceuncle on March 04, 2013, 10:50:46 AM
@HungryHorace
It's possible to detect sprite collision with one or more bitplanes.  You define which bitplanes and which sprites and the hardware flags the collision for you.
You can also define the priority of the sprites both to each other and to the bitplanes. That's what's used for situations where you want a sprite to pass 'behind' parts of the background.
The 'mask' referred to is just a single bitplane.  The hardware is told to detect sprite collision with that one bitplane and ignore the rest.
All this can (and should) be incorporated into AMOS Pro redevelopment.
The tricky bits would be synchronising with the existing AMOS sprite handling and making the AMOS instructions simple enough to be usable.

I would think the hardest part comes when you try to set up a suitable background for a game.  The bitplanes determine the colours so a fair bit (sic) of planning is needed to get it right.

I enjoyed that article you linked to.  It's nice to get info on how things were done - helps to confirm how the Amiga hardware was designed to be used.  The RKM info is a bit like having  a huge Lego Technics set with no model  instructions! ;D
Title: Re: AMOS - Collision detection with background
Post by: Lonewolf10 on March 07, 2013, 08:32:55 PM
Thanks Lonewolf10.

No problem :)

I also came across one of those docs files from way back.  The ones that people typed in by hand.  I've attached the archive it came from, plus the individual file to save hunting around for it.

Thanks, will download them at the weekend. You can never have too much documentation :)

I don't understand why AMOS doesn't take advantage of this feature.
I suspect it was maybe considered a bit too complex to inflict on AMOS programmers at the time.  I had a think about how it could be put into AMOS Basic instruction format and it's not easy to come up with something workable.

That's a good point.

Just thinking out loud - maybe it could be implemented as:
  • A set of instructions to set up the background detections and priorities required
  • Instructions to put the settings into action (e.g.  Back Col On, Back Col Off, etc.)
  • Instructions to test for background collisions along the lines of the current AMOS ones for Sprites and Bobs.
  • Extend AMAL to do the same (hard one that!)

Sounds like a good idea to me.
Title: Re: AMOS - Collision detection with background
Post by: HonestFlames on February 28, 2014, 10:44:59 AM
Sorry to resurrect an old thread, but this is relevant to what I'm doing at the moment.

I've just read the documentation regarding the collision control register and I've deciphered it to a degree.

I must not be quite 'getting' it, because Amos Pro has a Set Hardcol command which seems to be intended for the purpose of letting me get friendly with the CLXCON register.

Set Hardcol bitmap1,bitmap2

bitmap1 corresponds to bits 12-15, which are: -

15 - Enable collision detection, sprite 7
14 - Enable collision detection, sprite 5
13 - Enable collision detection, sprite 3
12 - Enable collision detection, sprite 1

Now, as I'm using sprite 0 as a 16-colour sprite, it combines with sprite 1 and I should set bit 12.

bitmap2 corresponds to bits 0-5, which are: -
5 - Bitplane 6 collision match bit
4 - Bitplane 5 collision match bit
3 - Bitplane 4 collision match bit
2 - Bitplane 3 collision match bit
1 - Bitplane 2 collision match bit
0 - Bitplane 1 collision match bit

Setting or clearing these lets me choose any bitplanes to ignore when checking for collisions. I'm using a dual-playfield screen (3 planes each) and I only want to check the front playfield for collisions. Because I haven't done my research, I'm guessing these are planes 4,5 and 6.

In testing, though, on a simple lowres screen of any amount of bitplanes, testing Hardcol(0) never results in a collision being reported.

Now, I'm using WinUAE and I have checked and re-checked that I have switched on full collision detection, but this really has me stumped.

Has anyone ever been successful in using Set Hardcol in this way?
Title: Re: AMOS - Collision detection with background
Post by: SamuraiCrow on February 28, 2014, 06:01:08 PM
I think you're wrong about the playfield bitplanes.  I think playfield 2 is bitplanes 1,3 and 5 while the other playfield is planes 0, 2, and 4.
Title: Re: AMOS - Collision detection with background
Post by: HonestFlames on February 28, 2014, 06:27:20 PM
You're more than likely correct!

I'm becoming mildly frustrated though. I created a quick test app where I open a 4-colour screen, grab a 16x16 sprite and test collisions against drawn circles... I can't get a single ounce of success.

No matter what, the following never results in Hardcol(0) returning the promised -1 value.

Code: [Select]
Repeat
Set Hardcol 1,1
Sprite 0,X Mouse,Y Mouse,1
Text 16,16,"Hardcol(0)="+Str$(Hardcol(0))
Multi Wait
Until Mouse Click
Title: Re: AMOS - Collision detection with background
Post by: SamuraiCrow on March 03, 2014, 02:24:20 PM
If you're using an emulator to test your code, make sure sprite-to-playfield collision checking is being emulated.  Usually that is a rarely-used feature and is deactivated to make the emulation go faster.
Title: Re: AMOS - Collision detection with background
Post by: HonestFlames on March 03, 2014, 06:16:54 PM
Yes, I did check this after about 10 minutes ;)

I'm going to start POKEing at CLXCON next. If that doesn't work, I'm not sure. Back when I first had an Amiga, I wrote an extension, so I could bodge one of those together again.

Not pretty, but it would solve this one issue.
Title: Re: AMOS - Collision detection with background
Post by: bruceuncle on March 04, 2014, 09:59:31 AM
I was going to add Set Hardcol and =Hardcol() to the bug list as this has cropped up a couple of times now.  So I had a delve into the code and found the problem is that the AMOS Manual is way off track!  It's not a bug at all.   :)

So forget what the manual says, the correct syntax, parameters and usage are:

Set Hardcol EnableBits, MatchBits

EnableBits is a bitmap of which bitplanes you want checked.
MatchBits is a bitmap of what value to check for in each bitplane (%0 or %1).  That may sound a little strange but it just means you can check for either a set bit (%1) which is like checking for hitting a wall, or a cleared bit (%0) which is like checking for hitting a hole.

EnableBits corresponds to bits 6 to 11 in CLXCON, MatchBits corresponds to bits 0 to 5 in CLXCON.  Set Hardcol always sets bits 12 to 15 in CLXCON to %1111.  This just means that the odd numbered hardware sprites will also be included in the checks.  So effectively all hardware sprites are always included.

The problems start when you try to check the results!

Result=Hardcol(SpriteNumber)

SpriteNumber is the number of the hardware sprite you want to check.
Result is only useful if you're checking hardware sprite to hardware sprite collision when it will be -1 for a "hit".  For checking bitplane collisions, it will be zero even if you hit a bitplane pixel.  You then need to use:

Result=Col(SpriteNumber)

SpriteNumber is the number of the sprite to check for in sprite-to-sprite collisions.  BUT -1 will check for bitplane collisions.
Result would be the hardware sprite number that you hit in a sprite-to-sprite check.  Any non-zero value will be a bitplane hit if you specified -1 for SpriteNumber.

I haven't investigated whether there's any special meaning to the values returned when a bitplane collision has occurred.  I thought I'd get this and an example program posted a.s.a.p. to avoid any further confusion.  I suspect the value would indicate odd or even bitplane hits and maybe even bitplane-to-bitplane hits (useful for dual playfield).  I need to investigate a bit further....

This code (file also attached) is a quick demo of a sprite that collides with a blue box in the background but not with a pink one.  You need the collisions sprite bank from the Tutorials directory if you're just copying the code.  If you download the attachment, the bank's embedded in the program.

Code: [Select]
'==================================================
'   Demo of Hardware Sprite Collision with Bitplane
'
'   Author : bruceuncle
'     Date : 04/03/2014
'==================================================
'
'   This code just positions the screen at the same 
'   hardware coords as your Default screen: 
'
G_ADDR=Screen Base
G_XPOS=Deek(G_ADDR+82)
G_YPOS=Deek(G_ADDR+84) and $FF
For S=0 To 7
   Trap Screen Close S
Next S
Screen Open 0,320,200,8,Lowres
Screen Display 0,G_XPOS,G_YPOS,320,2000
'
'   The embedded sprite bank is the one in Tutorials used 
'   in the Collision Detection example program:
'
Get Sprite Palette : Colour 0,0 : Curs Off : Flash Off : Cls 0 : Hide On
'
'   Ink 2 means we'll be drawing in bitplane 1 (cyan colour). 
'   This is the bitplane we want to detect collisions in.
'   
Ink 2 : Box 80,80 To 239,119
'
'   Ink 1 means we'll be drawing in bitplane 0 (sorta pink colour). 
'   This is a bitplane we're not interested in.
'   
Ink 1 : Box 120,20 To 199,175

Pen 2 : Paper 0
Locate 0,23 : Centre "Press Right Mouse Key to Exit"

X=160 : Y=40 : DX=2 : DY=2
Sprite 1,X Hard(X),Y Hard(Y),2
'
'   The sprite must be masked!
'
Make Mask 1
'
'   Turn on hardware collision detection.
'   1st param is which bitplanes to turn on collision detection for.
'      Corresponds to bits 6 to 11 in the CLXCON hardware register.
'      Always set unused bitplanes to %0 in the bitmap.
'   2nd param is what value in the bitplane to check against (%0 or %1)
'      Corresponds to bits 0 to 5 in the CLXCON hardware register.         
'      Unused bitplanes have no effect in the bitmap.
'   AMOS always sets bits 12 to 15 to %1 in the CLXCON hardware register.
'   That means the odd numbered sprites will also be included in the checks.
'   So, effectively, all hardware sprites are always checked in AMOS. 
'
'   For this example we're looking for a collision with bitplane 1 so 
'   we will get a "hit" on the blue box but not on the pink one.
'   AMOS always trims leading zeros.  The value we're really loading
'   is %000010, which is a bitmap of all 6 possible bitplanes.  As our screen
'   is only 8 colours, we're only using the first three bitplanes.

Set Hardcol %10,%10
'
Do
   Exit If Mouse Key=2
   Add X,DX : Add Y,DY
   If X>294 or X<26 Then DX=-DX
   If Y>174 or Y<26 Then DY=-DY
   Sprite 1,X Hard(X),Y Hard(Y),2
   '
   '   After a hit, we delay for four frames to give the sprite a chance
   '   to get clear:
   '
   If G_WAIT>0
      Dec G_WAIT
   Else
      '   
      '   Check sprite 1 for a hardware collision:
      '     
      C=Hardcol(1)
      '
      '   =Col(-1) means check for bitplane collisions (which bitplanes
      '      will be the ones we set up using Set Hardcol.
      '   0 is returned for no collision, non-zero is a collision.
      '   I haven't investigated what the actual returned values mean yet!
      '
      If Col(-1)
         '
         '   If we got a hit, I'm just jiggling the direction and sounding
         '   a ding.  The G_WAIT is just to delay the next checks until
         '   the sprite has moved away from the box a bit.  Helps prevent
         '   "head banging"!
         ' 
         Bell : DX=-DX : Add X,DX : G_WAIT=4
      End If
   End If
   Wait Vbl
Loop
'
Screen Close 0
Edit

Remember, its bitplanes that you're checking collisions with, not colour numbers.  So checking set bits in bitplane zero will register a hit for colours 1 (%000001), 3 (%000011), 5 (%000101), etc.  So you need to choose the colours in your backgrounds carefully.
Title: Re: AMOS - Collision detection with background
Post by: bruceuncle on March 05, 2014, 10:42:32 AM
I've investigated what AMOS does with these instructions and the following applies:

Set Hardcol EnableBits, MatchBits

This remains exactly as in the previous post.

=Hardcol(SpriteNumber)
=Col(SpriteNumber)

These work a little differently.

So these are the parameters and results for the two instructions:

Result=Hardcol(SpriteNumber)

     SpriteNumber     Result
     
0 thru 7
Checks all possible hardware collisions for the specified SpriteNumber and returns -1 for a sprite-to-sprite collision.  Returns 0 for a sprite to playfield collision.  Saves the results (which sprite or bitplane was hit) for =Col() to use to retrieve the sprite number that was hit or whether a playfield was hit.
     
-1
Checks only for a playfield-to-playfield collision and returns -1 for a hit and 0 for no hit.  No need to use =Col() to retrieve any results.  Note that this also clears AMOS's own collision table used by =Col() so there's no point in trying to use that instruction anyway!


Result=Col(SpriteNumber)

     SpriteNumber     Result
     
0 thru 7
Will return -1 if the specified SpriteNumber was hit and 0 for no hit.  Note that the sprite numbers are paired due to Set Hardcol always enabling both odd and even sprites numbers.  So if you get a hit for, say, sprite 2, you'll always also get a hit for sprite 3, and so on.  There's no way to tell which one of each pair is involved.
     
8 thru 11
Will return -1 if a bitplane hit has been detected.  Values of 8 or 9 check for an odd numbered bitplane hit, values of 10 or 11 check for an even numbered bitplane hit.  It doesn't matter which number you use in each pair, it's just a quirk caused by that sprite number pairing mentioned above.  As the odd versus even bitplane number checking is only relevant in Dual Playfield mode, using any value from 8 thru 11 appears to work in single playfield modes.  (Can any hardware expert out there verify that this is the way CLXDAT is supposed to work?)
     
-1 thru -255
Will work through AMOS's table of collision results and return the sprite number (sic) for the first collision it finds (where a bit = %1).  It will start at whatever number is specified in SpriteNumber (converting it to a positive number first).

That's all folks!  Now all I've got to do is get the documentation up to date again  :o .
Title: Re: AMOS - Collision detection with background
Post by: Lonewolf10 on March 08, 2014, 03:37:10 PM

Great work there bruceuncle ;)

I have never used sprite collision detection before, but if I do I now have a working example :)
Title: Re: AMOS - Collision detection with background
Post by: gibs on May 09, 2014, 07:37:08 PM
Hi Bruce Uncle.
Thanks for the documentation.
However I have a question:
In your example, if I use "Ink 4" instead of "Ink2", so I am on the 3rd bit plane, right ?
So I need to set "Set Hardcol %100,%100"

But if I do that, the ball also detect collision in bit plan 0.

I also tried "Set Hardcol %1,%1", same result.

Thanks.
Title: Re: AMOS - Collision detection with background
Post by: bruceuncle on May 10, 2014, 08:25:31 AM
Hi Bruce Uncle.
Thanks for the documentation.
However I have a question:
In your example, if I use "Ink 4" instead of "Ink2", so I am on the 3rd bit plane, right ?
So I need to set "Set Hardcol %100,%100"

But if I do that, the ball also detect collision in bit plan 0.

I also tried "Set Hardcol %1,%1", same result.

Thanks.

Oops!   :-[  There should have been an updated attachment on that last post.  The first version of the example worked for bitplane 1, but only by luck!  (Well, I did say I hadn't worked out what all the replies were in that example post...)  The culprit  was my using =Col(-1).

The full description of the usage is in that previous post.

I've attached the updated version and the code's here.   You need the collisions sprite bank from the Tutorials directory if you're just copying the code.  If you download the attachment, the bank's embedded in the program.

Code: [Select]
'==================================================
'   Demo of Hardware Sprite Collision with Bitplane
'
'   Author : bruceuncle
'     Date : 05/03/2014
'==================================================
'
'   This code just positions the screen at the same 
'   hardware coords as your Default screen: 
'
G_ADDR=Screen Base
G_XPOS=Deek(G_ADDR+82)
G_YPOS=Deek(G_ADDR+84) and $FF
For S=0 To 7
   Trap Screen Close S
Next S
Screen Open 0,320,200,8,Lowres
Screen Display 0,G_XPOS,G_YPOS,320,2000
'
'   The embedded sprite bank is the one in Tutorials used 
'   in the Collision Detection example program:
'
Get Sprite Palette : Colour 0,0 : Curs Off : Flash Off : Cls 0 : Hide On
'
'   Ink 2 means we'll be drawing in bitplane 1 (cyan colour). 
'   This is the bitplane we want to detect collisions in.
'   
Ink 2 : Box 80,80 To 239,119
'
'   Ink 1 means we'll be drawing in bitplane 0 (sorta pink colour). 
'   This is a bitplane we're not interested in.
'   
Ink 1 : Box 120,20 To 199,175

Pen 2 : Paper 0
Locate 0,24 : Centre "Right Mouse Button to Exit"

X=160 : Y=40 : DX=2 : DY=2
'
'   Must be a hardware sprite (0 thru 7) not a computed one:
'
Sprite 1,X Hard(X),Y Hard(Y),2
'
'   The sprite must be masked!
'
Make Mask 1
'
'   Turn on hardware collision detection.
'   1st param is which bitplanes to turn on collision detection for.
'      Corresponds to bits 6 to 11 in the CLXCON hardware register.
'      Always set unused bitplanes to %0 in the bitmap.
'   2nd param is what value in the bitplane to check against (%0 or %1)
'      Corresponds to bits 0 to 5 in the CLXCON hardware register.         
'      Unused bitplanes have no effect in the bitmap.
'   AMOS always sets bits 12 to 15 to %1 in the CLXCON hardware register.
'   That means the odd numbered sprites will also be included in the checks.
'   So, effectively, all hardware sprites are always checked in AMOS. 
'
'   For this example we're looking for a collision with bitplane 1 so 
'   we will get a "hit" on the blue box but not on the pink one.
'   AMOS always trims leading zeros.  The value we're really loading
'   is %000010, which is a bitmap of all 6 possible bitplanes.  As our screen
'   is only 8 colours, we're only using the first three bitplanes.

Set Hardcol %10,%10
'
Do
   Exit If Mouse Key=2
   Add X,DX : Add Y,DY
   If X>294 or X<26 Then DX=-DX
   If Y>174 or Y<26 Then DY=-DY
   Sprite 1,X Hard(X),Y Hard(Y),2
   If G_WAIT>0
      '
      '   After a hit, we delay for four frames to give the sprite a chance
      '   to get clear:
      '
      Dec G_WAIT
   Else
      '   
      '   Check sprite 1 for a hardware collision.  The results go into AMOS's
      '   internal collision table.
      ' 
      C=Hardcol(1)
      '
      '   Display positions 8 thru 15 from AMOS's collision table:
      '
      Locate 0,23 : For I=8 To 11 : Print Hex$(Col(I),2); : Next I
      '
      '   =Col(8) or =Col(9) means "check for the sprite colliding with an
      '                             even-numbered bitplane specified in
      '                             Set Harcol"
      '   =Col(10) or =Col(11) means "check for the sprite colliding with an
      '                               odd-numbered bitplane specified in
      '                               Set Harcol"
      '
      '   0 is returned for no collision, -1 is a collision.
      '
      '   The above applies to dual playfield mode.
      '   In single playfield mode, it doesn't matter what you use. 
      '
      If Col(8)
         '
         '   If we got a hit, I'm just jiggling the direction and sounding
         '   a ding.  The G_WAIT is just to delay the next checks until
         '   the sprite has moved away from the box a bit.  Helps prevent
         '   "head banging"!
         ' 
         Bell : DX=-DX : Add X,DX : G_WAIT=4
      End If
   End If
   Wait Vbl
Loop
'
Screen Close 0
Show On
Edit
Title: Re: AMOS - Collision detection with background
Post by: gibs on May 10, 2014, 09:47:17 AM
Thanks for the quick answer :)
But I have another question:

In your updated example, let's draw a (red) line in the 3rd biplane using color 7.
Colour 7,$F00: Ink 7: Draw 80,150 to 239,150

Then the detection is also activated to this bit plane, which is weird as we set it in the 2nd bit plane only.
Title: Re: AMOS - Collision detection with background
Post by: bruceuncle on May 10, 2014, 11:12:16 AM
In your updated example, let's draw a (red) line in the 3rd biplane using color 7.
Colour 7,$F00: Ink 7: Draw 80,150 to 239,150

Then the detection is also activated to this bit plane, which is weird as we set it in the 2nd bit plane only.

Ah, you're confusing colour numbers with bitplanes.  Colour 7 is all bitplanes (7 = %111).  So if you just want a single bitplane, you'd use Colour 1 (%001 - the first bitplane), Colour 2 (%010 - the second bitplane) or Colour 4 (%100 - the third bitplane).  Colour 0 (%000) is no bitplanes.  Colours 3, 5, 6 & 7 (for an 8 colour screen) all set pixels bits in more than one bitplane, so you'll register 'hits' in any of those bitplanes.

The Amiga's bitplane display format means it's no easy task to decide what colours you need and how to turn them into what bitplanes to use.  Hardware sprite/bitplane collision detection complicates that task.  It becomes even more complex for dual playfield screens.  You have to carefully plan your colour and bitplane usage.
Title: Re: AMOS - Collision detection with background
Post by: gibs on May 10, 2014, 11:30:22 AM
Oh ok thanks  ;)
Title: Re: AMOS - Collision detection with background
Post by: Hungry Horace on March 10, 2015, 08:20:45 PM
bruceuncle, your example is really nice, and it been of some help to me understanding the commands.

I am still always very hazy when it comes to bitplaces / bitmaps etc. though.  I kind of get the prinicple (how the colours are made up of true/false values in each place combining) ... my problem is understanding the application.

So my game is running with a 16 colour image as the background - great. This uses up planes 0-3 . Detecting collision based on colours or from useage of colours within that background isnt really practical.  4 hardware Sprites are being used and are 16x16 in size, taking advantage of colours 16-31.

Lets say I only have 3 'states' i want to check for.  One creates a 'no go' zone. One slows my hero down and the the last one slows them down and causes damage.

Is it possible to create a new 'invisible' image (btimap?) which i can check my sprites against?  If so, how do i open it / reference it?  Can i have it on a logical screen whilst the player only sees the 'drawn only one' physical screen?

Can i use another plane as a 'mask' to hide my hero behind and create the illusion of going behind another object? (see the Serious F1 thread)....



Thank you for any help/advice!!!
Title: Re: AMOS - Collision detection with background
Post by: bruceuncle on March 11, 2015, 03:02:43 AM
I am still always very hazy when it comes to bitplaces / bitmaps etc. though.  I kind of get the prinicple (how the colours are made up of true/false values in each place combining) ... my problem is understanding the application.

Thank you for any help/advice!!!
Yeah, I have to stop and draw myself pictures every time I have to think about collisions, sprites, colour maps and bitplanes.  Both the Amiga's strength (at the time) and its weakness, in that it takes a lot of planning to get what you want out of it.  At least AMOS makes it easier to set up and test rather than doing it in C or Assembler.

I'm still up to my neck in Resource macros - they work great but programming in them can be a nightmare.  I wasted a whole Sunday's worth of "quality Amiga time" the weekend before last trying to track down why some macros worked sometimes and not others.  The tip in the docs of using Resource itself to extract the binary from a load file was the culprit.  AmigaDOS  saves in multiples of longwords, so sometimes there's and extra zero word at the end which makes Resource think it's hit the next macro in the list and lock-up or Guru follows...  Laugh?  I could have cried.   :-[

Anyways, enough idle (sic) chit chat.  I'll have a look as soon as the Resource work is out of the way and we've got sources for all Lonewolf10's extensions collection.  (Which all helps me understand how people have used amos.library and AMOSPro.Lib so's none of the bug fixes or enhancement thought bubbles will stuff anything up.)  So, if you'll excuse the cliché, "I'll get back to you."  ;)