void ExplodingSprite::makeChunks_multi(unsigned int n) { unsigned int chunk_width = getFrame()->getWidth()/n; unsigned int chunk_height = getFrame()->getHeight()/n; Sint16 source_x = getFrame()->getSourceX(); Sint16 source_y = getFrame()->getSourceY(); int speedx = static_cast<int>(velocityX())+1; // Make sure it's not 0; int speedy = static_cast<int>(velocityY())+1; // Make sure it's an int. SDL_Surface* spriteSurface(getFrame()->getSurface()); for (unsigned int i = 0; i < n; ++i) { for (unsigned int j = 0; j < n; ++j) { float sx = (rand() % speedx + rand()%80+20) * (rand()%2?-1:1); // 'cause %0 is float sy = (rand() % speedy + rand()%80+40) * (rand()%2?-1:1); // float except Frame* frame = new Frame(spriteSurface, chunk_width, chunk_height, source_x+i*chunk_width, // x coord of surface source_y+j*chunk_height // y coord of surface ); Chunk chunk( Vector2f(X()+i*chunk_width, // x coord of destination Y()+j*chunk_height), // y coord of destination Vector2f(sx, sy), getName()+"Chunk", // getName(), frame); chunks.push_back(chunk); frames.push_back(frame); } } }
/*void ExplodingSprite::makeChunks(unsigned int n) { // Break the SDL_Surface into n*n squares; where each square // has width and height of frameWidth/n and frameHeight/n unsigned int chunk_width = std::max(1u, getFrame()->getWidth()/n); unsigned int chunk_height = std::max(1u, getFrame()->getHeight()/n); int speedx = static_cast<int>(velocityX()); // Wanna test for zero... int speedy = static_cast<int>(velocityY()); // Make sure it's an int. if (speedx == 0) speedx = 1; // Make sure it's not 0; if (speedy == 0) speedy = 1; // Make sure it's not 0; // Get the SDL_Surface so we can chunk it: SDL_Surface* spriteSurface(getFrame()->getSurface()); Sint16 source_y = getFrame()->getSourceY(); while (source_y < getFrame()->getHeight() ) { Sint16 source_x = getFrame()->getSourceX(); while ( source_x < getFrame()->getWidth() ) { // Give each chunk it's own speed/direction: float sx = (rand() % speedx + 40) * (rand()%2?-1:1); // 'cause %0 is float sy = (rand() % speedy + 40) * (rand()%2?-1:1); // float except Frame* frame = new Frame(spriteSurface, chunk_width, chunk_height, source_x, source_y ); Chunk chunk( Vector2f(X()+source_x, // x coord of destination Y()+source_y), // y coord of destination Vector2f(sx, sy), getName()+"/chunk", frame); // chunks uses value semantics, as does frames, but there's // a big difference: chunks.push_back(chunk); frames.push_back(frame); source_x += chunk_width; } source_y += chunk_height; } } */ void ExplodingSprite::makeChunks(unsigned int n) { const Frame* frame = getFrame(); unsigned int chunk_width = frame->getWidth()/n; unsigned int chunk_height = frame->getHeight()/n; Sint16 source_x = frame->getSourceX(); Sint16 source_y = frame->getSourceY(); int speedx = static_cast<int>(velocityX()); // Wanna test for zero... int speedy = static_cast<int>(velocityY()); // Make sure it's an int. if (speedx == 0) speedx = 1; // Make sure it's not 0; if (speedy == 0) speedy = 1; // Make sure it's not 0; // Get the SDL_Surface so we can chunk it: SDL_Surface* spriteSurface(frame->getSurface()); for (unsigned int i = 0; i < n; ++i) { for (unsigned int j = 0; j < n; ++j) { float sx = (rand() % speedx + 40) * (rand()%2?-1:1); // 'cause %0 is float sy = (rand() % speedy + 40) * (rand()%2?-1:1); // float except frames.push_back( new Frame(spriteSurface, chunk_width, chunk_height, source_x+i*chunk_width, // x coord of surface source_y+j*chunk_height) // y coord of surface ); Chunk chunk( Vector2f(X()+i*chunk_width, // x coord of destination Y()+j*chunk_height), // y coord of destination Vector2f(sx, sy), getName()+"/chunk", frames.back() ); chunks.push_back(chunk); } } }
void ExplodingSprite::makeChunks(unsigned int n) { // std::cout << n << std::endl; // Break the SDL_Surface into n*n squares; where each square // has width and height of frameWidth/n and frameHeight/n unsigned int chunk_width = std::max(1u, getFrame()->getWidth() / n); unsigned int chunk_height = std::max(1u, getFrame()->getHeight() / n); int speedx = static_cast<int>(velocityX()); // Wanna test for zero... int speedy = static_cast<int>(velocityY()); // Make sure it's an int. if (speedx == 0) speedx = 1; // Make sure it's not 0; if (speedy == 0) speedy = 1; // Make sure it's not 0; // Get the SDL_Surface so we can chunk it: SDL_Surface* spriteSurface(getFrame()->getSurface()); Sint16 source_y = getFrame()->getSourceY(); while (source_y < getFrame()->getHeight()) { Sint16 source_x = getFrame()->getSourceX(); while (source_x < getFrame()->getWidth()) { // std::cout << source_x << ", " << source_y << std::endl; // Give each chunk it's own speed/direction: // float sx = (rand() % speedx + 40) * (rand() % 2 ? -1 : 1); // 'cause %0 is // float sy = (rand() % speedy + 40) * (rand() % 2 ? -1 : 1); // float except float sx = (Gamedata::getInstance().getRandInRange(10, 40)) * (rand() % 2 ? -1 : 1); // 'cause %0 is float sy = (Gamedata::getInstance().getRandInRange(10, 40)) * (rand() % 2 ? -1 : 1); // float except // std::cout << sx << ", " << sy << std::endl; Frame* frame = new Frame(spriteSurface, chunk_width, chunk_height, source_x, source_y); Chunk chunk(Vector2f(X() + source_x, // x coord of destination Y() + source_y), // y coord of destination Vector2f(sx, sy), getName() + "/chunk", frame); // chunks uses value semantics, as does frames, but there's // a big difference: chunks.push_back(chunk); frames.push_back(frame); source_x += chunk_width; } source_y += chunk_height; } }
void ExplodingSprite::makeChunks(unsigned int n) { // Break the SDL_Surface into n*n squares; where each square // has width and height of frameWidth/n and frameHeight/n unsigned int chunk_width = frame->getWidth()/n; unsigned int chunk_height = frame->getHeight()/n; Sint16 source_x = frame->getSourceX(); Sint16 source_y = frame->getSourceY(); int speedx = static_cast<int>(velocityX()); // Wanna test for zero... int speedy = static_cast<int>(velocityY()); // Make sure it's an int. if (speedx == 0) speedx = 1; // Make sure it's not 0; if (speedy == 0) speedy = 1; // Make sure it's not 0; // Get the SDL_Surface so we can chunk it: SDL_Surface* spriteSurface(frame->getSurface()); // i tracks the width, j tracks the height: for (unsigned int i = 0; i < n; ++i) { for (unsigned int j = 0; j < n; ++j) { // Give each chunk it's own speed/direction: float sx = (rand() % speedx + 40) * (rand()%2?-1:1); // 'cause %0 is float sy = (rand() % speedy + 40) * (rand()%2?-1:1); // float except Frame* frame = new Frame(spriteSurface, chunk_width, chunk_height, source_x+i*chunk_width, // x coord of surface source_y+j*chunk_height // y coord of surface ); Chunk chunk( Vector2f(X()+i*chunk_width, // x coord of destination Y()+j*chunk_height), // y coord of destination Vector2f(sx, sy), getName()+"Chunk", frame); // chunks uses value semantics, as does frames, but there's // a big difference: chunks.push_back(chunk); frames.push_back(frame); } } }