DustCloudParticle::DustCloudParticle(unsigned int numParticles, float minSize, float maxSize, float xPos, float yPos) { RenderComponent::RenderComponent(); //gameObjectRef->AddComponent(COMPONENT_RENDER, this); SceneManager* sceneMan = SceneManager::GetSceneManager(); RenderManager* renderMan = RenderManager::getRenderManager(); ResourceManager* ResMan = ResourceManager::GetResourceManager(); //RenderResource * originalImage = ; //std::function<bool(void)> charge = isCharging; objRef = sceneMan->InstantiateObject(sceneMan->findLayer("layer2"), -1, xPos, yPos); objRef->toggleVisible(); for (unsigned int i = 0; i < numParticles; i++){ SDLRenderObject * sprite = sceneMan->InstantiateObject(sceneMan->findLayer("layer2"), -1, xPos, yPos); RenderResource * resource = new RenderResource((RenderResource*)ResMan->findResourcebyID(4001)); resource->load(); sprite->setResourceObject(resource); sprite->setScale(sprite->calcXScale(minSize + (maxSize-minSize)*(rand()%100)/100)); std::list<motion> movements; movements.push_back(makeMotion(moveLinearXY(sprite, xPos, yPos, xPos+ 40 -(rand() % 80), yPos + 40 - (rand() % 80)),0, 1, ease_QuadIn)); movements.push_back(makeMotion(rotateTransform(sprite, rand() % 360, (rand() % 90) - 45), 0, 1)); Animation * movement = new Animation((float)(700 - (rand() % 200)), movements); particle p; p.animations = movement; p.sprite = sprite; p.timer = (float)progress; particles.push_back(p); } }
ShrapnelExplosionParticle::ShrapnelExplosionParticle(SDLRenderObject * base, unsigned int numParticles, float x, float y) { RenderComponent::RenderComponent(); //gameObjectRef->AddComponent(COMPONENT_RENDER, this); SceneManager* sceneMan = SceneManager::GetSceneManager(); RenderManager* renderMan = RenderManager::getRenderManager(); objRef = sceneMan->InstantiateObject(sceneMan->findLayer("layer2"), -1, x, y, base->getPosZ()); objRef->toggleVisible(); baseImage = base->renderResource; SDL_Rect baseRect = base->getRenderRect(); unsigned int scale = 2; float size = (float)(baseRect.w/scale); float centerX = x; float centerY = y; for (unsigned int i = 0; i < numParticles; i++){ SDLRenderObject * sprite = sceneMan->InstantiateObject(sceneMan->findLayer("layer2"), -1, centerX, centerY); //play->setResourceObject(renderMan->renderText("Timer", 255, 0, 255, 50, "BowlbyOneSC-Regular")); sprite->setResourceObject(baseImage); int xPos = (baseRect.w - int(size) > 0) ? rand() % (baseRect.w - int(size)) : 0; int yPos = (baseRect.h - int(size) > 0) ? rand() % (baseRect.h - int(size)) : 0; SDL_Rect rect = { xPos, yPos , (int)size, (int)size }; sprite->setScaleX(base->getScaleX()); sprite->setScaleY(base->getScaleY()); sprite->setRenderRect(rect); float u = (float)((rand() % 360) / 360.0); float v = (float)((rand() % 360) / 360.0); float angle1 = (float)(3.14 * 2 * u); float angle2 = acos(2 * v - 1); std::list<motion> movements; movements.push_back(makeMotion(moveLinearXY(sprite, centerX, centerY, centerX + sin(angle1)*cos(angle2) * 300, centerY + sin(angle1)* sin(angle2) * 300), 0, 1, ease_QuadOut)); movements.push_back(makeMotion(moveLinearZ(sprite, 0, cos(angle1) * 10), 0, 1, ease_QuadOut)); movements.push_back(makeMotion(rotateTransform(sprite, rand() % 360, (rand() % 90) - 45), 0, 1)); Animation * movement = new Animation((float)(1000.0f - (rand() % 200)), movements); //int maxtime = 100000; //in seconds //std:list<motion> motions; particle p; p.animations = movement; p.sprite = sprite; p.timer = 0; particles.push_back(p); } }
void ChickenClassComponent::animation(SDLRenderObject** objRef, map_obj& allObjs, map_anim& animations) { SceneManager* sceneMan = SceneManager::GetSceneManager(); RenderManager* renderMan = RenderManager::getRenderManager(); SDLRenderObject * base = sceneMan->InstantiateObject(sceneMan->findLayer("layer2"), 0, 0, 0); base->toggleIfRenderImage(); SDLRenderObject * armL = sceneMan->InstantiateObject(sceneMan->findLayer("layer2"), 100103, 0, 0); SDLRenderObject * legL = sceneMan->InstantiateObject(sceneMan->findLayer("layer2"), 100105, 30, 300); SDLRenderObject * body = sceneMan->InstantiateObject(sceneMan->findLayer("layer2"), 100101, 0, -18); SDLRenderObject * legR = sceneMan->InstantiateObject(sceneMan->findLayer("layer2"), 100104, 50, 300); SDLRenderObject * armR = sceneMan->InstantiateObject(sceneMan->findLayer("layer2"), 100102, 0, 0); //PlayerPhysicsComponent pos = gameObjectRef->GetComponent(COMPONENT_PHYSICS); //objRef->setAnchor(0.5, 0.5); armR->setAnchor(174 / double(armR->renderRect.w), 154 / double(armR->renderRect.h)); armL->setAnchor(178 / double(armL->renderRect.w), 168 / double(armL->renderRect.h)); legR->setAnchor(128 / double(legR->renderRect.w), 39 / double(legR->renderRect.h)); legL->setAnchor(253 / double(legL->renderRect.w), 62 / double(legL->renderRect.h)); //armR->setCurrentFrame(1); body->setParent(base); armL->setParent(body); armR->setParent(body); legL->setParent(body); legR->setParent(body); //body->setScale(0.1); //body->calcScale(50,50); body->setScale(body->calcXScale(50)); //body->setScale(body->calcXScale(90)); *objRef = base; allObjs["base"] = base; allObjs["body"] = body; allObjs["legL"] = legL; allObjs["legR"] = legR; allObjs["armL"] = armL; allObjs["armR"] = armR; SDLRenderObject * box = sceneMan->InstantiateBlankObject(sceneMan->findLayer("layer2"), 0, 0, 0, 0); box->setIfRenderRect(true); //box->setParent(base); allObjs["box"] = box; //SDLRenderObject * name = sceneMan->InstantiateBlankObject(sceneMan->findLayer("layer2"), 0, 0, 0, 0); // changing the values in InstantiateBlankObject does not stop the text from being stretched // need fixing (to not stretch text to fill box) // text, R, G, B, fontsize, fontname //std::string playerName = GamerServices::sInstance->GetLocalPlayerName(); //name->setResourceObject(renderMan->renderText(playerName.c_str(), 200, 0, 200, 20, "BowlbyOneSC-Regular")); //name->setParent(base); //name->setPos(0, -60); //allObjs["name"] = name; /////// IDLE ANIMATION std::list<motion> motions; motions.push_back(makeMotion(keyframeJump(armR, 0), 0.0, 0.0)); motions.push_back(makeMotion(moveCircArc(armR, 0, 50, 50, 0, 360), 0, 1)); motions.push_back(makeMotion(moveCircArc(armL, 0, 50, 50, 180, 360), 0, 1)); motions.push_back(makeMotion(rotateTransform(legR, 0, 0), 0, 0)); motions.push_back(makeMotion(rotateTransform(legL, 0, 0), 0, 0)); Animation* idle = new Animation(400, motions); animations["idle"] = idle; //auto mot = idle.motions.begin(); //currentAnimation = idle; ////// WALKING ANIMATION std::list<motion> motions2; motions2.push_back(makeMotion(keyframeJump(armR, 0), 0.0, 0.0)); motions2.push_back(makeMotion(moveCircArc(armR, 0, 50, 50, 0, 360), 0, 1)); motions2.push_back(makeMotion(moveCircArc(armL, 0, 50, 50, 180, 360), 0, 1)); motions2.push_back(makeMotion(rotateTransform(legR, -60, 120), 0, 0.5, ease_QuadInOut)); motions2.push_back(makeMotion(rotateTransform(legR, 60, -120), 0.5, 0.5, ease_QuadInOut)); motions2.push_back(makeMotion(rotateTransform(legL, 60, -120), 0, 0.5, ease_QuadInOut)); motions2.push_back(makeMotion(rotateTransform(legL, -60, 120), 0.5, 0.5, ease_QuadInOut)); //motions2.push_back(makeMotion(rotateTransform(legR, -30, 60), 0.5, 0.5, ease_QuadIn)); animations["walk"] = new Animation(400, motions2); ////// THROW ANIMATION std::list<motion> motions3; motions3.push_back(makeMotion(keyframeJump(armR, 1), 0.0, 0.0)); motions3.push_back(makeMotion(rotateTransform(armR, -30, 0), 0.0, 1.0,ease_QuadOut)); animations["throw"] = new Animation(100, motions3); ////// CHARGE ANIMATION std::list<motion> motions4; motions4.push_back(makeMotion(rotateTransform(armR,-20,0), 0.0, 0.0)); animations["charge"] = new Animation(100, motions4); }
//==========Functions============= void readFile(char *fname) { char filename[1024]; //holds filename FILE *SceneFile; //points to the file char cmd[512]; // holds a command char Buff[2048]; int line=1; //keep track of line #s GLdouble x, y, z, angle, ni; char axis; //Initialize number of lights & objects numLights = 0; numObjs = 0; //Start reading scene with identity transform loadIdentityTransform(¤tTransform[curGroupLevel]); //Open the file if ((SceneFile = fopen(fname, "r")) == NULL) { printf("Error opening scene file \n"); exit(1); } fscanf(SceneFile, "%s", cmd); //stores first word into cmd //Loop to read contents of the file while (!feof(SceneFile)) { if (!strcmp(cmd, "view")) //compares string to view { fscanf(SceneFile, "%d", &view.size); //printf("View size: %d\n", view.size); fscanf(SceneFile, "%lf", &view.d); //printf("View distance to corner of image plane: %f\n", view.d); } else if (!strncmp(cmd, "#", 1)) { /* Comment, let's ignore! */ fgets(Buff, 2048, SceneFile); //takes in till \n is found } else if (!strcmp(cmd, "group")) { ++curGroupLevel; //printf("Current group level: %d\n", curGroupLevel); // get transform for previous group level currentTransform[curGroupLevel] = currentTransform[curGroupLevel-1]; } else if (!strcmp(cmd, "groupend")) { --curGroupLevel; //printf("Current group level: %d\n", curGroupLevel); } else if (!strcmp(cmd, "background")) { fscanf(SceneFile, "%lf", &backgroundColor.red); fscanf(SceneFile, "%lf", &backgroundColor.green); fscanf(SceneFile, "%lf", &backgroundColor.blue); } else if (!strcmp(cmd, "ambient")) { fscanf(SceneFile, "%lf", &ambient_light.red); fscanf(SceneFile, "%lf", &ambient_light.green); fscanf(SceneFile, "%lf", &ambient_light.blue); } else if (!strcmp(cmd, "light")) { if (numLights>=MAX_LIGHTS) { fprintf(stderr, "Error: max number of lights exceeded in description file\n"); fprintf(stderr, "Line %d\n", line); exit(-1); } fscanf(SceneFile,"%lf", &lightSources[numLights].color.red); fscanf(SceneFile,"%lf", &lightSources[numLights].color.green); fscanf(SceneFile,"%lf", &lightSources[numLights].color.blue); fscanf(SceneFile,"%lf", &lightSources[numLights].position.x); fscanf(SceneFile,"%lf", &lightSources[numLights].position.y); fscanf(SceneFile,"%lf", &lightSources[numLights].position.z); //printf("Color red: %lf\n", lightSources[numLights].color.red); //printf("Color green: %lf\n", lightSources[numLights].color.green); //printf("Color blue: %lf\n", lightSources[numLights].color.blue); //printf("Position x: %lf\n", lightSources[numLights].position.x); //printf("Position y: %lf\n", lightSources[numLights].position.y); //printf("Position z: %lf\n", lightSources[numLights].position.z); numLights++; } else if (!strcmp(cmd, "sphere")) { objects[numObjs].transform = currentTransform[curGroupLevel]; objects[numObjs].material = currentMaterial; numObjs++; if (numObjs>MAX_OBJECTS) { fprintf(stderr, "Error: max number of objects exceeded in description file\n"); fprintf(stderr, "Line %d\n", line); exit(-1); } } else if (!strcmp(cmd, "material")) { fscanf(SceneFile, "%lf", ¤tMaterial.diffuse.red); fscanf(SceneFile, "%lf", ¤tMaterial.diffuse.green); fscanf(SceneFile, "%lf", ¤tMaterial.diffuse.blue); fscanf(SceneFile, "%lf", ¤tMaterial.specular.red); fscanf(SceneFile, "%lf", ¤tMaterial.specular.green); fscanf(SceneFile, "%lf", ¤tMaterial.specular.blue); fscanf(SceneFile, "%lf", ¤tMaterial.shininess); // What do I do with this? // you need to put this into the object } else if (!strcmp(cmd, "refraction")) { //needs to be setup later } else if (!strcmp(cmd, "move")) { fscanf(SceneFile, "%lf", &x); fscanf(SceneFile, "%lf", &y); fscanf(SceneFile, "%lf", &z); //save current matrix off to the side tempSave = currentTransform[curGroupLevel]; //set current matrix to identity (loadIdentityTransoform b/c // we can't send in our current matrix) loadIdentityTransform(¤tTransform[curGroupLevel]); //apply passed in move to identity. so that it's first (reversing //order) applyTransform(translateTransform(x,y,z),¤tTransform[curGroupLevel]); //now put save matrix on to transform passed in. (reversing order) applyTransform( tempSave, ¤tTransform[curGroupLevel]); } else if (!strcmp(cmd, "scale")) { //printf("Scale\n"); fscanf(SceneFile, "%lf", &x); fscanf(SceneFile, "%lf", &y); fscanf(SceneFile, "%lf", &z); //save current matrix off to the side tempSave = currentTransform [curGroupLevel]; //set current matrix to identity (loadIdentTransform b/c we can't send in //our current matrix) loadIdentityTransform(¤tTransform[curGroupLevel]); //apply passed in scale to identity. so that it's first (reversing //order) applyTransform( scaleTransform(x, y, z), ¤tTransform[curGroupLevel]); //now put save matrix on to transform passed in. (reversing order) applyTransform( tempSave, ¤tTransform[curGroupLevel]); } else if (!strcmp(cmd, "rotate")) { fscanf(SceneFile, "%lf", &angle); fscanf(SceneFile, "%lf", &x); fscanf(SceneFile, "%lf", &y); fscanf(SceneFile, "%lf", &z); //save current matrix off to the side tempSave = currentTransform[curGroupLevel]; //set current matrix to identity (loadIdentTransform b/c we can't send in //our current matrix) loadIdentityTransform(¤tTransform[curGroupLevel]); //apply passed in rotate to identity. so that it's first (reversing //order) applyTransform(rotateTransform(angle,x,y,z), ¤tTransform[curGroupLevel]); //now put save matrix on to transform passed in. (reversing order) applyTransform( tempSave, ¤tTransform[curGroupLevel]); } else { fprintf(stderr, "Error: Unknown cmd '%s' in description file\n", cmd); fprintf(stderr, "Line %d\n", line); exit(-1); } fscanf(SceneFile, "%s", cmd); //get next command line++; } fclose(SceneFile); //close the scene file }
EggImplosionParticle::EggImplosionParticle(SDLRenderObject * base, unsigned int divisions, float x, float y) { RenderComponent::RenderComponent(); //gameObjectRef->AddComponent(COMPONENT_RENDER, this); SceneManager* sceneMan = SceneManager::GetSceneManager(); RenderManager* renderMan = RenderManager::getRenderManager(); ResourceManager* ResMan = ResourceManager::GetResourceManager(); objRef = sceneMan->InstantiateObject(sceneMan->findLayer("layer2"), -1, x, y, base->getPosZ()); objRef->toggleVisible(); //baseImage = base->renderResource; //RenderResource * baseImage = (RenderResource*)ResMan->findResourcebyID(74); //SDL_Rect baseRect = objRef->getRenderRect(); //unsigned int scale = 2; //float size = baseRect.w / scale; float centerX = base->getPosX(); float centerY = base->getPosY(); //for (int x = 1; x < float(divisions+1)*2.0; x+=2){ // for (int y = 1; y < float(divisions+1)*2.0; y+=2){ for (unsigned x = 0; x <= divisions; x++){ for (unsigned y = 0; y <= divisions; y++){ SDLRenderObject * sprite = sceneMan->InstantiateObject(sceneMan->findLayer("layer2"), 74, centerX, centerY); sprite->setScale(2); float yStart = (float)sprite->getWidth() *((x*2+1) / (float(divisions + 1)*2.0f) - sprite->getAnchorX()); float xStart = (float)sprite->getHeight() *((y*2+1) / (float(divisions + 1)*2.0f) - sprite->getAnchorY()); sprite->flipV = true; sprite->setPos(centerX, centerY); //play->setResourceObject(renderMan->renderText("Timer", 255, 0, 255, 50, "BowlbyOneSC-Regular")); sprite->setResourceObject(baseImage); SDL_Rect baseRect = sprite->getRenderRect(); /*int xPos = (baseRect.w - int(baseRect.w / (divisions + 1.0)) > 0) ? rand() % (baseRect.w - int(baseRect.w / (divisions + 1.0))) : 0; int yPos = (baseRect.h - int(baseRect.h / (divisions + 1.0)) > 0) ? rand() % (baseRect.h - int(baseRect.h / (divisions + 1.0))) : 0;*/ int xPos = x * int(baseRect.h / (divisions + 1.0)); int yPos = y * int(baseRect.h / (divisions + 1.0)); SDL_Rect rect = { xPos, yPos, (int)round(baseRect.w / (divisions + 1.0)), (int)round(baseRect.h / (divisions + 1.0)) }; //sprite->setScaleX(base->getScaleX()); sprite->setRenderRect(rect); float u = (float)((rand() % 360) / 360.0f); float v = (float)((rand() % 360) / 360.0f); float angle1 = 3.14f * 2.0f * u; float angle2 = acos(2 * v - 1); std::list<motion> movements; movements.push_back(makeMotion(moveLinearXY(sprite, centerX + sin(angle1)*cos(angle2) * 300, centerY + sin(angle1)* sin(angle2) * 300, xStart + centerX, yStart+ centerY), 0, 1, ease_QuadOut)); movements.push_back(makeMotion(moveLinearZ(sprite, cos(angle1) * 10, 0), 0, 1, ease_QuadOut)); float spinAngle = (float)(rand() % 360); //movements.push_back(makeMotion(rotateTransform(sprite, rand() % 360, (rand() % 90) - 45), 0, 1)); movements.push_back(makeMotion(rotateTransform(sprite, spinAngle, -spinAngle+90), 0, 1,ease_QuadOut)); Animation * movement = new Animation(1000, movements); //int maxtime = 100000; //in seconds //std:list<motion> motions; particle p; p.animations = movement; p.sprite = sprite; p.timer = 0; particles.push_back(p); } } }