| 70 | } |
| 71 | |
| 72 | bool PlayerObject::init(int playerFrame, Layer* gameLayer_) |
| 73 | { |
| 74 | // cap the icon limit |
| 75 | int frame = GameToolbox::inRange(playerFrame, 1, 13); |
| 76 | |
| 77 | auto sprStr1 = StringUtils::format("player_%02d_001.png", frame); |
| 78 | auto sprStr2 = StringUtils::format("player_%02d_2_001.png", frame); |
| 79 | GameToolbox::log("1: {}, 2: {}", sprStr1, sprStr2); |
| 80 | |
| 81 | gameLayer = gameLayer_; |
| 82 | |
| 83 | // Check if layer is playlayer |
| 84 | inPlayLayer = dynamic_cast<PlayLayer*>(gameLayer_) != nullptr; |
| 85 | |
| 86 | setTextureRect(Rect(0, 0, 30, 30)); // player hitbox lol |
| 87 | |
| 88 | m_pMainSprite = Sprite::createWithSpriteFrameName(sprStr1); |
| 89 | m_pMainSprite->setStretchEnabled(false); |
| 90 | addChild(m_pMainSprite, 1); |
| 91 | |
| 92 | m_pSecondarySprite = Sprite::createWithSpriteFrameName(sprStr2); |
| 93 | m_pSecondarySprite->setStretchEnabled(false); |
| 94 | m_pMainSprite->addChild(m_pSecondarySprite, -1); |
| 95 | m_pSecondarySprite->setPosition(m_pMainSprite->getContentSize() / 2.f); |
| 96 | |
| 97 | m_pShipSprite = Sprite::createWithSpriteFrameName("ship_01_001.png"); |
| 98 | m_pShipSprite->setStretchEnabled(false); |
| 99 | m_pShipSprite->setVisible(false); |
| 100 | m_pShipSprite->setPosition({0, -5}); |
| 101 | addChild(m_pShipSprite, 2); |
| 102 | |
| 103 | m_pShipSecondarySprite = Sprite::createWithSpriteFrameName("ship_01_2_001.png"); |
| 104 | m_pShipSecondarySprite->setStretchEnabled(false); |
| 105 | m_pShipSprite->addChild(m_pShipSecondarySprite, -1); |
| 106 | m_pShipSecondarySprite->setPosition(m_pShipSprite->getContentSize() / 2.f); |
| 107 | |
| 108 | _ballSprite = Sprite::createWithSpriteFrameName("player_ball_01_001.png"); |
| 109 | _ballSprite->setStretchEnabled(false); |
| 110 | _ballSprite->setVisible(false); |
| 111 | addChild(_ballSprite, 1); |
| 112 | |
| 113 | _ballSecondarySprite = Sprite::createWithSpriteFrameName("player_ball_01_2_001.png"); |
| 114 | _ballSecondarySprite->setStretchEnabled(false); |
| 115 | _ballSprite->addChild(_ballSecondarySprite, -1); |
| 116 | _ballSecondarySprite->setPosition(_ballSprite->getContentSize() / 2.f); |
| 117 | |
| 118 | _ufoSprite = Sprite::createWithSpriteFrameName("bird_01_001.png"); |
| 119 | _ufoSprite->setStretchEnabled(false); |
| 120 | _ufoSprite->setVisible(false); |
| 121 | _ufoSprite->setPositionY(-7); |
| 122 | addChild(_ufoSprite, 1); |
| 123 | |
| 124 | _ufoSecondarySprite = Sprite::createWithSpriteFrameName("bird_01_2_001.png"); |
| 125 | _ufoSecondarySprite->setStretchEnabled(false); |
| 126 | _ufoSprite->addChild(_ufoSecondarySprite, -1); |
| 127 | _ufoSecondarySprite->setPosition(_ufoSprite->getContentSize() / 2.f); |
| 128 | |
| 129 | _ufoTertiarySprite = Sprite::createWithSpriteFrameName("bird_01_3_001.png"); |
no test coverage detected