#include #include #include #include #include #include #include #include #include #include "hash.h" #include "structure.h" #include "base.h" #include "display.h" #include "proj.h" #include "entities.h" // ------------------------------------------------------------------------------------------------------------------------------------------------ // bool is_colliding_with_map(cube_0* cb) { for(int k = 0; k < current_room->map_size; k++) { for(int d = 0; d < 8; d++) { if(distance_pt_cube_0_3d(cb->x+cb->w*(d%2==0), cb->y+cb->h*((d/2)%2==0), cb->z+cb->d*((d/4)%2==0), current_room->map[k]) <= 0.01) { return true; } } } return false; } bool is_colliding_with_tp(cube_0* cb) { for(int k = 0; k < current_room->tps_size; k++) { for(int d = 0; d < 8; d++) { if(distance_pt_cube_0_3d(cb->x+cb->w*(d%2==0), cb->y+cb->h*((d/2)%2==0), cb->z+cb->d*((d/4)%2==0), current_room->tps[k]->hitbox) <= 0.01) { return true; } } } return false; } // ------------------------------------------------------------------------------------------------------------------------------------------------ // void update_entity(entity* ent, float dtime) { (*ent->updatePos)(ent->pos->x, ent->pos->y, ent->pos->z, ent->pos->w, ent->pos->h, ent->pos->d, ent->pos->hz_angle, ent->pos->vt_angle, dtime, ent, ent->pos); } void update_entities(float dtime) { for(int k = 0; k < current_room->ent_len; k++) { if(current_room->ents[k]->updatePos != NULL) { //printf("e\n"); update_entity(current_room->ents[k], dtime); } } } // ------------------------------------------------------------------------------------------------------------------------------------------------ // void speen(double x, double y, double z, double w, double h, double d, double hz_angle, double vt_angle, float dtime, entity* ent, cube_0* ret) { ret->hz_angle += ((double)dtime)*15.0; } void speen2(double x, double y, double z, double w, double h, double d, double hz_angle, double vt_angle, float dtime, entity* ent, cube_0* ret) { ret->hz_angle += ((double)dtime)*22.5; if((int)(5.0*ret->hz_angle) != (int)(5.0*(ret->hz_angle - ((double)dtime)*22.5))) { double dx = (x+w/2 - camx); double dy = (y+h/2 - camy); double dz = (z+d/2 - camz); double total = sqrt(dx*dx + dy*dy + dz*dz); dx = 170.0*dx/total; dy = 170.0*dy/total; dz = 170.0*dz/total; appendProj(x+w/2, y+h/2, z+d/2, 0.1, 0.1, 0.1, -dx, -dy, -dz, 0.0, 0.0, 0.0, 255, 0, 0, 10, 3.0); } } void speen3(double x, double y, double z, double w, double h, double d, double hz_angle, double vt_angle, float dtime, entity* ent, cube_0* ret) { ret->vt_angle += ((double)dtime)*22.5; } // metad{1,2,3} = og pos // metad{4,5,6} = amplitudes // metai{1} = frequency multiplier // metai{2} = frequency divider // metai{3} = phase void moving_xyz(double x, double y, double z, double w, double h, double d, double hz_angle, double vt_angle, float dtime, entity* ent, cube_0* ret) { ret->x = ent->metad1 + ent->metad4*cos((double)(ent->metai1*sim_time/ent->metai2 + ent->metai3*3.14159/180.0)); ret->y = ent->metad2 + ent->metad5*cos((double)(ent->metai1*sim_time/ent->metai2 + ent->metai3*3.14159/180.0)); ret->z = ent->metad3 + ent->metad6*cos((double)(ent->metai1*sim_time/ent->metai2 + ent->metai3*3.14159/180.0)); //printf("%lf %lf %lf\n", ret->x, ret->y, ret->z); } void detectHit(float dtime, int* hp, int* dmg, entity* ent, cube_0* ret) { if(ret->red == 193) { ret->red = 0; ret->green = 192; ret->blue = 0; coins += *hp; player_hp -= (*dmg); if(*dmg != 0) { fade_dmg = 255; } *hp = 0; } } void translatePlayer(float dtime, int* hp, int* dmg, entity* ent, cube_0* ret) { double vx = ent->metad4*(cos((double)(ent->metai1*(sim_time+(double)dtime)/ent->metai2 + ent->metai3*3.14159/180.0))-cos((double)(ent->metai1*sim_time/ent->metai2 + ent->metai3*3.14159/180.0))); double vy = ent->metad5*(cos((double)(ent->metai1*(sim_time+(double)dtime)/ent->metai2 + ent->metai3*3.14159/180.0))-cos((double)(ent->metai1*sim_time/ent->metai2 + ent->metai3*3.14159/180.0))); double vz = ent->metad6*(cos((double)(ent->metai1*(sim_time+(double)dtime)/ent->metai2 + ent->metai3*3.14159/180.0))-cos((double)(ent->metai1*sim_time/ent->metai2 + ent->metai3*3.14159/180.0))); //printf("(%lf %lf) (%lf %lf) (%lf %lf)\n", vx, camvx, vy, camvy, vz, camvz); if(true) { double oldvx = camvx; camvx += vx/dtime; camx -= oldvx*dtime; camx += camvx*dtime; noResetSpeed = true; } if(true) { double oldvy = camvy; camvy += vy/dtime; camy -= oldvy*dtime; camy += camvy*dtime; noResetSpeed = true; } if(true) { double oldvz = camvz; camvz += vz/dtime; camz -= oldvz*dtime; camz += camvz*dtime; noResetSpeed = true; } } void go_to_player(double x, double y, double z, double w, double h, double d, double hz_angle, double vt_angle, float dtime, entity* ent, cube_0* ret) { double dx = (x+w/2 - camx); double dy = (y+h/2 - camy); double dz = (z+d/2 - camz); double total = sqrt(dx*dx + dy*dy + dz*dz); dx = 110.0*dx/total; dy = 110.0*dy/total; dz = 110.0*dz/total; ret->x -= dtime*dx; if(is_colliding_with_map(ret) || is_colliding_with_tp(ret)) { ret->x += dtime*dx; } ret->y -= dtime*dy; if(is_colliding_with_map(ret) || is_colliding_with_tp(ret)) { ret->y += dtime*dy; } ret->z -= dtime*dz; if(is_colliding_with_map(ret) || is_colliding_with_tp(ret)) { ret->z += dtime*dz; } if((int)(ret->x+ret->y+ret->z) != (int)(ret->x+ret->y+ret->z-dx-dy-dz)) { } } void explodeOnHit(float dtime, int* hp, int* dmg, entity* ent, cube_0* ret) { player_hp -= (*dmg); if(*dmg != 0) { fade_dmg = 255; } *hp = 0; }