1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2024-11-14 01:14:48 +00:00
hyperrogue/rogueviz/ads/control.cpp

232 lines
6.2 KiB
C++
Raw Normal View History

2022-09-11 10:16:50 +00:00
namespace hr {
namespace ads_game {
multi::config scfg_ads;
vector<string> move_names = { "acc down", "acc left", "acc up", "acc right", "fire", "pause", "display times", "switch spin", "menu", "[paused] future", "(paused] past", "[paused] move switch" };
2022-09-11 10:16:50 +00:00
void fire() {
2022-09-12 10:57:52 +00:00
if(!pdata.ammo) return;
2022-09-28 23:12:08 +00:00
playSound(nullptr, "fire");
2022-09-12 10:57:52 +00:00
pdata.ammo--;
auto c = vctr;
2022-09-11 10:16:50 +00:00
ads_matrix S0 = ads_inverse(current * vctrV) * spin(ang*degree);
ads_matrix S1 = S0 * lorentz(0, 2, ads_missile_rapidity);
2022-09-11 10:16:50 +00:00
auto& ro = ci_at[c].rocks;
auto r = std::make_unique<ads_object> (oMissile, c, S1, rsrc_color[rtAmmo]);
r->shape = &shape_missile;
2022-09-17 15:34:11 +00:00
r->life_start = 0;
2022-09-11 10:16:50 +00:00
ads_matrix Scell(Id, 0);
cell *lcell = hybrid::get_at(vctr, 0);
auto wcell = make_pair(vctr, 0);
2022-09-11 10:16:50 +00:00
int steps = 0;
compute_life(lcell, unshift(r->at), [&] (cell *c1, ld t) {
2022-09-11 10:16:50 +00:00
if(true) for(int i=0; i<lcell->type; i++) {
auto lcell1 = lcell->cmove(i);
auto wcell1 = hybrid::get_where(lcell1);
if(wcell1.first == c1) {
Scell = Scell * currentmap->adj(lcell, i);
optimize_shift(Scell);
lcell = lcell1;
wcell = wcell1;
adjust_to_zero(Scell, wcell, cgi.plevel);
steps++;
lcell = hybrid::get_at(wcell.first, 0);
break;
}
}
if(true) if(wcell.first != c1) {
println(hlog, "warning: got lost after ", steps, " steps");
println(hlog, wcell);
println(hlog, c1);
println(hlog, "their distance is ", PIU(celldistance(wcell.first, c1)));
return true;
}
auto& ci = ci_at[c1];
hybrid::in_underlying_geometry([&] {
gen_terrain(c1, ci);
});
if(among(ci.type, wtSolid, wtDestructible)) {
r->life_end = t;
2022-09-11 10:16:50 +00:00
auto Scell_inv = ads_inverse(Scell);
Scell_inv = Scell_inv * r->at;
2022-09-11 10:16:50 +00:00
Scell_inv = Scell_inv * ads_matrix(Id, t);
optimize_shift(Scell_inv);
auto X = ads_inverse(Scell);
X = X * (r->at * ads_matrix(Id, t));
2022-09-11 10:16:50 +00:00
optimize_shift(X);
ads_matrix prel = ads_inverse(S0) * r->at * ads_matrix(Id, t);
2022-09-11 10:16:50 +00:00
println(hlog, "crashed: proper time = ", t/TAU, " wall time = ", Scell_inv.shift / TAU, " player time = ", (prel.shift+ship_pt) / TAU, " start = ", ship_pt / TAU);
if(abs(X.shift - Scell_inv.shift) > .2) {
println(hlog, "INTRANSITIVITY ERROR! ", X.shift, " vs ", Scell_inv.shift);
exit(1);
}
return true;
}
return false;
});
ro.emplace_back(std::move(r));
2022-09-11 10:16:50 +00:00
}
bool handleKey(int sym, int uni) {
2022-09-18 08:21:29 +00:00
if(cmode & sm::NORMAL) {
char* t = scfg_ads.keyaction;
2022-09-11 10:16:50 +00:00
if(t[sym] >= 16 && t[sym] < 32) return true;
2022-09-18 08:21:29 +00:00
if(sym == 'v') pushScreen(game_menu);
if(sym == SDLK_ESCAPE) pushScreen(game_menu);
return true;
2022-09-11 10:16:50 +00:00
}
return false;
}
void apply_lorentz(transmatrix lor) {
current = ads_matrix(lor, 0) * current;
}
2022-09-19 21:16:16 +00:00
ld read_movement() {
2022-10-16 07:46:04 +00:00
ld mdx = multi::axespressed[4]/30000.;
ld mdy = multi::axespressed[5]/30000.;
#if CAP_VR
if(vrhr::active()) {
mdy -= vrhr::vrgo_y;
mdx += vrhr::vrgo_x;
}
#endif
if(mdx || mdy) {
ang = atan2(mdy, mdx) / degree;
return hypot(mdx, mdy);
}
2022-09-19 21:16:16 +00:00
auto& a = multi::actionspressed;
bool left = a[16+1];
bool right = a[16+3];
bool up = a[16+2];
bool down = a[16];
int clicks = (left?1:0) + (right?1:0) + (up?1:0) + (down?1:0);
if(left && right) left = right = false;
if(up && down) up = down = false;
if(left) ang = 180;
if(right) ang = 0;
if(up) ang = 90;
if(down) ang = 270;
if(left && up) ang = 135;
if(left && down) ang = 225;
if(right && up) ang = 45;
if(right && down) ang = 315;
ld mul = clicks ? 1 : 0;
if(clicks > 2) mul *= .3;
if(!paused) {
if(game_over || pdata.fuel < 0) mul = 0;
}
return mul;
}
2022-09-11 10:16:50 +00:00
bool ads_turn(int idelta) {
multi::handleInput(idelta, scfg_ads);
ld delta = idelta / 1000.;
2022-09-11 10:16:50 +00:00
if(!(cmode & sm::NORMAL)) return false;
hybrid::in_actual([&] {
2022-09-11 10:16:50 +00:00
2022-09-11 11:42:51 +00:00
handle_crashes();
2022-09-11 10:16:50 +00:00
auto& a = multi::actionspressed;
auto& la = multi::lactionpressed;
2022-09-17 15:34:19 +00:00
if(a[16+4] && !la[16+4] && !paused) fire();
2022-10-15 12:22:09 +00:00
if(a[16+5] && !la[16+5]) switch_pause();
2022-09-11 10:16:50 +00:00
if(a[16+6] && !la[16+6]) view_proper_times = !view_proper_times;
if(a[16+7] && !la[16+7]) auto_rotate = !auto_rotate;
2022-09-18 22:11:48 +00:00
if(a[16+8] && !la[16+8]) pushScreen(game_menu);
2022-09-11 10:16:50 +00:00
if(auto_angle) pconf.model_orientation += ang;
if(true) {
2022-09-11 10:16:50 +00:00
/* proper time passed */
ld pt = delta * ads_simspeed;
2022-09-11 10:16:50 +00:00
2022-09-19 21:16:16 +00:00
ld mul = read_movement();
ld dv = pt * ads_accel * mul;
2022-09-12 10:57:52 +00:00
if(paused && a[16+11]) {
2022-09-18 08:22:13 +00:00
current = ads_matrix(spin(ang*degree) * xpush(mul*delta*-pause_speed) * spin(-ang*degree), 0) * current;
}
else
apply_lorentz(spin(ang*degree) * lorentz(0, 2, -dv) * spin(-ang*degree));
2022-09-12 11:20:04 +00:00
if(!paused) {
pdata.fuel -= dv;
gen_particles(rpoisson(dv*fuel_particle_qty), vctr, ads_inverse(current * vctrV) * spin(ang*degree+M_PI) * rots::uxpush(0.06 * ads_scale), rsrc_color[rtFuel], fuel_particle_rapidity, fuel_particle_life, 0.02);
}
ld tc = 0;
if(!paused) tc = pt;
else if(a[16+9]) tc = pt;
else if(a[16+10]) tc = -pt;
2022-09-11 10:16:50 +00:00
2022-09-17 15:47:31 +00:00
if(!paused && !game_over) {
2022-09-20 10:36:16 +00:00
shipstate ss;
ss.at = ads_inverse(current * vctrV) * spin((ang+90)*degree);
ss.ang = ang;
2022-09-29 12:24:57 +00:00
ss.current = current;
2022-09-20 10:36:16 +00:00
ss.start = ship_pt;
ss.duration = pt;
ss.vctrV = vctrV;
ss.vctr = vctr;
history.emplace_back(ss);
ci_at[vctr].shipstates.emplace_back(ss);
2022-09-17 15:34:54 +00:00
}
current.T = cspin(3, 2, tc) * current.T;
2022-09-11 10:16:50 +00:00
optimize_shift(current);
hassert(eqmatrix(chg_shift(current.shift) * current.T, unshift(current)));
if(auto_rotate)
current.T = cspin(1, 0, tc) * current.T;
else if(!paused)
ang += tc / degree;
if(!paused) {
ship_pt += pt;
pdata.oxygen -= pt;
if(pdata.oxygen < 0) {
pdata.oxygen = 0;
game_over = true;
}
2022-09-12 10:57:52 +00:00
}
else view_pt += tc;
2022-09-11 10:16:50 +00:00
}
if(auto_angle) pconf.model_orientation -= ang;
2022-09-11 10:16:50 +00:00
fixmatrix_ads(current.T);
2022-09-18 22:12:00 +00:00
fixmatrix_ads(new_vctrV.T);
});
2022-09-11 10:16:50 +00:00
return true;
}
}}