GMLscripts.com

Discuss and collaborate on GML scripts
Invert

You are not logged in.

#1 Re: Script Submission » Seamless Room Wrapping » 2016-10-27 07:27:11

I made a couple changes...

edited all the scripts to match the style guide and added a couple more useful functions.
changed the camera functions to take x and y coordinates instead of just using the object's x and y.
changed every '/2' with '*0.5'. I read somewhere this is faster?
updated the download link to the new project.


point_direction

Expand/// point_direction_xwrap(x1,y1,x2,y2)
//  
//  real
//
//  returns the direction of the  shortest route from
//  point (x1,y1) to point (x2,y2) with room wrapping
//  along the x axis only.
//
/// GMLscripts.com/license
{
    var x1, y1, x2, y2, xwr;
    x1 = argument0;
    y1 = argument1;
    x2 = argument2;
    y2 = argument3;
    xwr = (x2 - x1 > 0.5 * room_width) - (x1 - x2 > 0.5 * room_width);
    return point_direction(x1+xwr*room_width,y1,x2,y2);
}
Expand/// point_direction_ywrap(x1,y1,x2,y2)
//  
//  real
//
//  returns the direction of the  shortest route from
//  point (x1,y1) to point (x2,y2) with room wrapping
//  along the y axis only.
//
/// GMLscripts.com/license
{
    var x1, y1, x2, y2, ywr;
    x1 = argument0;
    y1 = argument1;
    x2 = argument2;
    y2 = argument3;
    ywr = (y2 - y1 > 0.5 * room_height) - (y1 - y2 > 0.5 * room_height);
    return point_direction(x1,y1+ywr*room_height,x2,y2);
}
Expand/// point_direction_xwrap(x1,y1,x2,y2)
//  
//  real
//
//  returns the direction of the  shortest route from
//  point (x1,y1) to point (x2,y2) with room wrapping
//  along the x and y axis.
//
/// GMLscripts.com/license
{
    var x1, y1, x2, y2, xwr, ywr;
    x1 = argument0;
    y1 = argument1;
    x2 = argument2;
    y2 = argument3;
    xwr = (x2 - x1 > 0.5 * room_width) - (x1 - x2 > 0.5 * room_width);
    ywr = (y2 - y1 > 0.5 * room_height) - (y1 - y2 > 0.5 * room_height);
    return point_direction(x1+xwr*room_width,y1+ywr*room_height,x2,y2);
}

point_distance

Expand/// point_distance_xwrap(x1,y1,x2,y2)
//  
//  real
//
//  returns the shortest distance between two points 
//  (x1,y1) and (x2,y2) with room wrapping along the
//  x axis only.
//
/// GMLscripts.com/license
{
    var x1, y1, x2, y2, xwr;
    x1 = argument0;
    y1 = argument1;
    x2 = argument2;
    y2 = argument3;
    xwr = (x2 - x1 > 0.5 * room_width) - (x1 - x2 > 0.5 * room_width);
    return point_distance(x1+xwr*room_width,y1,x2,y2);
}
Expand/// point_distance_ywrap(x1,y1,x2,y2)
//  
//  real
//
//  returns the shortest distance between two points 
//  (x1,y1) and (x2,y2) with room wrapping along the
//  y axis only.
//
/// GMLscripts.com/license
{
    var x1, y1, x2, y2, ywr;
    x1 = argument0;
    y1 = argument1;
    x2 = argument2;
    y2 = argument3;
    ywr = (y2 - y1 > 0.5 * room_height) - (y1 - y2 > 0.5 * room_height);
    return point_distance(x1,y1+ywr*room_height,x2,y2);
}
Expand/// point_distance_xywrap(x1,y1,x2,y2)
//  
//  real
//
//  returns the shortest distance between two points 
//  (x1,y1) and (x2,y2) with room wrapping along the
//  x and y axis.
//
/// GMLscripts.com/license
{
    var x1, y1, x2, y2, xwr, ywr;
    x1 = argument0;
    y1 = argument1;
    x2 = argument2;
    y2 = argument3;
    xwr = (x2 - x1 > 0.5 * room_width) - (x1 - x2 > 0.5 * room_width);
    ywr = (y2 - y1 > 0.5 * room_height) - (y1 - y2 > 0.5 * room_height);
    return point_distance(x1+xwr*room_width,y1+ywr*room_height,x2,y2);
}

move

Expand/// move_xwrap(hsp,vsp) 
//  
//  void
// 
//  moves object by amount. wraps horizontally.
//    
/// GMLscripts.com/license
{
    var hsp, vsp;
    hsp = argument0;
    vsp = argument1;
    x += hsp;
    if (x < 0 || x > room_width)
    {
        x -= sign(x - 0.5*room_width) * room_width;
    }
    y += vsp;
}
Expand/// move_ywrap(hsp,vsp)
//  
//  void
// 
//  moves object by amount. wraps vertically.
//    
/// GMLscripts.com/license
{
    var hsp, vsp;
    hsp = argument0;
    vsp = argument1;
    x += hsp;
    y += vsp;
    if (y < 0 || y > room_height)
    {
        y -= sign(y - 0.5*room_height) * room_height;
    }
}
Expand/// move_xywrap(hsp,vsp) 
//  
//  void
// 
//  moves object by amount. wraps both directions.
//    
/// GMLscripts.com/license
{
    var hsp, vsp;
    hsp = argument0;
    vsp = argument1;
    x += hsp;
    if ((x < 0) || (x > room_width))
    {
        x -= sign(x - 0.5*room_width) * room_width;
    }
    y += vsp;
    if ((y < 0) || (y > room_height))
    {
        y -= sign(y - 0.5*room_height) * room_height;
    }
}

camera_set_position

