D
Dragoen_Mage
Guest
I am trying to implement a modular movement boost system in a 2D platformer. I wrote a script that should detect when a box drawn by the collision_rectangle that is 1 pixel larger on each side (34w x 66h) than the sprite of my player object with the origin point centered (32w x 64h) overlaps with another object, then pull two variables from that object to set the player objects boost multiplier. The script works with objects that the player can walk through so that the sprites collision masks overlap. Objects that stop the player object on collision do not update the boost multiplier. The objects that the player object can collide with are all child objects of my oWall object. Am I just misunderstanding how the collision_rectangle works?
Script Code
Script Call with movement modification
Collision Code Curtsy of Shaun Spalding
Script Code
Code:
///@func scBoost(X1,Y1,X2,Y2,obj)
///@arg Left edge
///@arg Right edge
///@arg Top edge
///@arg Bottom edge
///@arg Object
var X1 = argument[0]
var Y1 = argument[1]
var X2 = argument[2]
var Y2 = argument[3]
var obj = argument[4]
if (collision_rectangle(X1,Y1,X2,Y2,obj,false,false))
{
vboost=obj.vboost
hboost=obj.hboost
}
Code:
//boost check in step event
vboost=1
hboost=1
xleft = x-17
xright = x+18
ytop = y-34
ybottom = y+33
scBoost(xleft,ytop,xright,ybottom,oBoost_Up);
scBoost(xleft,ytop,xright,ybottom,oBoost_Down);
scBoost(xleft,ytop,xright,ybottom,oBoost_Right);
scBoost(xleft,ytop,xright,ybottom,oBoost_Left);
//Horizontal Movement
var move = (key_right - key_left) * hboost;
hsp = move * walkspeed;
//Jump
vsp = vsp + grv
if (place_meeting(x,y+1,oWall)) && (key_jump) && (doublejump==0)
{
vsp = -8 * vboost;
doublejump = 1;
}
Code:
//Horizontal Collision
if (place_meeting(x+hsp,y,oWall))
{
while (!place_meeting(x+sign(hsp),y,oWall))
{
x = x + sign(hsp);
}
hsp= 0;
}
x=x+hsp
//Vertical Collision
if (place_meeting(x,y+vsp,oWall))
{
while (!place_meeting(x,y+sign(vsp),oWall))
{
y = y + sign(vsp);
}
vsp = 0;
doublejump = 0;
}
y=y+vsp