rush6432 Posted December 29, 2011 Report Share Posted December 29, 2011 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. Link to comment Share on other sites More sharing options...
SCPCD Posted December 29, 2011 Report Share Posted December 29, 2011 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 Link to comment Share on other sites More sharing options...
rush6432 Posted December 29, 2011 Author Report Share Posted December 29, 2011 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 Link to comment Share on other sites More sharing options...
rush6432 Posted December 30, 2011 Author Report Share Posted December 30, 2011 Just thought i'd report back here and say that it works Thanks for pointing out what needed to be changed. Very much appreciated. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now