Expand/// camera_set_position_xwrap(x1,y1)
//  
//  void
// 
//  sets postion of view[0] to (x1,y1) and wraps
//  around the room horizontally using multiple
//  views that scale to the size of view[0].
//    
/// GMLscripts.com/license
{
    var x1, y1;
    x1 = argument0;
    y1 = argument1;
    view_xview[0] = x1 - 0.5*view_wview[0];
    view_yview[0] = y1 - 0.5*view_hview[0];
    
    if (x1 < 0.5*view_wview[0]) // the view is colliding with the left edge of the room
    {
        view_visible[0] = false;
        view_visible[1] = true;
        view_visible[2] = true;
        view_visible[3] = false;
        view_visible[4] = false;
        view_xview[1] = room_width - 0.5*view_wview[0] + x1; 
        view_yview[1] = y1 - 0.5*view_hview[0];
        view_wview[1] = 0.5*view_wview[0] - x1; 
        view_hview[1] = view_hview[0]; 
        view_xport[1] = 0; 
        view_yport[1] = 0; 
        view_wport[1] = view_wport[0] / view_wview[0] * view_wview[1];
        view_hport[1] = view_hport[0]; 
        view_xview[2] = 0; 
        view_yview[2] = y1 - 0.5*view_hview[0]; 
        view_wview[2] = x1 + 0.5*view_wview[0]; 
        view_hview[2] = view_hview[0];
        view_xport[2] = view_wport[1];
        view_yport[2] = 0;
        view_wport[2] = view_wport[0] / view_wview[0] * view_wview[2]; 
        view_hport[2] = view_hport[0]; 
    }
    else if (x1 + 0.5*view_wview[0] > room_width) // the view is colliding with the right edge of the room
    {
        view_visible[0] = false;
        view_visible[1] = true;
        view_visible[2] = true;
        view_visible[3] = false;
        view_visible[4] = false;
        view_xview[1] = x1 - 0.5*view_wview[0]; 
        view_yview[1] = y1 - 0.5*view_hview[0]; 
        view_wview[1] = 0.5*view_wview[0] + room_width - x1; 
        view_hview[1] = view_hview[0];
        view_xport[1] = 0; 
        view_yport[1] = 0; 
        view_wport[1] = view_wport[0] / view_wview[0] * view_wview[1];
        view_hport[1] = view_hport[0]; 
        view_xview[2] = 0; 
        view_yview[2] = y1 - 0.5*view_hview[0]; 
        view_wview[2] = 0.5*view_wview[0] + x1 - room_width; 
        view_hview[2] = view_hview[0]; 
        view_xport[2] = view_wport[1]; 
        view_yport[2] = 0; 
        view_wport[2] = view_wport[0] / view_wview[0] * view_wview[2];
        view_hport[2] = view_hport[0];  
    }
    else // the view is not colliding with the edge of the room
    {
        view_visible[0] = true;
        view_visible[1] = false;
        view_visible[2] = false;
        view_visible[3] = false;
        view_visible[4] = false;
    }
}
Expand/// camera_set_position_ywrap(x1,y1)
//  
//  void
// 
//  sets postion of view[0] to (x1,y1) and wraps
//  around the room horizontally using multiple
//  views that scale to the size of view[0].
//    
/// GMLscripts.com/license
{
    var x1, y1;
    x1 = argument0;
    y1 = argument1;
    view_xview[0] = x1 - 0.5*view_wview[0];
    view_yview[0] = y1 - 0.5*view_hview[0];
    
    if (y1 < 0.5*view_hview[0]) // the view is colliding with the top edge of the room
    {
        view_visible[0] = false;
        view_visible[1] = true;
        view_visible[2] = true;
        view_visible[3] = false;
        view_visible[4] = false;
        view_yview[1] = room_height - 0.5*view_hview[0] + y1; 
        view_xview[1] = x1 - 0.5*view_wview[0];
        view_hview[1] = 0.5*view_hview[0] - y1; 
        view_wview[1] = view_wview[0]; 
        view_yport[1] = 0;
        view_xport[1] = 0;
        view_hport[1] = view_hport[0] / view_hview[0] * view_hview[1];
        view_wport[1] = view_wport[0];
        view_yview[2] = 0; 
        view_xview[2] = x1 - 0.5*view_wview[0];
        view_hview[2] = y1 + 0.5*view_hview[0]; 
        view_wview[2] = view_wview[0];
        view_yport[2] = view_hport[1]; 
        view_xport[2] = 0;
        view_hport[2] = view_hport[0] / view_hview[0] * view_hview[2]; 
        view_wport[2] = view_wport[0];   
    }
    else if (y1 + 0.5*view_hview[0] > room_height)  // the view is colliding with the bottom edge of the room
    {
        view_visible[0] = false;
        view_visible[1] = true;
        view_visible[2] = true;
        view_visible[3] = false;
        view_visible[4] = false;
        view_xview[1] = x1 - 0.5*view_wview[0];
        view_yview[1] = y1 - 0.5*view_hview[0];
        view_wview[1] = view_wview[0];
        view_hview[1] = 0.5*view_hview[0] + room_height - y1;
        view_xport[1] = 0;
        view_yport[1] = 0;
        view_wport[1] = view_wport[0] / view_wview[0] * view_wview[1];
        view_hport[1] = view_hport[0] / view_hview[0] * view_hview[1];
        view_xview[2] = x - 0.5*view_wview[0];
        view_yview[2] = 0;
        view_wview[2] = view_wview[0];
        view_hview[2] = 0.5*view_hview[0] + y1 - room_height;
        view_xport[2] = 0;
        view_yport[2] = view_hport[1];
        view_wport[2] = view_wport[0] / view_wview[0] * view_wview[2];
        view_hport[2] = view_hport[0] / view_hview[0] * view_hview[2];
    }
    else // the view is not colliding with the edge of the room
    {
        view_visible[0] = true;
        view_visible[1] = false;
        view_visible[2] = false;
        view_visible[3] = false;
        view_visible[4] = false;
    }
}
Expand/// camera_set_position_xywrap(x1,y1)
//  
//  void
// 
//  sets postion of view[0] to (x1,y1) and wraps
//  around the room horizontally and vertically
//  using multiple views that scale to the size
//  of view[0].
//    
/// GMLscripts.com/license
{
    var x1, y1;
    x1 = argument0;
    y1 = argument1;
    view_xview[0] = x1 - 0.5*view_wview[0];
    view_yview[0] = y1 - 0.5*view_hview[0];
    if (x1 < 0.5*view_wview[0]) // the view is colliding with the left edge of the room
    {
        if (y1 < 0.5*view_hview[0]) // the view is colliding with the top left corner of the room
        {
            view_visible[0] = false;
            view_visible[1] = true;
            view_visible[2] = true;
            view_visible[3] = true;
            view_visible[4] = true;
            view_xview[1] = room_width + x1 - 0.5*view_wview[0];
            view_yview[1] = room_height + y1 - 0.5*view_hview[0];
            view_wview[1] = 0.5*view_wview[0] - x1;
            view_hview[1] = 0.5*view_hview[0] - y1;
            view_xport[1] = 0;
            view_yport[1] = 0;
            view_wport[1] = view_wport[0] / view_wview[0] * view_wview[1]; 
            view_hport[1] = view_hport[0] / view_hview[0] * view_hview[1];
            view_xview[2] = 0;
            view_yview[2] = room_height + y1 - 0.5*view_hview[0];
            view_wview[2] = 0.5*view_wview[0] + x1;
            view_hview[2] = 0.5*view_hview[0] - y1;
            view_xport[2] = view_wport[1];
            view_yport[2] = 0;
            view_wport[2] = view_wport[0] / view_wview[0] * view_wview[2]; 
            view_hport[2] = view_hport[0] / view_hview[0] * view_hview[2];
            view_xview[3] = room_width + x1 - 0.5*view_wview[0];
            view_yview[3] = 0;
            view_wview[3] = 0.5*view_wview[0] - x1;
            view_hview[3] = y1 + 0.5*view_hview[0];
            view_xport[3] = 0;
            view_yport[3] = view_hport[1];
            view_wport[3] = view_wport[0] / view_wview[0] * view_wview[3];
            view_hport[3] = view_hport[0] / view_hview[0] * view_hview[3];
            view_xview[4] = 0;
            view_yview[4] = 0;
            view_wview[4] = x1 + 0.5*view_wview[0];
            view_hview[4] = y1 + 0.5*view_hview[0];
            view_xport[4] = view_wport[3];
            view_yport[4] = view_hport[2];
            view_wport[4] = view_wport[0] / view_wview[0] * view_wview[4];
            view_hport[4] = view_hport[0] / view_hview[0] * view_hview[4];
        }
        else if (y1 + 0.5*view_hview[0] > room_height) // the view is colliding with the bottom left corner of the room
        {
            view_visible[0] = false;
            view_visible[1] = true;
            view_visible[2] = true;
            view_visible[3] = true;
            view_visible[4] = true;
            view_xview[1] = x1 - 0.5*view_wview[0] + room_width;
            view_yview[1] = y1 - 0.5*view_hview[0];
            view_wview[1] = 0.5*view_wview[0] - x1;
            view_hview[1] = room_height - y1 + 0.5*view_hview[0];
            view_xport[1] = 0;
            view_yport[1] = 0;
            view_wport[1] = view_wport[0] / view_wview[0] * view_wview[1];
            view_hport[1] = view_hport[0] / view_hview[0] * view_hview[1];
            view_xview[2] = 0;
            view_yview[2] = y1 - 0.5*view_hview[0];
            view_wview[2] = x1 + 0.5*view_wview[0];
            view_hview[2] = 0.5*view_hview[0] + room_height - y1;
            view_xport[2] = view_wport[1];
            view_yport[2] = 0;
            view_wport[2] = view_wport[0] / view_wview[0] * view_wview[2];
            view_hport[2] = view_hport[0] / view_hview[0] * view_hview[2];
            view_xview[3] = x1 - 0.5*view_wview[0] + room_width;
            view_yview[3] = 0;
            view_wview[3] = 0.5*view_wview[0] - x1;
            view_hview[3] = y1 + 0.5*view_hview[0] - room_height;
            view_xport[3] = 0;
            view_yport[3] = view_hport[1];
            view_wport[3] = view_wport[0] / view_wview[0] * view_wview[3];
            view_hport[3] = view_hport[0] / view_hview[0] * view_hview[3];
            view_xview[4] = 0;
            view_yview[4] = 0;
            view_wview[4] = x + 0.5*view_wview[0];
            view_hview[4] = y + 0.5*view_hview[0] - room_height;
            view_xport[4] = view_wport[3];
            view_yport[4] = view_hport[2];
            view_wport[4] = view_wport[0] / view_wview[0] * view_wview[4];
            view_hport[4] = view_hport[0] / view_hview[0] * view_hview[4];
        }
        else  // the view is colliding with the left edge of the room
        {
            view_visible[0] = false;
            view_visible[1] = true;
            view_visible[2] = true;
            view_visible[3] = false;
            view_visible[4] = false;
            view_xview[1] = room_width - 0.5*view_wview[0] + x1; 
            view_yview[1] = y1 - 0.5*view_hview[0];
            view_wview[1] = 0.5*view_wview[0] - x1; 
            view_hview[1] = view_hview[0]; 
            view_xport[1] = 0; 
            view_yport[1] = 0; 
            view_wport[1] = view_wport[0] / view_wview[0] * view_wview[1];
            view_hport[1] = view_hport[0]; 
            view_xview[2] = 0; 
            view_yview[2] = y1 - 0.5*view_hview[0]; 
            view_wview[2] = x1 + 0.5*view_wview[0]; 
            view_hview[2] = view_hview[0];
            view_xport[2] = view_wport[1];
            view_yport[2] = 0;
            view_wport[2] = view_wport[0] / view_wview[0] * view_wview[2]; 
            view_hport[2] = view_hport[0]; 
        }
    }
    else if (x1 + 0.5*view_wview[0] > room_width) // the view is colliding with the rigth edge of the room
    {
        if (y1 < 0.5*view_hview[0]) // the view is colliding with the top rigth edge of the room
        {   
            view_visible[0] = false;
            view_visible[1] = true;
            view_visible[2] = true;
            view_visible[3] = true;
            view_visible[4] = true;
            view_xview[1] = x1 - 0.5*view_wview[0];
            view_yview[1] = room_height + y1 - 0.5*view_hview[0];
            view_wview[1] = room_width - x1 + 0.5*view_wview[0];
            view_hview[1] = 0.5*view_hview[0] - y1;
            view_xport[1] = 0;
            view_yport[1] = 0;
            view_wport[1] = view_wport[0] / view_wview[0] * view_wview[1];
            view_hport[1] = view_hport[0] / view_hview[0] * view_hview[1];
            view_xview[2] = 0;
            view_yview[2] = room_height + y1 - 0.5*view_hview[0];
            view_wview[2] = x1 + 0.5*view_wview[0] - room_width;
            view_hview[2] = 0.5*view_hview[0] - y1;
            view_xport[2] = view_wport[1];
            view_yport[2] = 0;
            view_wport[2] = view_wport[0] / view_wview[0] * view_wview[2];
            view_hport[2] = view_hport[0] / view_hview[0] * view_hview[2];
            view_xview[3] = x1 - 0.5*view_wview[0];
            view_yview[3] = 0;
            view_wview[3] = 0.5*view_wview[0] + room_width - x1;
            view_hview[3] = y1 + 0.5*view_hview[0];
            view_xport[3] = 0;
            view_yport[3] = view_hport[1];
            view_wport[3] = view_wport[0] / view_wview[0] * view_wview[3];
            view_hport[3] = view_hport[0] / view_hview[0] * view_hview[3];
            view_xview[4] = 0;
            view_yview[4] = 0;
            view_wview[4] = x1 + 0.5*view_wview[0] - room_width;
            view_hview[4] = y1 + 0.5*view_hview[0]
            view_xport[4] = view_wport[3];
            view_yport[4] = view_hport[2];
            view_wport[4] = view_wport[0] / view_wview[0] * view_wview[4];
            view_hport[4] = view_hport[0] / view_hview[0] * view_hview[4];
        }
        else if (y1 + 0.5*view_hview[0] > room_height) // the view is colliding with the bottom right edge of the room
        {
            view_visible[0] = false;
            view_visible[1] = true;
            view_visible[2] = true;
            view_visible[3] = true;
            view_visible[4] = true;
            
            view_xview[1] = x1 - 0.5*view_wview[0];
            view_yview[1] = y1 - 0.5*view_hview[0];
            view_wview[1] = room_width - x1 + 0.5*view_wview[0];
            view_hview[1] = room_height - y1 + 0.5*view_hview[0];
            
            view_xport[1] = 0;
            view_yport[1] = 0;
            view_wport[1] = view_wport[0] / view_wview[0] * view_wview[1];
            view_hport[1] = view_hport[0] / view_hview[0] * view_hview[1];
            
            view_xview[2] = 0;
            view_yview[2] = y1 - 0.5*view_hview[0];
            view_wview[2] = x1 + 0.5*view_wview[0] - room_width;
            view_hview[2] = 0.5*view_hview[0] + room_height - y1;
            
            view_xport[2] = view_wport[1];
            view_yport[2] = 0;
            view_wport[2] = view_wport[0] / view_wview[0] * view_wview[2];
            view_hport[2] = view_hport[0] / view_hview[0] * view_hview[2];
            
            view_xview[3] = x1 - 0.5*view_wview[0];
            view_yview[3] = 0;
            view_wview[3] = room_width - x1 + 0.5*view_wview[0];
            view_hview[3] = y1 + 0.5*view_hview[0] - room_height;
            
            view_xport[3] = 0;
            view_yport[3] = view_hport[1];
            view_wport[3] = view_wport[0] / view_wview[0] * view_wview[3];
            view_hport[3] = view_hport[0] / view_hview[0] * view_hview[3];
            
            view_xview[4] = 0;
            view_yview[4] = 0;
            view_wview[4] = x1 + 0.5*view_wview[0] - room_width;
            view_hview[4] = y1 + 0.5*view_hview[0] - room_height;
            
            view_xport[4] = view_wport[3];
            view_yport[4] = view_hport[2];
            view_wport[4] = view_wport[0] / view_wview[0] * view_wview[4];
            view_hport[4] = view_hport[0] / view_hview[0] * view_hview[4];   
        }
        else // the view is colliding with the right edge of the room
        {
            view_visible[0] = false;
            view_visible[1] = true;
            view_visible[2] = true;
            view_visible[3] = false;
            view_visible[4] = false;
            view_xview[1] = x1 - 0.5*view_wview[0]; 
            view_yview[1] = y1 - 0.5*view_hview[0]; 
            view_wview[1] = 0.5*view_wview[0] + room_width - x1; 
            view_hview[1] = view_hview[0]; 
            view_xport[1] = 0; 
            view_yport[1] = 0; 
            view_wport[1] = view_wport[0] / view_wview[0] * view_wview[1];
            view_hport[1] = view_hport[0]; 
            view_xview[2] = 0; 
            view_yview[2] = y1 - 0.5*view_hview[0]; 
            view_wview[2] = 0.5*view_wview[0] + x1 - room_width; 
            view_hview[2] = view_hview[0]; 
            view_xport[2] = view_wport[1]; 
            view_yport[2] = 0; 
            view_wport[2] = view_wport[0] / view_wview[0] * view_wview[2];
            view_hport[2] = view_hport[0];    
        }
    }
    else if (y1 < 0.5*view_hview[0]) // the view is colliding with the top edge of the room
    {
        view_visible[0] = false;
        view_visible[1] = true;
        view_visible[2] = true;
        view_visible[3] = false;
        view_visible[4] = false;
        view_yview[1] = room_height - 0.5*view_hview[0] + y1; 
        view_xview[1] = x1 - 0.5*view_wview[0];
        view_hview[1] = 0.5*view_hview[0] - y1; 
        view_wview[1] = view_wview[0]; 
        view_yport[1] = 0;
        view_xport[1] = 0;
        view_hport[1] = view_hport[0] / view_hview[0] * view_hview[1];
        view_wport[1] = view_wport[0];
        view_yview[2] = 0; 
        view_xview[2] = x1 - 0.5*view_wview[0];
        view_hview[2] = y1 + 0.5*view_hview[0]; 
        view_wview[2] = view_wview[0];
        view_yport[2] = view_hport[1]; 
        view_xport[2] = 0;
        view_hport[2] = view_hport[0] / view_hview[0] * view_hview[2]; 
        view_wport[2] = view_wport[0];   
    }
    else if (y1 + 0.5*view_hview[0] > room_height) // the view is colliding with the bottom edge of the room
    {
        view_visible[0] = false;
        view_visible[1] = true;
        view_visible[2] = true;
        view_visible[3] = false;
        view_visible[4] = false;
        view_xview[1] = x1 - 0.5*view_wview[0];
        view_yview[1] = y1 - 0.5*view_hview[0];
        view_wview[1] = view_wview[0];
        view_hview[1] = 0.5*view_hview[0] + room_height - y1;
        view_xport[1] = 0;
        view_yport[1] = 0;
        view_wport[1] = view_wport[0] / view_wview[0] * view_wview[1];
        view_hport[1] = view_hport[0] / view_hview[0] * view_hview[1];
        view_xview[2] = x1 - 0.5*view_wview[0];
        view_yview[2] = 0;
        view_wview[2] = view_wview[0];
        view_hview[2] = 0.5*view_hview[0] + y1 - room_height;
        view_xport[2] = 0;
        view_yport[2] = view_hport[1];
        view_wport[2] = view_wport[0] / view_wview[0] * view_wview[2];
        view_hport[2] = view_hport[0] / view_hview[0] * view_hview[2];
    }
    else
    {
        view_visible[0] = true;
        view_visible[1] = false;
        view_visible[2] = false;
        view_visible[3] = false;
        view_visible[4] = false;
    }
}

