AS3_Val initializeAnimation( void* self, AS3_Val args ) { Animation* a; Entity* parent; int isPlay, loop; int maxTime, minTime; AS3_ArrayValue(args, "PtrType, IntType, IntType, IntType, IntType", &parent, &isPlay, &loop, &maxTime, &minTime); a = newAnimation(isPlay, loop, maxTime, minTime); parent->animation = a; return AS3_Array("PtrType, PtrType, PtrType, PtrType, PtrType, PtrType, PtrType, PtrType", a, &a->isPlay, &a->loop, &a->minTime, &a->maxTime, &a->durationTime, &a->time, &a->timeMode); }
void SpriteSheetAnimator::AddAnimation(std::string animation, int argCount, ... ) { std::vector<int> frameList; va_list vars; int itr; va_start(vars,argCount); for ( itr = 0; itr < argCount; itr++) { int arg = va_arg(vars,int); frameList.push_back( arg ); } va_end(vars); std::pair< std::string,std::vector<int> > newAnimation(animation,frameList); this->animationLists.insert(newAnimation); std::vector<int>::iterator fitr; }
void AnimationEditor::newAnimation() { animation_ = new Animation(const_cast<ProcessorNetwork*>(evaluator_->getProcessorNetwork())); workspace_->setAnimation(animation_); animation_->setDuration(20); emit newAnimation(animation_); }
void plInit(Player* P, World *W) { P->ULPos = vec2(-20.f, -70.f); P->URPos = vec2(20.f, -70.f); P->DLPos = vec2(-35.f, 70.f); P->DRPos = vec2(35.f, 70.f); strcpy(P->SndFoot[0], "snd_step1"); strcpy(P->SndFoot[1], "snd_step2"); P->timer.restart(); P->VxUL = newVertex(); vxSetPosition(P->VxUL, P->ULPos); P->VxUR = newVertex(); vxSetPosition(P->VxUR, P->URPos); P->VxDR = newVertex(); vxSetPosition(P->VxDR, P->DRPos); P->VxDL = newVertex(); vxSetPosition(P->VxDL, P->DLPos); vxSetMass(P->VxUL, 0.01f); vxSetMass(P->VxUR, 0.01f); vxSetMass(P->VxDL, 1.5f); vxSetMass(P->VxDR, 1.5f); P->Shape = polyRectangle(P->VxUL, P->VxUR, P->VxDR, P->VxDL); wdAddVxFromPoly(W, P->Shape); P->GroundAngle = M_PI_2; P->Dir = DIR_RIGHT; animAnglesStatesInit(&P->Angles); animPositionsStatesInit(&P->Positions); P->aniRun = newAnimation(ANIM_ANGLES, ANIM_ALL_TRIGGERS, TRUE); aniLoadFromFile(P->aniRun, (ResourcePath()+"data/anims/animRun.ani").c_str()); //aniSetForce(P->aniRun, 0.65f); P->aniJump = newAnimation(ANIM_ANGLES, ANIM_ALL_TRIGGERS, TRUE); aniLoadFromFile(P->aniJump, (ResourcePath()+"data/anims/animJump.ani").c_str()); aniSetForce(P->aniJump, 0.65f); P->aniFall = newAnimation(ANIM_ANGLES, ANIM_ALL_TRIGGERS, TRUE); aniLoadFromFile(P->aniFall, (ResourcePath()+"data/anims/animFall.ani").c_str()); P->aniHello = newAnimation(ANIM_ANGLES, ANIM_ALL_TRIGGERS, TRUE); aniLoadFromFile(P->aniHello, (ResourcePath()+"data/anims/animHello.ani").c_str()); P->aniStand = newAnimation(ANIM_ANGLES, ANIM_ALL_TRIGGERS, TRUE); aniLoadFromFile(P->aniStand, (ResourcePath()+"data/anims/animStand.ani").c_str()); unsigned int i=0; for (i=0; i<polyGetVxCount(P->Shape); i++) vxSetFixed(polyGetVertex(P->Shape, i), FALSE); P->GrabR = NULL; P->GrabL = NULL; P->VxULStatus = P->VxURStatus = P->VxDRStatus = P->VxDLStatus = P->RdUStatus = P->RdRStatus = P->RdDStatus = P->RdLStatus = nullCollisionInfo(); P->State = PL_NOSTATE; plResetJump(P); /* On crée les vertices du personnage, pour l'animation et quand il meurt */ for (int i=0; i<12; i++) P->vxBodyParts[i] = newVertex(); vxSetPosition(P->vxBodyParts[bpBase], vec2(0.f, 100.f)); Vec2 B = vxGetPosition(P->vxBodyParts[bpBase]); vxSetPosition(P->vxBodyParts[bpNeck], vec2(B.x, B.y - 60.f)); vxSetPosition(P->vxBodyParts[bpHeadLeft], vec2Add(vxGetPosition(P->vxBodyParts[bpNeck]), vec2(-20.f, -20.f))); vxSetPosition(P->vxBodyParts[bpHeadRight], vec2Add(vxGetPosition(P->vxBodyParts[bpNeck]), vec2(20.f, -20.f))); vxSetPosition(P->vxBodyParts[bpLeftArm1], vec2Add(vxGetPosition(P->vxBodyParts[bpNeck]), vec2(0.f, 25.f))); vxSetPosition(P->vxBodyParts[bpLeftArm2], vec2Add(vxGetPosition(P->vxBodyParts[bpNeck]), vec2(0.f, 50.f))); vxSetPosition(P->vxBodyParts[bpRightArm1], vec2Add(vxGetPosition(P->vxBodyParts[bpNeck]), vec2(0.f, 25.f))); vxSetPosition(P->vxBodyParts[bpRightArm2], vec2Add(vxGetPosition(P->vxBodyParts[bpNeck]), vec2(0.f, 50.f))); vxSetPosition(P->vxBodyParts[bpLeftLeg1], vec2Add(vxGetPosition(P->vxBodyParts[bpBase]), vec2(0.f, 30.f))); vxSetPosition(P->vxBodyParts[bpLeftLeg2], vec2Add(vxGetPosition(P->vxBodyParts[bpBase]), vec2(0.f, 60.f))); vxSetPosition(P->vxBodyParts[bpRightLeg1], vec2Add(vxGetPosition(P->vxBodyParts[bpBase]), vec2(0.f, 30.f))); vxSetPosition(P->vxBodyParts[bpRightLeg2], vec2Add(vxGetPosition(P->vxBodyParts[bpBase]), vec2(0.f, 60.f))); for (int i=0; i<12; i++) { switch (i) { case bpNeck: case bpLeftLeg1: case bpRightLeg1: P->BodyRigids[i] = newRigid(P->vxBodyParts[i], P->vxBodyParts[bpBase], -1.f); break; case bpLeftArm1: case bpRightArm1: case bpHeadLeft: case bpHeadRight: P->BodyRigids[i] = newRigid(P->vxBodyParts[i], P->vxBodyParts[bpNeck], -1.f); break; case bpLeftArm2: case bpRightArm2: case bpLeftLeg2: case bpRightLeg2: P->BodyRigids[i] = newRigid(P->vxBodyParts[i], P->vxBodyParts[i-1], -1.f); break; case bpBase: P->BodyRigids[i] = newRigid(P->vxBodyParts[bpHeadLeft], P->vxBodyParts[bpHeadRight], -1.f); break; default: break; } } P->CurrentAnim = P->aniStand; aniUpdateForCurrentState(P->CurrentAnim, P); aniUpdate(P->CurrentAnim, P, 1.f); }
void Apsis::Sprite::Thing::_parseJSONFile() { _openJSONFile(); if (_value.isMember("name")) { _name = _value["name"].asCString(); } else { // Get name from path size_t start = _path.find_last_of('/'); if (start == std::string::npos) { start = 0; } else { start ++; } size_t end = _path.find_last_of('.'); if (end == std::string::npos) { _name = _path.substr(start); } else { _name = _path.substr(start, end-start); } } if (_value.isMember("width")) { _object.set("width", _value["width"].asDouble()); } if (_value.isMember("height")) { _object.set("height", _value["height"].asDouble()); } // Animation if (_value.isMember("animations")) { // TODO: better handling of invalid values for (Json::Value::iterator it = _value["animations"].begin(); it != _value["animations"].end(); ++it) { // Create an animation structure Sprite::Animation newAnimation((*it)["name"].asCString()); // Store all of the sprites int spriteIndex = -1; do { spriteIndex = _sheet.enumerateSprites((*it)["sprites"].asCString(), spriteIndex+1); if (spriteIndex != -1) { newAnimation.addFrame(spriteIndex); } } while(spriteIndex != -1); _animations.push_back(newAnimation); } } // Events (collision) if (_value.isMember("on_collides")) { // TODO: better handling of invalid values for (Json::Value::iterator it = _value["on_collides"].begin(); it != _value["on_collides"].end(); ++it) { std::string event_name = "collide_with_"; std::string rule_name = ""; unsigned int event_id = 0; // get collision event name if (!(*it).isObject()) { throw "Thing description's 'on_collides' array does not contain objects."; } if ((*it).isMember("with")) { if (!(*it)["with"].isObject()) { throw "Thing description's 'on_collide' has a member where 'with' is not an object."; } if ((*it)["with"].isMember("type") && (*it)["with"].isMember("name")) { event_name = event_name.append((*it)["with"]["type"].asCString()); event_name = event_name.append("_"); event_name = event_name.append((*it)["with"]["name"].asCString()); event_id = Apsis::Registry::Event::id(event_name.c_str()); // Tell the object we respond to this event _object.respondTo(event_id); } else { throw "Thing description's 'on_collide' members should have a 'with' object with 'type' and 'name fields."; } } else { throw "Thing description's 'on_collide' has a member without a 'with' object."; } if ((*it).isMember("do")) { if (!(*it)["do"].isString()) { throw "Thing description's 'on_collide' has a member where the 'do' field is not a string."; } rule_name = (*it)["do"].asCString(); std::string rule_path = "assets/rules/" + std::string(rule_name) + ".json"; _rules.addRule(Registry::Rule::load(rule_path.c_str())); } else { throw "Thing description's 'on_collide' has a member without a 'do' object."; } if ((*it).isMember("properties")) { if (!(*it)["properties"].isObject()) { throw "Thing description's 'on_collide' has a member where 'properties' is not an object."; } Json::Value::Members members = (*it)["properties"].getMemberNames(); for (Json::Value::Members::iterator property_it = members.begin(); property_it != members.end(); ++property_it) { const char* name = (*property_it).c_str(); unsigned int property_id = Apsis::Registry::Property::id(name); if ((*it)["properties"][name].isDouble()) { _object.setForEvent(event_id, property_id, (*it)["properties"][name].asDouble()); } else if ((*it)["properties"][name].isString()) { _object.setForEvent(event_id, property_id, (*it)["properties"][name].asCString()); } else if ((*it)["properties"][name].isIntegral()) { _object.setForEvent(event_id, property_id, (long)(*it)["properties"][name].asInt()); } } } } } // Rules if (_value.isMember("rules")) { // TODO: better handling of invalid values for (Json::Value::iterator it = _value["rules"].begin(); it != _value["rules"].end(); ++it) { std::string rule_path; if ((*it).isObject()) { rule_path = (*it)["name"].asCString(); } else if ((*it).isString()) { rule_path = (*it).asCString(); } rule_path = "assets/rules/" + rule_path + ".json"; _rules.addRule(Registry::Rule::load(rule_path.c_str())); } } // Properties if (_value.isMember("properties") && _value["properties"].isObject()) { // TODO: better handling of invalid values Json::Value::Members members = _value["properties"].getMemberNames(); for (Json::Value::Members::iterator it = members.begin(); it != members.end(); ++it) { const char* name = (*it).c_str(); unsigned int property_id = Apsis::Registry::Property::id(name); if (_value["properties"][name].isDouble()) { _object.set(property_id, _value["properties"][name].asDouble()); } else if (_value["properties"][name].isString()) { _object.set(property_id, _value["properties"][name].asCString()); } else if (_value["properties"][name].isIntegral()) { _object.set(property_id, (long)_value["properties"][name].asInt()); } } } }