summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordavidovski <david@sendula.com>2021-07-17 23:46:56 +0100
committerdavidovski <david@sendula.com>2021-07-17 23:46:56 +0100
commit0a0f2de6a140d0b35d1cd31a0e9659c465d8d65d (patch)
tree13ca83007db9faf4bbb97dce6eba712901034cc3
Pong
-rw-r--r--CMakeLists.txt41
-rw-r--r--README.md27
-rw-r--r--assets-fx/example.pngbin0 -> 3569 bytes
-rw-r--r--assets-fx/fxconv-metadata.txt3
-rw-r--r--assets-fx/icon.pngbin0 -> 8291 bytes
-rw-r--r--src/main.c118
6 files changed, 189 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000..a4ab8df
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,41 @@
+# Configure with [fxsdk build-fx] or [fxsdk build-cg], which provide the
+# toolchain file and module path of the fxSDK
+
+cmake_minimum_required(VERSION 3.15)
+project(pong)
+
+include(GenerateG1A)
+include(GenerateG3A)
+include(Fxconv)
+find_package(Gint 2.1 REQUIRED)
+
+set(SOURCES
+ src/main.c
+ # ...
+)
+# Shared assets, fx-9860G-only assets and fx-CG-50-only assets
+set(ASSETS
+ # ...
+)
+set(ASSETS_fx
+ assets-fx/example.png
+ # ...
+)
+set(ASSETS_cg
+ assets-cg/example.png
+ # ...
+)
+
+fxconv_declare_assets(${ASSETS} ${ASSETS_fx} ${ASSETS_cg} WITH_METADATA)
+
+add_executable(breakout ${SOURCES} ${ASSETS} ${ASSETS_${FXSDK_PLATFORM}})
+target_compile_options(breakout PRIVATE -Wall -Wextra -Os)
+target_link_libraries(breakout Gint::Gint)
+
+if("${FXSDK_PLATFORM_LONG}" STREQUAL fx9860G)
+ generate_g1a(TARGET breakout OUTPUT "pong.g1a"
+ NAME "pong" ICON assets-fx/icon.png)
+elseif("${FXSDK_PLATFORM_LONG}" STREQUAL fxCG50)
+ generate_g3a(TARGET breakout OUTPUT "pong.g3a"
+ NAME "pong" ICONS assets-cg/icon-uns.png assets-cg/icon-sel.png)
+endif()
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..307c784
--- /dev/null
+++ b/README.md
@@ -0,0 +1,27 @@
+# Pong
+
+This is my first attempt with [gint](https://gitea.planet-casio.com/Lephenixnoir/gint) creating an add-in for fx series casio calculators.
+
+## Controls
+
+Since this is a very simple game, controls are not included within the add-in. The controls are as following:
+
+### player 1
+4 - move up
+1 - move down
+5 - serve the ball
+### player 2
+รท - move up
+- - move down
+x - serve the ball
+
+No score system has been added, yet the game will be played indefinitely.
+
+## Building
+
+I would recommend using [fxsdk](https://gitea.planet-casio.com/Lephenixnoir/fxsdk) to build this with the following:
+
+`fxsdk build-fx`
+to build for fx series calculators. This should create the pong.g1a file, which you can then copy to your calculator.
+
+
diff --git a/assets-fx/example.png b/assets-fx/example.png
new file mode 100644
index 0000000..b26ba9a
--- /dev/null
+++ b/assets-fx/example.png
Binary files differ
diff --git a/assets-fx/fxconv-metadata.txt b/assets-fx/fxconv-metadata.txt
new file mode 100644
index 0000000..d435d5f
--- /dev/null
+++ b/assets-fx/fxconv-metadata.txt
@@ -0,0 +1,3 @@
+example.png:
+ type: bopti-image
+ name: img_example
diff --git a/assets-fx/icon.png b/assets-fx/icon.png
new file mode 100644
index 0000000..811e60f
--- /dev/null
+++ b/assets-fx/icon.png
Binary files differ
diff --git a/src/main.c b/src/main.c
new file mode 100644
index 0000000..d1e7ede
--- /dev/null
+++ b/src/main.c
@@ -0,0 +1,118 @@
+// Pong add-in by davidovski
+// Copyright (C) 2021 davidovski
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+#include <gint/display.h>
+#include <gint/keyboard.h>
+#include <gint/keycodes.h>
+#include <gint/clock.h>
+#include <math.h>
+
+
+int s1 = 0;
+int s2 = 0;
+
+float bx = 64;
+float by = 32;
+int bs = 2;
+
+float vx = 0;
+float vy = 0;
+
+float s = 1;
+
+int p1 = 24;
+int p2 = 24;
+int h = 16;
+int w = 2;
+int main(void)
+{
+ int tick = 1;
+ bool game = true;
+ while (game) {
+ dclear(C_WHITE);
+
+ drect(1, p1, 1 + w, p1 + h, C_BLACK);
+ drect(125, p2, 125 + w, p2 + h, C_BLACK);
+
+ drect(bx-1, by-1, bx+1, by+1, C_BLACK);
+
+ dupdate();
+
+
+ pollevent();
+
+ if (keydown(KEY_EXIT))
+ game = false;
+
+ if (keydown(KEY_1) && p1 + h < 64)
+ p1 += 1;
+ if (keydown(KEY_4) && p1 > 0)
+ p1 -= 1;
+ if (keydown(KEY_5) && bs == 1) {
+ bs = 0;
+ vy = 0;
+ vx = s;
+ }
+
+ if (keydown(KEY_SUB) && p2 + h < 64)
+ p2 += 1;
+ if (keydown(KEY_DIV) && p2 > 0)
+ p2 -= 1;
+ if (keydown(KEY_MUL) && bs == 2) {
+ bs = 0;
+ vy = 0;
+ vx = -s;
+ }
+
+ if (bs == 1) { //player 1 serve
+ bx = 5;
+ by = p1 + (h/2);
+ } else if (bs == 2) { // player 2 serve
+ bx = 123;
+ by = p2 + (h/2);
+ } else {
+
+ if (by < 1) vy *= -1;
+ if (by > 63) vy *= -1;
+
+ if (bx < 0) bs = 2;
+ if (bx > 128) bs = 1;
+
+
+ // collided with player 1
+ if (by > p1 && by < p1+h+2 && bx <= 5) {
+ int dy = p1+(h/2) - by;
+ vx = fabs(vx);
+ vy += dy * 0.1;
+
+ }
+ if (by > p2 && by < p2+h+2 && bx >= 123) {
+
+ int dy = p2+(h/2) - by;
+ vx = -fabs(vx);
+ vy += dy * -0.1;
+ }
+
+ bx += vx;
+ by += vy;
+ }
+
+ tick++;
+ sleep_us(20*1000);
+ }
+ game = true;
+ return 0;
+}