Pong
This commit is contained in:
commit
0a0f2de6a1
|
@ -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()
|
|
@ -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.
|
||||||
|
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 3.5 KiB |
|
@ -0,0 +1,3 @@
|
||||||
|
example.png:
|
||||||
|
type: bopti-image
|
||||||
|
name: img_example
|
Binary file not shown.
After Width: | Height: | Size: 8.1 KiB |
|
@ -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;
|
||||||
|
}
|
Loading…
Reference in New Issue