+Muddyfunster Posted December 26, 2018 Share Posted December 26, 2018 Hi all, I've been working on a new project and I've run into a problem that I'm struggling to work around. I'm using the DPC+ Kernel and have an issue with sprite collision. I understand the constraints of working with virtual sprites in that they are all basically copies of p1. My problem is to do with checking for collisions between these virtual sprites and player 0. I've drawn a little picture to illustrate : Playfield is represented by the red box, Green is "off screen" Blue circles are "player8" virtual sprite and are used to show lives left Player 0 enters from the top of the screen and exits the bottom and can move left and right. when player 0 re-enters at the top he inherits the X position where he exited. My problem occurs because player0 can hit player 8, triggering a collision and a loss of a life. Player0 starts off with his Y variable set to -16 so that he is offscreen and uses an 8.8 variable for movement for both X and Y axis I tried a simple : if player0y < 17 then goto skip_collision_check My logic is this check should cover everything below 0 and everything up to y becoming = 17 (0 + the size of the sprite) This works with the sprite is fully visible on the playfield but not when part of the sprite is offscreen. i've tried gating the collision check every way I can think of but it looks like the IF statement isn't seeing a negative y co-ordinate as being less than 0. Any ideas or suggestions would be appreciated. Quote Link to comment Share on other sites More sharing options...
+Lewis2907 Posted December 26, 2018 Share Posted December 26, 2018 This may help. I was using DPC for this, I came close to your want your asking I think. Hope this helps. http://atariage.com/forums/index.php?app=core&module=attach§ion=attach&attach_id=472376 Quote Link to comment Share on other sites More sharing options...
+Random Terrain Posted December 26, 2018 Share Posted December 26, 2018 Isn't negative 16 above 200? If so, try something like this: if player0y < 17 || player0y > 200 then goto __skip_collision_check Quote Link to comment Share on other sites More sharing options...
bogax Posted December 26, 2018 Share Posted December 26, 2018 (edited) Hi all, I've been working on a new project and I've run into a problem that I'm struggling to work around. I'm using the DPC+ Kernel and have an issue with sprite collision. I understand the constraints of working with virtual sprites in that they are all basically copies of p1. My problem is to do with checking for collisions between these virtual sprites and player 0. I've drawn a little picture to illustrate : sprite explanation.png Playfield is represented by the red box, Green is "off screen" Blue circles are "player8" virtual sprite and are used to show lives left Player 0 enters from the top of the screen and exits the bottom and can move left and right. when player 0 re-enters at the top he inherits the X position where he exited. My problem occurs because player0 can hit player 8, triggering a collision and a loss of a life. Player0 starts off with his Y variable set to -16 so that he is offscreen and uses an 8.8 variable for movement for both X and Y axis I tried a simple : if player0y < 17 then goto skip_collision_check My logic is this check should cover everything below 0 and everything up to y becoming = 17 (0 + the size of the sprite) This works with the sprite is fully visible on the playfield but not when part of the sprite is offscreen. i've tried gating the collision check every way I can think of but it looks like the IF statement isn't seeing a negative y co-ordinate as being less than 0. Any ideas or suggestions would be appreciated. The processor (and therfore bB) doesn't really know about negative numbers You can subtract and there is a flag for negative numbers. The flag reflects the state of of bit 7 (There's also an overflow flag which is (the carry from bit 6) ^ (the carry from bit 7)) (It's a pity that bB doesn't give you access to the flags) But it's really how you interpret the numbers (go read about 2's complement (Wikipedia)) Your bytes go from 0..255 255 = -1, n + 255 = n - 1 (this is all MOD 256) if you want a range of say -17 to +17, your if statement would be something like If x >= 239 && x <= 17 then and in bB you can write that as if x >= -17 && x <= 17 then 239 = 256 - 17 Using 239 takes less time and code Edited December 26, 2018 by bogax Quote Link to comment Share on other sites More sharing options...
+Muddyfunster Posted December 26, 2018 Author Share Posted December 26, 2018 Lewis, thanks for the code example, RT, Your code tweak was actually perfect and with Bogax's additional guidance I understand more clearly now where I was going wrong. Thanks a lot ! 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.