+atari2600land Posted June 7, 2006 Share Posted June 7, 2006 (edited) Whenever I have an item (in this example player1) scrolling down and I put a line of code that says: if collision(player0,player1) then score=score + 1 : goto whatever how come the only way to make the collision have less than one score is by having both sprites be 1 pixel in height? It always is like score+6 or 7 or 8 when it finally decides to go to whatever? And how do I stop this? Edited June 7, 2006 by atari2600land Quote Link to comment Share on other sites More sharing options...
+Atarius Maximus Posted June 7, 2006 Share Posted June 7, 2006 (edited) Whenever I have an item (in this example player1) scrolling down and I put a line of code that says: if collision(player0,player1) then score=score + 1 : goto whatever how come the only way to make the collision have less than one score is by having both sprites be 1 pixel in height? It always is like score+6 or 7 or 8 when it finally decides to go to whatever? And how do I stop this? That's because every time the car scrolls down one pixel and the two sprites are still touching each other, it registers another collision, for all 6 or 7 pixels of your sprite (the approximate height of your sprite). You could try adding another condition to the collision, like checking the Y value of the enemy car in addition to the collision state: If b>90 && collision(player0,player1) then score=score+1 -- that might work. You'll have to experiment a little bit, and that value of 90 is just a guess. Steve Edited June 7, 2006 by Atarius Maximus Quote Link to comment Share on other sites More sharing options...
+batari Posted June 7, 2006 Share Posted June 7, 2006 Whenever I have an item (in this example player1) scrolling down and I put a line of code that says: if collision(player0,player1) then score=score + 1 : goto whatever how come the only way to make the collision have less than one score is by having both sprites be 1 pixel in height? It always is like score+6 or 7 or 8 when it finally decides to go to whatever? And how do I stop this? It adds one point per frame as long as the two objects are still colliding. To avoid this, you can set a variable that ignores collisions until the objects are no longer colliding. For example: if z=0 && collision(player0,player1) then score=score + 1 : z=1: goto whatever if !collision(player0,player1) then z=0 I think this will work, though if you run out of variables, you should use a single bit instead of a whole variable. Quote Link to comment Share on other sites More sharing options...
+atari2600land Posted June 7, 2006 Author Share Posted June 7, 2006 (edited) For some reason neither are working. I'll add some of the code around the problem. 1000 rem maingame 1001 AUDV0 = 0 : f=f+1 1005 x = 40 : y = 70 : a = 40 : b = 2 : g = 4 1007 scorecolor = 68 1008 score = 1 1040 COLUP0 = 66 : COLUP1 = 30 1042 if g=0 then goto 1272 1050 COLUBK = 16 1060 player0: %00000000 %01110000 %01010000 %00000000 %00100000 %00000000 %01010000 %00000000 end 1070 player1: %01100000 %10000000 %10000000 %10000000 %10000000 %01110000 end 1080 if b < 99 then 1110 1090 a = rand if a>=85 && b>99 then a = 49:s=0 if a>=170 && b>99 then a = 53:s=0 if a>=255 && b>99 then a = 59:s=0 1110 player0x = x : player0y = y : player1x = a : player1y = b 1120 b=b+1 1188 drawscreen 1190 if joy0left then x = x - 1 if x<20 then x=20 if x>80 then x=80 1200 if joy0right then x = x + 1 if x<20 then x=20 if x>80 then x=80 1258 rem : THIS IS WHERE I'M HAVING THE PROBLEM. 1259 if y=63 && collision(player0,player1) then score=score + 1 1261 goto 1040 1272 drawscreen 1279 COLUBK =212 1290 if !switchreset then goto 1272 Or maybe I'm typing them in wrong. Also, if there isn't a collision, I want g to decrease by 1 (g=g-1). Edited June 8, 2006 by atari2600land Quote Link to comment Share on other sites More sharing options...
+atari2600land Posted June 8, 2006 Author Share Posted June 8, 2006 (edited) Problem partly solved. It was: 1259 if b=70 && collision(player0,player1) then goto 1042 then I added 2 lines after 1040 that say: 1041 goto 1050 1042 score=score+1 but how can I get g to decrease by 1 with every non collision, and tell it to go to the game over sequence when it reaches 0? Edited June 8, 2006 by atari2600land Quote Link to comment Share on other sites More sharing options...
MausBoy Posted June 8, 2006 Share Posted June 8, 2006 It seems to me like you aren't referencing help.html for the answers you are looking for. putting an "!" before collision means "if not" instead of "if", so; if b=0 && collision(player0,player1) then b = 1 : score = score + 1 if !collision(player0,player1) then b = 0 These commands together do the following: 1 check to see if b is 0 2 if it is, check to see if player0 and player1 are touching 3 if they are, then change b's value to 1 and add 1 to the score 4 check to see if player0 and player are NOT touching 5 if not, change b's value to 0 You should be able to follow the logic in that to see that this means that if player0 and player1 touch, 1 is added to the score then a flag is set. this flag dosnt turn off until player0 and player1 are no longer touching, so no more points are added to the score until that has happened and they have touched again. Does that make sense? Cuz it's confusing me now. I think: if b = 0 && collision(player0,player1) then b = 1 : score = score + 1 else b = 0 does the same thing. Quote Link to comment Share on other sites More sharing options...
+batari Posted June 8, 2006 Share Posted June 8, 2006 It seems to me like you aren't referencing help.html for the answers you are looking for. putting an "!" before collision means "if not" instead of "if", so; if b=0 && collision(player0,player1) then b = 1 : score = score + 1 if !collision(player0,player1) then b = 0 These commands together do the following: 1 check to see if b is 0 2 if it is, check to see if player0 and player1 are touching 3 if they are, then change b's value to 1 and add 1 to the score 4 check to see if player0 and player are NOT touching 5 if not, change b's value to 0 You should be able to follow the logic in that to see that this means that if player0 and player1 touch, 1 is added to the score thenbe set a flag is set. this flag dosnt turn off until player0 and player1 are no longer touching, so no more points are added to the score until that has happened and they have touched again. Does that make sense? Cuz it's confusing me now. I think: if b = 0 && collision(player0,player1) then b = 1 : score = score + 1 else b = 0 does the same thing. Not quite. With mine, b will equal one until no collision is occuring, then it will be zero. With the one you suggested, b will equal one only until the next frame, regardless of any collision. 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.