Headcannon Game Engine Script Commands - If Conditionals (Collision)
"If Blocks" test for certain conditions, and cause the code within to be processed only if
that condition is true. They start with any available "If" Command to define the condition,
and must be ended with an "EndIf" command.
If the condition is true,
processing continues through the code within the "If Block", through the "EndIf", and beyond.
If the condition is not true, the code within the Block is skipped, and processing
resumes with the Command that immediately follows that Block's "EndIF".
Also available is the "Else" Command, which causes code to execute when the
condition is not true. An "IF"/"Else"/"EndIf" Block starts with the desired "IF" Command,
followed by code to execute if the condition is true, and then the "Else" Command, followed by the
code to execute if the condition is not true, and finally, the "EndIf" Command.
Index:
Player Overlap Collision IFs:
(D) (E) | _If(Object_Collide_Player) |
(D) (E) | _If(Object_Offset_Collide_Player) |
(D) (E) | _If(PlayerBound_Inside_Object) |
Player TouchCollision IFs:
(D) (E) | _If(Player_Touch_Object) |
(D) (E) | _If(Player_Impact_Object) |
Projectile Overlap Collision IFs:
(D) (E) | _If(Object_Collide_Projectile) |
(D) (E) | _If(Object_Offset_Collide_Projectile) |
Projectile Touch Collision IFs:
(D) (E) | _If(Projectile_Touch_Object) |
(D) (E) | _If(Projectile_Impact_Object) |
Collision Axis Test IFs:
(D) (E) | _If(Player_CollisionAxis) |
(D) (E) | _If(Projectile_CollisionAxis) |
Descriptions:
Player Overlap Collision IFs:
_If(Object_Collide_Player)
_If(Object_Offset_Collide_Player)
(COL) (Example)
These "If" condition Commands test for collision between a Player Character and an
Object. They are satisfied when the Collision Boxes of a Player overlap with the Collision
Boxes of an Object.
The "Offset" version should be used when the Object is using
"Animation Offsets" so that collision is tested properly. The non-"Offset" version
doesn't account for "Animation Offsets", and so is slightly faster.
Because these conditions are meant to be used inside a Game Object's Scripted "Collision" Function
when it is called during the movement of a Player Character, the test is performed
on the Object for which the Function is running (the "Current Object"), and the Player that is currently moving and causing collisions to be processed (the "Current Player")
Advanced - Manually setting the "Current Player" by using one of the "Set_CurrPlayer_???" Commands will allow this test to function correctly from within
the Object's Scripted "Movement" Function, but interaction with more than one Player will require performing the test once for each.
If Level Looping is enabled, the "Current Player" should instead be set by using one of the "_Player_SetCollisionArea_???"
Commands so that the collision will be properly tested when the Object's X/Y Position is not on the same side of the looping area as the Player.
Setting the "Current Player" in conjunction with the use of one of the "Set_CurrObj(???)" Commands would allow the use of this condition
from any Function within the game
There are three types of "Collision Boxes" that can be used for these tests:
0 | - | _Box_Main | - | "Main" | | (Usually used for level/floor type collision, collision with solid objects, and "pick up" collision) |
1 | - | _Box_Attack | - | "Attack" | | (Usually used to inflict "damage" onto another Player or Object) |
2 | - | _Box_Hurt | - | "Hurt" | | (Usually used to recieve "damage" from another Player or Object) |
Parameters:
- Player Box
This value specifies which type of "Collision Box" from the Player Character to test
for collision with the Game Object
- Object Box
This value specifies which type of "Collision Box" from the Game Object to test for
collision with the Player Character
_If(PlayerBound_Inside_Object)
(COL) (Example)
This "If" condition Command tests whether or not the specified side of a Player Character's "MainBounds" Box
is within the "MainBounds" Box area of an Object
Because this condition is meant to be used inside a Game Object's Scripted "Collision" Function
when it is called during the movement of a Player Character, the test is performed
on the Object for which the Function is running (the "Current Object"), and the Player that is currently moving and causing collisions to be processed (the "Current Player")
Advanced - Manually setting the "Current Player" by using one of the "Set_CurrPlayer_???" Commands will allow this test to function correctly from within
the Object's Scripted "Movement" Function, but interaction with more than one Player will require performing the test once for each.
If Level Looping is enabled, the "Current Player" should instead be set by using one of the "_Player_SetCollisionArea_???"
Commands so that the collision will be properly tested when the Object's X/Y Position is not on the same side of the looping area as the Player.
Setting the "Current Player" in conjunction with the use of one of the "Set_CurrObj(???)" Commands would allow the use of this condition
from any Function within the game
Parameters:
- Boundary
This value specifies which side of the Player's "MainBounds" box should be tested against the Object's "MainBounds" Box
0 | - | _Side_Right | - | Right side of the Player's MainBounds Box |
1 | - | _Side_Left | - | Left side of the Player's MainBounds Box |
2 | - | _Side_Bottom | - | Bottom of the Player's MainBounds Box |
3 | - | _Side_Top | - | Top of the Player's MainBounds Box |
4 | - | _Side_Pos | - | X/Y Position of Player |
- In/Out
0 | - | _Out | - | Test if the given side of the Player MainBounds is outside of the Object's MainBounds |
1 | - | _In | - | Test if the given side of the Player MainBounds is inside of the Object's MainBounds |
Player Touch Collision IFs:
_If(Player_Touch_Object)
_If(Player_Impact_Object)
(COL) (Example)
These "If" condition commands test whether or not a certain portion of a Player Character's "MainBounds" Box
is or isn't touching a certain portion of an Object's "MainBounds" Box. "Touch"
simply tests for whether or not one of the outer edges of one Box collides with
the opposite outter edge of another Box, however "Impact" also tests whether the Player is
actually moving toward the Object in the corresponding direction
Because these conditions are meant to be used inside a Game Object's Scripted "Collision" Function
when it is called during the movement of a Player Character, the test is performed
on the Object for which the Function is running (the "Current Object"), and the Player that is currently moving and causing collisions to be processed (the "Current Player")
Advanced - Manually setting the "Current Player" by using one of the "Set_CurrPlayer_???" Commands will allow this test to function correctly from within
the Object's Scripted "Movement" Function, but interaction with more than one Player will require performing the test once for each.
If Level Looping is enabled, the "Current Player" should instead be set by using one of the "_Player_SetCollisionArea_???"
Commands so that the collision will be properly tested when the Object's X/Y Position is not on the same side of the looping area as the Player.
Setting the "Current Player" in conjunction with the use of one of the "Set_CurrObj(???)" Commands would allow the use of this condition
from any Function within the game
Parameters:
- Direction
This value specifies which parts of the "MainBounds" Boxes to test:
0 | - | _Side_Right | - | If Player right side touches Object's left side |
1 | - | _Side_Left | - | If Player left side touches Object's right side |
2 | - | _Side_Bottom | - | If Player bottom side touches Object's top side |
3 | - | _Side_Top | - | If Player top side touches Object's bottom side |
- Condition
This value specifies which type test to perform:
0 | - | _False | - | The "If" is satisfied if the given sides are not touching |
1 | - | _True | - | The "If" is satisfied if the given sides are touching |
Projectile Overlap Collision IFs:
_If(Object_Collide_Projectile)
_If(Object_Offset_Collide_Projectile)
(COL) (Example)
These "If" condition Commands test for collision between an Object and a "Projectile
Object". They are satisfied when the Collision Boxes of a "Projectile" overlap the
Collision Boxes of an Object.
The "Offset" versions should be used when the Object is
using "Animation Offsets" so that collision is tested properly. The non-"Offset" version
doesn't account for "Animation Offsets", and so is slightly faster.
Because these conditions are meant to be used inside a Game Object's Scripted "Collision" Function
when it is called during the movement of a "Projectile Object", the test is performed
on the Object for which the Function is running (the "Current Object"), and the "Projectile Object" that is currently moving and causing collisions to be processed (the "Current Projectile")
Advanced - Manually setting the "Current Projectile" by using one of the "_Set_CurrProjectile(???)" Commands will allow this test to function correctly from within
the Object's Scripted "Movement" Function, but interaction with more than one Projectile will require performing the test once for each.
Setting the "Current Projectile" in conjunction with the use of one of the "Set_CurrObj(???)" Commands would allow the use of this condition
from any Function within the game
There are three types of "Collision Boxes" that can be used in a collision test:
0 | - | _Box_Main | - | "Main" | | (Usually used for level/floor type collision, collision with solid objects, and "pick up" collision) |
1 | - | _Box_Attack | - | "Attack" | | (Usually used to inflict "damage" onto another Object) |
2 | - | _Box_Hurt | - | "Hurt" | | (Usually used to recieve "damage" from another Object) |
Parameters:
- Projectile Box
This value specifies which type of "Collision Box" from the "Projectile Object" to
test for collision with the Game Object
- Object Box
This value specifies which type of "Collision Box" from the Game Object to test for
collision with the "Projectile Object"
Projectile Touch Collision IFs:
_If(Projectile_Touch_Object)
_If(Projectile_Impact_Object)
(COL) (Example)
These "If" condition Commands test whether or not a certain portion of a "Projectile
Object"'s "MainBounds" Box
is or isn't touching a certain portion of an Object's "MainBounds" Box. "Touch"
simply tests for whether or not one of the outer edges of one Box collides with
the opposite outter edge of another Box, however "Impact" also tests whether the "Projectile" is
moving toward the Object in the corresponding direction
Because these conditions are meant to be used inside a Game Object's Scripted "Collision" Function
when it is called during the movement of a "Projectile Object", the test is performed
on the Object for which the Function is running (the "Current Object"), and the "Projectile Object" that is currently moving and causing collisions to be processed (the "Current Projectile")
Advanced - Manually setting the "Current Projectile" by using one of the "_Set_CurrProjectile(???)" Commands will allow this test to function correctly from within
the Object's Scripted "Movement" Function, but interaction with more than one Projectile will require performing the test once for each.
Setting the "Current Projectile" in conjunction with the use of one of the "Set_CurrObj(???)" Commands would allow the use of this condition
from any Function within the game
Parameters:
- Direction
This value specifies which parts of the "MainBounds" Boxes to test:
0 | - | _Side_Right | - | If Projectile right side touches Object's left side |
1 | - | _Side_Left | - | If Projectile left side touches Object's right side |
2 | - | _Side_Bottom | - | If Projectile bottom side touches Object's top side |
3 | - | _Side_Top | - | If Projectile top side touches Object's bottom side |
- Condition
This value specifies which type test to perform:
0 | - | _False | - | The "If" is satisfied if the given sides are not touching |
1 | - | _True | - | The "If" is satisfied if the given sides are touching |
Collision Axis Test IFs:
_If(Player_CollisionAxis)
_If(Projectile_CollisionAxis)
(COL) (Example)
These "If" condition Commands check the axis on which the Player/"Projectile" has applied
its last pixel-unit of movement before testing for collision. Because they test for collision for each pixel-unit of movement, the Player/"Projectile" will only move and test for one unit along either axis at a time
(Ex: A Player with X velocity of 2 and Y velocity of 1 will move once along the X axis, test for collision, once more along the X axis, test for collision, once along the Y axis, test for collision)
Because these conditions are meant to be used inside a Game Object's Scripted "Collision" Function
when it is called during the movement of a Player Character or "Projectile Object", the test is performed
on the Object for which the Function is running (the "Current Object"), and the Player/"Projectile" that is currently moving and causing collisions to be processed (the "Current Player"/"Current Projectile")
Parameters:
- Direction
This value specifies which axis to test for
0 | - | _XAxis | - | If Player/"Projectile" has moved Horizontally (On the X axis) |
1 | - | _YAxis | - | If Player/"Projectile" has moved Vertically (On the Y axis) |
- Condition
This value specifies which type test to perform:
0 | - | _False | - | The "If" is satisfied if the Player/Projectile has not moved along the given axis |
1 | - | _True | - | The "If" is satisfied if the Player/Projectile has moved along the given axis |
Examples:
Player Overlap Collision IFs:
This section lists examples of complete sets of "If"/"Else"/"Endif" Commands, because they have no individual use
_If(Object_Collide_Player)
_If(Object_Offset_Collide_Player)
(Description)
_If(PlayerBound_Inside_Object)
(Description)
#_If(Object_Collide_Player)
:_Box_Main ;(Player Box)
:_Box_Main ;(Object Box)
;***
;Code here is processed only if the "MainBounds" Box of the "Current Player" overlaps with the "MainBounds" Box of the "Current Object".
;Remember that "MainBounds" is only tested for the "Primary Sprite" for both the Player and Object.
;***
#_EndIf
; ----------
#_If(Object_Offset_Collide_Player)
:_Box_Attack ;(Player Box)
:_Box_Hurt ;(Object Box)
;***
;Code here is processed only if any "Attack" Boxes from the "Current Player" overlap with any "Hurt" Boxes from the "Current Object".
;All "Attack" and "Hurt" Boxes for each Sprite that corresponds with each active Animation for both the Player and Object are tested.
;Command 816 takes into account "Animation Offsets" when testing for overlapping Boxes; Collisions will be correct based on what's
;on-screen, no matter where "Animation Offsets" place each Sprite. Command 347 will not do this
;***
#_Else
;***
;Code here is processed only if absolutely no "Attack" Boxes from the "Current Player" overlap with any "Hurt" Boxes from the "Current Object".
;All "Attack" and "Hurt" Boxes for each Sprite that corresponds with each active Animation for both the Player and Object are tested.
;Command 816 takes into account "Animation Offsets" when testing for overlapping Boxes; Collisions will be correct based on what's
;on-screen, no matter where "Animation Offsets" place each Sprite. Command 347 will not do this
;***
#_EndIf
; ----------
#__If(Object_Collide_Player)
:_Box_Hurt ;(Player Box)
:_Box_Attack ;(Object Box)
;***
;Code here is processed only if any "Hurt" Boxes from the "Current Player" overlap with any "Attack" Boxes from the "Current Object".
;All "Attack" and "Hurt" Boxes for each Sprite that corresponds with each active Animation for both the Player and Object are tested.
;Command 347 does not take into account "Animation Offsets" when testing for overlapping Boxes; If any Animations are being run "With Offsets",
;the collision test will not match the image on-screen (They will behave as if no offset was used). Command 816 should be used if the Object uses "Animation Offsets"
;***
#_EndIf
; ----------
#_If(PlayerBound_Inside_Object)
:_Side_Bottom ;(Side)
:_True ;(Condition)
;***
;Code here is processed only if the bottom-most (Y2) side of the "Current Player"'s "MainBounds" Box overlaps with the "MainBounds" Box area of the "Current Object".
;Remember that "MainBounds" is only tested for the "Primary Sprite" for both the Player and Object.
;***
#_EndIf
; ----------
#_If(PlayerBound_Inside_Object)
:_Side_Left ;(Side)
:_False ;(Condition)
;***
;Code here is processed only if the left-most (X1) side of the "Current Player"'s "MainBounds" Box does not overlap with the "MainBounds" Box area of the "Current Object".
;Remember that "MainBounds" is only tested for the "Primary Sprite" for both the Player and Object.
;***
#_Else
;***
;Code here is processed only if the left-most (X1) side of the "Current Player"'s "MainBounds" Box does overlap with the "MainBounds" Box area of the "Current Object".
;Remember that "MainBounds" is only tested for the "Primary Sprite" for both the Player and Object.
;***
#_EndIf
Player Touch Collision IFs:
_If(Player_Touch_Object)
_If(Player_Impact_Object)
(Description)
#_If(Player_Touch_Object)
:_Side_Bottom ;(Side) Player bottom touches Object top
:_True ;(Condition)
;***
;Code here is processed only if the bottom-most (Y2) side of the "Current Player"'s "MainBounds" Box overlaps with the top-most (Y1) side of the "Current Object"'s "MainBounds" Box.
;Remember that "MainBounds" is only tested for the "Primary Sprite" for both the Player and Object.
;***
#_EndIf
; ----------
#_If(Player_Impact_Object)
:_Side_Left ;(Side) Player left impacts Object right
:_False ;(Condition)
;***
;Code here is processed only if one of the following conditions is true:
;-The left-most (X1) side of the "Current Player"'s "MainBounds" Box does not overlap with the right-most (X2) side of the "Current Object"'s "MainBounds" Box.
;-The "Current Player" is not "moving toward" the "Current Object. In this case, the Object is to the left of the Player, so, the Player must have positive or zero X Velocity.
;Remember that "MainBounds" is only tested for the "Primary Sprite" for both the Player and Object.
;***
#_Else
;***
;Code here is processed only if both of the following conditions are true:
;-The left-most (X1) side of the "Current Player"'s "MainBounds" Box does overlap with the right-most (X2) side of the "Current Object"'s "MainBounds" Box.
;-The "Current Player" is "moving toward" the "Current Object. In this case, the Object is to the left of the Player, so, the Player must have negative X Velocity.
;Remember that "MainBounds" is only tested for the "Primary Sprite" for both the Player and Object.
;***
#_EndIf
Projectile Overlap Collision IFs:
348 - _If(Object_Collide_Projectile)
817 - _If(Object_Offset_Collide_Projectile)
(Description)
#_If(Object_Collide_Projectile)
:_Box_Main ;(Projectile Box)
:_Box_Main ;(Object Box)
;***
;Code here is processed only if the "MainBounds" Box of the "Current Projectile" overlaps with the "MainBounds" Box of the "Current Object".
;Remember that "MainBounds" is only tested for the "Primary Sprite" for both the Projectile and Object.
;***
#_EndIf
; ----------
#_If(Object_Offset_Collide_Projectile)
:_Box_Attack ;(Projectile Box)
:_Box_Hurt ;(Object Box)
;***
;Code here is processed only if any "Attack" Boxes from the "Current Projectile" overlap with any "Hurt" Boxes from the "Current Object".
;All "Attack" and "Hurt" Boxes for each Sprite that corresponds with each active Animation for both the Projectile and Object are tested.
;Command 817 takes into account "Animation Offsets" when testing for overlapping Boxes; Collisions will be correct based on what's
;on-screen, no matter where "Animation Offsets" place each Sprite. Command 348 will not do this
;***
#_Else
;***
;Code here is processed only if absolutely no "Attack" Boxes from the "Current Projectile" overlap with any "Hurt" Boxes from the "Current Object".
;All "Attack" and "Hurt" Boxes for each Sprite that corresponds with each active Animation for both the Projectile and Object are tested.
;Command 817 takes into account "Animation Offsets" when testing for overlapping Boxes; Collisions will be correct based on what's
;on-screen, no matter where "Animation Offsets" place each Sprite. Command 348 will not do this
;***
#_EndIf
; ----------
#_If(Object_Collide_Projectile)
:_Box_Hurt ;(Projectile Box)
:_Box_Attack ;(Object Box)
;***
;Code here is processed only if any "Hurt" Boxes from the "Current Projectile" overlap with any "Attack" Boxes from the "Current Object".
;All "Attack" and "Hurt" Boxes for each Sprite that corresponds with each active Animation for both the Projectile and Object are tested.
;Command 348 does not take into account "Animation Offsets" when testing for overlapping Boxes; If any Animations are being run "With Offsets",
;the collision test will not match the image on-screen (They will behave as if no offset was used). Command 817 should be used if the Object uses "Animation Offsets"
;***
#_EndIf
Projectile Touch Collision IFs:
_If(Projectile_Touch_Object)
_If(Projectile_Impact_Object)
(Description)
#_If(Projectile_Touch_Object)
:_Side_Bottom ;(Side) Projectile bottom touches Object top
:_True ;(Condition)
;***
;Code here is processed only if the bottom-most (Y2) side of the "Current Projectile"'s "MainBounds" Box overlaps with the top-most (Y1) side of the "Current Object"'s "MainBounds" Box.
;Remember that "MainBounds" is only tested for the "Primary Sprite" for both the Projectile and Object.
;***
#_EndIf
; ----------
#_If(Projectile_Impact_Object)
:_Side_Left ;(Side) Projectile left impacts Object right
:_False ;(Condition)
;***
;Code here is processed only if one of the following conditions is true:
;-The left-most (X1) side of the "Current Projectile"'s "MainBounds" Box does not overlap with the right-most (X2) side of the "Current Object"'s "MainBounds" Box.
;-The "Current Projectile" is not "moving toward" the "Current Object. In this case, the Object is to the left of the Projectile, so, the Projectile must have positive or zero X Velocity.
;Remember that "MainBounds" is only tested for the "Primary Sprite" for both the Projectile and Object.
;***
#_Else
;***
;Code here is processed only if both of the following conditions are true:
;-The left-most (X1) side of the "Current Projectile"'s "MainBounds" Box does overlap with the right-most (X2) side of the "Current Object"'s "MainBounds" Box.
;-The "Current Projectile" is "moving toward" the "Current Object. In this case, the Object is to the left of the Projectile, so, the Projectile must have negative X Velocity.
;Remember that "MainBounds" is only tested for the "Primary Sprite" for both the Projectile and Object.
;***
#_EndIf
Collision Axis Test IFs:
_If(Player_CollisionAxis)
_If(Projectile_CollisionAxis)
(Description)
#_If(Player_CollisionAxis)
:_XAxis ;(Axis)
:_True ;(Condition)
;***
;Code here is processed only if the "Current Player" has just moved on the X axis
;***
#_EndIf
; ----------
#_If(Projectile_CollisionAxis)
:_YAxis ;(Axis)
:_False ;(Condition)
;***
;Code here is processed only if the "Current Player" has not just moved on the Y axis
;***
#_Else
;***
;Code here is processed only if the "Current Player" has just moved on the Y axis
;***
#_EndIf