Jump to content
IGNORED

Collision Detection With Virtual Sprite NUSIZ Copies


KevKelley

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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.

 

 

BBPv031919.bas

Link to comment
Share on other sites

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.

 

BBPv031919_2.bas

 

 

 

 

 

 

 

 

Edited by Lillapojkenpåön
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji 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.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...