eastern-flames/eastern flames/scripts/st_moving/st_moving.gml

251 lines
6.9 KiB
Plaintext
Raw Permalink Normal View History

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-23 13:06:02 +00:00
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-19 22:06:21 +00:00
/*var remainingmov = mov+1 - (
2022-08-18 20:47:07 +00:00
abs(x+hspd-16-returnpos.x*ts.x)/ts.x +
abs(y+vspd-16-returnpos.y*ts.y)/ts.y
2022-08-19 22:06:21 +00:00
);*/
var dist = c_tiledist(pos.x, pos.y, returnpos.y, returnpos.y);
//var remainingmov = dist.x + dist.y;
2022-08-18 20:47:07 +00:00
//var shitmode = point_distance(x, y, returnpos.x*ts.x, returnpos.y*ts.y);
2022-08-15 04:06:41 +00:00
//if shitmode > mov*ts.x {
2022-08-19 22:06:21 +00:00
//while !remainingmov {
/*hspd = 0;
2022-08-15 04:06:41 +00:00
vspd = 0;
2022-08-19 22:06:21 +00:00
x = linear_approach(x, returnpos.x*ts.x, 1);
y = linear_approach(y, returnpos.y*ts.y, 1);
2022-08-18 20:47:07 +00:00
log(x, returnpos.x*ts.x);
log(y, returnpos.y*ts.y);
2022-08-15 04:06:41 +00:00
var remainingmov = mov+1 - (
2022-08-18 20:47:07 +00:00
abs(x+hspd-16-returnpos.x*ts.x)/ts.x +
abs(y+vspd-16-returnpos.y*ts.y)/ts.y
2022-08-19 22:06:21 +00:00
);*/
2022-08-15 04:06:41 +00:00
//log("oob, " + string(remainingmov));
/*} else {
log("not oob!");*/
2022-08-19 22:06:21 +00:00
//}
2022-08-23 13:06:02 +00:00
var dude = c_gettile(x, y, true);
/*if dude != noone {
2022-08-19 22:06:21 +00:00
var dist = c_tiledist(dude.x, dude.y, returnpos.x, returnpos.y);
2022-08-20 18:53:31 +00:00
var friend = c_containsunit(dude.x, dude.y);
if dist.x + dist.y <= data.mov.val && dude.passable && (friend == noone || friend == id) {
2022-08-19 22:06:21 +00:00
pos.x = dude.x;
pos.y = dude.y;
if !stop {
x += hspd*ts.x;
y += vspd*ts.y;
}
} else {
x -= hspd*ts.x;
y -= vspd*ts.y;
x = linear_approach(x, returnpos.x*ts.x+abs(sprite_width)/4, 1);
y = linear_approach(y, returnpos.y*ts.y, 1);
}
} else {
x -= hspd*ts.x;
y -= vspd*ts.y;
x = linear_approach(x, returnpos.x*ts.x+abs(sprite_width)/4, 1);
y = linear_approach(y, returnpos.y*ts.y, 1);
2022-08-23 13:06:02 +00:00
}*/
if dude != noone && !stop {
var dist = c_tiledist(dude.x, dude.y, returnpos.x, returnpos.y);
x = clamp(x+hspd*ts.x, max(0, returnpos.x*ts.x-(data.mov.val*ts.x-ts.x/2-dist.y*ts.y)), min(20*ts.x, returnpos.x*ts.x+(data.mov.val*ts.x+ts.x-dist.y*ts.y)));
y = clamp(y+vspd*ts.y, max(0, returnpos.y*ts.y-(data.mov.val*ts.y-ts.x/2-dist.x*ts.x)), min(20*ts.y, returnpos.y*ts.y+(data.mov.val*ts.y+ts.y-dist.x*ts.x)));
//y = clamp(y+vspd*ts.y, max(0, returnpos.y*ts.y-dist.y*ts.y+dist.x*ts.x), min(14*ts.y, returnpos.y*ts.y+dist.y*ts.y-dist.x*ts.x));
log(x, y);
dude = c_gettile(x, y, true);
if dude != noone {
pos.x = dude.x;
pos.y = dude.y;
}
} else if dude == noone {
x = linear_approach(x, returnpos.x*ts.x, 2);
y = linear_approach(y, returnpos.y*ts.y, 2);
2022-08-15 04:06:41 +00:00
}
2022-08-19 22:06:21 +00:00
//prevremainingmov = remainingmov;
2022-08-15 04:36:37 +00:00
c_decolor_all(c_red);
c_decolor_all(c_green);
2022-08-18 20:47:07 +00:00
var guy = c_gettile(pos.x, pos.y);
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);
2022-08-20 18:53:31 +00:00
if stop {
//var dist = c_tiledist();
//hitpos.y = clamp(hitpos.y+downp-upp, -data.rng.val, data.rng.val);
//hitpos.x = clamp(hitpos.x+rightp-leftp, -(data.rng.val-abs(hitpos.y)), (data.rng.val-abs(hitpos.y)));
//hitpos.y = clamp(hitpos.y, -(data.rng.val-abs(hitpos.x)), (data.rng.val-abs(hitpos.x)));
var shits = c_tiledist(0, 0, hitpos.x+rightp-leftp, hitpos.y+downp-upp);
var dist = shits.x + shits.y;
if dist <= data.rng.val && !(data.rng.val && hitpos.x == 0 && hitpos.y == 0) {
hitpos.x += rightp-leftp;
hitpos.y += downp-upp;
} else {
switch dir {
case DIR.LEFT:
hitpos.x = -1;
hitpos.y = 0;
break;
case DIR.DOWN:
hitpos.x = 0;
hitpos.y = 1;
break;
case DIR.UP:
hitpos.x = 0;
hitpos.y = -1;
break;
case DIR.RIGHT:
hitpos.x = 1;
hitpos.y = 0;
break;
}
}
}
2022-08-23 06:49:38 +00:00
hitting = noone;
2022-08-17 16:49:45 +00:00
if guy != noone {
2022-08-20 18:53:31 +00:00
hitting = c_gettile(guy.x+hitpos.x, guy.y+hitpos.y);
2022-08-15 17:51:51 +00:00
switch dir {
case DIR.LEFT:
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:
2022-08-16 02:04:23 +00:00
sprite_index = data.down;
2022-08-15 17:51:51 +00:00
break;
case DIR.UP:
2022-08-16 02:04:23 +00:00
sprite_index = data.up;
2022-08-15 17:51:51 +00:00
break;
case DIR.RIGHT:
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;
2022-08-19 01:05:37 +00:00
//image_xscale = -1;
2022-08-16 02:04:23 +00:00
break;
2022-08-15 17:51:51 +00:00
}
2022-08-18 20:47:07 +00:00
if hitting != noone && stop c_colortile(hitting.x, hitting.y, c_red);
2022-08-17 16:49:45 +00:00
if hitting != noone && select && stop {
2022-08-23 06:49:38 +00:00
//log("found one");
//log(hitting.contents, hitting.x, hitting.y);
2022-08-16 01:01:09 +00:00
var i;
for (i=0; i<array_length(hitting.contents); i++) {
if instance_exists(hitting.contents[i]) {
2022-08-23 06:49:38 +00:00
//log("is instance");
2022-08-16 01:01:09 +00:00
if hitting.contents[i].object_index = o_unit {
2022-08-23 06:49:38 +00:00
//log("is unit");
//log("found two");
2022-08-23 13:06:02 +00:00
//if hitting.contents[i].alignment != alignment ^^ !data.str.val {
if hitting.contents[i].alignment == ARMY.THEM ^^ !data.str.val {
2022-08-20 18:53:31 +00:00
c_moveunit(id, c_gettile(pos.x, pos.y));
c_generatecombatstack([id, hitting.contents[i]]);
2022-08-23 09:25:43 +00:00
waiting = true;
c_deselectunit(id);
2022-08-23 13:06:02 +00:00
exit
2022-08-20 18:53:31 +00:00
}
2022-08-16 01:01:09 +00:00
}
}
}
2022-08-15 17:51:51 +00:00
}
}
if back {
2022-08-18 20:47:07 +00:00
c_moveunit(id, c_gettile(returnpos.x, returnpos.y));
2022-08-16 01:01:09 +00:00
c_deselectunit(id);
2022-08-15 17:51:51 +00:00
}
2022-08-23 09:25:43 +00:00
if dir == DIR.NONE && select && stop {
2022-08-23 10:09:17 +00:00
se_play(se_move);
2022-08-16 22:28:01 +00:00
c_moveunit(id, c_gettile(x, y, true));
waiting = true;
c_deselectunit(id);
}
2022-08-18 20:47:07 +00:00
/*if x < (returnpos.x-mov)*ts.x {
x = (returnpos.x-mov)*ts.x;
} else if x > (returnpos.x+mov+1)*ts.x {
x = (returnpos.x+mov+1)*ts.x;
2022-08-15 04:06:41 +00:00
} else {
x += hspd*ts.x;
}
2022-08-18 20:47:07 +00:00
if y < (returnpos.y-mov)*ts.y {
y = (returnpos.y-mov)*ts.y;
} else if y > (returnpos.y+mov+1)*ts.y {
y = (returnpos.y+mov+1)*ts.y;
2022-08-15 04:06:41 +00:00
} 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(
2022-08-18 20:47:07 +00:00
(returnpos.x+i)*ts.x,
(returnpos.y+j)*ts.y,
(returnpos.x+i+1)*ts.x,
(returnpos.y+j+1)*ts.y, false
2022-08-15 04:06:41 +00:00
);
}
}
}
draw_set_alpha(1);*/
2022-08-23 06:49:38 +00:00
if hitting != noone && stop {
var i;
for (i=0; i<array_length(hitting.contents); i++) {
if instance_exists(hitting.contents[i]) {
if hitting.contents[i].object_index = o_unit {
if hitting.contents[i].alignment != alignment ^^ !data.str.val {
var them = hitting.contents[i];
draw_sprite_ext(s_box, 0, 320-120, 360, 8, -4, 0, c_white, 1);
draw_set_color(c_white);
draw_set_halign(fa_center);
//draw_set_valign(fa_middle);
draw_text(320-60, 245, data.name);
draw_text(320, 245, "VS");
draw_text_ext(320+60, 245, them.data.name, 14, 80);
draw_text(320-60, 280, string(data.str.val - them.data.def.val) + (data.spd.val > them.data.spd.val+5 ? " x 2" : ""));
draw_text(320, 280, "POW");
draw_text(320+60, 280, string(them.data.str.val - data.def.val) + (them.data.spd.val > data.spd.val+5 ? " x 2" : ""));
2022-08-23 13:06:02 +00:00
draw_text(320-60, 315, string(data.hit.val)+"%");
2022-08-23 06:49:38 +00:00
draw_text(320, 315, "HIT");
2022-08-23 13:06:02 +00:00
draw_text(320+60, 315, string(them.data.hit.val)+"%");
2022-08-23 06:49:38 +00:00
draw_set_halign(fa_left);
draw_set_valign(fa_top);
}
}
}
}
}
2022-08-15 04:06:41 +00:00
}
2022-08-15 04:36:37 +00:00
#macro ts global.tilesize
enum DIR {
NONE,
LEFT,
DOWN,
UP,
RIGHT,
}