S
SebtheDev()
Guest
Hey there,
For my upcoming game - PlayUSA we are implementing controller support, the problem is that as the map has cities on it I need to have the cities selectable, but since it is very unlikely that a user is going to select the exact direction of the city so I was wondering if any of you guys knew a good way to do this!
My Code:
And the collision_line_first script (I got this online):
Help would be greatly appreciated (and maybe rewarded!)
Thanks,
Seb
For my upcoming game - PlayUSA we are implementing controller support, the problem is that as the map has cities on it I need to have the cities selectable, but since it is very unlikely that a user is going to select the exact direction of the city so I was wondering if any of you guys knew a good way to do this!
My Code:
Code:
if(instance_exists(obj_map_city)) {
if ((gamepad_axis_value(0, gp_axislh) != 0) || (gamepad_axis_value(0, gp_axislv) != 0) and game_state = 2) {
var haxis = gamepad_axis_value(0, gp_axislh);
var vaxis = gamepad_axis_value(0, gp_axislv);
direction = point_direction(0, 0, haxis, vaxis);
var new_parent = collision_line_first(x,y,x+lengthdir_x(640,direction),y+lengthdir_y(360,direction),obj_map_city,true,parent);
show_message(new_parent);
x = new_parent.x;
y = new_parent.y;
parent = new_parent;
} else if(parent != 0) {
x = parent.x;
y = parent.y;
}
}
Code:
///@desc collision_line_first
///@param x1
///@param y1
///@param x2
///@param y2
///@param object
///@param prec
///@param notme
/// collision_line_first(x1,y1,x2,y2,object,prec,notme)
//
// Returns the instance id of an object colliding with a given line and
// closest to the first point, or noone if no instance found.
// The solution is found in log2(range) collision checks.
//
// x1,y2 first point on collision line, real
// x2,y2 second point on collision line, real
// object which objects to look for (or all), real
// prec if true, use precise collision checking, bool
// notme if true, ignore the calling instance, bool
//
/// GMLscripts.com/license
{
var ox,oy,dx,dy,object,prec,notme,sx,sy,inst,i;
ox = argument0;
oy = argument1;
dx = argument2;
dy = argument3;
object = argument4;
prec = argument5;
notme = argument6;
sx = dx - ox;
sy = dy - oy;
inst = collision_line(ox,oy,dx,dy,object,prec,notme);
if (inst != noone) {
while ((abs(sx) >= 1) || (abs(sy) >= 1)) {
sx /= 2;
sy /= 2;
i = collision_line(ox,oy,dx,dy,object,prec,notme);
if (i) {
dx -= sx;
dy -= sy;
inst = i;
}else{
dx += sx;
dy += sy;
}
}
}
return inst;
}
Thanks,
Seb