void CritterObject::think() { if (movementQueue()->size() > 0) { if (!_moving) { _moving = true; delete _ui; _orientation = hexagon()->orientationTo(movementQueue()->back()); auto animation = _generateMovementAnimation(); animation->setActionFrame(_running ? 2 : 4); animation->addEventHandler("actionFrame", std::bind(&CritterObject::onMovementAnimationEnded, this, std::placeholders::_1)); animation->addEventHandler("animationEnded", std::bind(&CritterObject::onMovementAnimationEnded, this, std::placeholders::_1)); animation->play(); _ui = animation; } } else { auto anim = (UI::Animation*)ui(); if (!_moving && (!anim || !anim->playing())) { if (SDL_GetTicks() > _nextIdleAnim) { setActionAnimation("aa"); _setupNextIdleAnim(); } } } Object::think(); }
// TODO: handle ANIMATE_INTERRUPT void Opcode80CE::_run() { Logger::debug("SCRIPT") << "[80CE] [=] void animate_move_obj_to_tile(void* who, int tile, int speed)" << std::endl; int speed = _script->dataStack()->popInteger(); int tile = _script->dataStack()->popInteger(); auto object = _script->dataStack()->popObject(); // ANIMATE_WALK (0) // ANIMATE_RUN (1) // ANIMATE_INTERRUPT (16) - flag to interrupt current animation auto critter = dynamic_cast<Game::CritterObject*>(object); auto state = Game::Game::getInstance()->locationState(); if (state) { auto tileObj = state->hexagonGrid()->at(tile); auto path = state->hexagonGrid()->findPath(object->hexagon(), tileObj); if (path.size()) { critter->stopMovement(); critter->setRunning((speed & 1) != 0); auto queue = critter->movementQueue(); for (auto pathHexagon : path) { queue->push_back(pathHexagon); } } } }
void Opcode8116::_run() { Logger::debug("SCRIPT") << "[8116] [+] void add_mult_objs_to_inven(GameObject* who, GameItemObject* item, int amount)" << std::endl; auto amount = _script->dataStack()->popInteger(); auto item = dynamic_cast<Game::ItemObject *>(_script->dataStack()->popObject()); auto invenObj = _script->dataStack()->popObject(); if (!item) { _error("add_mult_objs_to_inven - item not instanceof GameItemObject"); return; } item->setAmount(amount); // who can be critter or container std::vector<Game::ItemObject *> *inven; if (auto critterObj = dynamic_cast<Game::CritterObject *>(invenObj)) { inven = critterObj->inventory(); } else if (auto contObj = dynamic_cast<Game::ContainerItemObject *>(invenObj)) { inven = contObj->inventory(); } else { _error("add_mult_objs_to_inven - wrong WHO parameter"); return; } inven->push_back(item); if (item->hexagon()) { auto location = Game::Game::getInstance()->locationState(); if (location) { location->removeObjectFromMap(item); } } }
Hex::Hex(QGraphicsItem *parent){ // draw the polygon // points needed to draw hexagon: (1,0), (2,0), (3,1), (2,2), (1,2), (0,1) QVector<QPointF> hexPoints; hexPoints << QPointF(1,0) << QPointF(2,0) << QPointF(3,1) << QPointF(2,2) << QPointF(1,2) << QPointF(0,1); // scale the points int SCALE_BY = 40; for (size_t i = 0, n = hexPoints.size(); i < n; ++i){ hexPoints[i] = hexPoints[i] * SCALE_BY; } // create a polygon with the scaled points QPolygonF hexagon(hexPoints); // draw the poly setPolygon(hexagon); // initialize isPlaced = false; // initialize side attacks to 0 side0Attack = 0; side1Attack = 0; side2Attack = 0; side3Attack = 0; side4Attack = 0; side5Attack = 0; // create QGraphicsTextItems to represent visually each side's attack QGraphicsTextItem* text0 = new QGraphicsTextItem(QString::number(0),this); QGraphicsTextItem* text1 = new QGraphicsTextItem(QString::number(0),this); QGraphicsTextItem* text2 = new QGraphicsTextItem(QString::number(0),this); QGraphicsTextItem* text3 = new QGraphicsTextItem(QString::number(0),this); QGraphicsTextItem* text4 = new QGraphicsTextItem(QString::number(0),this); QGraphicsTextItem* text5 = new QGraphicsTextItem(QString::number(0),this); attackTexts.append(text0); attackTexts.append(text1); attackTexts.append(text2); attackTexts.append(text3); attackTexts.append(text4); attackTexts.append(text5); // set the correct position of the attack texts text0->setPos(50,0); text1->setPos(20,15); text2->setPos(20,40); text3->setPos(50,55); text4->setPos(80,40); text5->setPos(80,15); // make all attack texts invisible for (size_t i = 0, n = attackTexts.size(); i < n; i++){ attackTexts[i]->setVisible(false); } }
BWCNC::Part * BWCNC::HexGrid::make_inner_hexagon( BWCNC::PartContext & k, double inner_fraction, int nth_inner, const Eigen::Vector3d & start ) { Eigen::Vector3d pos(0,0,0); double nested_sidelen = 0; nested_params( inner_fraction, nth_inner, start, pos, nested_sidelen ); return hexagon( k, nested_sidelen, pos, nullptr, true ); }
void collageHexagon(int n, int m, float r, float v) { for(int i = 0; i < n; i++) { pushCT(); for(int j=0; j <ceil((float) m/2); j++) { hexagon(r); translate2D(3*r,0); } popCT(); if(i%2==0) translate2D(3*r/2,v); else translate2D(-3*r/2,v); } }
void Opcode80A9::_run() { Logger::debug("SCRIPT") << "[80A9] [+] void override_map_start(int x, int y, int elevation, int orientation)" << std::endl; auto orientation = _script->dataStack()->popInteger(); auto elevation = _script->dataStack()->popInteger(); auto y = _script->dataStack()->popInteger(); auto x = _script->dataStack()->popInteger(); auto position = y*200 + x; auto game = Game::Game::getInstance(); auto player = game->player(); auto hexagon = game->locationState()->hexagonGrid()->at(position); Game::getInstance()->locationState()->moveObjectToHexagon(player, hexagon); //player->setPosition(position); player->setOrientation(orientation); player->setElevation(elevation); Game::Game::getInstance()->locationState()->centerCameraAtHexagon(player->hexagon()); }
void GameCritterObject::think() { if (movementQueue()->size() > 0) { if (!_moving) { _moving = true; delete _ui; _orientation = hexagon()->orientationTo(movementQueue()->back()); auto animation = _generateMovementAnimation(); animation->setActionFrame(_running ? 2 : 4); animation->addEventHandler("actionFrame", std::bind(&GameCritterObject::onMovementAnimationEnded, this, std::placeholders::_1)); animation->addEventHandler("animationEnded", std::bind(&GameCritterObject::onMovementAnimationEnded, this, std::placeholders::_1)); animation->play(); _ui = animation; } } GameObject::think(); }
int tank(int selection) { float vol; if (selection == 1) { vol = cube(); } else if (selection ==2) { vol = sphere(); } else if (selection == 3) { vol = hexagon(); } else { printf("Please enter a valid integer."); } return(vol); }
void Opcode80D8::_run() { Logger::debug("SCRIPT") << "[80D8] [=] void add_obj_to_inven(void* who, void* item)" << std::endl; auto item = dynamic_cast<Game::ItemObject*>(_script->dataStack()->popObject()); auto invenObj = _script->dataStack()->popObject(); if (!item) { _error("add_obj_to_inven - item not instanceof GameItemObject"); return; } std::vector<Game::ItemObject*>* inven; if (auto critterObj = dynamic_cast<Game::CritterObject*>(invenObj)) { inven = critterObj->inventory(); } else if (auto contObj = dynamic_cast<Game::ContainerItemObject*>(invenObj)) { inven = contObj->inventory(); } else { _error("add_obj_to_inven - wrong WHO parameter"); return; } inven->push_back(item); if (item->hexagon()) { auto location = Game::Game::getInstance()->locationState(); if (location) { location->moveObjectToHexagon(item, nullptr); } } }
void Shapes::hexagon(Vertex vertices[], int start, Vector2f position, float radius, bool flatTopped) { hexagon(vertices, start, position, radius, Color(255, 255, 255), flatTopped); }
void BWCNC::HexGrid::fill_partctx_with_grid( BWCNC::PartContext & k ) { const uint8_t skip0[] = {1,0,0,0,0,0}; //const uint8_t skip01[] = {1,1,0,0,0,0}; const uint8_t skip05[] = {1,0,0,0,0,1}; const uint8_t skip015[] = {1,1,0,0,0,1}; const uint8_t skip1[] = {0,1,0,0,0,0}; //const uint8_t skip2[] = {0,0,1,0,0,0}; // debugging only const uint8_t skip5[] = {0,0,0,0,0,1}; //############################################################################################################### //#### Row #1 //############################################################################################################### double x_ref = 0, y_ref = m_sidelen/2.0; Eigen::Vector3d start( x_ref, y_ref, 0); for( int i = m_nested; i > 0; i-- ) k.add_part( make_inner_hexagon( k, m_nested_spacing, i, start ) ); if( m_includegrid ) k.add_part( hexagon( k, m_sidelen, start ) ); for( int j = 1; j < m_cols; j++ ) { start = Eigen::Vector3d( j * sqrt(3) * m_sidelen, y_ref, 0); for( int i = m_nested; i > 0; i-- ) k.add_part( make_inner_hexagon( k, m_nested_spacing, i, start ) ); if( m_includegrid ) k.add_part( hexagon( k, m_sidelen, start, skip5 ) ); } //############################################################################################################### //#### End of Row #1 //############################################################################################################### //############################################################################################################### //#### remaining rows //############################################################################################################### double xoffset; for( int row = 2; row <= m_rows; row++ ) { bool row_iseven = (row % 2 == 0); x_ref = row_iseven ? (sqrt(3) * m_sidelen / 2.0) : 0.0; xoffset = row_iseven ? 0.5 : 0.0; y_ref += 1.5 * m_sidelen; start = Eigen::Vector3d( x_ref, y_ref, 0); for( int i = m_nested; i > 0; i-- ) k.add_part( make_inner_hexagon( k, m_nested_spacing, i, start ) ); if( m_includegrid ) { if( row_iseven ) k.add_part( hexagon( k, m_sidelen, start, skip0 ) ); else k.add_part( hexagon( k, m_sidelen, start, skip1 ) ); } for( int j = 1; j < m_cols; j++ ) { x_ref = (j + xoffset) * sqrt(3) * m_sidelen; start = Eigen::Vector3d( x_ref, y_ref, 0); for( int i = m_nested; i > 0; i-- ) k.add_part( make_inner_hexagon( k, m_nested_spacing, i, start ) ); if( m_includegrid ) { Part * p = nullptr; if( row_iseven ) { if( j < m_cols - 1 ) p = hexagon( k, m_sidelen, start, skip015 ); else p = hexagon( k, m_sidelen, start, skip05 ); } else { if( j == 1 ) p = hexagon( k, m_sidelen, start, skip1 ); else p = hexagon( k, m_sidelen, start, skip015 ); } if( p != nullptr ) { //std::cerr << "context: " << k.get_bbox(); //std::cerr << " -- adding new: " << p->get_bbox(); k.add_part( p ); //std::cerr << " -- results in context: " << k.get_bbox() << "\n"; } //else std::cerr << "no hexagon part was made\n"; } } } //############################################################################################################### //#### end of remaining rows //############################################################################################################### }