int main(int argc, char *argv[]) { uint8_t scr[H][W][3]; srand(time(NULL)); time_t start = time(NULL); star_t *stars = new star_t[N_STARS]; for(int idx=0; idx<N_STARS; idx++) { new_star(&stars[idx]); stars[idx].x = rand() % W; } for(;time(NULL) - start < DURATION;) { memset(scr, 0x00, sizeof scr); for(int idx=0; idx<N_STARS; idx++) { scr[stars[idx].y][stars[idx].x][0] = scr[stars[idx].y][stars[idx].x][1] = scr[stars[idx].y][stars[idx].x][2] = stars[idx].g; } write(1, scr, sizeof scr); for(int idx=0; idx<N_STARS; idx++) { stars[idx].x += stars[idx].dx; if (stars[idx].x < 0) new_star(&stars[idx]); } usleep(50000); } return 0; }
static int cbot(unit_t *player, block_t *self, map_t *map) { self->ch = CHAR_USED_BLOCK; self->status = MODIFIED; int y = (int)player->pos.y-1; int x = (int)player->pos.x; if(y >= 0) { if(map->block[y][x].status == EMPTY) { new_star(y, x, RIGHT, map); } } return 0; }
void CEntityGalaxy::HandleMouseButtonDown(std::shared_ptr<C2DVector> coords_) { // onclick add another massive star like the last one, in the place we // clicked if (this->m_collection.size() <= (this->m_original_star_num)) // m_original_star_num is the current total // of stars counting the black hole { std::unique_ptr<CEntityParticle> new_star(new CEntityParticle( *(this->m_collection[0]))); // use the first star as a prototype new_star->Reposition(*coords_); //make it super massive! float mass = 10000.0f; new_star->SetMass(mass); new_star->SetScale(10.0f); // set id new_star->SetId(this->m_collection.size()); new_star->HandleMouseButtonDown(coords_); this->m_collection.push_back(std::move(new_star)); } }
CEntityGalaxy::CEntityGalaxy(unsigned int id_, const C2DVector& initial_pos_, const CEntityParticle& star_, unsigned int star_number_, float _bounding_box_side, bool use_CUDA_) : CEntity(id_, std::unique_ptr<IMoveable>(new CMoveableParticle(initial_pos_)), NULL), m_rand_pos(), m_rand_mass(), m_using_CUDA(use_CUDA_), m_original_star_num(star_number_) { // first check proper number of stars is given if (this->m_original_star_num <= 1) { this->m_original_star_num = 1; } m_rand_pos.SetRealBounds(-_bounding_box_side / 2.0f, _bounding_box_side / 2.0f); m_rand_mass.SetRealBounds(1, 4); for ( unsigned int i = 0; i < this->m_original_star_num - 1; ++i) //Mind the (-1), we want to add another massive star in the centre! { std::unique_ptr<CEntityParticle> new_star(new CEntityParticle(star_)); // randomize position. C2DVector pos = initial_pos_ + C2DVector(m_rand_pos.RandReal(), m_rand_pos.RandReal()); C2DVector initial_vel = C2DVector(m_rand_pos.RandReal() / 200.0f, m_rand_pos.RandReal() / 200.0f); // randomize mass float mass = m_rand_mass.RandReal(); // adjust size accordingly (assuming constant density). TODO: randomize // density and have britness change by it. Make them turn into black // holes too new_star->SetScale(mass); new_star->Reposition(pos); new_star->Boost(pos + initial_vel); new_star->SetMass(mass); // set id new_star->SetId(i); // add a copy of star_ to the collection this->m_collection.push_back(std::move(new_star)); } // now add a supemassive black hole to be fixed in the center std::unique_ptr<CEntityParticle> super_massive_black_hole( new CEntityParticle(star_)); super_massive_black_hole->SetScale(10.0f); super_massive_black_hole->Reposition(initial_pos_); float mass = 100.0f; super_massive_black_hole->SetMass(mass); // set id super_massive_black_hole->SetId(star_number_); // make super_massibe_black_hole static super_massive_black_hole->Block(); // add a copy of star_ to the collection this->m_collection.push_back(std::move(super_massive_black_hole)); }