Compare commits

..

2 Commits

4 changed files with 44 additions and 9 deletions

View File

@ -13,6 +13,7 @@ c_addweapon(id, wp.nothing);
equippedweapon = noone; equippedweapon = noone;
waiting = false; waiting = false;
targeting = new vec2(0, 0); targeting = new vec2(0, 0);
hitpos = new vec2(0, 0);
marked = false; marked = false;
continuecombat = function(me, them) { continuecombat = function(me, them) {

View File

@ -1,4 +1,6 @@
state(); state();
if data.hp.val <= 0 { if data.hp.val <= 0 {
c_deselectunit(id);
c_deleteunit(pos.x, pos.y, id); c_deleteunit(pos.x, pos.y, id);
} }
//depth = x;

View File

@ -23,5 +23,5 @@ function c_containsunit(x, y) {
} }
} }
} }
return false; return noone;
} }

View File

@ -39,7 +39,8 @@ function st_moving() {
var dude = c_gettile(x+hspd+abs(sprite_width)/4, y+vspd, true); var dude = c_gettile(x+hspd+abs(sprite_width)/4, y+vspd, true);
if dude != noone { if dude != noone {
var dist = c_tiledist(dude.x, dude.y, returnpos.x, returnpos.y); var dist = c_tiledist(dude.x, dude.y, returnpos.x, returnpos.y);
if dist.x + dist.y <= data.mov.val && dude.passable { var friend = c_containsunit(dude.x, dude.y);
if dist.x + dist.y <= data.mov.val && dude.passable && (friend == noone || friend == id) {
pos.x = dude.x; pos.x = dude.x;
pos.y = dude.y; pos.y = dude.y;
if !stop { if !stop {
@ -66,24 +67,53 @@ function st_moving() {
//log("selecting"); //log("selecting");
//var rng = [1]; //var rng = [1];
var guy = c_gettile(x, y, true); var guy = c_gettile(x, y, true);
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;
}
}
}
var hitting = noone; var hitting = noone;
if guy != noone { if guy != noone {
hitting = c_gettile(guy.x+hitpos.x, guy.y+hitpos.y);
switch dir { switch dir {
case DIR.LEFT: case DIR.LEFT:
hitting = c_gettile(guy.x-1, guy.y);
sprite_index = data.down; sprite_index = data.down;
image_xscale = -1; image_xscale = -1;
break; break;
case DIR.DOWN: case DIR.DOWN:
hitting = c_gettile(guy.x, guy.y+1);
sprite_index = data.down; sprite_index = data.down;
break; break;
case DIR.UP: case DIR.UP:
hitting = c_gettile(guy.x, guy.y-1);
sprite_index = data.up; sprite_index = data.up;
break; break;
case DIR.RIGHT: case DIR.RIGHT:
hitting = c_gettile(guy.x+1, guy.y);
sprite_index = data.down; sprite_index = data.down;
image_xscale = 1; image_xscale = 1;
break; break;
@ -104,8 +134,10 @@ function st_moving() {
if hitting.contents[i].object_index = o_unit { if hitting.contents[i].object_index = o_unit {
log("is unit"); log("is unit");
log("found two"); log("found two");
c_moveunit(id, c_gettile(x, y, true)); if hitting.contents[i].alignment != alignment ^^ !data.str.val {
c_generatecombatstack([id, hitting.contents[i]]); c_moveunit(id, c_gettile(pos.x, pos.y));
c_generatecombatstack([id, hitting.contents[i]]);
}
} }
} }
} }