fucbillgates
Member
This code would be used inside an event script and in tandem with event functions.
-First setup the position of the player * 48 to get the pixel position of the character.
-I'm storing the player position into variables 5 and 6.
-The second set is the variable number 22 and 23 I have the x and y position of the picture stored in 22=x 23=y. I'm copying them into variable 3 and 4 just for this check.
Setting Positions
$gameVariables.setValue(5,$gamePlayer.x*48);
$gameVariables.setValue(6,$gamePlayer.y*48);
$gameVariables.setValue(3,$gameVariables.value(22));
$gameVariables.setValue(4,$gameVariables.value(23));
-Now take the values in 3,4,5,6 and do a distance check.
-sqrt((x1-x2)^2+(y1-y2)^2) is the check for distance between points and since javascript has Math.pow and sqrt It's not hard to do.
-I store the result into a temp distance variable, since it appears that after the script is done the distance variable has gone out of scope and was deleted I'm calling it temp.
-Now I can just check if the object is within the distance I want to consider a collision.
-I set game variable 30 to 1 or 0 if a collision is going on then I can have a event just look at variable 30 using a conditional branch and respond to the collision.
Checking Distance
var distance=Math.abs(Math.sqrt(
Math.pow($gameVariables.value(3)-$gameVariables.value(5),2)+
Math.pow($gameVariables.value(4)-$gameVariables.value(6),2)
));
if (distance<24)
{
$gameVariables.setValue(30,1);
}
else
{
$gameVariables.setValue(30,0);
}
-So at this point you would use a conditional branch to respond to the collision and do something like reduce a health variable
-Then you can display your image using a script too.
Display Image
$gameScreen.showPicture(1,'BloodSplash',0,$gamePlayer.x*48,$gamePlayer.y*48,96,96,255,0);
-The event at this point has..
~This is the inside of your event~
Contents
Script Setting Positions
Script Checking Distance
if : Collision = 1 //Remember Collision in this case is var 30
Control Variables : #0032 PlayerHealth -= 1
Script DisplayImage
:End
Now you can have a event that moves an image around the screen and you can check if that image hit the player
and replace the player x and y with another x and y variable and you can check picture to picture collision.
-First setup the position of the player * 48 to get the pixel position of the character.
-I'm storing the player position into variables 5 and 6.
-The second set is the variable number 22 and 23 I have the x and y position of the picture stored in 22=x 23=y. I'm copying them into variable 3 and 4 just for this check.
Setting Positions
$gameVariables.setValue(5,$gamePlayer.x*48);
$gameVariables.setValue(6,$gamePlayer.y*48);
$gameVariables.setValue(3,$gameVariables.value(22));
$gameVariables.setValue(4,$gameVariables.value(23));
-Now take the values in 3,4,5,6 and do a distance check.
-sqrt((x1-x2)^2+(y1-y2)^2) is the check for distance between points and since javascript has Math.pow and sqrt It's not hard to do.
-I store the result into a temp distance variable, since it appears that after the script is done the distance variable has gone out of scope and was deleted I'm calling it temp.
-Now I can just check if the object is within the distance I want to consider a collision.
-I set game variable 30 to 1 or 0 if a collision is going on then I can have a event just look at variable 30 using a conditional branch and respond to the collision.
Checking Distance
var distance=Math.abs(Math.sqrt(
Math.pow($gameVariables.value(3)-$gameVariables.value(5),2)+
Math.pow($gameVariables.value(4)-$gameVariables.value(6),2)
));
if (distance<24)
{
$gameVariables.setValue(30,1);
}
else
{
$gameVariables.setValue(30,0);
}
-So at this point you would use a conditional branch to respond to the collision and do something like reduce a health variable
-Then you can display your image using a script too.
Display Image
$gameScreen.showPicture(1,'BloodSplash',0,$gamePlayer.x*48,$gamePlayer.y*48,96,96,255,0);
-The event at this point has..
~This is the inside of your event~
Contents
Script Setting Positions
Script Checking Distance
if : Collision = 1 //Remember Collision in this case is var 30
Control Variables : #0032 PlayerHealth -= 1
Script DisplayImage
:End
Now you can have a event that moves an image around the screen and you can check if that image hit the player
and replace the player x and y with another x and y variable and you can check picture to picture collision.