From b1baf393baa2715720d69e4a69e7aba624777b85 Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Sat, 17 Sep 2022 15:16:04 +0200 Subject: [PATCH] ads-game:: display other frames of reference while paused --- rogueviz/ads/ads-game.cpp | 7 +++-- rogueviz/ads/control.cpp | 66 ++++++++++++++++++++++++++++----------- rogueviz/ads/display.cpp | 11 +++++-- rogueviz/ads/globals.cpp | 14 ++++++--- rogueviz/ads/map.cpp | 1 + 5 files changed, 73 insertions(+), 26 deletions(-) diff --git a/rogueviz/ads/ads-game.cpp b/rogueviz/ads/ads-game.cpp index 16657539..913fd3ad 100644 --- a/rogueviz/ads/ads-game.cpp +++ b/rogueviz/ads/ads-game.cpp @@ -32,10 +32,13 @@ void run_ads_game() { change_default_key('t', 16 + 6); change_default_key('o', 16 + 7); change_default_key('m', 16 + 8); + change_default_key('i', 16 + 9); + change_default_key('k', 16 + 10); + change_default_key('l', 16 + 11); nomap = true; no_find_player = true; - vctr = cwt.at; + vctr = new_vctr = cwt.at; cell *c = hybrid::get_where(vctr).first; hybrid::in_underlying_geometry([&] { gen_terrain(c, ci_at[c], -2); @@ -43,7 +46,7 @@ void run_ads_game() { ci_at[c].type = wtNone; ci_at[c].rocks.clear(); }); - vctrV = ads_matrix(Id, 0); + vctrV = new_vctrV = ads_matrix(Id, 0); rogueviz::rv_hook(hooks_prestats, 100, view_ads_game); rogueviz::rv_hook(hooks_handleKey, 0, handleKey); rogueviz::rv_hook(shmup::hooks_turn, 0, ads_turn); diff --git a/rogueviz/ads/control.cpp b/rogueviz/ads/control.cpp index 2c1ad4c3..da6bb3e5 100644 --- a/rogueviz/ads/control.cpp +++ b/rogueviz/ads/control.cpp @@ -2,7 +2,7 @@ namespace hr { namespace ads_game { -vector move_names = { "acc down", "acc left", "acc up", "acc right", "fire", "pause", "display times", "switch spin", "menu" }; +vector move_names = { "acc down", "acc left", "acc up", "acc right", "fire", "pause", "display times", "switch spin", "menu", "[paused] future", "(paused] past", "[paused] move switch" }; void fire() { if(!pdata.ammo) return; @@ -118,12 +118,25 @@ bool ads_turn(int idelta) { for(int i=0; i 2) mul *= .3; - if(pdata.fuel < 0) mul = 0; + if(!paused) { + if(game_over || pdata.fuel < 0) mul = 0; + } - apply_lorentz(spin(ang*degree) * lorentz(0, 2, -delta*accel*mul) * spin(-ang*degree)); - pdata.fuel -= delta*accel*mul; + if(paused && a[16+11]) { + current = ads_matrix(spin(ang*degree) * xpush(mul*delta*5) * spin(-ang*degree), 0) * current; + } + else + apply_lorentz(spin(ang*degree) * lorentz(0, 2, -delta*accel*mul) * spin(-ang*degree)); - cell *c = hybrid::get_where(vctr).first; - gen_particles(rpoisson(delta*accel*mul*20), c, ads_inverse(current * vctrV) * spin(ang*degree+M_PI) * rots::uxpush(0.06), rsrc_color[rtFuel], 0.15, 0.02); + if(!paused) { + pdata.fuel -= delta*accel*mul; + cell *c = hybrid::get_where(vctr).first; + gen_particles(rpoisson(delta*accel*mul*20), c, ads_inverse(current * vctrV) * spin(ang*degree+M_PI) * rots::uxpush(0.06), rsrc_color[rtFuel], 0.15, 0.02); + } - current.T = cspin(3, 2, pt) * current.T; + ld tc = 0; + if(!paused) tc = pt; + else if(a[16+9]) tc = pt; + else if(a[16+10]) tc = -pt; + + current.T = cspin(3, 2, tc) * current.T; + optimize_shift(current); hassert(eqmatrix(chg_shift(current.shift) * current.T, unshift(current))); if(auto_rotate) - current.T = cspin(1, 0, pt) * current.T; - else - ang += pt / degree; + current.T = cspin(1, 0, tc) * current.T; + else if(!paused) + ang += tc / degree; - ship_pt += pt; - pdata.oxygen -= pt; - if(pdata.oxygen < 0) { - pdata.oxygen = 0; - game_over = true; + if(!paused) { + ship_pt += pt; + pdata.oxygen -= pt; + if(pdata.oxygen < 0) { + pdata.oxygen = 0; + game_over = true; + } } + else view_pt += tc; } fixmatrix_ads(current.T); diff --git a/rogueviz/ads/display.cpp b/rogueviz/ads/display.cpp index e4424359..e8190f4e 100644 --- a/rogueviz/ads/display.cpp +++ b/rogueviz/ads/display.cpp @@ -24,7 +24,7 @@ void draw_game_cell(cell *cs, ads_matrix V, ld plev) { if(1) { ld d = hdist0(center.h); - if(d < vctr_dist) vctr_dist = d, vctr = PIA( hybrid::get_at(c, 0) ), vctrV = V; + if(d < vctr_dist) vctr_dist = d, new_vctr = PIA( hybrid::get_at(c, 0) ), new_vctrV = V; } auto& ci = ci_at[c]; @@ -132,6 +132,8 @@ bool view_ads_game() { gen_budget = 5; displayed.clear(); + vctr = new_vctr; + vctrV = new_vctrV; cross_result base; if(1) { // todo rebase @@ -207,7 +209,7 @@ bool view_ads_game() { }); } - if(!game_over) { + if(!game_over && !paused) { poly_outline = 0xFF; color_t shipcolor = 0x2020FFFF; if(ship_pt < invincibility_pt) { @@ -222,6 +224,11 @@ bool view_ads_game() { queuestr(shiftless(Id), .1, str, 0xFFFFFF, 8); } } + + if(paused && view_proper_times) { + string str = format(tformat, view_pt / TAU); + queuestr(shiftless(Id), .1, str, 0xFFFF00, 8); + } if(false) queuepolyat(shiftless(rgpushxto0(base.h)), cgi.shGem[0], 0x2020FFFF, PPR::LINE); diff --git a/rogueviz/ads/globals.cpp b/rogueviz/ads/globals.cpp index b84a17e1..612e10ea 100644 --- a/rogueviz/ads/globals.cpp +++ b/rogueviz/ads/globals.cpp @@ -8,14 +8,17 @@ ld simspeed = TAU; /** by how much do WAS keys accelerate */ ld accel = 6; -/** transform world coordinates to ship coordinates */ +/** transform world coordinates to current view coordinates */ ads_matrix current; -/** SL cell closest to the ship */ -cell *vctr; +/** transform world coordinates to ship coordinates (used when paused) */ +ads_matrix current_ship; + +/** SL cell closest to the current view/ship */ +cell *vctr, *new_vctr, *vctr_ship; /** world coordinates of vctr -- technically, this is a shiftmatrix */ -ads_matrix vctrV; +ads_matrix vctrV, new_vctrV, vctrV_ship; /** how far is vctr from the ship */ ld vctr_dist; @@ -26,6 +29,9 @@ ld ang = 0; /** ship's current proper time */ ld ship_pt; +/** paused camera's current proper time */ +ld view_pt; + /** until when is the ship invincible */ ld invincibility_pt; diff --git a/rogueviz/ads/map.cpp b/rogueviz/ads/map.cpp index bc5e7df5..fb7a700f 100644 --- a/rogueviz/ads/map.cpp +++ b/rogueviz/ads/map.cpp @@ -194,6 +194,7 @@ void crash_ship() { } void handle_crashes() { + if(paused) return; vector missiles; vector rocks; vector resources;