Jump to content

Photo

Collision Detection With Virtual Sprite NUSIZ Copies


11 replies to this topic

#1 KevKelley OFFLINE  

KevKelley

    Chopper Commander

  • 213 posts
  • Lots of hobbies, little time, loads of fun.
  • Location:Orlando

Posted Sun Mar 17, 2019 8:40 PM

I had been playing around with NUSIZ copies of some of the virtual sprites but I can't quite figure out how to get collision detection to work for them.

 

Basically this is the code:

 if collision(player0,player3) then goto _CAR_HIT

 rem player collision with right car
 if collision(player0,player8) then goto _CAR_HIT

 rem player collision with car------------------------------------------------------------------------------------------------------------------
 if collision(player0,player2) then goto _CAR_HIT

 rem player collision with truck
 if collision(player0,player5) then goto _CAR_HIT else goto _SKIP_CAR_HIT

_CAR_HIT

 player0y=32 : player0x = 73
 AUDV1=15: AUDC1 = 3 : AUDF1 = 29 
 player1y=170 : player1x=rand
 pfscore1 = pfscore1/4
_SKIP_CAR_HIT

I understand that the virtual sprites are copies of player1 so I tried doing some kind of check for collision with that sprite.  I got collision detection to work with the NUSIZ copies but then player0 collides with everything else not as intended. 

 

I looked through some of the sample code, like the DPC+ shooting NUSIZ copies program to see if I can try to understand but I had a hard time following the code (but I kind of understand the principle). I was wondering if there is some underlying principle or idea to check collision between player0 and the copies.



#2 Lewis2907 OFFLINE  

Lewis2907

    Moonsweeper

  • 324 posts
  • Location:Senatobia, MS

Posted Mon Mar 18, 2019 5:08 AM

http://atariage.com/...ttach_id=530879

I used collision detection for all the sprites in DPC. I have notes in the programs to help as well. Hopes this helps, thanks.

#3 KevKelley OFFLINE  

KevKelley

    Chopper Commander

  • Topic Starter
  • 213 posts
  • Lots of hobbies, little time, loads of fun.
  • Location:Orlando

Posted Mon Mar 18, 2019 6:24 AM

I'll check it out. I've been doing trial and error to see what works. That led me to simplify some code. I was trying to figure out a way for my game to check if the collision was with the real player1 or a virtual Sprite first. I think I have an idea but wasn't sure if I was missing something. This has kind of been stumping me for a little bit.

#4 KevKelley OFFLINE  

KevKelley

    Chopper Commander

  • Topic Starter
  • 213 posts
  • Lots of hobbies, little time, loads of fun.
  • Location:Orlando

Posted Mon Mar 18, 2019 12:36 PM

I was playing around with it some more.  I wasn't quite sure when looking at the code you posted so I continued to do some trial and error and kind of got it working with the following:

 rem player/car collision -------------------------------------------------------------------------------------------------------------------------

 if collision(player0,player1) then goto _CAR_HIT 

 rem player collision with truck

 if collision(player0,player3) then goto _CAR_HIT

 rem player collision with right car
 if collision(player0,player8) then goto _CAR_HIT

 rem player collision with car------------------------------------------------------------------------------------------------------------------
 if collision(player0,player2) then goto _CAR_HIT

 rem player collision with truck
 if collision(player0,player5) then goto _CAR_HIT else goto _SKIP_CAR_HIT
 
_CAR_HIT
 if player0x <= player1x + 8 && player0x + 8 >= player1x && player1y + player1height >= player0y && player1y <= player0y + player0height then goto _SKIP_CAR_HIT 
 if collision(player0,player4) then goto _SKIP_CAR_HIT
 if collision(player0,player6) then goto _SKIP_CAR_HIT
 if collision(player0,player7) then goto _SKIP_CAR_HIT

 player0y=32 : player0x = 73
 AUDV1=15: AUDC1 = 3 : AUDF1 = 29 
 player1y=170 : player1x=rand
 pfscore1 = pfscore1/4
_SKIP_CAR_HIT

This didn't work all the time.  I noticed it still detected collision between the other virtual sprites when I would touch them from the left.  I assume this has to deal with how the sprites are drawn on the screen so I expanded the bounding box by one and changed the checks to this:

 if player0x <= player1x + 15 && player0x + 15 >= player1x && player1y + (player1height+9) >= player0y && player1y <= (player0y + 19) then goto _SKIP_CAR_HIT 
 if player0x <= player4x + 15 && player0x + 15 >= player4x && player4y + (player4height+9) >= player0y && player4y <= (player0y + 19) then goto _SKIP_CAR_HIT
 if player0x <= player6x + 15 && player0x + 15 >= player6x && player6y + (player6height+9) >= player0y && player6y <= (player0y + 19) then goto _SKIP_CAR_HIT
 if player0x <= player7x + 15 && player0x + 15 >= player7x && player7y + (player7height+9) >= player0y && player7y <= (player0y + 19) then goto _SKIP_CAR_HIT 

And it seemed to work fine for the most part, with pretty much all interactions working as intended.  I am still testing it out but I have only had a couple unintended collisions with the virtual sprites (I had created bigger bounding boxes to try and reduce this) and  when player0 and player1 collision is detected and player0 captures player1, player1 collision with the players2-8 kind of overrides. So when player0 has player1, player0 collision isn't detected and player0 may overlap a little with the car sprites. 

 

I keep tweaking the code to see if this is a good way to move ahead or if I should find another way to check collision.


