Twister::Twister( const Orbital::vector_type& pos, const Orbital::vector_type& v ) : Orbital( pos, v ) { angleAcc = 0; angleVel = random( 0.1f, 0.9f ); angle = random_angle() * (180/3.145); }
MenuOrbital::MenuOrbital( const vector_type& pos, const vector_type& ) : Orbital( pos, vector_type(0,0) ) { time = random( 0.0f, 3.0f );; angle = random_angle(); isActive = false; activationDelay = ACTIVATION_DELAY; isDeadly = false; }
blue_magic_particle::blue_magic_particle() : particle { world_space::vector::zero() , world_space::vector{world_space::radians::circle() / 6.0 * uniform(0, 6), 45.0} / 1.0s , world_space::acceleration::zero() , random_angle() , uniform(-1.0, 1.0) * _dtheta_max / 1.0s , 1.0 , world_space::scale_velocity{0.0} , world_space::seconds{uniform(2.0, 2.4)} } {}
void step_rat(void) { // The keepout is used to know where to -not- put the paddle // the 'bouncepos' is where we expect the ball's y-coord to be when // it intersects with the paddle area static uint8_t right_keepout_top, right_keepout_bot; static uint8_t left_keepout_top, left_keepout_bot; static uint16_t dest_paddle_pos; static uint16_t right_dest, left_dest; // Save old ball location so we can do some vector stuff oldball_x = ball_x; oldball_y = ball_y; // move ball according to the vector ball_x += ball_dx; ball_y += ball_dy; /************************************* TOP & BOTTOM WALLS */ // bouncing off bottom wall, reverse direction // if (ball_y > (SCREEN_H_FIXED - BALL_RADIUS*2*FIXED_MATH - BOTBAR_H_FIXED)) { if (ball_y > (SCREEN_H - BOTBAR_H - BALL_RADIUS*2)*FIXED_MATH) { //DEBUG(putstring_nl("bottom wall bounce")); ball_y = (SCREEN_H - BOTBAR_H - BALL_RADIUS*2)*FIXED_MATH; ball_dy = -ball_dy; } // bouncing off top wall, reverse direction if (ball_y < TOPBAR_H_FIXED) { //DEBUG(putstring_nl("top wall bounce")); ball_y = TOPBAR_H_FIXED; ball_dy = -ball_dy; } /************************************* LEFT & RIGHT WALLS */ // the ball hits either wall, the ball resets location & angle if ( ((INT_MSB(ball_x)) > (SCREEN_W - BALL_RADIUS*2)) || ((int8_t)(INT_MSB(ball_x)) <= 0) || ((ball_dx ==0) && (ball_dy==0)) ) { if(DEBUGGING) { if ((int8_t)(INT_MSB(ball_x)) <= 0) { putstring("Left wall collide"); if (! minute_changed) { putstring_nl("...on accident"); } else { putstring_nl("...on purpose"); } } else { putstring("Right wall collide"); if (! hour_changed) { putstring_nl("...on accident"); } else { putstring_nl("...on purpose"); } } } // place ball in the middle of the screen ball_x = (SCREEN_W/2 - BALL_RADIUS)*FIXED_MATH; ball_y = (SCREEN_H/2 - BALL_RADIUS)*FIXED_MATH; // TODO JMM: don't use cosine/sine... pick one randomly and calc the other one. int8_t angle = random_angle(); ball_dx = (int16_t) (((int32_t) MAX_BALL_SPEED * cosine(angle)) / 0x7FFF); ball_dy = (int16_t) (((int32_t) MAX_BALL_SPEED * sine(angle)) / 0x7FFF); glcdFillRectangle(LEFTPADDLE_X, left_keepout_top, PADDLE_W, left_keepout_bot - left_keepout_top, 0); glcdFillRectangle(RIGHTPADDLE_X, right_keepout_top, PADDLE_W, right_keepout_bot - right_keepout_top, 0); right_keepout_top = right_keepout_bot = 0; left_keepout_top = left_keepout_bot = 0; redraw_time_rat = 1; minute_changed = hour_changed = 0; ticksremaining = calculate_dest_pos(&left_dest, &right_dest, &dest_paddle_pos, ball_dx > 0); //left_score = time_h; //right_score = time_m; setscore_rat(); } // save old paddle position oldleftpaddle_y = leftpaddle_y; oldrightpaddle_y = rightpaddle_y; /* if(ball_dx > 0) { // For debugging, print the ball location DEBUG(putstring("ball @ (")); DEBUG(uart_putw_dec(ball_x)); DEBUG(putstring(", ")); DEBUG(uart_putw_dec(ball_y)); DEBUG(putstring(")")); DEBUG(putstring(" ball_dx @ (")); DEBUG(uart_putw_dec(ball_dx)); DEBUG(putstring(")")); DEBUG(putstring(" ball_dy @ (")); DEBUG(uart_putw_dec(ball_dy)); DEBUG(putstring(")")); DEBUG(putstring(" ball_dy @ (")); DEBUG(uart_putw_dec(ball_dy)); DEBUG(putstring(")")); }*/ /*if(!minute_changed) { if((ball_dx < 0) && (ball_x < (SCREEN_W/2)*FIXED_MATH)) { move_paddle(&leftpaddle_y, ball_y); } } else { //Minute changed. We now have to miss the ball on purpose, if at all possible. //If we don't succeed this time around, we will try again next time around. if((ball_dx < 0) && (ball_x < (SCREEN_W/2)*FIXED_MATH) ) { move_paddle(&leftpaddle_y, dest_paddle_pos); } }*/ //ticksremaining--; if((ball_dx < 0) && (ball_x < (SCREEN_W/2)*FIXED_MATH) ) { move_paddle(&leftpaddle_y, minute_changed?dest_paddle_pos:(ball_y-(PADDLE_H_FIXED/3))); } else if((ball_dx > 0) && (ball_x > (SCREEN_W/2)*FIXED_MATH) ) { move_paddle(&rightpaddle_y, hour_changed?dest_paddle_pos:(ball_y-(PADDLE_H_FIXED/3))); } else { if(ball_dx < 0) ticksremaining = calculate_dest_pos(&left_dest, &right_dest, &dest_paddle_pos, 1); else ticksremaining = calculate_dest_pos(&left_dest, &right_dest, &dest_paddle_pos, 0); } // make sure the paddles dont hit the top or bottom if (leftpaddle_y < TOPBAR_H_FIXED +1) leftpaddle_y = TOPBAR_H_FIXED + 1; if (rightpaddle_y < TOPBAR_H_FIXED + 1) rightpaddle_y = TOPBAR_H_FIXED + 1; if (leftpaddle_y > ((SCREEN_H - PADDLE_H - BOTBAR_H)*FIXED_MATH - 1)) leftpaddle_y = ((SCREEN_H - PADDLE_H - BOTBAR_H)*FIXED_MATH - 1); if (rightpaddle_y> ((SCREEN_H - PADDLE_H - BOTBAR_H)*FIXED_MATH - 1)) rightpaddle_y = ((SCREEN_H - PADDLE_H - BOTBAR_H)*FIXED_MATH - 1); if ((ball_dx > 0) && intersectrect(INT_MSB(ball_x), INT_MSB(ball_y), BALL_RADIUS*2, BALL_RADIUS*2, RIGHTPADDLE_X, INT_MSB(rightpaddle_y), PADDLE_W, PADDLE_H)) { ball_dx = -ball_dx; ball_x = RIGHTPADDLE_X_FIXED - (BALL_RADIUS*2*FIXED_MATH); //ball_y = right_dest; //ticksremaining = calculate_dest_pos(&left_dest, &right_dest, &dest_paddle_pos, 1); } if ((ball_dx < 0) && intersectrect(INT_MSB(ball_x), INT_MSB(ball_y), BALL_RADIUS*2, BALL_RADIUS*2, LEFTPADDLE_X, INT_MSB(leftpaddle_y), PADDLE_W, PADDLE_H)) { ball_dx = -ball_dx; ball_x = LEFTPADDLE_X_FIXED + PADDLE_W_FIXED; //ball_y = left_dest; //ticksremaining = calculate_dest_pos(&left_dest, &right_dest, &dest_paddle_pos, 0); } }
void SceneMovementAnimatorTask::genRandomMovement( MovementAnimation& movement, ParticipantArray& participants ) { STUDIO_ASSERT( movement.m_positions > 0 && movement.m_positions < MAX_RANDOM_POSITIONS, "Random postions should be between 1 and %d", MAX_RANDOM_POSITIONS ); for ( size_t particpant_index=0; particpant_index < participants.size(); ) { Fixture* pf = getActorRepresentative( participants[ particpant_index ].m_actor_uid ); if ( !pf ) continue; UINT tilt_start = movement.m_tilt_start, tilt_end = movement.m_tilt_end; UINT pan_start = movement.m_pan_start, pan_end = movement.m_pan_end; AngleList pan; AngleList tilt; ChannelValueArray dimmer; ChannelValueArray speed; channel_address tilt_channel = participants[ particpant_index ].m_head.m_tilt; if ( tilt_channel != INVALID_CHANNEL ) { Channel* cp = pf->getChannel( tilt_channel ); tilt_start = std::max<UINT>( tilt_start, cp->getMinAngle() ); tilt_end = std::min<UINT>( tilt_end, cp->getMaxAngle() ); } channel_address pan_channel = participants[ particpant_index ].m_head.m_pan; if ( pan_channel != INVALID_CHANNEL ) { Channel* cp = pf->getChannel( pan_channel ); pan_start = std::max<UINT>( pan_start, cp->getMinAngle() ); pan_end = std::min<UINT>( pan_end, cp->getMaxAngle() ); } // Generate random locations within the tilt and pan bounds for ( UINT generate=0; generate < movement.m_positions; generate++ ) { UINT tilt_angle = random_angle( tilt_start, tilt_end ); UINT pan_angle = random_angle( pan_start, pan_end ); UINT wait_periods = movement.m_dest_wait_periods; // No light during movement if ( movement.m_backout_home_return && wait_periods > 1 ) { pan.push_back( pan_angle ); tilt.push_back( tilt_angle ); speed.push_back( 0 ); dimmer.push_back( 0 ); wait_periods--; } for ( UINT wait=0; wait < wait_periods; wait++ ) { pan.push_back( pan_angle ); tilt.push_back( tilt_angle ); speed.push_back( movement.m_speed ); dimmer.push_back( 255 ); } } if ( !movement.m_backout_home_return ) // TEMP fix for dimmer channel contention dimmer.clear(); // Populate the channel arrays for the next group of fixtures populateChannelAnimations( participants, particpant_index, tilt, pan, dimmer, speed, movement.m_group_size, movement.m_run_once ); } }
void PixelFeatureLayer<Dtype>::Forward_cpu( const vector<Blob<Dtype>*>& bottom, const vector<Blob<Dtype>*>& top) { const PixelFeatureParameter& parameter = this->layer_param_.pixel_feature_param(); Dtype* top_data = top[0]->mutable_cpu_data(); switch (this->layer_param_.pixel_feature_param().type()) { case PixelFeatureParameter_Feature_POSITION: { if (!ran_once) { const Dtype scale = parameter.pos_scale(); const Dtype offset_h = parameter.offset_h(); const Dtype offset_w = parameter.offset_w(); for (unsigned int n = 0; n < num_; ++n) { for (unsigned int y = 0; y < height_; ++y) { Dtype y_offset = scale * y + offset_h; for (unsigned int x = 0; x < width_; ++x) { top_data[top[0]->offset(n, 0, y, x)] = y_offset; top_data[top[0]->offset(n, 1, y, x)] = scale * x + offset_w; } } } } break; } case PixelFeatureParameter_Feature_POSITION_AND_RGB: { const Dtype scale = parameter.pos_scale(); const Dtype color_scale = parameter.color_scale(); const Dtype offset_h = parameter.offset_h(); const Dtype offset_w = parameter.offset_w(); for (unsigned int n = 0; n < num_; ++n) { for (unsigned int y = 0; y < height_; ++y) { Dtype y_offset = scale * y + offset_h; for (unsigned int x = 0; x < width_; ++x) { top_data[top[0]->offset(n, 0, y, x)] = y_offset; top_data[top[0]->offset(n, 1, y, x)] = scale * x + offset_w; for (unsigned int c = 0; c < bottom[0]->channels(); ++c) { top_data[top[0]->offset(n, c+2, y, x)] = color_scale * bottom[0]->data_at(n, c, y, x); } } } } break; } case PixelFeatureParameter_Feature_RGB_AND_POSITION: { const Dtype scale = parameter.pos_scale(); const Dtype color_scale = parameter.color_scale(); const Dtype offset_h = parameter.offset_h(); const Dtype offset_w = parameter.offset_w(); for (unsigned int n = 0; n < num_; ++n) { for (unsigned int y = 0; y < height_; ++y) { Dtype y_offset = scale * y + offset_h; for (unsigned int x = 0; x < width_; ++x) { for (unsigned int c = 0; c < bottom[0]->channels(); ++c) { top_data[top[0]->offset(n, c, y, x)] = color_scale * bottom[0]->data_at(n, c, y, x); } top_data[top[0]->offset(n, bottom[0]->channels(), y, x)] = y_offset; top_data[top[0]->offset(n, bottom[0]->channels() + 1, y, x)] = scale * x + offset_w; } } } break; } case PixelFeatureParameter_Feature_RGB: { const Dtype color_scale = parameter.color_scale(); for (unsigned int n = 0; n < num_; ++n) { for (unsigned int y = 0; y < height_; ++y) { for (unsigned int x = 0; x < width_; ++x) { for (unsigned int c = 0; c < bottom[0]->channels(); ++c) { top_data[top[0]->offset(n, c, y, x)] = color_scale * bottom[0]->data_at(n, c, y, x); } } } } break; } case PixelFeatureParameter_Feature_RANDOM_POSITION: case PixelFeatureParameter_Feature_NUM_RANDOM_POSITION: { if (!ran_once) { const int input_height = bottom[0]->height(); const int input_width = bottom[0]->width(); const Dtype scale = parameter.pos_scale(); boost::uniform_real<Dtype> random_height(0, input_height); boost::variate_generator<caffe::rng_t*, boost::uniform_real<Dtype> > variate_height(caffe_rng(), random_height); boost::uniform_real<Dtype> random_width(0, input_width); boost::variate_generator<caffe::rng_t*, boost::uniform_real<Dtype> > variate_width(caffe_rng(), random_width); for (unsigned int n = 0; n < num_; ++n) { for (unsigned int y = 0; y < height_; ++y) { for (unsigned int x = 0; x < width_; ++x) { top_data[top[0]->offset(n, 0, y, x)] = scale * variate_height(); top_data[top[0]->offset(n, 1, y, x)] = scale * variate_width(); } } } } break; } case PixelFeatureParameter_Feature_WARPED_POSITION: { if (!ran_once) { const Dtype angle = -parameter.rotation_angle() / 180.0 * M_PI; const Dtype scale = parameter.pos_scale(); const Dtype angle_sigma = parameter.rotation_sigma(); const Dtype cosAngle = std::cos(angle); const Dtype sinAngle = std::sin(angle); const Dtype mid_y = height_ / 2; const Dtype mid_x = width_ / 2; Dtype scaled_y, scaled_x; for (unsigned int n = 0; n < num_; ++n) { for (unsigned int y = 0; y < height_; ++y) { scaled_y = y * scale - mid_y; for (unsigned int x = 0; x < width_; ++x) { scaled_x = x * scale - mid_x; top_data[top[0]->offset(n, 0, y, x)] = sinAngle * scaled_x + cosAngle * scaled_y + mid_y; top_data[top[0]->offset(n, 1, y, x)] = cosAngle * scaled_x - sinAngle * scaled_y + mid_x; top_data[top[0]->offset(n, 2, y, x)] = angle / angle_sigma; } } } } break; } case PixelFeatureParameter_Feature_RANDOM_ROTATE: { if (!ran_once) { boost::uniform_real<Dtype> random_angle(-10, 10); boost::variate_generator<caffe::rng_t*, boost::uniform_real<Dtype> > variate_angle(caffe_rng(), random_angle); const Dtype angle = variate_angle() / 180.0 * M_PI; const Dtype scale = 1; const Dtype cosAngle = std::cos(angle); const Dtype sinAngle = std::sin(angle); const Dtype mid_y = height_ / 2; const Dtype mid_x = width_ / 2; Dtype scaled_y, scaled_x; for (unsigned int n = 0; n < num_; ++n) { for (unsigned int y = 0; y < height_; ++y) { scaled_y = y * scale - mid_y; for (unsigned int x = 0; x < width_; ++x) { scaled_x = x * scale - mid_x; top_data[top[0]->offset(n, 0, y, x)] = sinAngle * scaled_x + cosAngle * (scaled_y - mid_y) + mid_y; top_data[top[0]->offset(n, 1, y, x)] = cosAngle * scaled_x - sinAngle * scaled_y + mid_x; } } } } break; } default: LOG(FATAL) << "Undefined feature type of pixel feature layer"; } ran_once = true; }
sgeroids::view::planar::background::object::object( sge::renderer::device::core &_renderer, sge::renderer::vertex::declaration const &_vertex_declaration, sgeroids::view::planar::texture_tree &_texture_tree, sgeroids::model::play_area const &_play_area, sgeroids::random_generator &_rng, star_size const _star_size, star_count const _star_count) : sprite_buffers_( sge::sprite::buffers::parameters( _renderer, _vertex_declaration), sge::sprite::buffers::option::dynamic), sprite_collection_(), sprite_state_( _renderer, sge::sprite::state::parameters< sprite_state_choices >()), sprites_(), sprite_render_range_(), texture_tree_( _texture_tree), play_area_( _play_area), star_size_( _star_size), star_count_( _star_count) { typedef fcppt::random::distribution::basic< fcppt::random::distribution::parameters::uniform_int< int > > int_distribution; typedef fcppt::random::distribution::basic< fcppt::random::distribution::parameters::uniform_real< float > > float_distribution; typedef fcppt::random::variate< sgeroids::random_generator, int_distribution > int_rng; typedef fcppt::random::variate< sgeroids::random_generator, float_distribution > float_rng; int_rng random_x( _rng, int_distribution( int_distribution::param_type::min( 0), int_distribution::param_type::max( play_area_.get().size().w()))); int_rng random_y( _rng, int_distribution( int_distribution::param_type::min( 0), int_distribution::param_type::max( play_area_.get().size().h()))); float_rng random_angle( _rng, float_distribution( float_distribution::param_type::min( 0.f), float_distribution::param_type::sup( 6.f))); int_rng random_radius( _rng, int_distribution( int_distribution::param_type::min( math::unit_magnitude() * star_size_.get()), int_distribution::param_type::max( math::unit_magnitude() * star_size_.get() * 4))); for ( star_count::value_type index = 0; index < star_count_.get(); ++index ) sprites_.push_back( planar::sprite::object( sge::sprite::roles::connection{} = sprite_collection_.connection( 0 ), sge::sprite::roles::texture0{} = sgeroids::view::planar::sprite::object::texture_type{ texture_tree_.get( sge::resource_tree::path() / FCPPT_TEXT("star") ) }, sge::sprite::roles::size{} = planar::sprite_size_from_texture_and_radius( *texture_tree_.get( sge::resource_tree::path() / FCPPT_TEXT("star")), planar::radius(random_radius()) ), sge::sprite::roles::center{} = planar::sprite::object::vector( random_x(), random_y() ), sge::sprite::roles::rotation{} = 0.f, sge::sprite::roles::color{} = sge::image::color::any::convert< sgeroids::view::planar::sprite::color_format >( sge::image::color::predef::white() ) ) ); sprites_.push_back( planar::sprite::object( sge::sprite::roles::connection{} = sprite_collection_.connection( 2 ), sge::sprite::roles::texture0{} = sgeroids::view::planar::sprite::object::texture_type{ texture_tree_.get( sge::resource_tree::path() / FCPPT_TEXT("planet") ) }, sge::sprite::roles::size{} = planar::sprite_size_from_texture_and_radius( *texture_tree_.get( sge::resource_tree::path() / FCPPT_TEXT("planet")), planar::radius(30 * random_radius()) ), sge::sprite::roles::center{} = planar::sprite::object::vector( random_x(), random_y() ), sge::sprite::roles::rotation{} = random_angle(), sge::sprite::roles::color{} = sge::image::color::any::convert< sgeroids::view::planar::sprite::color_format >( sge::image::color::predef::white() ) ) ); sprites_.push_back( planar::sprite::object( sge::sprite::roles::connection{} = sprite_collection_.connection( 1 ), sge::sprite::roles::texture0{} = sgeroids::view::planar::sprite::object::texture_type{ texture_tree_.get( sge::resource_tree::path() / FCPPT_TEXT("nebula")) }, sge::sprite::roles::size{} = planar::sprite_size_from_texture_and_radius( *texture_tree_.get( sge::resource_tree::path() / FCPPT_TEXT("nebula")), planar::radius(math::unit_magnitude() * 1024 * 1024) ), sge::sprite::roles::center{} = planar::sprite::object::vector( random_x(), random_y() ), sge::sprite::roles::rotation{} = random_angle(), sge::sprite::roles::color{} = sge::image::color::any::convert< sgeroids::view::planar::sprite::color_format >( sge::image::color::predef::white() ) ) ); sprite_render_range_ = sge::sprite::geometry::sort_and_update( sprite_collection_.range(), sge::sprite::compare::default_(), sprite_buffers_); }
///////// GAME ///////////// void do_game() { // Reset timer old_time = time; // Ask SDL for the time in milliseconds time = SDL_GetTicks(); // Print frame rate if (PRINT_FPS && (time_since_fps > 1000)) { print_fps(); time_since_fps = 0; } else { time_since_fps += time - old_time; } // Work out how much game time has passed since the previous frame float dt = (float)(time - old_time)*GAME_SPEED; // Maybe create new bot ** TEMP ** if (rand()/(float)RAND_MAX < 0.01*dt) { spawn_bot(bot, random_int(DISPLAY_WIDTH - PLAYER_BOUND_WIDTH) + PLAYER_BOUND_WIDTH, random_int(DISPLAY_HEIGHT - PLAYER_BOUND_WIDTH) + PLAYER_BOUND_WIDTH, random_angle()); } // Handle game objects do_walls(wal); do_player(&plr, bul, wal, dt); do_bots(bot, &plr, bul, wal, dt); do_bullets(bul, dt); // check for collisions between various objects int bul_i, bot_i, wall_i; for (bul_i = 0; bul_i < BULLET_MAX; bul_i++) { if (bul[bul_i].ex) { // Check for player being hit by a bullet if (player_hit_by_bullet(&plr, &bul[bul_i])) { bullet_destroy(&bul[bul_i]); player_take_bullet(&plr, &bul[bul_i]); } // Check for bot being hit by a bullet for (bot_i = 0; bot_i < BOT_MAX; bot_i++) { if (bot_hit_by_bullet(&bot[bot_i], &bul[bul_i])) { bullet_destroy(&bul[bul_i]); bot_take_bullet(&bot[bot_i], &bul[bul_i]); } } // Check for wall being hit by a bullet for (wall_i = 0; wall_i < WALL_MAX; wall_i++) { if (wall_hit_by_bullet(&wal[wall_i], &bul[bul_i])) { bullet_destroy(&bul[bul_i]); wall_take_bullet(&wal[wall_i]); } } } } }