Skip to content

Commit b315ca7

Browse files
committed
Initial Commit (why doesnt it work on android)
0 parents  commit b315ca7

File tree

8 files changed

+323
-0
lines changed

8 files changed

+323
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: Build Geode Mod
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- "**"
8+
9+
jobs:
10+
build:
11+
strategy:
12+
fail-fast: false
13+
matrix:
14+
config:
15+
- name: Windows
16+
os: windows-latest
17+
18+
- name: macOS
19+
os: macos-latest
20+
21+
- name: Android32
22+
os: ubuntu-latest
23+
target: Android32
24+
25+
- name: Android64
26+
os: ubuntu-latest
27+
target: Android64
28+
29+
name: ${{ matrix.config.name }}
30+
runs-on: ${{ matrix.config.os }}
31+
32+
steps:
33+
- uses: actions/checkout@v4
34+
35+
- name: Build the mod
36+
uses: geode-sdk/build-geode-mod@main
37+
with:
38+
combine: true
39+
target: ${{ matrix.config.target }}
40+
41+
package:
42+
name: Package builds
43+
runs-on: ubuntu-latest
44+
needs: ['build']
45+
46+
steps:
47+
- uses: geode-sdk/build-geode-mod/combine@main
48+
id: build
49+
50+
- uses: actions/upload-artifact@v4
51+
with:
52+
name: Build Output
53+
path: ${{ steps.build.outputs.build-output }}

.gitignore

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Prerequisites
2+
*.d
3+
4+
# Compiled Object files
5+
*.slo
6+
*.lo
7+
*.o
8+
*.obj
9+
10+
# Precompiled Headers
11+
*.gch
12+
*.pch
13+
14+
# Compiled Dynamic libraries
15+
*.so
16+
*.dylib
17+
*.dll
18+
19+
# Fortran module files
20+
*.mod
21+
*.smod
22+
23+
# Compiled Static libraries
24+
*.lai
25+
*.la
26+
*.a
27+
*.lib
28+
29+
# Executables
30+
*.exe
31+
*.out
32+
*.app
33+
34+
# Macos be like
35+
**/.DS_Store
36+
37+
# Cache files for Sublime Text
38+
*.tmlanguage.cache
39+
*.tmPreferences.cache
40+
*.stTheme.cache
41+
42+
# Ignore build folders
43+
**/build
44+
# Ignore platform specific build folders
45+
build-*/
46+
47+
# Workspace files are user-specific
48+
*.sublime-workspace
49+
50+
# ILY vscode
51+
**/.vscode
52+
53+
# Local History for Visual Studio Code
54+
.history/
55+
56+
# clangd
57+
.cache/
58+
59+
# Visual Studio
60+
.vs/
61+
62+
# CLion
63+
.idea/
64+
/cmake-build-*/

CMakeLists.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
cmake_minimum_required(VERSION 3.21)
2+
set(CMAKE_CXX_STANDARD 20)
3+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
4+
set(CMAKE_OSX_ARCHITECTURES "arm64;x86_64")
5+
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
6+
7+
project(PlatformerJoystick VERSION 1.0.0)
8+
9+
add_library(${PROJECT_NAME} SHARED src/JoystickNode.cpp src/main.cpp)
10+
11+
if (NOT DEFINED ENV{GEODE_SDK})
12+
message(FATAL_ERROR "Unable to find Geode SDK! Please define GEODE_SDK environment variable to point to Geode")
13+
else()
14+
message(STATUS "Found Geode: $ENV{GEODE_SDK}")
15+
endif()
16+
17+
add_subdirectory($ENV{GEODE_SDK} ${CMAKE_CURRENT_BINARY_DIR}/geode)
18+
19+
setup_geode_mod(${PROJECT_NAME})

