Jump to content
IGNORED

multisprite collision with x/y coordinate checking issues


chickenxhat

Recommended Posts

so i've been working on this one for a couple days, and have poured over both the code and forums and just can't figure out why it works sometimes but not all the time. maybe someone can check it out.

 

i've got routines that check if collision && if coordinates belong to each virtual sprite, and i'd like 4 out of 5 of them to be player-killing collisions, and the 5th to be point-adding collisions. i dont have the routine that adds points yet, just moving the 5th sprite to a random location on collision. i also have a routine that causes a shield to appear on joy0fire that causes the score to stop rolling up and will block the falling rocks. still working on that, but its coming together.

 

what actually occurs is that sometimes the 4 out of 5 sprites (falling rocks) don't actually return as a collision, and sometimes collisions with the 5th (a collectable rock) hurt the player. it seems that my routines are faulty, but the math makes sense to me. it should work! i don't understand why it doesn't! before i seek out another way to handle multiple sprites in my game i'd like to determine if there's a better way to do this. if i can't get it to work, i can't get this game to work either.

 

 

i think i did a decent job of adding comments on this .bas so it should be obvious what does what. any help or guidance or suggestions or revisions would be helpful.

 

 

edit: also, sometimes the collectible rock disappears and the only way to make it come back (even though it should have never disappeared) is to walk the length of playfield and it will show back up. weird. unintentional.

Moon.bas

Edited by chickenxhat
Link to comment
Share on other sites

well, seeing as no one is weighing in, i'm going to double-post with my findings.

 

here's the excerpt of code that handles collision detection with the player character and the 4 falling rocks in my game. i could use variables and clean it up and maybe some a couple bytes, but as i'm still learning vbB it helps me to actually see the objects written out.

 

 

 

 

 

rem player collisions

if collision(player0, player1) then pfscore2 = pfscore2/4 : goto __Start_Select

 

if collision(player0, player1) && player0y = player2y && player0x = player2x then pfscore2 = pfscore2/4 : goto __Start_Select

 

if collision(player0, player1) && player0y = player3y && player0x = player3x then pfscore2 = pfscore2/4 : goto __Start_Select

 

if collision(player0, player1) && player0y = player4y && player0x = player4x then pfscore2 = pfscore2/4 : goto __Start_Select

 

 

this code works sucks! originally player0,player1 collisions included an x/y check as well. apparently the virtual sprites are also player1, because the real player1's x and y weren't returning on those collisions, never registered as collisions.

 

so.. hope this helps someone in the future.

 

 

 

edit: well.. no. now this code doesn't differentiate between players 1-4 and player5. all sprite collisions are lethal. bah!

Edited by chickenxhat
Link to comment
Share on other sites

players 1-5 are player 1

 

the positions for players 1-5 are different from player0

that is, put one of the virtual sprites at some x, y and

player0 at the same x, y and they wont be in the same

place

 

if player0 is eight wide and player1 is eight wide

that gives you a range of 15 possible x positions

which would cause a collision

1 15

00000000 00000000

11111111

Link to comment
Share on other sites

i will absorb that information, and do thank you for it, but i feel as though i have not garnered a solution from your post. in the mean time, i'm exploring using the ball object instead of a separate virtual sprite, as differentiating between them is proving difficult or impossible for me.

Link to comment
Share on other sites

iirc the virtual sprites are offset by 8 from player0

in the x direction and by -2 in the y direction

so 0, 2 for player0 is 8, 0 for the virtual sprites

(I may have the sign wrong ie I may have the players

swapped)

so you'd do something like

x = player1x - 8 - player0x : y = player1y + 2 - player0y

if x<15 && y<15 then collision

for both player0 and player1 being 8x8 sprites

Link to comment
Share on other sites

thanks bogax. i'll explore that as well.

 

new question: what all standard collision arguments work in multisprite? i've got (player0,player1) working and (missile0,player1) working, but no other combinations. i know that (player?,player2-5) won't work, but why not combinations of missiles?

Link to comment
Share on other sites

here is my primitive multi collision detection that waists variables but it was the only way i could make it a for sure thing :P

 

b=player1x+1

g=player1x-3

i=player1y+1

l=player1y-7

n=player2x+1

o=player2x-3

q=player2y+1

r=player2y-7

u=player3x+1

y=player3x-3

w=player3y+1

h=player3y-7

if missile0x>g && missile0x<b && missile0y>l && missile0y<i then z=1

if missile0x>o && missile0x<n && missile0y>r && missile0y<q then z=2

if missile0x>y && missile0x<u && missile0y>h && missile0y<w then z=3

if z=1 then player1x=rand&150 : player1y=rand&90 : score=score+10 : p=p+1 : AUDV0=8 : AUDC0=8 : AUDF0=9

if z=2 then player2x=rand&90 : player2y=95 : score=score+10 : p=p+1 : AUDV0=8 : AUDC0=8 : AUDF0=9

if z=3 then player3x=rand&90 : player3y=0 : score=score+10 : p=p+1 : AUDV0=8 : AUDC0=8 : AUDF0=9

z=0

  • Like 1
Link to comment
Share on other sites

  • 1 year later...

Thank you Fothlyrdrag. Your collision detection works fine and helped me to solve my multisprite problem. but i only need 4 variables! use gosub! ok, now you have to do 2 gosubs for every multisprite player, but i need variables :)

 

Here is the listing. You will need it for player2, player3,4,5... too. If a collision happens, the ball/missile and player disapear.

 

gosub detectpl1
gosub detectpl1detail

gosub detectpl2
gosub detectpl2detail

 

detectpl1
u=player1x+1
v=player1x-7
w=player1y+1
x=player1y-7
return

detectpl1detail
if missile0x>v && missile0x<u && missile0y>x && missile0y<w then f = 0 : g = 0 : missile0x = 0 : missile0y = 0
if ballx>v && ballx<u && bally>x && bally<w then f = 0 : g = 0 : ballx = 0 : bally = 0

 

detectpl2
u=player2x+1
v=player2x-7
w=player2y+1
x=player2y-7
return

detectpl2detail
if missile0x>v && missile0x<u && missile0y>x && missile0y<w then j = 0 : k = 0 : missile0x = 0 : missile0y = 0
if ballx>v && ballx<u && bally>x && bally<w then j = 0 : k = 0 : ballx = 0 : bally = 0
return

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...