Edited by KevKelley, Mon Mar 18, 2019 12:36 PM.


#5 Lewis2907 OFFLINE  

Lewis2907

    Moonsweeper

  • 324 posts
  • Location:Senatobia, MS

Posted Mon Mar 18, 2019 2:26 PM

You have the adjust the + 15 and sometimes it can be - 4 etc. It took me a while to adjust to the correct info as the Sprite it was hitting and for wall collision as well

#6 KevKelley OFFLINE  

KevKelley

    Chopper Commander

  • Topic Starter
  • 213 posts
  • Lots of hobbies, little time, loads of fun.
  • Location:Orlando

Posted Mon Mar 18, 2019 3:16 PM

I started at 8. I just went larger to see if that would help but my battery was dying so I didn't fully test it but it seemed to improve so when the kids go down I plan on straining my brain some more.

The only other thing I had considered was that the only place copies would exist are on the x-axis for the different cars so I thought about using that somehow. Either way it is a learning experience.

The issue regarding player0 collision when player1 is captured I think might be better for gameplay. Normally, collision occurs when any part of player0 hits a Sprite but I kind of feel this way gives a little dimension and improves flexibility - when I play on emulation squeezing between two cars is really tight. Using a joystick might be much harder.

#7 Lillapojkenpćön OFFLINE  

Lillapojkenpćön

    Chopper Commander

  • 195 posts

Posted Mon Mar 18, 2019 5:46 PM

Do you have two or three copies?

Wide or normal spacing between them?

Do you want the nusiz copy that's colliding with something to dissapear or will it stay on screen?

How many virtual sprites would you like to behave like that?



#8 KevKelley OFFLINE  

KevKelley

    Chopper Commander

  • Topic Starter
  • 213 posts
  • Lots of hobbies, little time, loads of fun.
  • Location:Orlando

Posted Mon Mar 18, 2019 6:06 PM

For now I had 2 copies of one. They don't disappear. Basically they are an obstacle that can kill player0, similar to the crossing cars in frogger. Eventually I will have some with 2 or 3 copies (possibly 2 others).

#9 Lillapojkenpćön OFFLINE  

Lillapojkenpćön

    Chopper Commander

  • 195 posts

Posted Mon Mar 18, 2019 7:16 PM

 This example demonstrates if player0 and player1 is eight pixels wide and player1 is the nusiz copies

 

 if !collision(player0,player1) then _skip 

if ( player0y + player0height ) >= player1y && player0y<= ( player1y + player1height ) then gosub _whichcopy      ; first check if they are overlapping vertically, if they are gosub to the horisontal check (which copy)

 

_skip 

 

_whichcopy ; put this outside of the loop

 if ( player0x + 8 ) >= player1x && player0x <= ( player1x + 8 )  then something : return thisbank 
 if ( player0x + 8 ) >= ( player1x + 32 ) && player0x <= ( player1x + 40 ) then something     ; second copy begins 32 pixels from player1x, if the graphic is eight pixels wide it would end 40 pixels in
 return thisbank 

Edited by Lillapojkenpćön, Mon Mar 18, 2019 7:19 PM.


#10 KevKelley OFFLINE  

KevKelley

    Chopper Commander

  • Topic Starter
  • 213 posts
  • Lots of hobbies, little time, loads of fun.
  • Location:Orlando

Posted Mon Mar 18, 2019 8:37 PM

I tried using your code somehow but I didn't know if I had tried to implement it correctly but it wasn't working.  The NUSIZ copy is on player3 (for now) but it seems like if I do not include a collision(player0,player1) statement somewhere it doesn't recognize the NUSIZ copy at all... but every attempt I had make at a check seems to work 80% of the time, so it makes me wonder if it is conflicting with other parts of my program...

 

The main reason for the NUSIZ copies of the virtual sprites is that I had planned on using them to increase difficulty at certain intervals (at x points two copies of truck, at y points 3 copies of car, etc.)

 

The attached file is the what I was currently working on.  

 

 

Attached Files



#11 Lillapojkenpćön OFFLINE  

Lillapojkenpćön

    Chopper Commander

  • 195 posts

Posted Mon Mar 18, 2019 9:58 PM

It probably has something to do with the wrap around, when you set player3x from 10 to 162 the second copy is visible on the left side as if its x position is around 40, but since we're checking player3x + 64 or + 72 (not 32 and 40 since you had wide spacing) the hitbox will be between x-position 162 + 64 and 162 + 72.. so way offscreen.

 

I can think of a couple solutions for that but this will have to do for now.

 

Attached File  BBPv031919_2.bas   23KB   9 downloads

 

 

 

 

 

 

 

 


Edited by Lillapojkenpćön, Mon Mar 18, 2019 10:40 PM.


#12 KevKelley OFFLINE  

KevKelley

    Chopper Commander

  • Topic Starter
  • 213 posts
  • Lots of hobbies, little time, loads of fun.
  • Location:Orlando

Posted Tue Mar 19, 2019 10:38 PM

I see what you meant with your code. It looks like that is probably the best way to go. I fiddled with it some more today and I think the reason why it seemed like my code would work most of the time is that it would run through the check sometimes working while other times move straight to the car hit code. I couldn't figure out a way to make it work. I added more checks which seemed to minimize the unintended collisions but I felt this did nothing more than bloat the program. I was hoping for a more simple collision code so I can add a few lines for the various different difficulties and be done with it, which is why I was so fixated on what I had entered.




0 user(s) are browsing this forum

0 members, 0 guests, 0 anonymous users