2022-08-15 04:06:41 +00:00
|
|
|
function st_moving() {
|
2022-08-16 22:28:01 +00:00
|
|
|
var mov = data.mov.val;
|
2022-08-15 04:06:41 +00:00
|
|
|
c_input();
|
2022-08-17 16:49:45 +00:00
|
|
|
hspd = lerp(hspd, (right-left)*.07, .4);
|
|
|
|
vspd = lerp(vspd, (down-up)*.07, .4);
|
2022-08-16 22:28:01 +00:00
|
|
|
if !stop dir = DIR.NONE;
|
2022-08-15 04:36:37 +00:00
|
|
|
if left dir = DIR.LEFT;
|
|
|
|
if down dir = DIR.DOWN;
|
|
|
|
if up dir = DIR.UP;
|
|
|
|
if right dir = DIR.RIGHT;
|
|
|
|
if leftp dir = DIR.LEFT;
|
|
|
|
if downp dir = DIR.DOWN;
|
|
|
|
if upp dir = DIR.UP;
|
|
|
|
if rightp dir = DIR.RIGHT;
|
2022-08-15 04:06:41 +00:00
|
|
|
var remainingmov = mov+1 - (
|
|
|
|
abs(x+hspd-16-pos.x*ts.x)/ts.x +
|
|
|
|
abs(y+vspd-16-pos.y*ts.y)/ts.y
|
|
|
|
);
|
|
|
|
//var shitmode = point_distance(x, y, pos.x*ts.x, pos.y*ts.y);
|
|
|
|
//if shitmode > mov*ts.x {
|
2022-08-15 04:36:37 +00:00
|
|
|
if !stop {
|
|
|
|
x += hspd*ts.x;
|
|
|
|
y += vspd*ts.y;
|
|
|
|
}
|
2022-08-15 04:06:41 +00:00
|
|
|
while !remainingmov {
|
|
|
|
hspd = 0;
|
|
|
|
vspd = 0;
|
|
|
|
x = linear_approach(x, pos.x*ts.x+16, 1);
|
|
|
|
y = linear_approach(y, pos.y*ts.y+16, 1);
|
|
|
|
log(x, pos.x*ts.x);
|
|
|
|
log(y, pos.y*ts.y);
|
|
|
|
var remainingmov = mov+1 - (
|
|
|
|
abs(x+hspd-16-pos.x*ts.x)/ts.x +
|
|
|
|
abs(y+vspd-16-pos.y*ts.y)/ts.y
|
|
|
|
);
|
|
|
|
//log("oob, " + string(remainingmov));
|
|
|
|
/*} else {
|
|
|
|
log("not oob!");*/
|
|
|
|
|
|
|
|
}
|
|
|
|
prevremainingmov = remainingmov;
|
2022-08-15 04:36:37 +00:00
|
|
|
c_decolor_all(c_red);
|
|
|
|
c_decolor_all(c_green);
|
2022-08-15 17:51:51 +00:00
|
|
|
var guy = c_gettile(x, y, true);
|
2022-08-16 01:01:09 +00:00
|
|
|
c_colortile(guy.x, guy.y, c_green);
|
|
|
|
//log("selecting");
|
2022-08-16 02:04:23 +00:00
|
|
|
//var rng = [1];
|
2022-08-16 01:01:09 +00:00
|
|
|
var guy = c_gettile(x, y, true);
|
|
|
|
var hitting = noone;
|
2022-08-17 16:49:45 +00:00
|
|
|
if guy != noone {
|
2022-08-15 17:51:51 +00:00
|
|
|
switch dir {
|
|
|
|
case DIR.LEFT:
|
|
|
|
hitting = c_gettile(guy.x-1, guy.y);
|
2022-08-16 02:04:23 +00:00
|
|
|
sprite_index = data.down;
|
|
|
|
image_xscale = -1;
|
2022-08-15 17:51:51 +00:00
|
|
|
break;
|
|
|
|
case DIR.DOWN:
|
|
|
|
hitting = c_gettile(guy.x, guy.y+1);
|
2022-08-16 02:04:23 +00:00
|
|
|
sprite_index = data.down;
|
2022-08-15 17:51:51 +00:00
|
|
|
break;
|
|
|
|
case DIR.UP:
|
|
|
|
hitting = c_gettile(guy.x, guy.y-1);
|
2022-08-16 02:04:23 +00:00
|
|
|
sprite_index = data.up;
|
2022-08-15 17:51:51 +00:00
|
|
|
break;
|
|
|
|
case DIR.RIGHT:
|
|
|
|
hitting = c_gettile(guy.x+1, guy.y);
|
2022-08-16 02:04:23 +00:00
|
|
|
sprite_index = data.down;
|
|
|
|
image_xscale = 1;
|
2022-08-15 17:51:51 +00:00
|
|
|
break;
|
2022-08-16 02:04:23 +00:00
|
|
|
default:
|
|
|
|
sprite_index = data.idle;
|
|
|
|
image_xscale = -1;
|
|
|
|
break;
|
|
|
|
|
2022-08-15 17:51:51 +00:00
|
|
|
}
|
2022-08-17 16:49:45 +00:00
|
|
|
if hitting != noone && select && stop {
|
|
|
|
c_colortile(hitting.x, hitting.y, c_red);
|
2022-08-16 01:01:09 +00:00
|
|
|
log("found one");
|
|
|
|
log(hitting.contents, hitting.x, hitting.y);
|
|
|
|
var i;
|
|
|
|
for (i=0; i<array_length(hitting.contents); i++) {
|
|
|
|
if instance_exists(hitting.contents[i]) {
|
|
|
|
log("is instance");
|
|
|
|
if hitting.contents[i].object_index = o_unit {
|
|
|
|
log("is unit");
|
|
|
|
log("found two");
|
|
|
|
c_generatecombatstack([id, hitting.contents[i]]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-08-15 17:51:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if back {
|
2022-08-16 01:01:09 +00:00
|
|
|
c_deselectunit(id);
|
2022-08-15 17:51:51 +00:00
|
|
|
}
|
2022-08-16 22:28:01 +00:00
|
|
|
if dir == DIR.NONE && select {
|
|
|
|
c_moveunit(id, c_gettile(x, y, true));
|
|
|
|
waiting = true;
|
|
|
|
c_deselectunit(id);
|
|
|
|
}
|
2022-08-15 04:06:41 +00:00
|
|
|
/*if x < (pos.x-mov)*ts.x {
|
|
|
|
x = (pos.x-mov)*ts.x;
|
|
|
|
} else if x > (pos.x+mov+1)*ts.x {
|
|
|
|
x = (pos.x+mov+1)*ts.x;
|
|
|
|
} else {
|
|
|
|
x += hspd*ts.x;
|
|
|
|
}
|
|
|
|
if y < (pos.y-mov)*ts.y {
|
|
|
|
y = (pos.y-mov)*ts.y;
|
|
|
|
} else if y > (pos.y+mov+1)*ts.y {
|
|
|
|
y = (pos.y+mov+1)*ts.y;
|
|
|
|
} else {
|
|
|
|
y += vspd*ts.y;
|
|
|
|
}*/
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function st_movingdraw() {
|
|
|
|
/*var mov = 2;
|
|
|
|
draw_set_color(c_cyan);
|
|
|
|
draw_set_alpha(.4);
|
|
|
|
var i, j;
|
|
|
|
for (i=-mov; i<=mov; i++) {
|
|
|
|
for (j=-mov; j<=mov; j++) {
|
|
|
|
if abs(i)+abs(j) <= mov {
|
|
|
|
draw_rectangle(
|
|
|
|
(pos.x+i)*ts.x,
|
|
|
|
(pos.y+j)*ts.y,
|
|
|
|
(pos.x+i+1)*ts.x,
|
|
|
|
(pos.y+j+1)*ts.y, false
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
draw_set_alpha(1);*/
|
|
|
|
}
|
2022-08-15 04:36:37 +00:00
|
|
|
#macro ts global.tilesize
|
|
|
|
|
|
|
|
enum DIR {
|
|
|
|
NONE,
|
|
|
|
LEFT,
|
|
|
|
DOWN,
|
|
|
|
UP,
|
|
|
|
RIGHT,
|
|
|
|
}
|