build.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#! /bin/bash
2+
3+
if [ ! -d "build-android64" ]; then
4+
geode build -p android64
5+
fi
6+
7+
cmake --build build-android64
8+
adb push build-android64/*.geode /storage/emulated/0/Android/media/com.geode.launcher/game/geode/mods/
9+
adb shell am force-stop com.geode.launcher
10+
adb shell am start -n com.geode.launcher/com.geode.launcher.GeometryDashActivity
11+
adb logcat Geode:V \*:S

mod.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"geode": "4.3.1",
3+
"gd": {
4+
"win": "2.2074",
5+
"android": "2.2074",
6+
"mac": "2.2074",
7+
"ios": "2.2074"
8+
},
9+
"id": "km7dev.platformerjoystick",
10+
"name": "PlatformerJoystick",
11+
"version": "v1.0.0",
12+
"developer": "km7dev",
13+
"description": ""
14+
}

src/JoystickNode.cpp

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
#include "JoystickNode.hpp"
2+
3+
bool JoystickNode::init() {
4+
if (!CCMenu::init()) return false;
5+
setContentSize({100, 100});
6+
7+
m_bg = CCSprite::createWithSpriteFrameName("d_circle_02_001.png");
8+
m_bg->setScale(getContentSize().width / m_bg->getContentSize().width);
9+
m_bg->setOpacity(165);
10+
m_bg->setColor({189, 189, 189});
11+
addChildAtPosition(m_bg, Anchor::Center);
12+
13+
m_center = CCSprite::createWithSpriteFrameName("d_circle_02_001.png");
14+
m_center->setScale(getContentSize().width / m_center->getContentSize().width / 3);
15+
m_center->setOpacity(236);
16+
m_center->setZOrder(1);
17+
m_center->setColor({0, 0, 0});
18+
addChildAtPosition(m_center, Anchor::Center);
19+
20+
registerWithTouchDispatcher();
21+
22+
return true;
23+
}
24+
25+
JoystickNode *JoystickNode::create() {
26+
auto ret = new JoystickNode;
27+
if (!ret->init()) {
28+
delete ret;
29+
return nullptr;
30+
}
31+
ret->autorelease();
32+
return ret;
33+
}
34+
35+
bool JoystickNode::ccTouchBegan(CCTouch *touch, CCEvent *event) {
36+
if (getScaledContentSize().width / 2 < ccpDistance(getPosition(), touch->getLocation())) {
37+
return false;
38+
}
39+
40+
// m_offset = m_center->getPosition() - convertToNodeSpace(touch->getLocation());
41+
42+
return true;
43+
}
44+
45+
void handleInput(GJBaseGameLayer *layer, CCPoint input, CCPoint old) {
46+
if (old.x == 1) {
47+
layer->handleButton(false, 3, true);
48+
} else if (old.x == -1) {
49+
layer->handleButton(false, 2, true);
50+
}
51+
if (old.y == 1) {
52+
layer->handleButton(false, 3, false);
53+
} else if (old.y == -1) {
54+
layer->handleButton(false, 2, false);
55+
}
56+
57+
if (input.x == 1) {
58+
layer->handleButton(true, 3, true);
59+
} else if (input.x == -1) {
60+
layer->handleButton(true, 2, true);
61+
}
62+
if (input.y == 1) {
63+
layer->handleButton(true, 3, false);
64+
} else if (input.y == -1) {
65+
layer->handleButton(true, 2, false);
66+
}
67+
}
68+
69+
void JoystickNode::ccTouchEnded(CCTouch *touch, CCEvent *event) {
70+
if (auto pl = PlayLayer::get()) {
71+
handleInput(pl, {0, 0}, m_currentInput);
72+
}
73+
74+
m_currentInput = CCPoint{0, 0};
75+
76+
m_center->setPosition(getScaledContentSize() / 2);
77+
}
78+
79+
void JoystickNode::ccTouchMoved(CCTouch *touch, CCEvent *event) {
80+
auto pos = convertToNodeSpace(touch->getLocation());
81+
82+
auto fromCenter = pos - getScaledContentSize() / 2;
83+
84+
if (fromCenter.getLength() > getScaledContentWidth() / 2 - m_center->getScaledContentWidth() / 2) {
85+
fromCenter = fromCenter.normalize() * (getScaledContentWidth() / 2 - m_center->getScaledContentWidth() / 2);
86+
pos = fromCenter + getScaledContentSize() / 2;
87+
}
88+
89+
CCPoint inp = {0, 0};
90+
91+
auto angle = atan2(fromCenter.y, fromCenter.x);
92+
93+
if (std::abs(fromCenter.x) > fromCenter.normalize().x * 15) {
94+
if (angle > -M_PI / 3 && angle < M_PI / 3) {
95+
inp.x = 1;
96+
} else if (angle > 2 * M_PI / 3 || angle < 2 * -M_PI / 3) {
97+
inp.x = -1;
98+
}
99+
}
100+
101+
if (std::abs(fromCenter.y) > fromCenter.normalize().y * 15) {
102+
if (angle > M_PI / 6 && angle < 5 * M_PI / 6) {
103+
inp.y = 1;
104+
} else if (angle < -M_PI / 6 && angle > -5 * M_PI / 6) {
105+
inp.y = -1;
106+
}
107+
}
108+
109+
if (inp != m_currentInput) {
110+
if (auto pl = PlayLayer::get()) {
111+
handleInput(pl, inp, m_currentInput);
112+
}
113+
}
114+
m_currentInput = inp;
115+
116+
m_center->setPosition(pos);
117+
}
118+
119+
void JoystickNode::ccTouchCancelled(CCTouch *touch, CCEvent *event) {
120+
ccTouchEnded(touch, event);
121+
}
122+
123+
void JoystickNode::registerWithTouchDispatcher() {
124+
CCTouchDispatcher::get()->addTargetedDelegate(this, -512, true);
125+
}

src/JoystickNode.hpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include <Geode/Geode.hpp>
2+
3+
using namespace geode::prelude;
4+
5+
class JoystickNode : public CCMenu {
6+
protected:
7+
bool init() override;
8+
9+
bool ccTouchBegan(CCTouch *touch, CCEvent *event) override;
10+
void ccTouchEnded(CCTouch *touch, CCEvent *event) override;
11+
void ccTouchMoved(CCTouch *touch, CCEvent *event) override;
12+
void ccTouchCancelled(CCTouch *touch, CCEvent *event) override;
13+
void registerWithTouchDispatcher() override;
14+
15+
CCPoint m_currentInput = {0, 0};
16+
17+
CCSprite *m_bg = nullptr;
18+
CCSprite *m_center = nullptr;
19+
public:
20+
static JoystickNode *create();
21+
};

src/main.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include <Geode/Geode.hpp>
2+
#include "JoystickNode.hpp"
3+
4+
using namespace geode::prelude;
5+
6+
#include <Geode/modify/PlayLayer.hpp>
7+
class $modify(CML, PlayLayer) {
8+
bool init(GJGameLevel *level, bool useReplay, bool dontCreateObjects) {
9+
if (!PlayLayer::init(level, useReplay, dontCreateObjects)) return false;
10+
11+
auto node = JoystickNode::create();
12+
addChildAtPosition(node, Anchor::BottomLeft, {50, 50}, false);
13+
14+
return true;
15+
}
16+
};

0 commit comments

Comments
 (0)