place_meeting

Expand/// place_meeting_xwrap(x1, y1, obj)
//  
//  boolean
//
//  returns true if there is a collision with 
//  obj at (x1,y1) or if the calling object
//  is colliding with the edge of the room 
//  and there is a collision at the oppostite 
//  side of room to (x1,y1) horizontally. 
//  i.e. adds or subtracts room_width to the x
//  position to check depending on what side of
//  the room the given point, (x1,y1) is.
// 
/// GMLscripts.com/license
{
    var x1, y1, obj, xwrap;
    x1 = argument0;
    y1 = argument1;
    obj = argument2;
    xwrap = x1 + bbox_left - x < 0 || x1 + bbox_right - x + 1 > room_width;
    return place_meeting(x1,y1,obj) || (xwrap && place_meeting(x1 - sign(x1 - 0.5*room_width) * room_width, y1, obj));
}
Expand/// place_meeting_ywrap(x1, y1, obj)
//  
//  boolean
//
//  returns true if there is a collision with 
//  obj at (x1,y1) or if the calling object
//  is colliding with the edge of the room 
//  and there is a collision at the oppostite 
//  side of room to (x1,y1) horizontally. 
//  i.e. adds or subtracts room_width to the x
//  position to check depending on what side of
//  the room the given point, (x1,y1) is.
// 
/// GMLscripts.com/license
{
    var x1, y1, obj, ywrap;
    x1 = argument0;
    y1 = argument1;
    obj = argument2;
    ywrap = y1 + bbox_top - y < 0 || y1 + bbox_bottom - y + 1> room_height;
    return place_meeting(x1,y1,obj) || (ywrap && place_meeting(x1, y1 - sign(y1 - 0.5*room_height) * room_height, obj));
}
Expand/// place_meeting_xywrap(x1, y1, obj)
//  
//  boolean
//
//  returns true if there is a collision with 
//  obj at (x1,y1) or if the calling object
//  is colliding with the edge of the room 
//  and there is a collision at the oppostite 
//  side of room to (x1,y1) horizontally. 
//  i.e. adds or subtracts room_width to x1
//  depending on what side of room x1 is.
// 
/// GMLscripts.com/license
{
    var x1, y1, obj, xwrap, ywrap;
    x1 = argument0;
    y1 = argument1;
    obj = argument2;
    xwrap = x1 + bbox_left - x < 0 || x1 + bbox_right - x + 1> room_width;
    ywrap = y1 + bbox_top - y < 0 || y1 + bbox_bottom - y + 1> room_height;
    if place_meeting(x1,y1,obj) 
    {
        return true;
    }
    else if (xwrap && place_meeting(x1 - sign(x1 - 0.5*room_width) * room_width, y1, obj)) 
    {
        return true;
    }
    else if (ywrap && place_meeting(x1, y1 - sign(y1 - 0.5*room_height) * room_height, obj)) 
    {
        return true;
    }
    else
    {
        return (xwrap && ywrap) && place_meeting(x1 -sign(x1-0.5*room_width)*room_width, y1-sign(y1-0.5*room_height)*room_height, obj);
    }
}

