Jump to content

Photo

sprite collision questions (DPC)


4 replies to this topic

#1 Muddyfunster ONLINE  

Muddyfunster

    Chopper Commander

  • 237 posts

Posted Wed Dec 26, 2018 7:36 AM

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.

 

 

 



#2 Lewis2907 OFFLINE  

Lewis2907

    Moonsweeper

  • 303 posts
  • Location:Senatobia, MS

Posted Wed Dec 26, 2018 7:41 AM

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/...ttach_id=472376

#3 Random Terrain OFFLINE  

Random Terrain

    Visual batari Basic User

  • 28,815 posts
  • Controlled Randomness
    Replay Value
    Nonlinear
  • Location:North Carolina (USA)

Posted Wed Dec 26, 2018 8:31 AM

Isn't negative 16 above 200? If so, try something like this:

 

   if player0y < 17 || player0y > 200 then goto __skip_collision_check


#4 bogax OFFLINE  

bogax

    Dragonstomper

  • 787 posts

Posted Wed Dec 26, 2018 8:40 AM



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 :

 

attachicon.gifsprite 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 by bogax, Wed Dec 26, 2018 8:45 AM.


#5 Muddyfunster ONLINE  

Muddyfunster

    Chopper Commander

  • Topic Starter
  • 237 posts

Posted Wed Dec 26, 2018 1:02 PM

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 !






0 user(s) are browsing this forum

0 members, 0 guests, 0 anonymous users