void ItemTortoise::move(float dt) { if (isFarAwayFromMario()) { removeFromParent(); return; } if (_status == SLEEP || _status ==DEAD || !isLeftInWindow()) { return ; } // 根据方向,再具体确定 if (_dir == Common::LEFT) { if (canMoveLeft(dt)) { moveLeft(dt); } else { _dir = Common::RIGHT; if (_status == NORMAL) { stopAllActions(); runAnimation("TortoiseMoveLeft"); } } } else { if (canMoveRight(dt)) { moveRight(dt); } else { _dir = Common::LEFT; if (_status == NORMAL) { stopAllActions(); runAnimation("TortoiseMoveRight"); } } } if (canMoveDown(dt)) { moveDown(dt); } else { _speedDown = 10; } }
void ItemBoss::updateStatus() { if (_dir == Common::LEFT) { runAnimation("BossWalkLeft"); } else if (_dir == Common::RIGHT) { runAnimation("BossWalkRight"); } }
void ItemTortoise::revive(float dt) { _status = NORMAL; _speed = 50; stopAllActions(); if (_dir == Common::LEFT) { runAnimation("TortoiseMoveLeft"); } else { runAnimation("TortoiseMoveRight"); } }
bool Chicken::initWithLayer( HelloWorld * layer ) { if (initWithSpriteFrameName("chicken_001.png")) { _layer = layer; auto animation = Animation::create(); for (int i = 1; i <= 40; i++) { auto str = String::createWithFormat("chicken_%03d.png",i); auto frame = SpriteFrameCache::getInstance()->getSpriteFrameByName(str->getCString()); animation->addSpriteFrame(frame); } animation->setDelayPerUnit(1.0f / 1000 * 90); setNormalAnimation(animation); animation = Animation::create(); for (int i = 1; i <= 12; i++) { auto str = String::createWithFormat("ccchick_%03d.png",i); auto frame = SpriteFrameCache::getInstance()->getSpriteFrameByName(str->getCString()); animation->addSpriteFrame(frame); } animation->setDelayPerUnit(1.0f / 1000 * 40); setTrapAnimation(animation); layer->addChild(this); runAnimation(getNormalAnimation()); return true; } return false; }
bool ItemTortoise::marioUpHit(CCRect rcMario, CCRect rcItem, bool coll) { if (_mario->_status == Mario::FLY && _mario->_speedUp <= 0 && coll) { stopAllActions(); setGodMode(0.5f); runAnimation("TortoiseDead"); _speed = 0; //! mario 小跳 _mario->_speedUp = 150; _mario->_speedDown = 10; _mario->_status = Mario::FLY; _mario->updateStatus(); // 微调位置 if (_mario->getPositionX() < getPositionX()) { Common::moveNode(this, ccp(5, 0)); } else { Common::moveNode(this, ccp(-5, 0)); } return true; } return false; }
void LoadingLayer::onEnterTransitionDidFinish(){ // KKAds ads; // ads.setAdsVisibility(false); LayerColor::onEnterTransitionDidFinish(); runAnimation(); scheduleOnce(schedule_selector(LoadingLayer::updateToMainScene), 2.5f); }
void Chicken::setTrap() { if (!_isTrap) { _isTrap = true; runAnimation(getTrapAnimation()); } }
bool BlockSprite::onTouchBegan(Touch* touch, Event* event) { if(containsTouchLocation(touch)) { runAnimation(3); log("inside"); }else{ //log("outside"); } return true; }
bool ItemTortoise::init(CCDictionary* dict) { Item::init(); _type = Item::IT_tortoise; setPositionByProperty(dict); _dir = Common::LEFT; _speed = 50; _speedAcc = _speedDown = 10; _status = NORMAL; runAnimation("TortoiseMoveLeft"); return true; }
int main(int argc, char *argv[]) { Init(); Animal *animal = new Animal("animal.bmp", 200, 200); bool quit = false; while (!quit) { while (SDL_PollEvent(&event) != 0) { if (event.type == SDL_QUIT) { quit = true; } } loadMedia(); //SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255); //SDL_RenderClear(renderer); //////////////////////////////////// //animal->Render(); runAnimation(); /////////////////////////////////// //SDL_RenderPresent(renderer); //SDL_Delay(100); } Close(); return 0; }
void STGCharacter::runAction(STGCharacter::ActionState state) { runAnimation(_actionMap[state]); _lastActionState = _currentActionState; _currentActionState = state; }
void LuaProxy::runAnimation(int id, double x, double y, int extraData) { runAnimation(id, x, y, 0.0, 0.0, extraData); }
void LuaProxy::runAnimation(int id, double x, double y, double height, double width, int extraData) { runAnimation(id, x, y, height, width, 0.0, 0.0, extraData); }
void ItemTortoiseFly::updateStatus() { if (_status == NORMAL) { stopAllActions(); if (_dir == Common::LEFT) { runAnimation("TortoiseFlyLeft"); } else { runAnimation("TortoiseFlyRight"); } } else if (_status == DROPPING) { stopAllActions(); // 设置它下降的速度 _speedDown = _mario->_speedDown + 10; _mario->_speedDown = 10; if (_dir == Common::LEFT) { runAnimation("TortoiseMoveLeft"); } else { runAnimation("TortoiseMoveRight"); } } else if (_status == ONLAND) { // ..... } else if (_status == SLEEP) { stopAllActions(); runAnimation("TortoiseDead"); scheduleOnce(schedule_selector(ItemTortoiseFly::Recover), 10); setGodMode(0.2f); // 微调位置 if (_mario->getPositionX() < getPositionX()) { setPositionX(_mario->getPositionX() + _mario->boundingBox().size.width + 1); } else { setPositionX(_mario->getPositionX() - boundingBox().size.width - 1); } } else if (_status == CRAZY) { unschedule(schedule_selector(ItemTortoiseFly::Recover)); _speed = 200; _speedDown = _speedAcc = 10; } }
bool Obstacle::init(Obstacle::Type type) { if (!Node::init()) { return false; } this->setTag(OBSTACLE_TAG); bool isHorizontal = false; // type to params std::string fileName; switch (type) { case Type::BANANA: fileName = "banana.png"; break; case Type::BIRD: fileName = "bird_01.png"; isHorizontal = true; break; case Type::METER: fileName = "meteor_01.png"; break; case Type::UFO: fileName = "ufo_01.png"; isHorizontal = true; break; case Type::Role1: fileName = "b0010.png"; break; case Type::Role2: fileName = "b0011.png"; isHorizontal = true; break; case Type::Role3: fileName = "b0023.png"; break; case Type::Role4: fileName = "b0059.png"; isHorizontal = true; break; case Type::Role5: fileName = "b0061.png"; break; default: break; } fileName = StringUtils::format("obstacles/%s", fileName.c_str()); _sprite = Sprite::create(fileName); this->addChild(_sprite); runAnimation(); // collider Size colliderSize = _sprite->getContentSize() * 0.6f; auto physicsBody = PhysicsBody::createBox(colliderSize); physicsBody->setCategoryBitmask(OBSTACLE_BITMASK); physicsBody->setCollisionBitmask(FLYPLANT_BITMASK); physicsBody->setContactTestBitmask(FLYPLANT_BITMASK); physicsBody->setDynamic(true); physicsBody->setMass(10); this->setPhysicsBody(physicsBody); // random Size visibleSize = Director::getInstance()->getVisibleSize(); Point visibleOrigin = Director::getInstance()->getVisibleOrigin(); std::random_device randomDevice; std::mt19937 generator(randomDevice()); std::uniform_int_distribution<> distibution1(0, visibleSize.width); std::uniform_int_distribution<> distibution2(visibleSize.height/3.0f, visibleSize.height * 2.0f/3.0f); float width = distibution1(generator); float height = distibution2(generator); bool isLeft = true; std::uniform_int_distribution<> distibution3(0, 1); if (distibution3(generator) > 0) { isLeft = false; } if (!isHorizontal) { this->setPosition(visibleOrigin + Vec2(width, visibleSize.height)); physicsBody->setVelocity(Vect(0, -OBSTACLE_VELOCITY)); } else { if (isLeft) { this->setPosition(visibleOrigin + Vec2(0, height)); physicsBody->setVelocity(Vect(OBSTACLE_VELOCITY, -20)); } else { this->setPosition(visibleOrigin + Vec2(visibleSize.width, height)); physicsBody->setVelocity(Vect(-OBSTACLE_VELOCITY, -20)); } } return true; }