collide_move

Expand/// collide_move_xwrap(obj)
//  
//  void
// 
//  Checks for collision with obj and moves the 
//  calling object by the value of its 'hsp' & 'vsp'
//  varibles. Throws error if these are not set.
//  
//  wraps room horizontally
//    
/// GMLscripts.com/license
{
    var obj = argument0;
    if place_meeting_xwrap(x+hsp,y,obj)
    {
        while !place_meeting_xwrap(x+sign(hsp),y,obj)
        {
            x += sign(hsp);
        }
        hsp = 0;
    }
    else
    { 
        x += hsp;
    }
    if (x < 0 || x > room_width)
    {
        x -= sign(x - 0.5*room_width) * room_width;
    }
    if place_meeting_xwrap(x, y + vsp, obj)
    {
        while !place_meeting_xwrap(x,y+sign(vsp),obj)
        {
            y += sign(vsp);
        }
        vsp = 0;
    }
    else
    { 
        y += vsp;
    }
}
Expand/// collide_move_ywrap(obj)
//  
//  void
// 
//  Checks for collision with obj and moves the 
//  calling object by the value of its 'hsp' & 'vsp'
//  varibles. Throws error if these are not set.
//  
//  wraps room vertically
//
/// GMLscripts.com/license
{
    var obj = argument0;
    if place_meeting_ywrap(x+hsp,y,obj)
    {
        while !place_meeting_ywrap(x+sign(hsp),y,obj)
        {
            x += sign(hsp);
        }
        hsp = 0;
    }
    else
    { 
        x += hsp;
    }
    if place_meeting_ywrap(x, y + vsp, obj)
    {
        while !place_meeting_ywrap(x,y+sign(vsp),obj)
        {
            y += sign(vsp);
        }
        vsp = 0;
    }
    else
    { 
        y += vsp;
    }
    if (y < 0 || y > room_height)
    {
        y -= sign(y - 0.5*room_height) * room_height;
    }
}
Expand/// collide_move_xywrap(obj)
//  
//  void
// 
//  Checks for collision with obj and moves the 
//  calling object by the value of its 'hsp' & 'vsp'
//  varibles. Throws error if these are not set.
//
//  wraps room on x and y axis.
//  
/// GMLscripts.com/license
{
    var obj = argument0;
    if place_meeting_xywrap(x+hsp,y,obj)
    {
        while !place_meeting_xywrap(x+sign(hsp),y,obj)
        {
            x += sign(hsp);
        }
        hsp = 0;
    }
    else
    { 
        x += hsp;
    }
    if (x < 0 || x > room_width)
    {
        x -= sign(x - 0.5*room_width) * room_width;
    }
    if place_meeting_xywrap(x, y + vsp, obj)
    {
        while !place_meeting_xywrap(x,y+sign(vsp),obj)
        {
            y += sign(vsp);
        }
        vsp = 0;
    }
    else
    { 
        y += vsp;
    }
    if (y < 0 || y > room_height)
    {
        y -= sign(y - 0.5*room_height) * room_height;
    }
}

