1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2024-12-24 17:10:36 +00:00

used movei in movement animations; also replaced animateReplacement with indAnimateMovement

This commit is contained in:
Zeno Rogue 2019-11-22 16:32:05 +01:00
parent 8ac9562c31
commit 3078451283
3 changed files with 48 additions and 45 deletions

View File

@ -2933,7 +2933,7 @@ EX namespace kraken {
noconflict = false; */ noconflict = false; */
/* if(noconflict) */ { /* if(noconflict) */ {
// found = true; // found = true;
indAnimateMovement(acells[i].first, acells[i].second, LAYER_BIG, NOHINT); indAnimateMovement(match(acells[i].first, acells[i].second), LAYER_BIG);
acells[i] = acells[isize(acells)-1]; acells[i] = acells[isize(acells)-1];
acells.resize(isize(acells)-1); acells.resize(isize(acells)-1);
i--; i--;

View File

@ -8610,8 +8610,12 @@ EX bool movepcto(int d, int subdir IS(1), bool checkonly IS(false)) {
cell *c1 = cwt.at; cell *c1 = cwt.at;
int d = cwt.spin; int d = cwt.spin;
cwt += wstep; cwt += wstep;
if(switchplaces) if(switchplaces) {
animateReplacement(c1, cwt.at, LAYER_SMALL, d, cwt.spin); movei m(c1, cwt.at, cwt.spin);
indAnimateMovement(m, LAYER_SMALL);
indAnimateMovement(m.rev(), LAYER_SMALL);
commitAnimations(LAYER_SMALL);
}
else else
animateMovement(c1, cwt.at, LAYER_SMALL, d); animateMovement(c1, cwt.at, LAYER_SMALL, d);

View File

@ -5020,18 +5020,24 @@ EX int revhint(cell *c, int hint) {
else return hint; else return hint;
} }
EX void animateMovement(cell *src, cell *tgt, int layer, int direction_hint) { EX transmatrix adj(const movei& m) {
if(m.proper()) return currentmap->adj(m.s, m.d);
else return currentmap->relative_matrix(m.t, m.s, C0);
}
EX transmatrix iadj(const movei& m) {
if(m.proper()) return currentmap->iadj(m.s, m.d);
else return currentmap->relative_matrix(m.s, m.t, C0);
}
EX void animateMovement(const movei& m, int layer) {
if(vid.mspeed >= 5) return; // no animations! if(vid.mspeed >= 5) return; // no animations!
transmatrix T; transmatrix T = adj(m);
if(direction_hint >= 0 && direction_hint < src->degree() && tgt == src->move(direction_hint)) animation& a = animations[layer][m.t];
T = currentmap->iadj(src, direction_hint); if(animations[layer].count(m.s)) {
else a = animations[layer][m.s];
T = currentmap->relative_matrix(src, tgt, C0);
animation& a = animations[layer][tgt];
if(animations[layer].count(src)) {
a = animations[layer][src];
a.wherenow = T * a.wherenow; a.wherenow = T * a.wherenow;
animations[layer].erase(src); animations[layer].erase(m.s);
a.attacking = 0; a.attacking = 0;
} }
else { else {
@ -5040,21 +5046,23 @@ EX void animateMovement(cell *src, cell *tgt, int layer, int direction_hint) {
a.footphase = 0; a.footphase = 0;
a.mirrored = false; a.mirrored = false;
} }
if(direction_hint >= 0 && direction_hint < src->type) { if(m.proper() && m.s->c.mirror(m.d))
if(src->c.mirror(direction_hint)) a.mirrored = !a.mirrored;
a.mirrored = !a.mirrored; }
}
EX void animateMovement(cell *src, cell *tgt, int layer, int direction_hint) {
animateMovement(movei(src, tgt, direction_hint), layer);
} }
EX void animateAttack(cell *src, cell *tgt, int layer, int direction_hint) { EX void animateAttack(cell *src, cell *tgt, int layer, int direction_hint) {
animateAttack(movei(src, tgt, direction_hint), layer);
}
EX void animateAttack(const movei& m, int layer) {
if(vid.mspeed >= 5) return; // no animations! if(vid.mspeed >= 5) return; // no animations!
transmatrix T; transmatrix T = adj(m);
if(direction_hint >= 0 && direction_hint < src->degree() && tgt == src->move(direction_hint)) bool newanim = !animations[layer].count(m.s);
T = currentmap->iadj(src, direction_hint); animation& a = animations[layer][m.s];
else
T = currentmap->relative_matrix(src, tgt, C0);
bool newanim = !animations[layer].count(src);
animation& a = animations[layer][src];
a.attacking = 1; a.attacking = 1;
a.attackat = rspintox(tC0(inverse(T))) * xpush(hdist0(T*C0) / 3); a.attackat = rspintox(tC0(inverse(T))) * xpush(hdist0(T*C0) / 3);
if(newanim) a.wherenow = Id, a.ltick = ticks, a.footphase = 0; if(newanim) a.wherenow = Id, a.ltick = ticks, a.footphase = 0;
@ -5062,21 +5070,21 @@ EX void animateAttack(cell *src, cell *tgt, int layer, int direction_hint) {
vector<pair<cell*, animation> > animstack; vector<pair<cell*, animation> > animstack;
EX void indAnimateMovement(cell *src, cell *tgt, int layer, int direction_hint) { EX void indAnimateMovement(const movei& m, int layer) {
if(vid.mspeed >= 5) return; // no animations! if(vid.mspeed >= 5) return; // no animations!
if(animations[layer].count(tgt)) { if(animations[layer].count(m.t)) {
animation res = animations[layer][tgt]; animation res = animations[layer][m.t];
animations[layer].erase(tgt); animations[layer].erase(m.t);
animateMovement(src, tgt, layer, direction_hint); animateMovement(m, layer);
if(animations[layer].count(tgt)) if(animations[layer].count(m.t))
animstack.push_back(make_pair(tgt, animations[layer][tgt])); animstack.push_back(make_pair(m.t, animations[layer][m.t]));
animations[layer][tgt] = res; animations[layer][m.t] = res;
} }
else { else {
animateMovement(src, tgt, layer, direction_hint); animateMovement(m, layer);
if(animations[layer].count(tgt)) { if(animations[layer].count(m.t)) {
animstack.push_back(make_pair(tgt, animations[layer][tgt])); animstack.push_back(make_pair(m.t, animations[layer][m.t]));
animations[layer].erase(tgt); animations[layer].erase(m.t);
} }
} }
} }
@ -5087,15 +5095,6 @@ EX void commitAnimations(int layer) {
animstack.clear(); animstack.clear();
} }
EX void animateReplacement(cell *a, cell *b, int layer, int direction_hinta, int direction_hintb) {
if(vid.mspeed >= 5) return; // no animations!
static cell c1;
gmatrix[&c1] = gmatrix[b]; c1.master = b->master;
if(animations[layer].count(b)) animations[layer][&c1] = animations[layer][b];
animateMovement(a, b, layer, direction_hinta);
animateMovement(&c1, a, layer, direction_hintb);
}
EX void drawBug(const cellwalker& cw, color_t col) { EX void drawBug(const cellwalker& cw, color_t col) {
#if CAP_SHAPES #if CAP_SHAPES
initquickqueue(); initquickqueue();