+frankodragon Posted January 9, 2015 Share Posted January 9, 2015 This is a problem I've been running into using boxcollision and score1: The player collects a fruit in which it boosts up his HP (score1) and it disappears. No problem with that. However, even with trying using labels, and then without, if the player stays in the spot where the fruit was, the HP counter keeps rising. if boxcollision(xpos,ypos,16,16,fruit_x,fruit_y,16,16)then fruit_check=1: score1=score1+10: fruit_x=200: fruit_y=200 if fruit_check=1 then fruit_y=200:score1=score1+0 if fruit_y=200 && boxcollision(xpos,ypos,16,16,fruit_x,fruit_y,16,16)then score1=score1+0 Is there a way to just keep this as a one-time event? Quote Link to comment Share on other sites More sharing options...
omf Posted January 9, 2015 Share Posted January 9, 2015 can you not get rid of the fruit once collected so that it cant be touched again? this would solve the problem. failing that set a flag with a value and check this value is not true on the next fruit touch check 2 Quote Link to comment Share on other sites More sharing options...
+frankodragon Posted January 9, 2015 Author Share Posted January 9, 2015 The fruit disappears when you touch it. It's the score1 that keeps going up even if the fruit is gone like an invisible hotspot. if boxcollision(xpos,ypos,16,16,fruit_x,fruit_y,16,16)then goto __fruit_get __fruit_get if boxcollision(xpos,ypos,16,16,fruit_x,fruit_y,16,16)then score1=score1+10:fruit_check=1: fruit_x=200: fruit_y=200:goto __skip_fruit_get __skip_fruit_get if fruit_check=1 then fruit_y=200 I'm wondering how I can set the score1 to not go any further than 10 points. Quote Link to comment Share on other sites More sharing options...
PacManPlus Posted January 9, 2015 Share Posted January 9, 2015 (edited) How are you making the fruit 'disappear'? Once you move the object off screen after you touch it (HPOS = $B0) or disable it (explained below) the bounding box should no longer work. This what I do: I have a variable called "OSLIST" as a byte array for each object. For my constant definitions I have this: OBJ_ACTIVE = $00 OBJ_DISABLED = $FF If there is a collision, I move "OBJ_DISABLED" to the other object's OSLIST (Object State LIST) and no longer dynamically add it to the Display List. (I also usually have some other states defined for each object) Then, in any routine that processes objects (animation, collision detection, etc.) in the processing loop the first thing I do is check if the object is active. If not, skip it. -or- Once there is a collision with an item, move that item off screen (GCC used $B0 for Ms. Pac-Man - like for the player collision with the fruit for example). It could be any position > $A0, of course. To me, those are the easiest ways to do it. Hope this helps, Bob *EDIT* - I missed the code up top where you are moving the fruit to y=200 - that should normally do it. maybe you have to call some sort of 'draw item' routine to make sure it's moved properly? Edited January 9, 2015 by PacManPlus 2 Quote Link to comment Share on other sites More sharing options...
RevEng Posted January 9, 2015 Share Posted January 9, 2015 The box collision doesn't work reliably with off-screen sprites, due to the code that's responsible for detecting collisions with a objects that are partially off the top screen. (ie. with a Y coordinate less than 0) To avoid making things very expensive cyclewise, I offset the coordinates used so the problematic zero boundary coordinate winds up being somewhere between the screen top and bottom. When an object straddles that off-screen zero boundary, the bounding box covers most of the screen. You could move the y to another off-screen position that doesn't straddle the boundary, like 220, but it would be better if you skipped the off-screen check and use a state variable like omf suggested. [edit] the docs in the next release will include this info. Quote Link to comment Share on other sites More sharing options...
+frankodragon Posted January 12, 2015 Author Share Posted January 12, 2015 Thanks for the suggestions, guys. Then I thought about replacing the fruit with another object like a jar so the player cannot sit on the hotspot. So far, that works. 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.