Skip to content

Commit

Permalink
1.1.1.1.1.1.1.1.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
undefined06855 committed Nov 27, 2024
1 parent 3ce2266 commit 68b5b0a
Show file tree
Hide file tree
Showing 11 changed files with 115 additions and 42 deletions.
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -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!
Expand Down
2 changes: 1 addition & 1 deletion mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -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" ],
Expand Down
1 change: 1 addition & 0 deletions src/MenuLayer.cpp
Original file line number Diff line number Diff line change
@@ -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<HookedMenuGameLayer*>(m_menuGameLayer);
Expand Down
50 changes: 49 additions & 1 deletion src/NinjaSwipeLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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)
)
);
Expand All @@ -231,6 +233,8 @@ void NinjaSwipeLayer::killPlayer(MenuIcon* player) {
layer->flashAndRemove();
}

startShake();

// funny
// auto skibidi = cocos2d::CCNode::create();
// skibidi->release();
Expand Down Expand Up @@ -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) {
Expand Down
7 changes: 6 additions & 1 deletion src/NinjaSwipeLayer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -56,4 +60,5 @@ class NinjaSwipeLayer : public cocos2d::CCLayer {
void enterGameplay();
void updateComboShit();
void resetCombo();
void startShake();
};
23 changes: 10 additions & 13 deletions src/Swipe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ bool Swipe::init(cocos2d::CCTexture2D* texture) {
}

void Swipe::update(float dt) {
std::vector<SwipePoint> pointsForDeletion = {};
std::vector<SwipePoint*> 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);
}
Expand All @@ -53,17 +53,17 @@ void Swipe::draw() {
std::vector<cocos2d::CCPoint> points = {};
std::vector<cocos2d::CCPoint> 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());
Expand All @@ -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;
Expand Down
27 changes: 2 additions & 25 deletions src/Swipe.hpp
Original file line number Diff line number Diff line change
@@ -1,29 +1,6 @@
#pragma once
#include <Geode/Geode.hpp>

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<cocos2d::CCPoint, cocos2d::CCPoint> 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:
Expand All @@ -32,7 +9,7 @@ class Swipe : public cocos2d::CCNode {

cocos2d::CCGLProgram* m_program;
cocos2d::CCPoint m_lastPoint; // used to calculate angle
std::vector<SwipePoint> m_points;
std::vector<SwipePoint*> m_points;
cocos2d::CCTexture2D* m_texture;

void update(float dt);
Expand Down
26 changes: 26 additions & 0 deletions src/SwipePoint.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include "SwipePoint.hpp"

SwipePoint::SwipePoint(cocos2d::CCPoint location, float direction) {
m_location = location;
m_direction = direction;
}

std::pair<cocos2d::CCPoint, cocos2d::CCPoint> 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;
}
}
15 changes: 15 additions & 0 deletions src/SwipePoint.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#pragma once
#include <Geode/Geode.hpp>

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<cocos2d::CCPoint, cocos2d::CCPoint> calculatePointPositions();
float getDistanceFromTick();
};
2 changes: 1 addition & 1 deletion src/utils/random.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ std::uniform_int_distribution<int> bombSpawnDistribution = std::uniform_int_dist
std::uniform_int_distribution<int> menuIconTypeDistribution = std::uniform_int_distribution<int>(0, 1); // 0 = MenuIconType::Player 1 = MenuIconType::Bomb
std::uniform_int_distribution<int> spreeIconCountDistribution = std::uniform_int_distribution<int>(4, 15); // should be a bit more than normal
std::uniform_int_distribution<int> mixIconCountDistribution = std::uniform_int_distribution<int>(3, 5); // should be a bit more than normal

std::uniform_real_distribution<float> shakeMovementDistribution = std::uniform_real_distribution<float>(-1.f, 1.f);

// reimplemented from MenuGameLayer::resetPlayer
// it kinda broke when i tried to use it without using the menugamelayer's
Expand Down
1 change: 1 addition & 0 deletions src/utils/random.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ extern std::uniform_int_distribution<int> bombSpawnDistribution;
extern std::uniform_int_distribution<int> menuIconTypeDistribution;
extern std::uniform_int_distribution<int> spreeIconCountDistribution;
extern std::uniform_int_distribution<int> mixIconCountDistribution;
extern std::uniform_real_distribution<float> shakeMovementDistribution;

void randomisePlayerObject(PlayerObject* player);

Expand Down

0 comments on commit 68b5b0a

Please sign in to comment.