Jump to content
Jagware
Sign in to follow this  
rush6432

Collision

Recommended Posts

rush6432    0

So i quickly wrote a small bounding box collision setup somewhat here. having trouble getting it to work. am i doing something wrong thats totally obvious?? A second or third pair of eyes is greatly appreciated :)

(forgive the clr commands, just a bit picky on making sure registers are "clean" before use :) )

collision:

clr.w d0

clr.w d1

move.w OBJ1X,d0

add.w OBJ1W,d0

move.w OBJ2X,d1

cmp.w d0,d1

blt .none

 

clr.w d0

clr.w d1

move.w OBJ1X,d0

move.w OBJ2X,d1

add.w OBJ2W,d1

cmp.w d0,d1

bgt .none

 

clr.w d0

clr.w d1

move.w OBJ1Y,d0

add.w OBJ1H,d0

move.w OBJ2Y,d1

cmp.w d0,d1

blt .none

 

clr.w d0

clr.w d1

move.w OBJ1Y,d0

add.w OBJ1H,d0

move.w OBJ2Y,d1

cmp.w d0,d1

blt .none

 

clr.w d0

clr.w d1

move.w OBJ1Y,d0

move.w OBJ2Y,d1

add.w OBJ2H,d1

cmp.w d0,d1

bgt .none

 

move.w #$FFFF,BG

rts

.none:

move.w #$0000,BG

rts

 

 

 

all defined variables (OBJ1H,OBJ1W,OBJ2H,OBJ2W,OBJ1X,OBJ1Y, ECT ECT are all defined as words.)

the x and y locations of objects are directly tied to an objects position in the list and the height/width are defined elsewhere as words.

Seems like the bgt/blt commands are not working... or im just overlooking something stupid.

 

Basically it checks if its below or above on x and y axis to determine if its hitting the object and if it is it changes background from black to white

 

I did write this snippet quickly here so forgive any errors but i feel like i'm majorly overlooking the simplest thing here as to why it wont work.

Share this post


Link to post
Share on other sites
SCPCD    0

collision:
    clr.w d0
    clr.w d1
    move.w OBJ1X,d0
    add.w OBJ1W,d0
    move.w OBJ2X,d1
    cmp.w d0,d1
    blt .none; if OBJ2X < (OBJ1X+OBJ1W) goto .none => should be if OBJ2X > (OBJ1X+OBJ1W) goto .none

    clr.w d0
    clr.w d1
    move.w OBJ1X,d0
    move.w OBJ2X,d1
    add.w OBJ2W,d1
    cmp.w d0,d1
    bgt .none; if (OBJ2X+OBJ2W) > OBJ1X goto .none => should be if (OBJ2X+OBJ2W) < OBJ1X goto .none

    clr.w d0
    clr.w d1
    move.w OBJ1Y,d0
    add.w OBJ1H,d0
    move.w OBJ2Y,d1
    cmp.w d0,d1
    blt .none; if OBJ2Y < (OBJ1Y+OBJ1H) goto .none => should be if OBJ2Y > (OBJ1Y+OBJ1H) goto .none

    clr.w d0
    clr.w d1
    move.w OBJ1Y,d0
    add.w OBJ1H,d0
    move.w OBJ2Y,d1
    cmp.w d0,d1
    blt .none; if OBJ2Y < (OBJ1Y+OBJ1H) goto .none (why do it again ? :p)

    clr.w d0
    clr.w d1
    move.w OBJ1Y,d0
    move.w OBJ2Y,d1
    add.w OBJ2H,d1
    cmp.w d0,d1
    bgt .none; if (OBJ2Y+OBJ2H) > OBJ1Y goto .none => should be if (OBJ2Y+OBJ2H) < OBJ1Y goto .none

    move.w #$FFFF,BG
    rts
    
.none:
    move.w #$0000,BG
    rts

 

"cmp" computes: destination - source => condition code.

To check if destination > source :

    cmp src, dst
    bgt   dst_greater_than_src

To check if destination < source :

    cmp    src, dst
    blt    dst_lower_than_src

 

:)

Share this post


Link to post
Share on other sites
rush6432    0
collision:
    clr.w d0
    clr.w d1
    move.w OBJ1X,d0
    add.w OBJ1W,d0
    move.w OBJ2X,d1
    cmp.w d0,d1
    blt .none; if OBJ2X < (OBJ1X+OBJ1W) goto .none => should be if OBJ2X > (OBJ1X+OBJ1W) goto .none

    clr.w d0
    clr.w d1
    move.w OBJ1X,d0
    move.w OBJ2X,d1
    add.w OBJ2W,d1
    cmp.w d0,d1
    bgt .none; if (OBJ2X+OBJ2W) > OBJ1X goto .none => should be if (OBJ2X+OBJ2W) < OBJ1X goto .none

    clr.w d0
    clr.w d1
    move.w OBJ1Y,d0
    add.w OBJ1H,d0
    move.w OBJ2Y,d1
    cmp.w d0,d1
    blt .none; if OBJ2Y < (OBJ1Y+OBJ1H) goto .none => should be if OBJ2Y > (OBJ1Y+OBJ1H) goto .none

    clr.w d0
    clr.w d1
    move.w OBJ1Y,d0
    add.w OBJ1H,d0
    move.w OBJ2Y,d1
    cmp.w d0,d1
    blt .none; if OBJ2Y < (OBJ1Y+OBJ1H) goto .none (why do it again ? :p)

    clr.w d0
    clr.w d1
    move.w OBJ1Y,d0
    move.w OBJ2Y,d1
    add.w OBJ2H,d1
    cmp.w d0,d1
    bgt .none; if (OBJ2Y+OBJ2H) > OBJ1Y goto .none => should be if (OBJ2Y+OBJ2H) < OBJ1Y goto .none

    move.w #$FFFF,BG
    rts
    
.none:
    move.w #$0000,BG
    rts

 

"cmp" computes: destination - source => condition code.

To check if destination > source :

    cmp src, dst
    bgt   dst_greater_than_src

To check if destination < source :

    cmp    src, dst
    blt    dst_lower_than_src

 

:)

 

AHhh. extra cpy of routine in there ;) i did that this morning at around 7am with no coffee at work in 5 mins so i was going from memory what i had written at home.

 

THanks for the input and clearing that up. ill have to make some adjustments at home to the code and report back :)

 

Share this post


Link to post
Share on other sites
Guest
You are commenting as a guest. If you have an account, please sign in.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoticons maximum are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×