draw_self

Expand/// draw_self_xwrap()
//  
//  void
//
//  draws self at current position and at the 
//  other side of the room if wrapping horizontally
//
/// GMLscripts.com/license
{
    draw_self();
    if ((x - sprite_width < 0) || (x + sprite_width > room_width))
    {
        draw_sprite_ext(sprite_index, image_index, x-sign(x-0.5*room_width)*room_width, y, image_xscale, image_yscale, image_angle, image_blend, image_alpha);
    }
}
Expand/// draw_self_ywrap()
//  
//  void
//
//  draws self at current position and at the 
//  other side of the room if wrapping vertically.
//
/// GMLscripts.com/license
{
    draw_self();
    if ((y - sprite_height < 0) || (y + sprite_height > room_height))
    {
        draw_sprite_ext(sprite_index, image_index, x, y -sign(y-0.5*room_height)*room_height, image_xscale, image_yscale, image_angle, image_blend, image_alpha);
    }
}
Expand/// draw_self_xywrap()
//  
//  void
//
//  draws self at current position and at the 
//  other sides of the room if colliding width the
//  edges of the room.
// 
/// GMLscripts.com/license
{
    var xwrap, ywrap;
    xwrap = (x - sprite_width < 0) || (x + sprite_width > room_width);
    ywrap = (y - sprite_height < 0) || (y + sprite_height > room_height);
    draw_self();
    if xwrap
    {
        draw_sprite_ext(sprite_index, image_index, x-sign(x-0.5*room_width)*room_width, y, image_xscale, image_yscale, image_angle, image_blend, image_alpha);
    }
    if ywrap
    {
        draw_sprite_ext(sprite_index, image_index, x, y -sign(y-0.5*room_height)*room_height, image_xscale, image_yscale, image_angle, image_blend, image_alpha);
    }
    if xwrap && ywrap
    {
        draw_sprite_ext(sprite_index, image_index, x-sign(y-0.5*room_width)*room_width, y -sign(y-0.5*room_height)*room_height, image_xscale, image_yscale, image_angle, image_blend, image_alpha);
    }
}

#2 Re: Script Submission » Seamless Room Wrapping » 2016-10-26 07:27:37

Thanks xot. I also updated it with a download link to a gamemaker project using all three wrapping types. I've also been playing around with an astroids style game with gravity in the centre using the xywrap scripts. Makes for some interesting orbits smile

maxtroids.jpg

#3 Script Submission » Seamless Room Wrapping » 2016-10-23 07:56:11

bobsmojo
Replies: 5

Scripts for seamless room wrapping in Gamemaker using multiple views. Set up view[0] in your room as you normally would. When the view collides with the edge of the room it will split into multiple views each showing one side of the room. A player can walk in one direction until they come back to where they started with no concept of the edge of the room. Supports different view/port dimensions and dynamic changes to view[0] will apply to the rest of the views as they resize to view[0]'s dimensions each frame. Doesn't support rotating views and looks weird if the view is bigger than the room.

Gamemaker Project:  room_wraping.gmx.zip
Above project uses a camera object that follows the player. The view gets bigger the faster the camera object moves. You can toggle between x axis wrapping only, y axis wrapping only and wrapping both axis with the 1, 2 & 3 keys respectively.

Simple version with basic movement mechanics and no view stretching: room_wrapping_simple.gmx.zip

Untitled.jpg

scr_camera_xwrap()/scr_camera_ywrap()/scr_camera_xywrap()
These scripts centre the view on the object calling them. The relevent script should be called in the step event of the object that the view is following (eg. the player).

scr_place_meeting_xwrap(x, y, collision_object)/scr_place_meeting_ywrap(x, y,
collision_object)/scr_place_meeting_xywrap(x, y, collision_object)
Use instead of place_meeting() in your code.

scr_collide_move_xwrap(collision_object)/scr_collide_move_ywrap(collision_object)/scr_collide_move_xywrap(collision_object)
Checks for collisions and moves the calling object based on its 'hsp' and 'vsp' variables. (modified from Shaun Spaulding's platformer tutorial)

scr_draw_xwrap()/scr_draw_ywrap()/scr_draw_xywrap()
Call this script in the draw event of moving objects. Draws the object's sprite as it would normally appear when wrapping over the edge of the room.

X Axis

scr_camera_xwrap()

Expand    ///scr_camera_xwrap()
    view_xview[0] = x - view_wview[0]/2;
    view_yview[0] = y - view_hview[0]/2;
    if (x < view_wview[0]/2) // the view is colliding with the left edge of the room
    {
        view_visible[0] = false;
        view_visible[1] = true;
        view_visible[2] = true;
        view_visible[3] = false;
        view_visible[4] = false;
        view_xview[1] = room_width - view_wview[0]/2 + x; 
        view_yview[1] = y - view_hview[0]/2;
        view_wview[1] = view_wview[0]/2 - x; 
        view_hview[1] = view_hview[0]; 
        view_xport[1] = 0; 
        view_yport[1] = 0; 
        view_wport[1] = view_wport[0] / view_wview[0] * view_wview[1];
        view_hport[1] = view_hport[0]; 
        view_xview[2] = 0; 
        view_yview[2] = y - view_hview[0]/2; 
        view_wview[2] = x + view_wview[0]/2; 
        view_hview[2] = view_hview[0];
        view_xport[2] = view_wport[1];
        view_yport[2] = 0;
        view_wport[2] = view_wport[0] / view_wview[0] * view_wview[2]; 
        view_hport[2] = view_hport[0]; 
    }
    else if (x + view_wview[0]/2 > room_width) // the view is colliding with the right edge of the room
    {
        view_visible[0] = false;
        view_visible[1] = true;
        view_visible[2] = true;
        view_visible[3] = false;
        view_visible[4] = false;
        view_xview[1] = x - view_wview[0]/2; 
        view_yview[1] = y - view_hview[0]/2; 
        view_wview[1] = view_wview[0]/2 + room_width - x; 
        view_hview[1] = view_hview[0]; 
        view_xport[1] = 0; 
        view_yport[1] = 0; 
        view_wport[1] = view_wport[0] / view_wview[0] * view_wview[1];
        view_hport[1] = view_hport[0]; 
        view_xview[2] = 0; 
        view_yview[2] = y - view_hview[0]/2; 
        view_wview[2] = view_wview[0]/2 + x - room_width; 
        view_hview[2] = view_hview[0]; 
        view_xport[2] = view_wport[1]; 
        view_yport[2] = 0; 
        view_wport[2] = view_wport[0] / view_wview[0] * view_wview[2];
        view_hport[2] = view_hport[0];  
    }
    else // the view is not colliding with the edge of the room
    {
        view_visible[0] = true;
        view_visible[1] = false;
        view_visible[2] = false;
        view_visible[3] = false;
        view_visible[4] = false;
    }

scr_place_meeting_xwrap(x, y, collision_object)

Expand    ///scr_place_meeting_xwrap(x, y, collision_object)
    var _xwrap = argument0 + bbox_left - x < 0 || argument0 + bbox_right - x + 1> room_width;
    return place_meeting(argument0,argument1,argument2) || (_xwrap && place_meeting(argument0 - sign argument0 - room_width/2) * room_width, argument1, argument2));

