mirror of
https://github.com/zenorogue/hyperrogue.git
synced 2025-02-08 23:20:12 +00:00
ads-game:: ds-game more game-y
This commit is contained in:
parent
fbf0b487b1
commit
bdbf4e2935
@ -2,25 +2,111 @@ namespace hr {
|
|||||||
|
|
||||||
namespace ads_game {
|
namespace ads_game {
|
||||||
|
|
||||||
|
vector<ld> shape_disk;
|
||||||
|
|
||||||
void set_default_keys();
|
void set_default_keys();
|
||||||
|
|
||||||
transmatrix dscurrent, dscurrent_ship;
|
transmatrix dscurrent, dscurrent_ship;
|
||||||
|
|
||||||
vector<shipstate> ds_states;
|
vector<shipstate> ds_states;
|
||||||
|
|
||||||
|
vector<unique_ptr<ads_object>> rocks;
|
||||||
|
|
||||||
|
void init_ds_game() {
|
||||||
|
for(int i=0; i<500; i++) {
|
||||||
|
hyperpoint h = random_spin3() * C0;
|
||||||
|
println(hlog, "h = ", h);
|
||||||
|
|
||||||
|
transmatrix T = gpushxto0(h);
|
||||||
|
dynamicval<eGeometry> g(geometry, gSpace435);
|
||||||
|
for(int i=0; i<4; i++) T[i][3] = T[3][i] = i == 3;
|
||||||
|
transmatrix worldline = inverse(T);
|
||||||
|
worldline = worldline * spin(randd() * TAU);
|
||||||
|
worldline = worldline * lorentz(0, 3, randd());
|
||||||
|
|
||||||
|
auto r = std::make_unique<ads_object> (oRock, nullptr, ads_matrix(worldline, 0), 0xFFFFFFFF);
|
||||||
|
r->shape = &shape_disk;
|
||||||
|
rocks.emplace_back(std::move(r));
|
||||||
|
}
|
||||||
|
shape_disk.clear();
|
||||||
|
for(int d=0; d<=360; d += 15) {
|
||||||
|
shape_disk.push_back(sin(d*degree) * 0.1 * scale);
|
||||||
|
shape_disk.push_back(cos(d*degree) * 0.1 * scale);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ds_gen_particles(int qty, transmatrix from, color_t col, ld spd, ld t, ld spread = 1) {
|
||||||
|
for(int i=0; i<qty; i++) {
|
||||||
|
auto r = std::make_unique<ads_object>(oParticle, nullptr, ads_matrix(from * spin(randd() * TAU * spread) * lorentz(0, 3, (.5 + randd() * .5) * spd), 0), col );
|
||||||
|
r->shape = &shape_particle;
|
||||||
|
r->life_end = randd() * t;
|
||||||
|
r->life_start = 0;
|
||||||
|
rocks.emplace_back(std::move(r));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ds_handle_crashes() {
|
||||||
|
if(paused) return;
|
||||||
|
vector<ads_object*> dmissiles;
|
||||||
|
vector<ads_object*> drocks;
|
||||||
|
for(auto m: displayed) {
|
||||||
|
if(m->type == oMissile)
|
||||||
|
dmissiles.push_back(m);
|
||||||
|
if(m->type == oRock)
|
||||||
|
drocks.push_back(m);
|
||||||
|
}
|
||||||
|
|
||||||
|
for(auto m: dmissiles) {
|
||||||
|
hyperpoint h = kleinize(m->pt_main.h);
|
||||||
|
for(auto r: drocks) {
|
||||||
|
if(pointcrash(h, r->pts)) {
|
||||||
|
m->life_end = m->pt_main.shift;
|
||||||
|
r->life_end = r->pt_main.shift;
|
||||||
|
dynamicval<eGeometry> g(geometry, gSpace435);
|
||||||
|
ds_gen_particles(rpoisson(crash_particle_qty), m->at.T * lorentz(2, 3, m->life_end), missile_color, crash_particle_rapidity, crash_particle_life);
|
||||||
|
ds_gen_particles(rpoisson(crash_particle_qty), r->at.T * lorentz(2, 3, r->life_end), r->col, crash_particle_rapidity, crash_particle_life);
|
||||||
|
pdata.score++;
|
||||||
|
int qty = 2 + rpoisson(1);
|
||||||
|
for(int i=0; i<qty; i++) {
|
||||||
|
auto r1 = std::make_unique<ads_object> (oRock, nullptr, ads_matrix(r->at.T * lorentz(2, 3, r->life_end) * spin(randd() * TAU) * lorentz(0, 3, randd() * ds_split_speed), 0), 0xFFFFFFFF);
|
||||||
|
r1->shape = &shape_disk;
|
||||||
|
r1->life_start = 0;
|
||||||
|
rocks.emplace_back(std::move(r1));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ds_fire() {
|
||||||
|
if(!pdata.ammo) return;
|
||||||
|
pdata.ammo--;
|
||||||
|
dynamicval<eGeometry> g(geometry, gSpace435);
|
||||||
|
|
||||||
|
transmatrix S0 = inverse(dscurrent) * spin(ang*degree);
|
||||||
|
|
||||||
|
transmatrix S1 = S0 * lorentz(0, 3, missile_rapidity);
|
||||||
|
|
||||||
|
auto r = std::make_unique<ads_object> (oMissile, nullptr, ads_matrix(S1, 0), 0xC0C0FFFF);
|
||||||
|
r->shape = &shape_missile;
|
||||||
|
r->life_start = 0;
|
||||||
|
|
||||||
|
rocks.emplace_back(std::move(r));
|
||||||
|
}
|
||||||
|
|
||||||
bool ds_turn(int idelta) {
|
bool ds_turn(int idelta) {
|
||||||
multi::handleInput(idelta);
|
multi::handleInput(idelta);
|
||||||
ld delta = idelta / anims::period;
|
ld delta = idelta / anims::period;
|
||||||
|
|
||||||
if(!(cmode & sm::NORMAL)) return false;
|
if(!(cmode & sm::NORMAL)) return false;
|
||||||
|
|
||||||
// todo handle_crashes();
|
ds_handle_crashes();
|
||||||
|
|
||||||
auto& a = multi::actionspressed;
|
auto& a = multi::actionspressed;
|
||||||
auto& la = multi::lactionpressed;
|
auto& la = multi::lactionpressed;
|
||||||
|
|
||||||
// todo if(a[16+4] && !la[16+4] && !paused) fire();
|
|
||||||
|
|
||||||
|
if(a[16+4] && !la[16+4] && !paused) ds_fire();
|
||||||
if(a[16+5] && !la[16+5]) {
|
if(a[16+5] && !la[16+5]) {
|
||||||
paused = !paused;
|
paused = !paused;
|
||||||
if(paused) {
|
if(paused) {
|
||||||
@ -51,7 +137,7 @@ bool ds_turn(int idelta) {
|
|||||||
|
|
||||||
if(!paused) {
|
if(!paused) {
|
||||||
pdata.fuel -= delta*accel*mul;
|
pdata.fuel -= delta*accel*mul;
|
||||||
// todo gen_particles(rpoisson(delta*accel*mul*fuel_particle_qty), vctr, ads_inverse(current * vctrV) * spin(ang*degree+M_PI) * rots::uxpush(0.06 * scale), rsrc_color[rtFuel], fuel_particle_rapidity, fuel_particle_life, 0.02);
|
ds_gen_particles(rpoisson(delta*accel*mul*fuel_particle_qty), inverse(dscurrent) * spin(ang*degree+M_PI) * rots::uxpush(0.06 * scale), rsrc_color[rtFuel], fuel_particle_rapidity, fuel_particle_life, 0.02);
|
||||||
}
|
}
|
||||||
|
|
||||||
ld tc = 0;
|
ld tc = 0;
|
||||||
@ -78,13 +164,17 @@ bool ds_turn(int idelta) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else view_pt += tc;
|
else view_pt += tc;
|
||||||
|
|
||||||
|
if(a[16+4] && !la[16+4] && false) {
|
||||||
|
if(ds_states.size())
|
||||||
|
ds_states.back().duration = HUGE_VAL;
|
||||||
|
dscurrent = random_spin3();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<transmatrix> opoints;
|
|
||||||
|
|
||||||
hyperpoint pov = point30(0, 0, 1);
|
hyperpoint pov = point30(0, 0, 1);
|
||||||
|
|
||||||
cross_result ds_cross0(transmatrix T) {
|
cross_result ds_cross0(transmatrix T) {
|
||||||
@ -101,66 +191,62 @@ cross_result ds_cross0(transmatrix T) {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
transmatrix tpt(ld x, ld y) {
|
||||||
|
return cspin(0, 2, x * scale) * cspin(1, 2, y * scale);
|
||||||
|
}
|
||||||
|
|
||||||
void view_ds_game() {
|
void view_ds_game() {
|
||||||
displayed.clear();
|
displayed.clear();
|
||||||
|
|
||||||
if(opoints.empty()) {
|
|
||||||
for(int i=0; i<500; i++) {
|
|
||||||
hyperpoint h = random_spin3() * C0;
|
|
||||||
println(hlog, "h = ", h);
|
|
||||||
|
|
||||||
transmatrix T = gpushxto0(h);
|
|
||||||
dynamicval<eGeometry> g(geometry, gSpace435);
|
|
||||||
for(int i=0; i<4; i++) T[i][3] = T[3][i] = i == 3;
|
|
||||||
transmatrix worldline = inverse(T);
|
|
||||||
worldline = worldline * spin(randd() * TAU);
|
|
||||||
worldline = worldline * lorentz(0, 3, randd());
|
|
||||||
|
|
||||||
opoints.push_back(worldline);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(1) {
|
if(1) {
|
||||||
make_shape();
|
make_shape();
|
||||||
|
|
||||||
for(auto& worldline: opoints) {
|
for(auto& r: rocks) {
|
||||||
|
auto& rock = *r;
|
||||||
poly_outline = 0xFF;
|
poly_outline = 0xFF;
|
||||||
cross_result cr;
|
|
||||||
transmatrix at;
|
|
||||||
|
|
||||||
vector<hyperpoint> circle;
|
|
||||||
|
|
||||||
if(1) {
|
if(1) {
|
||||||
dynamicval<eGeometry> g(geometry, gSpace435);
|
dynamicval<eGeometry> g(geometry, gSpace435);
|
||||||
cr = ds_cross0(dscurrent * worldline);
|
rock.pt_main = ds_cross0(dscurrent * rock.at.T);
|
||||||
|
|
||||||
|
if(rock.pt_main.shift < rock.life_start) continue;
|
||||||
|
if(rock.pt_main.shift > rock.life_end) continue;
|
||||||
|
|
||||||
at = dscurrent * worldline * lorentz(2, 3, cr.shift);
|
transmatrix at1 = dscurrent * rock.at.T * lorentz(2, 3, rock.pt_main.shift);
|
||||||
|
rock.pts.clear();
|
||||||
|
|
||||||
|
auto& sh = *rock.shape;
|
||||||
|
|
||||||
for(int d=0; d<=360; d += 5) {
|
for(int i=0; i<isize(sh); i+=2) {
|
||||||
transmatrix T = at * spin(d*degree) * cspin(0, 2, 0.1);
|
transmatrix at2 = at1 * tpt(sh[i], sh[i+1]);
|
||||||
auto cr1 = ds_cross0(T);
|
auto cr1 = ds_cross0(at2);
|
||||||
circle.push_back(cr1.h);
|
rock.pts.push_back(cr1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<hyperpoint> circle_flat;
|
vector<hyperpoint> circle_flat;
|
||||||
for(auto c: circle) circle_flat.push_back(c / (1 + c[2]));
|
for(auto c: rock.pts) circle_flat.push_back(c.h / (1 + c.h[2]));
|
||||||
|
|
||||||
ld area = 0;
|
ld area = 0;
|
||||||
for(int i=0; i<isize(circle)-1; i++)
|
for(int i=0; i<isize(circle_flat)-1; i++)
|
||||||
area += (circle_flat[i] ^ circle_flat[i+1]) [2];
|
area += (circle_flat[i] ^ circle_flat[i+1]) [2];
|
||||||
|
|
||||||
if(area > 0) continue;
|
if(area > 0) continue;
|
||||||
|
|
||||||
// queuepolyat(shiftless(rgpushxto0(cr.h)), cgi.shGem[0], 0xFFFFFFF, PPR::LINE);
|
// queuepolyat(shiftless(rgpushxto0(cr.h)), cgi.shGem[0], 0xFFFFFFF, PPR::LINE);
|
||||||
for(auto p: circle) curvepoint(p);
|
for(auto p: rock.pts) curvepoint(p.h);
|
||||||
queuecurve(shiftless(Id), 0xFFFFFFFF, 0xFFFFFFFF, PPR::LINE);
|
color_t out = rock.col;
|
||||||
|
queuecurve(shiftless(Id), out, rock.col, PPR::LINE);
|
||||||
|
|
||||||
if(view_proper_times) {
|
if(view_proper_times) {
|
||||||
string str = format(tformat, cr.shift / time_unit);
|
string str = format(tformat, rock.pt_main.shift / time_unit);
|
||||||
queuestr(shiftless(rgpushxto0(cr.h)), .1, str, 0xFFFF00, 8);
|
queuestr(shiftless(rgpushxto0(rock.pt_main.h)), .1, str, 0xFFFF00, 8);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
if(rock.pt_main.h[2] > 0.1 && rock.life_end == HUGE_VAL) {
|
||||||
|
displayed.push_back(&rock);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ld delta = paused ? 1e-4 : -1e-4;
|
ld delta = paused ? 1e-4 : -1e-4;
|
||||||
for(auto& ss: ds_states) {
|
for(auto& ss: ds_states) {
|
||||||
@ -174,7 +260,7 @@ void view_ds_game() {
|
|||||||
|
|
||||||
auto& shape = shape_ship;
|
auto& shape = shape_ship;
|
||||||
for(int i=0; i<isize(shape); i += 2) {
|
for(int i=0; i<isize(shape); i += 2) {
|
||||||
transmatrix at1 = at * cspin(0, 2, shape[i] * scale) * cspin(1, 2, shape[i+1] * scale);
|
transmatrix at1 = at * tpt(shape[i], shape[i+1]);
|
||||||
pts.push_back(ds_cross0(at1).h);
|
pts.push_back(ds_cross0(at1).h);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -213,6 +299,7 @@ void view_ds_game() {
|
|||||||
void run_ds_game() {
|
void run_ds_game() {
|
||||||
|
|
||||||
set_default_keys();
|
set_default_keys();
|
||||||
|
init_ds_game();
|
||||||
|
|
||||||
rogueviz::rv_hook(hooks_frame, 100, view_ds_game);
|
rogueviz::rv_hook(hooks_frame, 100, view_ds_game);
|
||||||
rogueviz::rv_hook(shmup::hooks_turn, 0, ds_turn);
|
rogueviz::rv_hook(shmup::hooks_turn, 0, ds_turn);
|
||||||
|
@ -99,4 +99,8 @@ cell *starting_point;
|
|||||||
int max_gen_per_frame = 3;
|
int max_gen_per_frame = 3;
|
||||||
int draw_per_frame = 1000;
|
int draw_per_frame = 1000;
|
||||||
|
|
||||||
|
/* for DS */
|
||||||
|
|
||||||
|
ld ds_split_speed = 0.1;
|
||||||
|
|
||||||
}}
|
}}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user