| 162 | } |
| 163 | |
| 164 | void MapState::Tick( const Time current_time ) |
| 165 | { |
| 166 | const float time_since_map_start_s= ( current_time - map_start_time_ ).ToSeconds(); |
| 167 | const float tick_delta_s= ( current_time - last_tick_time_ ).ToSeconds(); |
| 168 | |
| 169 | last_tick_time_= current_time; |
| 170 | |
| 171 | for( Item& item : items_ ) |
| 172 | { |
| 173 | const unsigned int animation_frame= |
| 174 | static_cast<unsigned int>( std::round( GameConstants::animations_frames_per_second * time_since_map_start_s ) ); |
| 175 | |
| 176 | if( item.item_id < game_resources_->items_models.size() ) |
| 177 | item.animation_frame= animation_frame % game_resources_->items_models[ item.item_id ].frame_count; |
| 178 | else |
| 179 | item.animation_frame= 0; |
| 180 | } |
| 181 | |
| 182 | for( unsigned int i= 0u; i < sprite_effects_.size(); ) |
| 183 | { |
| 184 | SpriteEffect& effect= sprite_effects_[i]; |
| 185 | |
| 186 | const float time_delta_s= ( current_time - effect.start_time ).ToSeconds(); |
| 187 | |
| 188 | effect.frame= time_delta_s * GameConstants::sprites_animations_frames_per_second; |
| 189 | |
| 190 | const GameResources::SpriteEffectDescription& description= game_resources_->sprites_effects_description[ effect.effect_id ]; |
| 191 | |
| 192 | if( description.gravity ) |
| 193 | effect.speed.z+= tick_delta_s * GameConstants::particles_vertical_acceleration; |
| 194 | effect.pos+= tick_delta_s * effect.speed; |
| 195 | |
| 196 | bool force_kill= false; |
| 197 | |
| 198 | if( effect.pos.z < 0.0f ) |
| 199 | { |
| 200 | if( description.jump ) |
| 201 | { |
| 202 | effect.pos.z= 0.0f; |
| 203 | |
| 204 | const float c_speed_scale= 0.5f; |
| 205 | effect.speed.x*= c_speed_scale; |
| 206 | effect.speed.y*= c_speed_scale; |
| 207 | effect.speed.z*= -c_speed_scale; |
| 208 | } |
| 209 | |
| 210 | if( !description.looped || std::abs( effect.speed.z ) < 0.2f ) |
| 211 | force_kill= true; |
| 212 | } |
| 213 | |
| 214 | const float sprite_frame_count= float( game_resources_->effects_sprites[ effect.effect_id ].frame_count ); |
| 215 | |
| 216 | if( force_kill || |
| 217 | ( !description.looped && effect.frame >= sprite_frame_count ) || |
| 218 | time_delta_s > 10.0f ) |
| 219 | { |
| 220 | if( i < sprite_effects_.size() -1u ) |
| 221 | sprite_effects_[i]= sprite_effects_.back(); |