scr_collide_move_xwrap(collision_object)

Expand    ///scr_collide_move_xwrap(collision_object)
    if scr_place_meeting_xwrap(x+hsp,y,argument0)
    {
        while !scr_place_meeting_xwrap(x+sign(hsp),y,argument0)
        {
            x += sign(hsp);
        }
        hsp = 0;
    }
    else
    { 
        x += hsp;
    }
    if (x < 0 || x > room_width)
    {
        x -= sign(x - room_width/2) * room_width;
    }
    if scr_place_meeting_xwrap(x, y + vsp, argument0)
    {
        while !scr_place_meeting_xwrap(x,y+sign(vsp),argument0)
        {
            y += sign(vsp);
        }
        vsp = 0;
    }
    else
    { 
        y += vsp;
    }

scr_draw_xwrap()

Expand    ///scr_draw_xwrap()
    draw_self();
    if (x - sprite_width < 0 || x + sprite_width > room_width)
    {
        draw_sprite_ext(sprite_index, image_index, x-sign(x-room_width/2)*room_width, y, image_xscale, image_yscale, image_angle, image_blend, image_alpha);
    }


Y Axis

scr_camera_ywrap()

Expand    ///scr_camera_ywrap()
    view_xview[0] = x - view_wview[0]/2;
    view_yview[0] = y - view_hview[0]/2;

    if (y < view_hview[0]/2) // the view is colliding with the top edge of the room
    {
        view_visible[0] = false;
        view_visible[1] = true;
        view_visible[2] = true;
        view_visible[3] = false;
        view_visible[4] = false;
        view_yview[1] = room_height - view_hview[0]/2 + y; 
        view_xview[1] = x - view_wview[0]/2;
        view_hview[1] = view_hview[0]/2 - y; 
        view_wview[1] = view_wview[0]; 
        view_yport[1] = 0view_xport[1] = 0;
        view_hport[1] = view_hport[0] / view_hview[0] * view_hview[1];
        view_wport[1] = view_wport[0];
        view_yview[2] = 0; 
        view_xview[2] = x - view_wview[0]/2;
        view_hview[2] = y + view_hview[0]/2; 
        view_wview[2] = view_wview[0];
        view_yport[2] = view_hport[1]; 
        view_xport[2] = 0;
        view_hport[2] = view_hport[0] / view_hview[0] * view_hview[2]; 
        view_wport[2] = view_wport[0];   
    }
    else if (y + view_hview[0]/2 > room_height)  // the view is colliding with the bottom edge of the room
    {
        view_visible[0] = false;
        view_visible[1] = true;
        view_visible[2] = true;
        view_visible[3] = false;
        view_visible[4] = false;
        view_xview[1] = x - view_wview[0]/2;
        view_yview[1] = y - view_hview[0]/2;
        view_wview[1] = view_wview[0];
        view_hview[1] = view_hview[0]/2 + room_height - y;
        view_xport[1] = 0;
        view_yport[1] = 0;
        view_wport[1] = view_wport[0] / view_wview[0] * view_wview[1];
        view_hport[1] = view_hport[0] / view_hview[0] * view_hview[1];
        view_xview[2] = x - view_wview[0]/2;
        view_yview[2] = 0;
        view_wview[2] = view_wview[0];
        view_hview[2] = view_hview[0]/2 + y - room_height;
        view_xport[2] = 0;
        view_yport[2] = view_hport[1];
        view_wport[2] = view_wport[0] / view_wview[0] * view_wview[2];
        view_hport[2] = view_hport[0] / view_hview[0] * view_hview[2];
    }
    else // the view is not colliding with the edge of the room
    {
        view_visible[0] = true;
        view_visible[1] = false;
        view_visible[2] = false;
        view_visible[3] = false;
        view_visible[4] = false;
    }

scr_place_meeting_ywrap(x, y, collision_object)

Expand    ///scr_place_meeting_ywrap(x, y, collision_object)
    var ywrap = argument1 + bbox_top - y < 0 || argument1 + bbox_bottom - y + 1> room_height;
    return place_meeting(argument0,argument1,argument2) || ywrap && place_meeting(argument0, argument1 - sign(argument1 - room_height/2) * room_height, argument2);

scr_collide_move_ywrap(collision_object)

Expand    ///scr_collide_move_ywrap(collision_object)
    if scr_place_meeting_ywrap(x+hsp,y,argument0)
    {
        while !scr_place_meeting_ywrap(x+sign(hsp),y,argument0)
        {
            x += sign(hsp);
        }
        hsp = 0;
    }
    else
    { 
        x += hsp;
    }
    if scr_place_meeting_ywrap(x, y + vsp, argument0)
    {
        while !scr_place_meeting_ywrap(x,y+sign(vsp),argument0)
        {
            y += sign(vsp);
        }
        vsp = 0;
    }
    else
    { 
        y += vsp;
    }
    if (y < 0 || y > room_height)
    {
        y -= sign(y - room_height/2) * room_height;
    }

scr_draw_ywrap()

Expand    ///scr_draw_ywrap()
    draw_self();
    if (y - sprite_height < 0 || y + sprite_height > room_height)
    {
        draw_sprite_ext(sprite_index, image_index, x, y -sign(y-room_height/2)*room_height, image_xscale, image_yscale, image_angle, image_blend, image_alpha);
    }


X & Y Axis

scr_camera_xywrap()

