Explode::Explode(Entity::GameObject* _p) : Component::abstract(_p), untilBOOM(-1), exploding(false) { attachCallback(Event::Info::Clock, new Event::FixedCallback([this, _p] (Event::Data&) { if (!untilBOOM) { std::cout << "here is....." << std::endl; delete _p; std::cout << "..... the segfault?" << std::endl; return ; } if (untilBOOM > 0) untilBOOM -= 1; if (!untilBOOM) { EXPLODE(_p); } })); attachCallback(Event::Info::Explosion, new Event::FixedCallback([this, _p] (Event::Data& e) { Event::Type::Explosion* event = reinterpret_cast<Event::Type::Explosion*>(&e); double x; double y; if (exploding) return ; _p->getPosition(x, y); if (Component::matchPosition(event->x, event->y, x, y)) { EXPLODE(_p); exploding = true; untilBOOM = 0; } })); }
/* Vector */ Phisix::Vector::Vector(Entity::GameObject* _p, Component::Phisix* _c) : Component::abstract(_p), phisix(_c), speed(1.f) { direction = {false, false, false, false}; speedAxe[0] = 0.f; speedAxe[1] = 0.f; attachCallback(Event::Info::Clock, new Event::FixedCallback([this](Event::Data&) { double _speed = speed * phisix->getFriction(); double axeX = (-direction[Right] * _speed + direction[Left] * _speed) * speedAxe[1]; double axeY = (-direction[Down] * _speed + direction[Up] * _speed) * speedAxe[0]; parent->getPosition(x, y); auto _x = x; auto _y = y; auto _hitbox = parent->getHitBox(); if (axeX == 0.f && axeY == 0.f) return ; if (axeX != 0.f && axeY != 0.f) { axeX /= 2; axeY /= 2; } dispatchSelf(new Event::Type::RequireMovement(x, y, axeX, axeY)); })); attachCallback(Event::Info::Colliding, new Event::FixedCallback([this, _p](Event::Data& e) { Event::Type::Colliding *event = reinterpret_cast<Event::Type::Colliding*>(&e); x = event->endX; y = event->endY; _p->setPosition(x, y); })); attachCallback(Event::Info::selfMovement, new Event::FixedCallback([this](Event::Data& e){ Event::Type::selfMovement *event = reinterpret_cast<Event::Type::selfMovement*>(&e); direction[event->direction] = event->state; })); attachCallback(Event::Info::speedModifier, new Event::FixedCallback([this](Event::Data& e){ Event::Type::speedModifier *event = reinterpret_cast<Event::Type::speedModifier*>(&e); speed *= event->speed; })); attachCallback(Event::Info::speedAxeSetter, new Event::FixedCallback([this](Event::Data& e){ Event::Type::speedAxeSetter* event = reinterpret_cast<Event::Type::speedAxeSetter*>(&e); speedAxe[event->axe] = event->speed; })); }
int ModalComponentManager::runEventLoopForCurrentComponent() { // This can only be run from the message thread! jassert (MessageManager::getInstance()->isThisTheMessageThread()); Component* currentlyModal = getModalComponent (0); if (currentlyModal == nullptr) return 0; WeakReference<Component> prevFocused (Component::getCurrentlyFocusedComponent()); int returnValue = 0; bool finished = false; attachCallback (currentlyModal, new ReturnValueRetriever (returnValue, finished)); JUCE_TRY { while (! finished) { if (! MessageManager::getInstance()->runDispatchLoopUntil (20)) break; } } JUCE_CATCH_EXCEPTION if (prevFocused != nullptr) prevFocused->grabKeyboardFocus(); return returnValue; }
void APTouchManager::initWithNodeToAttatch() { for(int i=0;i<6;i++) { _touchToBeganNode.emplace(i, nullptr); _touchToNowNode.emplace(i, nullptr); } attachCallback(); }
void Explode::EXPLODE(Entity::GameObject* _p){ double x; double y; exploding = true; _p->getPosition(x, y); double spread = getSpread(elements[0]) + getSpread(elements[1]) + getSpread(elements[2]) - 1; if (spread - static_cast<int>(spread) != 0.f) spread -= 0.5f; attachCallback(Event::Info::Colliding, new Event::FixedCallback([this, x, y, spread] (Event::Data& e) { Event::Type::Colliding* _ = reinterpret_cast<Event::Type::Colliding*>(&e); if (_->endX > x) { std::cout <<"+x"<< _->endX - x<< std::endl; for (double dist = (_->endX - x < spread) ? (_->endX - x) : (spread); dist > 0.99; --dist) dispatch(x + dist, y); return ; } if (_->endX < x) { std::cout << "-x"<< _->endX-x<< std::endl; for (double dist = (x-_->endX < spread) ? (x-_->endX) : (spread) ; dist > 0.99; --dist) dispatch(x-dist, y); return ; } if (_->endY > y) { std::cout <<"+y"<< _->endY - y<< std::endl; for (double dist = (_->endY - y < spread) ? (_->endY - y) : (spread); dist > 0.99; --dist) dispatch(x, y + dist); return ; } if (_->endY < y) { std::cout <<"-y"<< _->endY-y<< std::endl; for (double dist = (y-_->endY < spread) ? (y-_->endY) : (spread) ; dist > 0.99; --dist) { std::cout << "dist:" << dist << std::endl; dispatch(x, y - dist); } return ; } })); std::cout << spread << "position (" << x<< ")(" << y << ")" << std::endl; dispatchSelf(new Event::Type::RequireExplosion(x,y, spread, 0)); dispatchSelf(new Event::Type::RequireExplosion(x,y, -spread, 0)); dispatchSelf(new Event::Type::RequireExplosion(x,y, 0, -spread)); dispatchSelf(new Event::Type::RequireExplosion(x,y, 0, spread)); dispatch(x, y); }
JoystickManager::joystick::joystick(Entity::GameObject* _p, SDL_Joystick* _k, int id) : Component::abstract(_p), _joystick(_k), _id(id) { joyState = { std::pair<int,bool>(1, 0), std::pair<int,bool>(0, 0), }; keyState = { std::pair<int,bool>(9, false), /* pose bomb || enter */ std::pair<int,bool>(11, false), /* elements */ std::pair<int,bool>(13, false), std::pair<int,bool>(15, false), std::pair<int,bool>(14, false), std::pair<int,bool>(12, false) }; attachCallback(Event::Info::Clock, new Event::FixedCallback([this](Event::Data&) { if (!_joystick) return ; int itt = 0; for (auto &axe : joyState) { double axis = SDL_JoystickGetAxis(_joystick, axe.first); int state = (!axis) ? (0) : (axis / axis); if (axis < 0) state = -state; axis = (axis < 0) ? (-axis) : (axis); dispatchSelf(new Event::Type::speedAxeSetter(axis / 32768, !(axe.first))); if (axe.second != state) { dispatchSelf(new Event::Type::Keyboard(!(axe.first) * 2 + 0, state < 0)); dispatchSelf(new Event::Type::Keyboard(!(axe.first) * 2 + 1, state > 0)); axe.second = state; } } for (auto &key : keyState) { if (SDL_JoystickGetButton(_joystick, key.first) != key.second) { dispatchSelf(new Event::Type::Keyboard(itt + 4, !key.second)); key.second = SDL_JoystickGetButton(_joystick, key.first); } ++itt; } })); }