From 68b5b0a5313613f1434c6364313086817e75f7fb Mon Sep 17 00:00:00 2001 From: undefined06855 Date: Wed, 27 Nov 2024 20:44:13 +0000 Subject: [PATCH] 1.1.1.1.1.1.1.1.1.1 --- changelog.md | 3 +++ mod.json | 2 +- src/MenuLayer.cpp | 1 + src/NinjaSwipeLayer.cpp | 50 ++++++++++++++++++++++++++++++++++++++++- src/NinjaSwipeLayer.hpp | 7 +++++- src/Swipe.cpp | 23 +++++++++---------- src/Swipe.hpp | 27 ++-------------------- src/SwipePoint.cpp | 26 +++++++++++++++++++++ src/SwipePoint.hpp | 15 +++++++++++++ src/utils/random.cpp | 2 +- src/utils/random.hpp | 1 + 11 files changed, 115 insertions(+), 42 deletions(-) create mode 100644 src/SwipePoint.cpp create mode 100644 src/SwipePoint.hpp diff --git a/changelog.md b/changelog.md index 80674f0..f079b31 100644 --- a/changelog.md +++ b/changelog.md @@ -1,4 +1,7 @@ # Icon Ninja Changelog +## v1.1.1 +- Improved swipe trail +- Added shake effect on bomb explosion ## v1.1.0 - Bombs! - Multiple players at once! diff --git a/mod.json b/mod.json index ef426a7..aabc8ee 100644 --- a/mod.json +++ b/mod.json @@ -7,7 +7,7 @@ "id": "undefined0.icon_ninja", "name": "Icon Ninja", - "version": "v1.1.0", + "version": "v1.1.1", "developer": "undefined0", "description": "Makes killing icons like Fruit Ninja!", "tags": [ "joke", "offline", "modtober24" ], diff --git a/src/MenuLayer.cpp b/src/MenuLayer.cpp index 16abda5..b3adc64 100644 --- a/src/MenuLayer.cpp +++ b/src/MenuLayer.cpp @@ -1,6 +1,7 @@ #include "MenuLayer.hpp" #include "MenuGameLayer.hpp" #include "NinjaSwipeLayer.hpp" +#include "utils/random.hpp" void HookedMenuLayer::keyDown(cocos2d::enumKeyCodes code) { auto mgl = static_cast(m_menuGameLayer); diff --git a/src/NinjaSwipeLayer.cpp b/src/NinjaSwipeLayer.cpp index 43453a9..9a07c21 100644 --- a/src/NinjaSwipeLayer.cpp +++ b/src/NinjaSwipeLayer.cpp @@ -96,6 +96,8 @@ bool NinjaSwipeLayer::ccTouchBegan(cocos2d::CCTouch* touch, cocos2d::CCEvent* ev } void NinjaSwipeLayer::ccTouchMoved(cocos2d::CCTouch* touch, cocos2d::CCEvent* event) { + if (m_lastSwipePoint.getDistanceSq(touch->getLocation()) < 1.f) return; // too close smh stop being stupid + checkSwipeIntersection(m_lastSwipePoint, touch->getLocation()); m_swipe->addPoint(touch->getLocation()); m_lastSwipePoint = touch->getLocation(); @@ -210,7 +212,7 @@ void NinjaSwipeLayer::killPlayer(MenuIcon* player) { player->m_bombSprite->runAction( cocos2d::CCSpawn::createWithTwoActions( - cocos2d::CCScaleBy::create(1.8f, 1.5f), + cocos2d::CCScaleBy::create(1.6f, 1.7f), cocos2d::CCRepeat::create(shake, 69420) ) ); @@ -231,6 +233,8 @@ void NinjaSwipeLayer::killPlayer(MenuIcon* player) { layer->flashAndRemove(); } + startShake(); + // funny // auto skibidi = cocos2d::CCNode::create(); // skibidi->release(); @@ -325,6 +329,50 @@ void NinjaSwipeLayer::update(float dt) { m_debugNode->drawCircle(origin, radius, { 0.f, 0.f, 0.f, 0.f }, 1, col, 32); } } + + updateShake(dt); +} + +void NinjaSwipeLayer::updateShake(float dt) { + if (m_shakeTick <= 0) { + MenuLayer::get()->setPosition({ 0.f, 0.f }); + return; + } + + m_shakeTick -= dt; + float shakePercentage = m_shakeTick / m_maxShakeTick; + + float offsetX = ninja::random::shakeMovementDistribution(ninja::random::gen) * 12.f * shakePercentage; + float offsetY = ninja::random::shakeMovementDistribution(ninja::random::gen) * 12.f * shakePercentage; + + MenuLayer::get()->setPosition({ offsetX, offsetY }); +} + +void NinjaSwipeLayer::startShake() { + if (GameManager::get()->getGameVariable("0172")) return; + + // I stay out too late + // Got nothing in my brain + // That's what people say, mm-mm + // That's what people say, mm-mm + + // I go on too many dates + // But I can't make 'em stay + // At least that's what people say, mm-mm + // That's what people say, mm-mm + + // But I keep cruisin' + // Can't stop, won't stop movin' + // It's like I got this music in my mind + // Sayin' it's gonna be alright + + // 'Cause the players gonna play, play, play, play, play + // And the haters gonna hate, hate, hate, hate, hate + // Baby, I'm just gonna shake, shake, shake, shake, shake + // I shake it off, I shake it off (hoo-hoo-hoo) + + m_shakeTick = m_maxShakeTick; + geode::log::info("shakey bakey"); } void NinjaSwipeLayer::removePlayer(MenuIcon* player) { diff --git a/src/NinjaSwipeLayer.hpp b/src/NinjaSwipeLayer.hpp index 0333839..02a21e4 100644 --- a/src/NinjaSwipeLayer.hpp +++ b/src/NinjaSwipeLayer.hpp @@ -12,7 +12,7 @@ class NinjaSwipeLayer : public cocos2d::CCLayer { static NinjaSwipeLayer* create(); bool init() override; - bool m_isDebug = false; + static const bool m_isDebug = false; cocos2d::CCDrawNode* m_debugNode; bool m_isFingerDown = false; @@ -40,10 +40,14 @@ class NinjaSwipeLayer : public cocos2d::CCLayer { cocos2d::CCLabelBMFont* m_hiComboLabel = nullptr; cocos2d::CCLayerRGBA* m_scoreLayer = nullptr; + float m_shakeTick = 0.f; + const float m_maxShakeTick = 0.7f; + bool ccTouchBegan(cocos2d::CCTouch* touch, cocos2d::CCEvent* event) override; void ccTouchMoved(cocos2d::CCTouch* touch, cocos2d::CCEvent* event) override; void ccTouchEnded(cocos2d::CCTouch* touch, cocos2d::CCEvent* event) override; void update(float dt) override; + void updateShake(float dt); void checkSwipeIntersection(const cocos2d::CCPoint& from, const cocos2d::CCPoint& to); bool lineIntersectsCircle(const cocos2d::CCPoint& circleCenter, const float circleRadius, const cocos2d::CCPoint& from, const cocos2d::CCPoint& to); @@ -56,4 +60,5 @@ class NinjaSwipeLayer : public cocos2d::CCLayer { void enterGameplay(); void updateComboShit(); void resetCombo(); + void startShake(); }; diff --git a/src/Swipe.cpp b/src/Swipe.cpp index bf9be68..108ee45 100644 --- a/src/Swipe.cpp +++ b/src/Swipe.cpp @@ -23,17 +23,17 @@ bool Swipe::init(cocos2d::CCTexture2D* texture) { } void Swipe::update(float dt) { - std::vector pointsForDeletion = {}; + std::vector pointsForDeletion = {}; - for (auto& point : m_points) { - point.size -= dt; + for (auto point : m_points) { + point->m_tick += dt; - if (point.size <= 0) { + if (point->m_tick >= point->m_tickLength) { pointsForDeletion.push_back(point); } } - for (auto& point : pointsForDeletion) { + for (auto point : pointsForDeletion) { auto pos = std::find(m_points.begin(), m_points.end(), point); if (pos != m_points.end()) m_points.erase(pos); } @@ -53,17 +53,17 @@ void Swipe::draw() { std::vector points = {}; std::vector texCoords = {}; - points.push_back(m_points.front().location); // taper to a point (front) + points.push_back(m_points.front()->m_location); // taper to a point (front) texCoords.push_back({0.f, 0.5f}); for (int i = 1; i < m_points.size() - 1; i++) { - auto& point = m_points[i]; - auto pointPositions = point.calculatePointPositions(); + auto point = m_points[i]; + auto pointPositions = point->calculatePointPositions(); points.push_back(pointPositions.first); texCoords.push_back({0.5f, 1.f}); // v is flipped points.push_back(pointPositions.second); texCoords.push_back({0.5f, 0.f}); // v is flipped } - points.push_back(m_points.back().location); // taper to a point (back) + points.push_back(m_points.back()->m_location); // taper to a point (back) texCoords.push_back({1.f, 0.5f}); glVertexAttribPointer(cocos2d::kCCVertexAttrib_Position, 2, GL_FLOAT, GL_FALSE, 0, points.data()); @@ -80,10 +80,7 @@ void Swipe::addPoint(cocos2d::CCPoint point) { // calculate positions of points float angle = atan2(m_lastPoint.y - point.y, m_lastPoint.x - point.x); - SwipePoint sp = { - .location = point, - .direction = angle - }; + auto sp = new SwipePoint(point, angle); m_points.push_back(sp); m_lastPoint = point; diff --git a/src/Swipe.hpp b/src/Swipe.hpp index 34f11e4..6fd8c8a 100644 --- a/src/Swipe.hpp +++ b/src/Swipe.hpp @@ -1,29 +1,6 @@ #pragma once #include - -struct SwipePoint { - cocos2d::CCPoint location; - float direction; - float size = 0.15f; - - bool operator==(const SwipePoint& other) { - return - location == other.location - && direction == other.direction - && size == other.size; - } - - std::pair calculatePointPositions() { - float angle1 = fmod(direction + 1.5708f, 2.f * M_PI); - float angle2 = fmod(direction - 1.5708f, 2.f * M_PI); - - float dist = 50.f * size; - - cocos2d::CCPoint p1 = location + cocos2d::CCPoint{ cos(angle1)*dist, sin(angle1)*dist }; - cocos2d::CCPoint p2 = location + cocos2d::CCPoint{ cos(angle2)*dist, sin(angle2)*dist }; - return { p1, p2 }; - } -}; +#include "SwipePoint.hpp" class Swipe : public cocos2d::CCNode { public: @@ -32,7 +9,7 @@ class Swipe : public cocos2d::CCNode { cocos2d::CCGLProgram* m_program; cocos2d::CCPoint m_lastPoint; // used to calculate angle - std::vector m_points; + std::vector m_points; cocos2d::CCTexture2D* m_texture; void update(float dt); diff --git a/src/SwipePoint.cpp b/src/SwipePoint.cpp new file mode 100644 index 0000000..a4b34c1 --- /dev/null +++ b/src/SwipePoint.cpp @@ -0,0 +1,26 @@ +#include "SwipePoint.hpp" + +SwipePoint::SwipePoint(cocos2d::CCPoint location, float direction) { + m_location = location; + m_direction = direction; +} + +std::pair SwipePoint::calculatePointPositions() { + float angle1 = fmod(m_direction + 1.5708f, 2.f * M_PI); + float angle2 = fmod(m_direction - 1.5708f, 2.f * M_PI); + + float dist = getDistanceFromTick(); + + cocos2d::CCPoint p1 = m_location + cocos2d::CCPoint{ cos(angle1)*dist, sin(angle1)*dist }; + cocos2d::CCPoint p2 = m_location + cocos2d::CCPoint{ cos(angle2)*dist, sin(angle2)*dist }; + return { p1, p2 }; +} + +float SwipePoint::getDistanceFromTick() { + // https://www.desmos.com/calculator/mcb1ys1alb + if (m_tick < 0.03f) { + return m_tick * 185.f; + } else { + return -m_tick * 46.f + 6.9f; + } +} diff --git a/src/SwipePoint.hpp b/src/SwipePoint.hpp new file mode 100644 index 0000000..997ac66 --- /dev/null +++ b/src/SwipePoint.hpp @@ -0,0 +1,15 @@ +#pragma once +#include + +class SwipePoint { +public: + SwipePoint(cocos2d::CCPoint location, float direction); + + cocos2d::CCPoint m_location; + float m_direction; + float m_tick = 0.f; + const float m_tickLength = 0.15f; + + std::pair calculatePointPositions(); + float getDistanceFromTick(); +}; diff --git a/src/utils/random.cpp b/src/utils/random.cpp index f9116f1..4fb7c12 100644 --- a/src/utils/random.cpp +++ b/src/utils/random.cpp @@ -16,7 +16,7 @@ std::uniform_int_distribution bombSpawnDistribution = std::uniform_int_dist std::uniform_int_distribution menuIconTypeDistribution = std::uniform_int_distribution(0, 1); // 0 = MenuIconType::Player 1 = MenuIconType::Bomb std::uniform_int_distribution spreeIconCountDistribution = std::uniform_int_distribution(4, 15); // should be a bit more than normal std::uniform_int_distribution mixIconCountDistribution = std::uniform_int_distribution(3, 5); // should be a bit more than normal - +std::uniform_real_distribution shakeMovementDistribution = std::uniform_real_distribution(-1.f, 1.f); // reimplemented from MenuGameLayer::resetPlayer // it kinda broke when i tried to use it without using the menugamelayer's diff --git a/src/utils/random.hpp b/src/utils/random.hpp index 8c695e3..6bc1653 100644 --- a/src/utils/random.hpp +++ b/src/utils/random.hpp @@ -15,6 +15,7 @@ extern std::uniform_int_distribution bombSpawnDistribution; extern std::uniform_int_distribution menuIconTypeDistribution; extern std::uniform_int_distribution spreeIconCountDistribution; extern std::uniform_int_distribution mixIconCountDistribution; +extern std::uniform_real_distribution shakeMovementDistribution; void randomisePlayerObject(PlayerObject* player);