Expand    ///scr_camera_xywrap()
    view_xview[0] = x - view_wview[0]/2;
    view_yview[0] = y - view_hview[0]/2;
    
    if (x < view_wview[0]/2) // the view is colliding with the left edge of the room
    {
        if (y < view_hview[0]/2) // the view is colliding with the top left corner of the room
        {
            view_visible[0] = false;
            view_visible[1] = true;
            view_visible[2] = true;
            view_visible[3] = true;
            view_visible[4] = true;
            view_xview[1] = room_width + x - view_wview[0]/2;
            view_yview[1] = room_height + y - view_hview[0]/2;
            view_wview[1] = view_wview[0]/2 - x;
            view_hview[1] = view_hview[0]/2 - y;
            view_xport[1] = 0;
            view_yport[1] = 0;
            view_wport[1] = view_wport[0] / view_wview[0] * view_wview[1]; 
            view_hport[1] = view_hport[0] / view_hview[0] * view_hview[1];
            view_xview[2] = 0;
            view_yview[2] = room_height + y - view_hview[0]/2;
            view_wview[2] = view_wview[0]/2 + x;
            view_hview[2] = view_hview[0]/2 - y;
            view_xport[2] = view_wport[1];
            view_yport[2] = 0;
            view_wport[2] = view_wport[0] / view_wview[0] * view_wview[2]; 
            view_hport[2] = view_hport[0] / view_hview[0] * view_hview[2];
            view_xview[3] = room_width + x - view_wview[0]/2;
            view_yview[3] = 0;
            view_wview[3] = view_wview[0]/2 - x;
            view_hview[3] = y + view_hview[0]/2;
            view_xport[3] = 0;
            view_yport[3] = view_hport[1];
            view_wport[3] = view_wport[0] / view_wview[0] * view_wview[3];
            view_hport[3] = view_hport[0] / view_hview[0] * view_hview[3];
            view_xview[4] = 0;
            view_yview[4] = 0;
            view_wview[4] = x + view_wview[0]/2;
            view_hview[4] = y + view_hview[0]/2;
            view_xport[4] = view_wport[3];
            view_yport[4] = view_hport[2];
            view_wport[4] = view_wport[0] / view_wview[0] * view_wview[4];
            view_hport[4] = view_hport[0] / view_hview[0] * view_hview[4];
        }
        else if (y + view_hview[0]/2 > room_height) // the view is colliding with the bottom left corner of the room
        {
            view_visible[0] = false;
            view_visible[1] = true;
            view_visible[2] = true;
            view_visible[3] = true;
            view_visible[4] = true;
            view_xview[1] = x - view_wview[0]/2 + room_width;
            view_yview[1] = y - view_hview[0]/2;
            view_wview[1] = view_wview[0]/2 - x;
            view_hview[1] = room_height - y + view_hview[0]/2;
            view_xport[1] = 0;
            view_yport[1] = 0;
            view_wport[1] = view_wport[0] / view_wview[0] * view_wview[1];
            view_hport[1] = view_hport[0] / view_hview[0] * view_hview[1];
            view_xview[2] = 0;
            view_yview[2] = y - view_hview[0]/2;
            view_wview[2] = x + view_wview[0]/2;
            view_hview[2] = view_hview[0]/2 + room_height - y;
            view_xport[2] = view_wport[1];
            view_yport[2] = 0;
            view_wport[2] = view_wport[0] / view_wview[0] * view_wview[2];
            view_hport[2] = view_hport[0] / view_hview[0] * view_hview[2];
            view_xview[3] = x - view_wview[0]/2 + room_width;
            view_yview[3] = 0;
            view_wview[3] = view_wview[0]/2 - x;
            view_hview[3] = y + view_hview[0]/2 - room_height;
            view_xport[3] = 0;
            view_yport[3] = view_hport[1];
            view_wport[3] = view_wport[0] / view_wview[0] * view_wview[3];
            view_hport[3] = view_hport[0] / view_hview[0] * view_hview[3];
            view_xview[4] = 0;
            view_yview[4] = 0;
            view_wview[4] = x + view_wview[0]/2;
            view_hview[4] = y + view_hview[0]/2 - room_height;
            view_xport[4] = view_wport[3];
            view_yport[4] = view_hport[2];
            view_wport[4] = view_wport[0] / view_wview[0] * view_wview[4];
            view_hport[4] = view_hport[0] / view_hview[0] * view_hview[4];
        }
        else  // the view is colliding with the left edge of the room
        {
            view_visible[0] = false;
            view_visible[1] = true;
            view_visible[2] = true;
            view_visible[3] = false;
            view_visible[4] = false;
            view_xview[1] = room_width - view_wview[0]/2 + x; 
            view_yview[1] = y - view_hview[0]/2;
            view_wview[1] = view_wview[0]/2 - x; 
            view_hview[1] = view_hview[0]; 
            view_xport[1] = 0; 
            view_yport[1] = 0; 
            view_wport[1] = view_wport[0] / view_wview[0] * view_wview[1];
            view_hport[1] = view_hport[0]; 
            view_xview[2] = 0; 
            view_yview[2] = y - view_hview[0]/2; 
            view_wview[2] = x + view_wview[0]/2; 
            view_hview[2] = view_hview[0];
            view_xport[2] = view_wport[1];
            view_yport[2] = 0;
            view_wport[2] = view_wport[0] / view_wview[0] * view_wview[2]; 
            view_hport[2] = view_hport[0]; 
        }
    }
    else if (x + view_wview[0]/2 > room_width) // the view is colliding with the rigth edge of the room
    {
        if (y < view_hview[0]/2) // the view is colliding with the top rigth edge of the room
        {       
            view_visible[0] = false;
            view_visible[1] = true;
            view_visible[2] = true;
            view_visible[3] = true;
            view_visible[4] = true;
            view_xview[1] = x - view_wview[0]/2;
            view_yview[1] = room_height + y - view_hview[0]/2;
            view_wview[1] = room_width - x + view_wview[0]/2;
            view_hview[1] = view_hview[0]/2 - y;
            view_xport[1] = 0;
            view_yport[1] = 0;
            view_wport[1] = view_wport[0] / view_wview[0] * view_wview[1];
            view_hport[1] = view_hport[0] / view_hview[0] * view_hview[1];
            view_xview[2] = 0;
            view_yview[2] = room_height + y - view_hview[0]/2;
            view_wview[2] = x + view_wview[0]/2 - room_width;
            view_hview[2] = view_hview[0]/2 - y;
            view_xport[2] = view_wport[1];
            view_yport[2] = 0;
            view_wport[2] = view_wport[0] / view_wview[0] * view_wview[2];
            view_hport[2] = view_hport[0] / view_hview[0] * view_hview[2];
            view_xview[3] = x - view_wview[0]/2;
            view_yview[3] = 0;
            view_wview[3] = view_wview[0]/2 + room_width - x;
            view_hview[3] = y + view_hview[0]/2;
            view_xport[3] = 0;
            view_yport[3] = view_hport[1];
            view_wport[3] = view_wport[0] / view_wview[0] * view_wview[3];
            view_hport[3] = view_hport[0] / view_hview[0] * view_hview[3];
            view_xview[4] = 0;
            view_yview[4] = 0;
            view_wview[4] = x + view_wview[0]/2 - room_width;
            view_hview[4] = y + view_hview[0]/2
            view_xport[4] = view_wport[3];
            view_yport[4] = view_hport[2];
            view_wport[4] = view_wport[0] / view_wview[0] * view_wview[4];
            view_hport[4] = view_hport[0] / view_hview[0] * view_hview[4];
        }
        else if (y + view_hview[0]/2 > room_height) // the view is colliding with the bottom right edge of the room
        {
            view_visible[0] = false;
            view_visible[1] = true;
            view_visible[2] = true;
            view_visible[3] = true;
            view_visible[4] = true;
            view_xview[1] = x - view_wview[0]/2;
            view_yview[1] = y - view_hview[0]/2;
            view_wview[1] = room_width - x + view_wview[0]/2;
            view_hview[1] = room_height - y + view_hview[0]/2;
            view_xport[1] = 0;
            view_yport[1] = 0;
            view_wport[1] = view_wport[0] / view_wview[0] * view_wview[1];
            view_hport[1] = view_hport[0] / view_hview[0] * view_hview[1];
            view_xview[2] = 0;
            view_yview[2] = y - view_hview[0]/2;
            view_wview[2] = x + view_wview[0]/2 - room_width;
            view_hview[2] = view_hview[0]/2 + room_height - y;
            view_xport[2] = view_wport[1];
            view_yport[2] = 0;
            view_wport[2] = view_wport[0] / view_wview[0] * view_wview[2];
            view_hport[2] = view_hport[0] / view_hview[0] * view_hview[2];
            view_xview[3] = x - view_wview[0]/2;
            view_yview[3] = 0;
            view_wview[3] = room_width - x + view_wview[0]/2;
            view_hview[3] = y + view_hview[0]/2 - room_height;
            view_xport[3] = 0;
            view_yport[3] = view_hport[1];
            view_wport[3] = view_wport[0] / view_wview[0] * view_wview[3];
            view_hport[3] = view_hport[0] / view_hview[0] * view_hview[3];
            view_xview[4] = 0;
            view_yview[4] = 0;
            view_wview[4] = x + view_wview[0]/2 - room_width;
            view_hview[4] = y + view_hview[0]/2 - room_height;
            view_xport[4] = view_wport[3];
            view_yport[4] = view_hport[2];
            view_wport[4] = view_wport[0] / view_wview[0] * view_wview[4];
            view_hport[4] = view_hport[0] / view_hview[0] * view_hview[4];   
        }
        else // the view is colliding with the right edge of the room
        {
            view_visible[0] = false;
            view_visible[1] = true;
            view_visible[2] = true;
            view_visible[3] = false;
            view_visible[4] = false;
            view_xview[1] = x - view_wview[0]/2; 
            view_yview[1] = y - view_hview[0]/2; 
            view_wview[1] = view_wview[0]/2 + room_width - x; 
            view_hview[1] = view_hview[0]; 
            view_xport[1] = 0; 
            view_yport[1] = 0; 
            view_wport[1] = view_wport[0] / view_wview[0] * view_wview[1];
            view_hport[1] = view_hport[0]; 
            view_xview[2] = 0; 
            view_yview[2] = y - view_hview[0]/2; 
            view_wview[2] = view_wview[0]/2 + x - room_width; 
            view_hview[2] = view_hview[0]; 
            view_xport[2] = view_wport[1]; 
            view_yport[2] = 0; 
            view_wport[2] = view_wport[0] / view_wview[0] * view_wview[2];
            view_hport[2] = view_hport[0];    
        }
    }
    else if (y < view_hview[0]/2) // the view is colliding with the top edge of the room
    {
        view_visible[0] = false;
        view_visible[1] = true;
        view_visible[2] = true;
        view_visible[3] = false;
        view_visible[4] = false;
        view_yview[1] = room_height - view_hview[0]/2 + y; 
        view_xview[1] = x - view_wview[0]/2;
        view_hview[1] = view_hview[0]/2 - y; 
        view_wview[1] = view_wview[0]; 
        view_yport[1] = 0;
        view_xport[1] = 0;
        view_hport[1] = view_hport[0] / view_hview[0] * view_hview[1];
        view_wport[1] = view_wport[0];
        view_yview[2] = 0; 
        view_xview[2] = x - view_wview[0]/2;
        view_hview[2] = y + view_hview[0]/2; 
        view_wview[2] = view_wview[0];
        view_yport[2] = view_hport[1]; 
        view_xport[2] = 0;
        view_hport[2] = view_hport[0] / view_hview[0] * view_hview[2]; 
        view_wport[2] = view_wport[0];   
    }
    else if (y + view_hview[0]/2 > room_height) // the view is colliding with the bottom edge of the room
    {
        view_visible[0] = false;
        view_visible[1] = true;
        view_visible[2] = true;
        view_visible[3] = false;
        view_visible[4] = false;
        view_xview[1] = x - view_wview[0]/2;
        view_yview[1] = y - view_hview[0]/2;
        view_wview[1] = view_wview[0];
        view_hview[1] = view_hview[0]/2 + room_height - y;
        view_xport[1] = 0;
        view_yport[1] = 0;
        view_wport[1] = view_wport[0] / view_wview[0] * view_wview[1];
        view_hport[1] = view_hport[0] / view_hview[0] * view_hview[1];
        view_xview[2] = x - view_wview[0]/2;
        view_yview[2] = 0;
        view_wview[2] = view_wview[0];
        view_hview[2] = view_hview[0]/2 + y - room_height;
        view_xport[2] = 0;
        view_yport[2] = view_hport[1];
        view_wport[2] = view_wport[0] / view_wview[0] * view_wview[2];
        view_hport[2] = view_hport[0] / view_hview[0] * view_hview[2];
    }
    else
    {
        view_visible[0] = true;
        view_visible[1] = false;
        view_visible[2] = false;
        view_visible[3] = false;
        view_visible[4] = false;
    }

