diff --git a/assets/config/assets.json b/assets/config/assets.json index 25825226..5de70aaf 100644 --- a/assets/config/assets.json +++ b/assets/config/assets.json @@ -119,6 +119,12 @@ }, "menubutton": { "file": "textures/menubutton.png" + }, + "bg-level1": { + "file": "textures/level-backgrounds/level1.png" + }, + "bg-level2": { + "file": "textures/level-backgrounds/level2.png" } }, "jsons": { diff --git a/assets/levels/level1.json b/assets/levels/level1.json index cb4538af..36ede095 100644 --- a/assets/levels/level1.json +++ b/assets/levels/level1.json @@ -1,4 +1,5 @@ { + "background": "bg-level1", "colors": [ [244, 78, 59], [251, 158, 0], diff --git a/assets/levels/level2.json b/assets/levels/level2.json index 60865ed7..514b3380 100644 --- a/assets/levels/level2.json +++ b/assets/levels/level2.json @@ -1,4 +1,5 @@ { + "background": "bg-level2", "colors": [ [244, 78, 59], [251, 158, 0], diff --git a/assets/levels/level3.json b/assets/levels/level3.json index 4390249e..7e2d0a45 100644 --- a/assets/levels/level3.json +++ b/assets/levels/level3.json @@ -1,4 +1,5 @@ { + "background": "bg-level1", "colors": [ [244, 78, 59], [251, 158, 0], diff --git a/assets/textures/level-backgrounds/level1.png b/assets/textures/level-backgrounds/level1.png new file mode 100644 index 00000000..e1862f25 Binary files /dev/null and b/assets/textures/level-backgrounds/level1.png differ diff --git a/assets/textures/level-backgrounds/level2.png b/assets/textures/level-backgrounds/level2.png new file mode 100644 index 00000000..b7689b0d Binary files /dev/null and b/assets/textures/level-backgrounds/level2.png differ diff --git a/build-android/build.gradle b/build-android/build.gradle index 614b1157..b07671e4 100644 --- a/build-android/build.gradle +++ b/build-android/build.gradle @@ -7,7 +7,7 @@ buildscript { } dependencies { - classpath "com.android.tools.build:gradle:4.1.2" + classpath 'com.android.tools.build:gradle:4.1.3' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files diff --git a/build-android/keystore.jks b/build-android/keystore.jks new file mode 100644 index 00000000..5bfaae11 Binary files /dev/null and b/build-android/keystore.jks differ diff --git a/cugl/lib/render/shaders/SpriteShader.frag b/cugl/lib/render/shaders/SpriteShader.frag index 0bd50b84..4c482880 100644 --- a/cugl/lib/render/shaders/SpriteShader.frag +++ b/cugl/lib/render/shaders/SpriteShader.frag @@ -69,7 +69,7 @@ float edgeThreshold = 100.0; float splatFalloffSize = .8; float splatCutoffSize = .2; vec4 defaultColor = vec4(0,0,0,0); -vec2 iResolution = uViewport; +vec2 iResolution; @@ -343,6 +343,8 @@ void main(void) { //Ben's code here to end: + iResolution = uViewport; + // uv are screen coordinates, uniformly scaled to go from 0..1 vertically vec2 uv = outPosition.xy / iResolution.yy; diff --git a/source/PPApp.cpp b/source/PPApp.cpp index 6e954b76..7c2eaf30 100644 --- a/source/PPApp.cpp +++ b/source/PPApp.cpp @@ -87,9 +87,11 @@ void PanicPainterApp::update(float timestep) { if (_gameplay.getPauseRequest()) { // TODO: Change this to pause screen when it's done. _currentScene = LEVEL_SCENE; + _level.resetState(); } else if (_gameplay.isComplete()) { _currentScene = LEVEL_SCENE; + _level.resetState(); } break; } @@ -104,6 +106,7 @@ void PanicPainterApp::update(float timestep) { //_menu.dispose(); _currentScene = LEVEL_SCENE; _menu.resetState(); + _level.resetState(); } break; } @@ -113,6 +116,7 @@ void PanicPainterApp::update(float timestep) { //_menu.init(_assets); _currentScene = MENU_SCENE; _level.resetState(); + _menu.resetState(); } else if (_level.getState() == SELECTED) { //_level.dispose(); diff --git a/source/scenes/gameplay/PPGameScene.cpp b/source/scenes/gameplay/PPGameScene.cpp index b8efe586..903584de 100644 --- a/source/scenes/gameplay/PPGameScene.cpp +++ b/source/scenes/gameplay/PPGameScene.cpp @@ -26,6 +26,8 @@ void GameScene::loadLevel(const char *levelName) { _palette.reset(); _action.reset(); + _complete = nullptr; + // Find Level file. const json_t levelJson = _assets->get(levelName); @@ -36,7 +38,7 @@ void GameScene::loadLevel(const char *levelName) { Rect safeArea = Application::get()->getSafeBounds(); auto background = PolygonNode::allocWithTexture(_assets->get - ("background")); + (levelJson->has("background") ? levelJson->getString("background") : "background")); background->setContentSize(Application::get()->getDisplaySize()); addChild(background); // Clear canvases. @@ -44,7 +46,7 @@ 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(); + auto bound = safeArea; bound.origin.x += PALETTE_WIDTH * bound.size.width; bound.size.width *= (1 - PALETTE_WIDTH); bound.size.height *= (1 - TIMER_HEIGHT); @@ -62,9 +64,33 @@ void GameScene::loadLevel(const char *levelName) { _canvases.push_back(queue); } - auto gtBound = Application::get()->getSafeBounds(); + _backBtn = PolygonNode::allocWithTexture + (_assets->get("backbutton")); + _backBtn->setScale(1.9f * + (safeArea.size.height * TIMER_HEIGHT) / _backBtn->getContentWidth()); + _backBtn->setAnchor(Vec2::ANCHOR_TOP_RIGHT); + _backBtn->setPosition(safeArea.size.width, safeArea.size.height); + // We manually define interactive area because there is that trail of paint + // in the button texture that shouldn't be interactive. + _backBtnArea = _backBtn->getBoundingBox(); + _backBtnArea.translate( + 0, + _backBtnArea.size.height - _backBtnArea.size.height * 0.75f); + _backBtnArea.scale(1, 0.75f); +#ifdef VIEW_DEBUG + // This draws the back button area above. + auto n = PolygonNode::alloc(_backBtnArea); + n->setAnchor(Vec2::ANCHOR_BOTTOM_LEFT); + n->setPosition(_backBtnArea.origin); + n->setContentSize(_backBtnArea.size); + addChild(n); +#endif + + auto gtBound = safeArea; gtBound.origin.y += (1 - TIMER_HEIGHT) * gtBound.size.height; gtBound.size.height *= TIMER_HEIGHT; + gtBound.size.width -= + gtBound.getMaxX() - _backBtn->getBoundingBox().getMinX(); _globalTimer = GlobalTimer::alloc(_assets, gtBound); // change position to keep it to the left of the screen. @@ -87,6 +113,8 @@ void GameScene::loadLevel(const char *levelName) { _action = make_shared(_state, _canvases); + addChild(_backBtn); + } void GameScene::update(float timestep) { @@ -100,8 +128,7 @@ void GameScene::update(float timestep) { auto &input = InputController::getInstance(); if (input.justReleased() && input.isJustTap() && - Rect(0, this->getSize().height - 120, 120, 120) - .contains(input.currentPoint())) { + InputController::inScene(input.currentPoint(), _backBtnArea)) { _pauseRequest = true; } diff --git a/source/scenes/gameplay/PPGameScene.h b/source/scenes/gameplay/PPGameScene.h index af497bc3..b1227a41 100644 --- a/source/scenes/gameplay/PPGameScene.h +++ b/source/scenes/gameplay/PPGameScene.h @@ -34,6 +34,9 @@ class GameScene final : public Scene2 { ptr _action; + ptr _backBtn; + Rect _backBtnArea; + // Boolean indicating level is complete ptr _complete;