diff --git a/assets/textures/background.png b/assets/textures/background.png index c05a4516..a0aae5d0 100644 Binary files a/assets/textures/background.png and b/assets/textures/background.png differ diff --git a/assets/textures/background.png.bak b/assets/textures/background.png.bak new file mode 100644 index 00000000..c05a4516 Binary files /dev/null and b/assets/textures/background.png.bak differ diff --git a/source/scenes/gameplay/PPCanvas.cpp b/source/scenes/gameplay/PPCanvas.cpp index c9546df4..5f69ee1a 100644 --- a/source/scenes/gameplay/PPCanvas.cpp +++ b/source/scenes/gameplay/PPCanvas.cpp @@ -1,11 +1,7 @@ #include "PPCanvas.h" #define PADDING 0 -#define PALETTE_PADDING 120 #define MAX_QUEUE 6 -#define OFFSET_FROM_TOP 240 -#define ADD_OFFSET_PER_ROW 240 -#define OFFSCREEN_ANIMATION_OFFSET 50 #define EASING STRONG_OUT #define DURATION 0.5 #define MINI_SCALE 0.75 @@ -25,19 +21,21 @@ void Canvas::_setup(const asset_t &assets, const vec &colors, const ptr &timer, uint queueInd, uint numOfQueues) { _timer = timer; - float containerWidth = getWidth() - PALETTE_PADDING; + float containerWidth = getWidth(); float laneWidth = containerWidth / MAX_QUEUE; float laneX = (containerWidth - laneWidth * numOfQueues) / 2 + - laneWidth / 2 + laneWidth * queueInd + PALETTE_PADDING; + laneWidth / 2 + laneWidth * queueInd; float canvasSize = laneWidth - PADDING * 2; + _yForActive = getHeight() * .05f; + _yForStandBy = _yForActive + getHeight() * .45f; + _startingY = _yForStandBy + getHeight() * .1f; + _yAfterLeaving = _yForActive - getHeight() * .1f; _block = CanvasBlock::alloc(assets, canvasSize, colors); _block->setScale(MINI_SCALE, MINI_SCALE); - _block->setAnchor(Vec2::ANCHOR_CENTER); - _block->setPosition( - laneX, - getHeight() - OFFSET_FROM_TOP + OFFSCREEN_ANIMATION_OFFSET); + _block->setAnchor(Vec2::ANCHOR_BOTTOM_CENTER); + _block->setPosition(laneX, _startingY); _block->setColor(Color4(255, 255, 255, 0)); addChild(_block); _previousState = HIDDEN; @@ -57,11 +55,9 @@ void Canvas::update(CanvasState state, const vec &canvasColors) { // Set y of block depending on state. if (state != _previousState) { - float targetY = getHeight() - OFFSET_FROM_TOP; - if (state == ACTIVE) targetY -= ADD_OFFSET_PER_ROW; Animation::alloc(_block, DURATION, { - {"y", targetY}, - {"opacity", 1}, + {"y", state == ACTIVE ? _yForActive : _yForStandBy}, + {"opacity", state == ACTIVE ? 1 : .75f}, {"scaleX", state == ACTIVE ? 1 : MINI_SCALE}, {"scaleY", state == ACTIVE ? 1 : MINI_SCALE}, }, EASING); @@ -78,7 +74,7 @@ void Canvas::update(CanvasState state, const vec &canvasColors) { _block->markLost(); } Animation::alloc(_block, DURATION, { - {"y", getHeight() - OFFSET_FROM_TOP - ADD_OFFSET_PER_ROW - OFFSCREEN_ANIMATION_OFFSET}, + {"y", _yAfterLeaving}, {"opacity", 0}, }, EASING); } diff --git a/source/scenes/gameplay/PPCanvas.h b/source/scenes/gameplay/PPCanvas.h index 69b37045..76fc4303 100644 --- a/source/scenes/gameplay/PPCanvas.h +++ b/source/scenes/gameplay/PPCanvas.h @@ -14,6 +14,11 @@ */ class Canvas : public SceneNode { private: + float _startingY; + float _yForStandBy; + float _yForActive; + float _yAfterLeaving; + /** Block */ ptr _block; diff --git a/source/scenes/gameplay/PPCanvasBlock.cpp b/source/scenes/gameplay/PPCanvasBlock.cpp index 3a4e8161..11d5a67b 100644 --- a/source/scenes/gameplay/PPCanvasBlock.cpp +++ b/source/scenes/gameplay/PPCanvasBlock.cpp @@ -14,7 +14,12 @@ ptr CanvasBlock::alloc( } void CanvasBlock::_setup(const asset_t &assets, const vec& colors) { - +#ifdef VIEW_DEBUG + auto n = PolygonNode::alloc(Rect(Vec2::ZERO, getContentSize())); + n->setColor(Color4f(0, 1, 0, .3)); + addChild(n); +#endif + string characters[] = {"panda", "bird-1", "bird-2", "cat-1", "cat-2", "dog-1", "dog-2", "dog-3", "frog", "octopus"}; int p = rand() % NUM_CHARACTERS; @@ -38,12 +43,11 @@ void CanvasBlock::_setup(const asset_t &assets, const vec& colors) { addChild(_talk_bubble); // Color strip - _colorStrip = ColorStrip::alloc(assets, colors); + _colorStrip = ColorStrip::alloc(_talk_bubble->getWidth() * .22f, assets, colors); _colorStrip->setAnchor(Vec2::ANCHOR_CENTER); auto bubbleBox = _talk_bubble->getBoundingBox(); _colorStrip->setPosition(bubbleBox.getMidX(), bubbleBox.getMidY() + 10); addChild(_colorStrip); - // Timer label _timerText = scene2::Label::alloc("", assets->get("roboto")); @@ -52,7 +56,6 @@ void CanvasBlock::_setup(const asset_t &assets, const vec& colors) { _timerText->setPosition(getWidth() / 2, 35); addChild(_timerText); - _hoverAllowed = true; } diff --git a/source/scenes/gameplay/PPColorStrip.cpp b/source/scenes/gameplay/PPColorStrip.cpp index 5865f14f..68fdb454 100644 --- a/source/scenes/gameplay/PPColorStrip.cpp +++ b/source/scenes/gameplay/PPColorStrip.cpp @@ -1,14 +1,10 @@ #include "PPColorStrip.h" -/** Size of each dot. */ -#define COLOR_SIZE 30 - -/** Space between dots. */ -#define PADDING 2 - -ptr ColorStrip::alloc(const asset_t& assets, - const vec &colors) { - auto result = make_shared(assets, colors); +ptr ColorStrip::alloc( + uint size, + const asset_t& assets, + const vec &colors) { + auto result = make_shared(size, assets, colors); return (result->init() ? result : nullptr); } @@ -25,15 +21,15 @@ void ColorStrip::update(const vec &canvasColors) { auto colorTexture = _assets->get("color-circle"); auto bg = PolygonNode::allocWithTexture(colorTexture); bg->setAnchor(Vec2::ANCHOR_BOTTOM_LEFT); - bg->setContentSize(COLOR_SIZE, COLOR_SIZE); + bg->setContentSize(_size, _size); float leftMostX = - (-PADDING * ((float)_lastNumberOfColors - 1) - - (float)_lastNumberOfColors * COLOR_SIZE) / 2; + (-(_size * 0.3f) * ((float)_lastNumberOfColors - 1) - + (float)_lastNumberOfColors * _size) / 2; bg->setPosition( - leftMostX + (float)(PADDING + COLOR_SIZE) * (float)i, - -(float)COLOR_SIZE / 2); + leftMostX + (float)((_size * 0.3f) + _size) * (float)i, + -(float)_size / 2); bg->setColor(_colors[canvasColors[i]]); addChild(bg); diff --git a/source/scenes/gameplay/PPColorStrip.h b/source/scenes/gameplay/PPColorStrip.h index 0a5ece33..393ad197 100644 --- a/source/scenes/gameplay/PPColorStrip.h +++ b/source/scenes/gameplay/PPColorStrip.h @@ -16,6 +16,8 @@ class ColorStrip : public SceneNode { */ uint _lastNumberOfColors; + uint _size; + /** Color list. */ const vec _colors; @@ -23,13 +25,15 @@ class ColorStrip : public SceneNode { public: /** @deprecated Constructor. */ - explicit ColorStrip(const asset_t &assets, const vec &colors) : + explicit ColorStrip(uint size, const asset_t &assets, const vec &colors) : SceneNode(), _lastNumberOfColors(0), - _colors(colors), _assets(assets) {}; + _colors(colors), _assets(assets), _size(size) {}; /** Allocate a color strip. */ - static ptr alloc(const asset_t &assets, - const vec &colors); + static ptr alloc( + uint size, + const asset_t &assets, + const vec &colors); /** * Update the color strip. diff --git a/source/scenes/gameplay/PPGameScene.cpp b/source/scenes/gameplay/PPGameScene.cpp index 2b3f4f9e..459fc4aa 100644 --- a/source/scenes/gameplay/PPGameScene.cpp +++ b/source/scenes/gameplay/PPGameScene.cpp @@ -2,6 +2,8 @@ #include #define ANIMATION_RELATIVE 10000000 +#define PALETTE_WIDTH .1f +#define TIMER_HEIGHT .1f void GameScene::dispose() { Scene2::dispose(); @@ -37,12 +39,16 @@ void GameScene::loadLevel(const char *levelName) { for (uint i = 0, j = _state.numQueues(); i < j; i++) { vec> queue; for (int i2 = (int) (_state.numCanvases(i)) - 1; i2 >= 0; i2--) { + auto bound = Application::get()->getSafeBounds(); + bound.origin.x += PALETTE_WIDTH * bound.size.width; + bound.size.width *= (1 - PALETTE_WIDTH); + bound.size.height *= (1 - TIMER_HEIGHT); auto c = Canvas::alloc( _assets, _state.getColors(), _state.getTimer(i, i2), i, j, - Application::get()->getDisplayBounds() + bound ); addChild(c); queue.insert(queue.begin(), 1, c); @@ -50,13 +56,19 @@ void GameScene::loadLevel(const char *levelName) { _canvases.push_back(queue); } - _globalTimer = GlobalTimer::alloc(_assets, screenSize); + auto gtBound = Application::get()->getSafeBounds(); + gtBound.origin.y += (1 - TIMER_HEIGHT) * gtBound.size.height; + gtBound.size.height *= TIMER_HEIGHT; + _globalTimer = GlobalTimer::alloc(_assets, gtBound); // change position to keep it to the left of the screen. _palette = ColorPalette::alloc(Rect( safeArea.origin, - Size(safeArea.size.width * .15f, safeArea.size.height) + Size( + safeArea.size.width * PALETTE_WIDTH, + safeArea.size.height * (1 - TIMER_HEIGHT) + ) ), _state.getColors(), _assets); addChild(_globalTimer); diff --git a/source/scenes/gameplay/PPGlobalTimer.cpp b/source/scenes/gameplay/PPGlobalTimer.cpp index 241a824c..a841cccc 100644 --- a/source/scenes/gameplay/PPGlobalTimer.cpp +++ b/source/scenes/gameplay/PPGlobalTimer.cpp @@ -2,9 +2,9 @@ ptr GlobalTimer::alloc( const asset_t &assets, - const Size entireScreen) { + const Rect &bounds) { auto result = make_shared(assets); - if (result->initWithBounds(entireScreen)) + if (result->initWithBounds(bounds)) result->_setup(); else return nullptr; @@ -12,13 +12,20 @@ ptr GlobalTimer::alloc( } void GlobalTimer::_setup() { +#ifdef VIEW_DEBUG + auto n = PolygonNode::alloc(Rect(Vec2::ZERO, getContentSize())); + n->setColor(Color4f(0, 1, 1, .3)); + addChild(n); +#endif + // Level timer label. - _levelTimerText = Label::alloc("1", _assets->get("jua")); - _levelTimerText->setHorizontalAlignment(Label::HAlign::LEFT); - _levelTimerText->setVerticalAlignment(Label::VAlign::TOP); - _levelTimerText->setPosition(getWidth() - 140, getHeight() - 50); +// auto font = _assets->get("jua"); +// _levelTimerText = Label::alloc("1", font); +// _levelTimerText->setHorizontalAlignment(Label::HAlign::LEFT); +// _levelTimerText->setVerticalAlignment(Label::VAlign::TOP); +// _levelTimerText->setPosition(getWidth() - 140, getHeight() - 50); - Rect boundingRect = Rect(0, getHeight() - 30, getWidth() - 150, 40); + Rect boundingRect = Rect(0, getHeight() - 30, getWidth(), 40); _levelProgressBarBackground = PolygonNode::allocWithTexture(_assets->get("level-timer-background"), boundingRect); _levelProgressBarBackground->setAnchor(Vec2::ANCHOR_MIDDLE_LEFT); _levelProgressBarBackground->setPosition(0, getHeight() - 30); @@ -27,15 +34,15 @@ void GlobalTimer::_setup() { _levelProgressBar->setAnchor(Vec2::ANCHOR_MIDDLE_LEFT); _levelProgressBar->setPosition(0, getHeight() - 30); - _progressBarWidth = getWidth() - 150; + _progressBarWidth = getWidth(); addChild(_levelProgressBarBackground); addChild(_levelProgressBar); - addChild(_levelTimerText); +// addChild(_levelTimerText); } void GlobalTimer::update(const ptr &levelTimer) { - _levelTimerText->setText(levelTimer->formatTime()); +// _levelTimerText->setText(levelTimer->formatTime()); float progress = levelTimer->timeLeft() / levelTimer->getDuration(); _levelProgressBar->setContentSize(progress * _progressBarWidth, 40); } diff --git a/source/scenes/gameplay/PPGlobalTimer.h b/source/scenes/gameplay/PPGlobalTimer.h index 4303c49f..adab7ee8 100644 --- a/source/scenes/gameplay/PPGlobalTimer.h +++ b/source/scenes/gameplay/PPGlobalTimer.h @@ -24,7 +24,7 @@ class GlobalTimer : public SceneNode { static ptr alloc( const asset_t &assets, - Size entireScreen); + const Rect &bounds); void update(const ptr &levelTimer); };