Ultimate Amiga

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1] 2   Go Down

Author Topic: AMOS - Collision detection with background  (Read 16013 times)

0 Members and 1 Guest are viewing this topic.

wojt_gl

  • A600
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 10
  • Generic Amiga User
AMOS - Collision detection with background
« 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!
Logged
- A500 + 8MB + 0,5MB + HxC
- A1200 + CF +Mtec 8mb/28MHz
- C64 + sd2iec + 1541 II
- (C116, C16, NES, PEGASUS, Atari, Atari 2600, Sega...)

bruceuncle

  • AMOS Dev
  • A500
  • *****
  • Karma: 6
  • Offline Offline
  • Gender: Male
  • Posts: 425
  • WINUAE Amiga User
Re: AMOS - Collision detection with background
« Reply #1 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) 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) for more info.

Hope this helps.  ;)
Logged
Repeat after me ...  "The AMOS Pro architecture is complex but it is not complicated."

wojt_gl

  • A600
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 10
  • Generic Amiga User
Re: AMOS - Collision detection with background
« Reply #2 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.
Logged
- A500 + 8MB + 0,5MB + HxC
- A1200 + CF +Mtec 8mb/28MHz
- C64 + sd2iec + 1541 II
- (C116, C16, NES, PEGASUS, Atari, Atari 2600, Sega...)

wojt_gl

  • A600
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 10
  • Generic Amiga User
Re: AMOS - Collision detection with background
« Reply #3 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...)?
Logged
- A500 + 8MB + 0,5MB + HxC
- A1200 + CF +Mtec 8mb/28MHz
- C64 + sd2iec + 1541 II
- (C116, C16, NES, PEGASUS, Atari, Atari 2600, Sega...)

bruceuncle

  • AMOS Dev
  • A500
  • *****
  • Karma: 6
  • Offline Offline
  • Gender: Male
  • Posts: 425
  • WINUAE Amiga User
Re: AMOS - Collision detection with background
« Reply #4 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
Logged
Repeat after me ...  "The AMOS Pro architecture is complex but it is not complicated."

Lonewolf10

  • AMOS Extensions Developer
  • AMOS Dev
  • A2000
  • *****
  • Karma: 3
  • Offline Offline
  • Gender: Male
  • Posts: 618
    • http://www.aliensrcooluk.com
Re: AMOS - Collision detection with background
« Reply #5 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.
« Last Edit: February 28, 2013, 08:18:58 PM by Lonewolf10 »
Logged

bruceuncle

  • AMOS Dev
  • A500
  • *****
  • Karma: 6
  • Offline Offline
  • Gender: Male
  • Posts: 425
  • WINUAE Amiga User
Re: AMOS - Collision detection with background
« Reply #6 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:
  • 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!)
Logged
Repeat after me ...  "The AMOS Pro architecture is complex but it is not complicated."

Hungry Horace

  • Amorphous Blue-Blob Man
  • Site Admin
  • A4000T
  • ******
  • Karma: 307
  • Offline Offline
  • Gender: Male
  • Posts: 3,364
  • Don't forget... Ameboid's need love too!
    • AUW
Re: AMOS - Collision detection with background
« Reply #7 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?
Logged
Quote from: KillerGorilla
because winuae is made of code and your amiga is made of stuff

bruceuncle

  • AMOS Dev
  • A500
  • *****
  • Karma: 6
  • Offline Offline
  • Gender: Male
  • Posts: 425
  • WINUAE Amiga User
Re: AMOS - Collision detection with background
« Reply #8 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
Logged
Repeat after me ...  "The AMOS Pro architecture is complex but it is not complicated."

Lonewolf10

  • AMOS Extensions Developer
  • AMOS Dev
  • A2000
  • *****
  • Karma: 3
  • Offline Offline
  • Gender: Male
  • Posts: 618
    • http://www.aliensrcooluk.com
Re: AMOS - Collision detection with background
« Reply #9 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.
Logged

HonestFlames

  • A600
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 31
Re: AMOS - Collision detection with background
« Reply #10 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?
Logged

SamuraiCrow

  • compile-time wierdo
  • Forum Mod
  • A1200
  • *****
  • Karma: 5
  • Offline Offline
  • Gender: Male
  • Posts: 946
  • Compile-time wierdo
Re: AMOS - Collision detection with background
« Reply #11 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.
Logged

HonestFlames

  • A600
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 31
Re: AMOS - Collision detection with background
« Reply #12 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
Logged

SamuraiCrow

  • compile-time wierdo
  • Forum Mod
  • A1200
  • *****
  • Karma: 5
  • Offline Offline
  • Gender: Male
  • Posts: 946
  • Compile-time wierdo
Re: AMOS - Collision detection with background
« Reply #13 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.
Logged

HonestFlames

  • A600
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 31
Re: AMOS - Collision detection with background
« Reply #14 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.
Logged
Pages: [1] 2   Go Up
 

TinyPortal 2.2.2 © 2005-2022