## Block- Man Script

The place for any Hollywood tutorials
Bugala
Posts: 1125
Joined: Sun Feb 14, 2010 7:11 pm

### Re: Block- Man Script

I think what you after with this one:

Code: Select all

``````elseif Collision(#BRUSH, 1, BM_XPos, BM_YPos, 2, BL_Xpos, BL_Ypos ) = True and BM_Xpos >= BL_Xpos
BM_XPos, BM_YPos = BM_XPos, BL_YPos - 16 ; Handle collision with top side of obstacle
DebugPrint("Hit The Top Side")
EndIf``````
Is actually:

Code: Select all

``elseif Collision(#BRUSH, 1, BM_XPos, BM_YPos, 2, BL_Xpos, BL_Ypos ) = True and BM_Ypos >= BL_Ypos + 32``

For in original version you were checking X-postition instead of Y-position
ocean77
Posts: 111
Joined: Mon Jan 28, 2019 8:34 pm

### Re: Block- Man Script

As far as I can tell each of the conditions do what they are supposed to, I just can't get them all to be considered. Just two at a time. I tested this by commenting out first the top two and then the bottom two.
Bugala
Posts: 1125
Joined: Sun Feb 14, 2010 7:11 pm

### Re: Block- Man Script

I think I can take tomorrow a better look. But didnt realise it yesterday yet, but seeing this again now I think I know what is likely the problem.

Thing is, you are assuming there are four different possibilities to collide. Left, Right, Top, Bottom.

But in reality you have only Two collisions happening, the first two: Left and Right.

For thing is, when you have collision that would fulfill TOP or BOTTOM, it will also at same time fulfill one of the LEFT or RIGHT conditions.

Thing is,

Code: Select all

``````IF Condition 1
ELSEIF Condition 2
ELSEIF Condition 3
ENDIF``````
Work in such way that if Condition 1 is fulfilled, then it doesnt even check Condition 2 and 3 at all.

So in this case you could have that Condition 2 (LEFT) and Condition 3 (BOTTOM) are both fulfilled, and in this case, only Condition 2 is executed, since it happens first in the list.

Since Collision in your code in practice always happens from two different sides at same time.

As an example:

Code: Select all

``````AAAAA
A   A
A   A
XXXXX
XAAAX
B   B
B   B
BBBBB
``````

You might think that Box B is hitting Box A from Bottom, which is true, but, B is also touching A from LEFT side, since they both have same X.

Therefore in your IF-ELSEIF-ELSEIF, it notices that condition of hitting from LEFT side is already true before it checks the BOTTOM, and hence the BOTTOM check is never checked or executed.
Bugala
Posts: 1125
Joined: Sun Feb 14, 2010 7:11 pm

### Re: Block- Man Script

Actually, to test this, try running this code:

Code: Select all

``````if Collision(#BRUSH, 1, BM_XPos, BM_YPos, 2, BL_Xpos, BL_Ypos ) = True and BM_Xpos =< BL_Xpos
BM_XPos, BM_YPos = BL_XPos - 16, BM_YPos ; Handle collision with left side of obstacle
DebugPrint("Hit The Left Side")
endif

if Collision(#BRUSH, 1, BM_XPos, BM_YPos, 2, BL_Xpos, BL_Ypos ) = True and BM_Xpos =< BL_Xpos + 32
BM_XPos, BM_YPos = BL_XPos + 32, BM_YPos ; Handle collision with right side of obstacle
DebugPrint("Hit The Right Side")
endif

if Collision(#BRUSH, 1, BM_XPos, BM_YPos, 2, BL_Xpos, BL_Ypos ) = True and BM_Ypos >= BL_Ypos
BM_XPos, BM_YPos = BM_XPos, BL_YPos + 32 ; Handle collision with bottom side of obstacle
DebugPrint("Hit The Bottom Side")
endif

if Collision(#BRUSH, 1, BM_XPos, BM_YPos, 2, BL_Xpos, BL_Ypos ) = True and BM_Xpos >= BL_Xpos
BM_XPos, BM_YPos = BM_XPos, BL_YPos - 16 ; Handle collision with top side of obstacle
DebugPrint("Hit The Top Side")
EndIf``````
Now it will check every condition and run those codes.

Basically I expect it to result in printing two conditions each time. One of LEFT-RIGHT and one of TOP-BOTTOM. Since every time there is a collision, two of those conditions will always be true if I checked right.
ocean77
Posts: 111
Joined: Mon Jan 28, 2019 8:34 pm

### Re: Block- Man Script

That doesn't work as intended.

If I reorganize them as follows:

Code: Select all

`````` if Collision(#BRUSH, 1, BM_XPos, BM_YPos, 2, BL_Xpos, BL_Ypos ) = True and BM_Xpos =< BL_Xpos
BM_XPos, BM_YPos = BL_XPos - 16, BM_YPos ; Handle collision with left side of obstacle
DebugPrint("Hit The Left Side")

elseif Collision(#BRUSH, 1, BM_XPos, BM_YPos, 2, BL_Xpos, BL_Ypos ) = True and BM_Ypos >= BL_Ypos
BM_XPos, BM_YPos = BM_XPos, BL_YPos + 32 ; Handle collision with bottom side of obstacle
DebugPrint("Hit The Bottom Side")

elseif Collision(#BRUSH, 1, BM_XPos, BM_YPos, 2, BL_Xpos, BL_Ypos ) = True and BM_Xpos >= BL_Xpos
BM_XPos, BM_YPos = BM_XPos, BL_YPos - 16 ; Handle collision with top side of obstacle
DebugPrint("Hit The Top Side")

elseif Collision(#BRUSH, 1, BM_XPos, BM_YPos, 2, BL_Xpos, BL_Ypos ) = True and BM_Xpos =< BL_Xpos + 32
BM_XPos, BM_YPos = BL_XPos + 32, BM_YPos ; Handle collision with right side of obstacle
DebugPrint("Hit The Right Side")

EndIf``````
Then all sides except the right one works... Well almost. The player still slips along the sides of the obstacle if it's too close to the corner.

I kind of want each of the obstacle's sides to trigger a separate event.