English Amiga Board

Go Back   English Amiga Board > Coders > Coders. General > Coders. Tutorials

Thread Tools
Old 15 August 2011, 03:27   #1
Registered User
Join Date: Nov 2010
Location: Italy
Posts: 307
[REQ:ASM] Sprite collisions basics


I can successfully check for collisions between S0+S1 against S4 enabling bit 12 only of CLXCON and then checking for bit 10 of CLXDAT.
However I don't understand why I can't detect S2 against S4. Only change I did is checking bit 12 of CLXDAT:

    moveq    #0,d1
    move.w    clxdat(a5),d1
    btst.l    #12,d1
    bne.s    do_this_and_that
I'm afraid I'm overlooking something really trivial because I've read over and over the AHRM and it looks very simple actually; this is why I'm not pasting any code but if it's needed...

Attached Thumbnails
Click image for larger version

Name:	collision.png
Views:	319
Size:	5.4 KB
ID:	29307  
jman is offline  
Old 15 August 2011, 09:45   #2

phx's Avatar
Join Date: Nov 2009
Location: Herford / Germany
Posts: 1,293
I remember I had some difficulties with clxcon as well, but that was 20 years ago.

One important thing is that you cannot read clxdat multiple times. The bits will be cleared and only become valid again after the video beam has drawn the next frame.
phx is offline  
Old 15 August 2011, 10:32   #3
Registered User
Join Date: May 2010
Location: Tintern/UK
Posts: 35
Slightly off topic - but would be interested to hear if anyone actually managed to make good use of sprite collision detection in a reasonably complex game - I always liked the idea but found it too restrictive to make work.
gggcumming is offline  
Old 15 August 2011, 12:03   #4
Registered User
Join Date: Nov 2010
Location: Italy
Posts: 307
Originally Posted by phx View Post
One important thing is that you cannot read clxdat multiple times. The bits will be cleared and only become valid again after the video beam has drawn the next frame.
You are right and I was stupid because even though I perfectly knew this I did check that register multiple times, silly me.
I have to copy the register content into a safe place (like I already do) and then forget about it.

@gggcumming: I must confess I'm ignorant on the subject. I thought that sprite collision routines were the base for _every_ amiga game, whenever one had to check (e.g.) for boundaries, collisions, paths and so on. Is my assumption wrong?

Last edited by jman; 18 August 2011 at 01:10.
jman is offline  
Old 15 August 2011, 23:10   #5
2 contact me: email only!

Codetapper's Avatar
Join Date: May 2001
Location: Auckland / New Zealand
Posts: 3,153
Most Amiga games do simple rectangle intersection for collisions, or testing a point in a rectangle. You can also use the blitter without a destination set to check for collisions.

If you relied on sprite collision, almost no Tiertex games would have collisions as they don't use sprites! Also when you re-use the sprite channels, I'm not sure how reliable the CLXDAT value is - as you could use the same sprite for enemy bullets and player bullets, and both player and enemy ships. Knowing which sprite hit the other would be a nightmare!
Codetapper is offline  
Old 03 September 2011, 01:07   #6
HD Installer
Harry's Avatar
Join Date: May 2010
Location: Hamburg/Germany
Posts: 828
In Fourmaze, also not all objects are sprites, and the game screen is 640 px wide, so i used a precompiled lookup table for pixel exact collision.
Usage of table is approximately like this:
//check if vertical match possible
if(((obj2.y+obj2.height)>obj1.y) && ((obj1.y+obj1.height)<obj2.y)){
  //check if horizontal match possible
  int tmpYOffset=obj1.y-obj2.y+obj2.height;
  //reserved value for no collision due bouncing objects (table uses same format/height for all animation frames)
  if((table1[frame][tmpYOffset]!=INT_MIN) &&
    //check if horizontal match occured
    (table1[frame][tmpYOffset]>(obj1.x-obj2.x)) && (table2[frame][tmpYOffset]<(obj2.x-obj1.x))){
    //your collision code here
Of course, you still have to write a piece of code where the tables are precompiled by checking where the masks of both objects overlap (for each frame). Contents of the tables is the starting and ending horizontal offset range in which the collision happens.

In each case one table is needed for each possible combination of player <-> enemy. This approach may result in some dozens of small tables, so most games go for the rectangle approach; some (like the flight sequence of Turrican 2) use rectangles smaller than the player object to prevent "telepathic" contact like it occurs in Beast1 (remember being hit by the jumping worms?).

Last edited by Harry; 03 September 2011 at 01:40. Reason: Second try of formatting
Harry is offline  

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
Basics of debugging ASM in WinUAE? bodhi Coders. Asm / Hardware 14 05 December 2017 07:50
[REQ] Mk2 Background and one Ninja sprite sandruzzo project.Sprites 0 05 April 2011 18:15
REQ:ASM How to use buffers jman Coders. Tutorials 7 01 December 2010 02:41
Disable Sprite Collisions DeAdLy_cOoKiE Retrogaming General Discussion 4 24 March 2006 18:56

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT +2. The time now is 10:09.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2019, vBulletin Solutions Inc.
Page generated in 0.06735 seconds with 14 queries