https://wiki.bennugd.org/api.php?action=feedcontributions&user=89.7.80.53&feedformat=atomBennu Wiki - User contributions [en]2024-03-29T15:34:55ZUser contributionsMediaWiki 1.36.2https://wiki.bennugd.org/index.php?title=Collision_box&diff=8254Collision box2011-06-09T19:07:50Z<p>89.7.80.53: </p>
<hr />
<div>[[Category:functions]]<br />
[[Category:processinteraction]]<br />
[[Category:mod_grproc]]<br />
<br />
==Definition==<br />
'''INT''' collision_box ( <'''INT''' processID|processTypeID> )<br />
<br />
Checks if a [[process]] collided with the process calling Collision_box().<br />
<br />
When a [[processTypeID]] is specified, there could be multiple fitting collisions. In this case, collision_box() returns a [[processID]] on each subsequent call, until it returns 0. This can be reset by use of the [[frame]]; statement, and in such case, frame(0); can be handy.<br />
<br />
The diference between collision_box and [[collision]] is that collision_box only checks the distance with the edges of the processes, on the other side collision() check pixel by pixel between these processes. Consequently, collision_box() is faster, but is more accurate collision().<br />
<br />
== Parameters ==<br />
{|<br />
| '''INT''' processID<nowiki>|</nowiki>processTypeID || - The ProcessID of the process or the ProcessTypeID of the type of processes to be checked.<br />
|}<br />
<br />
== Returns ==<br />
'''INT''' : The ID of the collided process.<br />
{|<br />
| 0 || - No collision<br />
|-<br />
| >0 || - The processID of the process colliding with the current process<br />
|}<br />
<br />
== Example ==<br />
<pre><br />
Process SpaceShip( int file , int graph , int x , int y , int angle , int maxspeed , int maxturnspeed )<br />
Private<br />
int speed;<br />
int collisionID;<br />
string text;<br />
Begin<br />
write_string(0,0,0,0,&text);<br />
Loop<br />
// Handle movement<br />
speed+=key(_up)*(speed<maxspeed)-key(_down)*(speed>-maxspeed);<br />
angle+=(key(_left)-key(_right))*maxturnspeed;<br />
advance(speed);<br />
// Handle collision_box<br />
if( (collisionID = collision_box(type main)))<br />
text = "collision with: " + collisionID;<br />
else<br />
text = "no collision";<br />
end<br />
frame;<br />
End<br />
End<br />
<br />
Process Main()<br />
Private<br />
int map;<br />
Begin<br />
<br />
// Create the graph for the ship<br />
map = new_map(20,20,8);<br />
map_clear(0,map,rgb(0,255,255));<br />
<br />
// Create the graph for the Main process<br />
graph = new_map(50,50,8);<br />
map_clear(0,graph,rgb(255,255,0));<br />
<br />
// Position the main process and create the ship<br />
x = y = z = 100;<br />
SpaceShip(0,map,100,100,0,20,5000);<br />
<br />
Repeat<br />
frame;<br />
Until(key(_ESC))<br />
<br />
let_me_alone();<br />
<br />
End<br />
</pre><br />
Used in example: [[write_string]](), [[key]](), [[collision_box]](), [[new_map]](), [[map_clear]](), [[advance]](), [[let_me_alone]](), [[graph]], [[type]]<br />
<br />
{{Moduledocbox<br />
| module = Mod_grproc<br />
}}</div>89.7.80.53