scr_place_meeting_xywrap(x, y, collision_object)

Expand    ///scr_place_meeting_xywrap(x, y, collision_object)
    var xwrap = argument0 + bbox_left - x < 0 || argument0 + bbox_right - x + 1> room_width;
    var ywrap = argument1 + bbox_top - y < 0 || argument1 + bbox_bottom - y + 1> room_height;
    return (place_meeting(argument0,argument1,argument2) || (xwrap && place_meeting(argument0 - sign(argument0 - room_width/2) * room_width, argument1, argument2)) || (ywrap && place_meeting(argument0, argument1 - sign(argument1 - room_height/2) * room_height, argument2)) || ((xwrap && ywrap) && place_meeting(argument0 -sign(argument0-room_width/2)*room_width, argument1-sign(argument1-room_height/2)*room_height, argument2)));

scr_collide_move_xywrap(collision_object)

Expand    ///scr_collide_move_xywrap(collision_object)
    if scr_place_meeting_xywrap(x+hsp,y,argument0)
    {
        while !scr_place_meeting_xywrap(x+sign(hsp),y,argument0)
        {
            x += sign(hsp);
        }
        hsp = 0;
    }
    else
    { 
        x += hsp;
    }
    if (x < 0 || x > room_width)
    {
        x -= sign(x - room_width/2) * room_width;
    }
    if scr_place_meeting_xywrap(x, y + vsp, argument0)
    {
        while !scr_place_meeting_xywrap(x,y+sign(vsp),argument0)
        {
            y += sign(vsp);
        }
        vsp = 0;
    }
    else
    { 
        y += vsp;
    }
    if (y < 0 || y > room_height)
    {
        y -= sign(y - room_height/2) * room_height;
    }

scr_draw_xywrap()

Expand    ///scr_draw_xywrap()
    draw_self();
    
    var
    xwrap = x - sprite_width < 0 || x + sprite_width > room_width,
    ywrap = y - sprite_height < 0 || y + sprite_height > room_height;
    
    if xwrap
    {
        draw_sprite_ext(sprite_index, image_index, x-sign(x-room_width/2)*room_width, y, image_xscale, image_yscale, image_angle, image_blend, image_alpha);
    }
    if ywrap
    {
        draw_sprite_ext(sprite_index, image_index, x, y -sign(y-room_height/2)*room_height, image_xscale, image_yscale, image_angle, image_blend, image_alpha);
    }
    if xwrap && ywrap
    {
        draw_sprite_ext(sprite_index, image_index, x-sign(y-room_width/2)*room_width, y -sign(y-room_height/2)*room_height, image_xscale, image_yscale, image_angle, image_blend, image_alpha);
    }

Board footer

Powered by FluxBB