Jump to content
IGNORED

Counter Problem


frankodragon

Recommended Posts

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

post-18158-0-67847700-1420781899_thumb.jpg

 

 

Is there a way to just keep this as a one-time event?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 by PacManPlus
  • Like 2
Link to comment
Share on other sites

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.

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