Skip to content
Snippets Groups Projects
Commit f39b44c3 authored by tag2y19's avatar tag2y19
Browse files

Write game

parents
No related branches found
No related tags found
No related merge requests found
build
#!/usr/bin/env sh
set -e
usage() {
printf 'Usage %s ' "${1}";
printf '[-h|--help] [-d|--debug] \n\t\t[-c \033[4mcflags\033[m] ';
printf '[-l \033[4mldlibs\033[m] ';
printf '[--ldflags \033[4mldflags\033[m]\n\t\t';
printf '[-p \033[4mpkgconfig package\033[m] ';
printf '[--cc \033[4mcompiler\033[m] ';
printf '\033[4mbuild dir\033[m\n\n';
}
ARGS=$(getopt -o "hdc:l:p:" \
--long "help,debug,cflags:,ldlibs:,ldflags:,pkg:,cc:" \
-n "$0" -- "$@");
if [ "$?" -ne "0" ]; then
exit 1;
fi
eval set -- "$ARGS";
zero="$0";
PKGS="gtk4 libadwaita-1 librsvg-2.0"
while true; do
case "$1" in
'-h'|'--help')
usage "${zero}";
exit 0;
;;
'-d'|'--debug')
DEBUG=1;
shift;
;;
'-c'|'--cflags')
CFLAGS="${CFLAGS} ${2}";
shift 2;
;;
'-l'|'--ldlibs')
LDLIBS="${LDLIBS} ${2}";
shift 2;
;;
'--ldflags')
LDFLAGS="${LDFLAGS} ${2}";
shift 2;
;;
'-p'|'--pkg')
case "${PKGS}" in
'*${2}*') ;;
*) PKGS="${PKGS} ${2}";;
esac
shift 2;
;;
'--cc')
CC="${2}";
shift 2;
;;
'--')
shift;
break;
;;
*)
usage "${zero}" >&2;
exit1 ;
;;
esac
done
if [ -z "${1}" ]; then
usage "${zero}" >&2;
exit 1;
fi
builddir="$(realpath "${1}")";
mkdir -p "${builddir}";
srcdir="$(realpath --relative-to "${builddir}" "$(dirname "${zero}")")";
srcs="$(cd "${builddir}/${srcdir}"; find ./src -name "*.c")";
ui_files="$(cd "${builddir}/${srcdir}"; find ./res/ -name "*.blp")";
res_files="$(cd "${builddir}/${srcdir}";
find ./res/ -name "*.gresource.xml")";
other_res_files=$(cd "${builddir}/${srcdir}";
find ./res -type f -! -name "*.blp" -a -! -name "*.gresource.xml");
if [ -n "${DEBUG}" ]; then
CFLAGS="${CFLAGS} -DDEBUG -O0 -g3";
else
CFLAGS="${CFLAGS} -O2";
fi
CFLAGS="${CFLAGS} -Wall -Wextra -Werror";
CFLAGS="${CFLAGS} -Wno-expansion-to-defined";
CFLAGS="${CFLAGS} -D_GNU_SOURCE";
CFLAGS="${CFLAGS} -I${srcdir}/inc -Iinc";
CFLAGS="${CFLAGS} $(pkg-config --cflags ${PKGS})";
LDLIBS="${LDLIBS} -lm -lwiringPi $(pkg-config --libs ${PKGS})";
{
# Blueprint {{{
cat << EOF
rule blueprint
command = blueprint-compiler compile --output \${out} \${in}
EOF
for ui_file in ${ui_files}; do
printf 'build %s: blueprint %s\n' \
"${ui_file%.blp}.ui" "${srcdir}/${ui_file}";
done
#}}}
# Resources {{{
cat << EOF
rule copy
command=cp \${in} \${out}
EOF
for res in ${other_res_files}; do
printf 'build %s: copy %s\n' "${res}" "${srcdir}/${res}";
done
printf '\n';
cat << EOF
rule resource
command = glib-compile-resources \${xml} --target=\${out} \$
--generate-source
EOF
for res in ${res_files}; do
printf "build %s: resource %s" "${res%.xml}.c" "${srcdir}/${res}";
for ui_file in ${ui_files}; do
printf ' %s' "${ui_file%.blp}.ui";
done
for res_file in ${other_res_files}; do
printf ' %s' "${res_file}";
done
printf '\n';
printf ' xml = %s\n' "${srcdir}/${res}";
done
printf '\n';
#}}}
# Regular old compiling {{{
cat << EOF
cflags = ${CFLAGS}
ldflags = ${LDFLAGS}
ldlibs = ${LDLIBS}
cc = ${CC:-gcc}
rule compile
deps = gcc
depfile = \${out}.d
command = \${cc} -MD -MF \${out}.d \${cflags} -c -o \${out} \${in}
rule link
command = \${cc} \${ldflags} -o \${out} \${in} \${ldlibs}
EOF
for src in ${srcs}; do
printf 'build %s: compile %s\n' "${src%.c}.o" "${srcdir}/${src}";
case ${src} in
./src/thirdparty/*)
printf ' cflags = %s -I%s\n' \
"${CFLAGS}" "${srcdir}/inc/thirdparty";
;;
*) ;;
esac
done
for res in ${res_files}; do
printf 'build %s: compile %s\n' "${res%.xml}.o" "${res%.xml}.c";
done
printf 'build game: link'
for src in ${srcs}; do
printf ' %s' "${src%.c}.o";
done
for src in ${ppsrcs}; do
printf ' %s' "${src%.cpp}.o";
done
for res in ${res_files}; do
printf ' %s' "${res%.xml}.o";
done
printf '\n\n';
#}}}
# Reconfiguring {{{
cat << EOF
rule configure
generator = 1
command = cd ${srcdir}; ./configure.sh ${ARGS}
build build.ninja: configure ${srcdir}/configure.sh
EOF
#}}}
cat << EOF
default game
EOF
} > ${builddir}/build.ninja
#ifndef MODELLER_APP_H
#define MODELLER_APP_H
#ifdef __cplusplus
extern "C" {
#endif
#include <adwaita.h>
#define GAME_APP_TYPE ( game_app_get_type() )
G_DECLARE_FINAL_TYPE(
GameApp, game_app, GAME, APP, AdwApplication );
GameApp* game_app_new();
void game_app_button_press( GameApp* app, int pin );
#ifdef __cplusplus
}
#endif
#endif
#ifndef GAME_PINS_H
#define GAME_PINS_H
#define LED_R1 4
#define LED_G1 25
#define LED_R2 27
#define LED_G2 23
#define LED_R3 22
#define LED_G3 24
#define LED_R4 17
#define LED_G4 26
#define BUTTON_G1 5
#define BUTTON_R1 6
#define BUTTON_G2 13
#define BUTTON_R2 19
#endif
#ifndef GAME_WINDOW_H
#define GAME_WINDOW_H
#ifdef __cplusplus
extern "C" {
#endif
#include "app.h"
#include <gtk/gtk.h>
#define GAME_WINDOW_TYPE ( game_window_get_type() )
G_DECLARE_FINAL_TYPE( GameWindow,
game_window, GAME, WINDOW, GtkWindow );
GameWindow* game_window_new( GameApp* app );
void game_window_button_press( GameWindow* window, int pin );
#ifdef __cplusplus
}
#endif
#endif
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
<gresource prefix="/xyz/tomg/game/">
<file preprocess="xml-stripblanks">res/window.ui</file>
<file preprocess="xml-stripblanks">res/logo.svg</file>
</gresource>
</gresources>
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 26.0.2, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg version="1.1" id="Artwork" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 1366 768" style="enable-background:new 0 0 1366 768;" xml:space="preserve">
<style type="text/css">
.st0{fill:#FFFFFF;}
</style>
<g>
<g>
<path class="st0" d="M503.92,334.59c0,11.82-9.68,20.37-23.14,20.37c-13.38,0-23.14-8.55-23.14-20.37v-36.03l9.64,0v36.03
c0,7.28,5.39,12.01,13.51,12.01c8.17,0,13.5-4.72,13.5-12.01v-36.03l9.64,0L503.92,334.59z"/>
<path class="st0" d="M534.95,313.26c7.21,0,13.52,4.7,13.52,14.85v25.75h-8.88v-25.13c0-5.21-3.12-7.58-7.18-7.58
c-3.41,0-7.85,1.65-11.52,4.75v27.96H512v-39.5h8.88v4.82C525.14,315.17,530.41,313.26,534.95,313.26L534.95,313.26z"/>
<path class="st0" d="M567.06,303.44c0,2.88-2.37,5.21-5.3,5.21s-5.3-2.33-5.3-5.21c0-2.88,2.37-5.21,5.3-5.21
S567.06,300.56,567.06,303.44z M557.32,353.86v-39.5h8.88v39.5H557.32z"/>
<path class="st0" d="M596.08,353.86h-9.49l-15.78-39.5h9.42l11.13,29.97l11.08-29.97h9.42L596.08,353.86z"/>
<path class="st0" d="M651.3,334.48c0,0.61-0.02,1.21-0.06,1.81l-28.93,0c0.02,0.24,0.05,0.47,0.09,0.7
c0.91,6.25,4.95,10.22,10.84,10.22c4,0,8.21-1.19,12.52-3.42l2.14,5.81c-4.55,3.5-10.05,5.37-15.24,5.37
c-11.81,0-19.6-9.32-19.6-20.85c0-11.61,7.76-20.92,19.51-20.86C644.85,313.26,651.33,322.28,651.3,334.48z M622.54,330.04h19.76
c-0.83-5.5-3.7-9.05-9.51-9.05C627.3,320.99,623.65,324.57,622.54,330.04z"/>
<path class="st0" d="M683.49,313.23l-1.52,8.62c-0.4-0.04-0.82-0.05-1.25-0.04c-4.44,0-9.49,1.84-13.67,5.4v26.65h-8.88v-39.5
h8.88v5.43c4.58-4.34,10.36-6.59,15.39-6.59C682.79,313.2,683.15,313.21,683.49,313.23z"/>
<path class="st0" d="M702.17,313.26c5.23,0,11.34,1.45,15.16,5.17l-3.71,5.8c-2.51-2.49-6.93-3.8-11.15-3.81
c-4.2,0-7.13,1.46-7.21,4.59c-0.08,2.38,1.61,3.26,8.24,4.97c6.46,1.66,15.14,3.57,15.16,12.51c0.03,9.13-9.14,12.48-17.07,12.48
c-6.36,0-12.87-2.16-16.16-6.25l3.71-5.82c2.42,3.24,7.41,4.94,12.14,4.95c4.92-0.01,8.53-1.93,8.55-5.21
c0.02-3.3-3.53-3.86-8.78-5.26c-10-2.62-14.57-4.95-14.56-11.84C686.48,316.49,694.32,313.26,702.17,313.26L702.17,313.26z"/>
<path class="st0" d="M734.96,303.44c0,2.88-2.37,5.21-5.3,5.21s-5.3-2.33-5.3-5.21c0-2.88,2.37-5.21,5.3-5.21
S734.96,300.56,734.96,303.44z M725.22,353.86v-39.5h8.88v39.5H725.22z"/>
<path class="st0" d="M768.79,352.26c-2.96,1.68-6.54,2.68-9.94,2.7c-6.32,0.02-12.03-3.36-12.03-12.18v-21.36h-7.72v-5.63
l7.35-1.43h0.37v-10.98h8.88v10.98h11.17v7.06H755.7v20.72c0,3.97,2.46,5.22,5.48,5.21c1.86-0.01,3.9-0.49,5.62-1.08
L768.79,352.26z"/>
<path class="st0" d="M790.99,369.66l-8.16,0.01l6.31-15.94l-17.39-39.37h9.65l11.98,28.67l11.34-28.67H814L790.99,369.66z"/>
<path class="st0" d="M876.62,334.11c0,11.53-7.99,20.85-20.3,20.85c-12.23,0-20.29-9.32-20.29-20.85
c0-11.61,8.07-20.93,20.29-20.86C868.63,313.26,876.62,322.58,876.62,334.11z M845.16,334.11c0,7.57,4.33,12.9,11.17,12.9
c6.92,0,11.17-5.26,11.17-12.9s-4.25-12.9-11.17-12.9C849.34,321.21,845.08,326.54,845.16,334.11z"/>
<path class="st0" d="M896.26,312.14v2.22h11.21v7.06h-11.21v32.44h-8.88v-32.44h-7.72v-5.63l7.35-1.43h0.37v-1.74
c0-10.76,5.96-15.65,13.63-15.63c3.65,0,7.84,1.09,11.82,3.21l-2.15,6.14c-3.01-1.18-5.83-1.79-8.37-1.77
C898.48,304.57,896.26,307.24,896.26,312.14z"/>
</g>
<g>
<path class="st0" d="M438.61,380.57l-10.34,12.7c-5.37-4.31-12.99-7.44-22.38-7.45c-8.52,0.01-14.37,2.66-14.77,10.27
c-0.22,5,2.28,6.73,17.99,10.96c13.49,3.64,31.18,7.85,31.31,27.19c0.13,20.09-19.2,27.97-35.12,27.97
c-13.67,0-28.54-5.76-36.01-15.33l10.71-12c5.59,6.85,16.1,10.81,25.31,10.78c9.85,0.03,15.49-4.4,15.55-10.79
c0.12-6.7-5.37-8.04-17.84-11.5c-21.31-5.95-31.44-10.44-31.46-26.33c0.03-20.21,16.58-27.86,34.49-27.86
C419.65,369.19,430.96,373.67,438.61,380.57z"/>
<path class="st0" d="M514.93,428.48c0,18.66-13.41,33.74-34.07,33.74c-20.53,0-34.07-15.08-34.07-33.74
c0-18.78,13.55-33.86,34.07-33.73C501.52,394.75,514.93,409.82,514.93,428.48z M464.91,428.48c0,10.8,6.17,18.41,15.94,18.41
c9.87,0,15.94-7.51,15.94-18.41c0-10.9-6.07-18.41-15.94-18.41C470.88,410.07,464.81,417.68,464.91,428.48z"/>
<path class="st0" d="M583.53,460.43h-17.89v-7.73c-6.54,6.27-14.71,9.52-22.04,9.52c-11.7,0-21.49-7.41-21.49-24.02v-41.66H540
l0,39.41c0,7.31,3.71,10.99,9.57,11.01c5.15,0.02,11.12-2.29,16.08-6.53v-43.89h17.89V460.43z"/>
<path class="st0" d="M639.36,457.85c-5.39,2.7-11.69,4.34-17.61,4.35c-11.07,0.03-20.8-5.61-20.8-20.61v-31.22h-12.28v-11.22
l11.88-2.62h0.39v-17.28h17.89v17.28h17.19v13.84h-17.19v28.9c0,6.16,3.45,8.25,8.23,8.24c2.72,0,5.8-0.69,8.69-1.6L639.36,457.85
z"/>
<path class="st0" d="M686.43,394.76c11.77,0,21.86,7.53,21.86,24.01v41.66h-17.89l0-39.41c0-7.63-4.67-11.02-10.73-11
c-5.02,0.01-10.99,2.36-16.05,6.57v43.84h-17.89v-89.45h17.89v33.34C670.33,398.03,678.7,394.75,686.43,394.76L686.43,394.76z"/>
<path class="st0" d="M780.87,460.43h-17.89v-6.85c-6.39,6-13.71,8.64-20.58,8.64c-16.23,0-27.6-14.95-27.6-33.74
c0-18.78,11.37-33.73,27.6-33.73c6.88,0,14.2,2.64,20.58,8.64v-6.85h17.89V460.43z M762.98,439.54v-22.11
c-5.04-5.02-11.57-7.56-16.62-7.57c-8.35,0.01-13.41,7.33-13.41,18.62c0,11.3,4.88,18.62,13.41,18.63
C751.41,447.1,757.94,444.56,762.98,439.54z"/>
<path class="st0" d="M873.48,394.75c11.44,0,21.1,7.41,21.07,24.02v41.66h-17.89l0-39.41c0.03-7.71-4.39-11.03-10.17-11.02
c-4.59,0.01-10.05,2.12-14.83,5.81c0.07,0.95,0.11,1.94,0.11,2.97v41.66h-17.89l0-39.41c0.01-7.66-4.33-11.01-9.96-11
c-4.68,0-10.24,2.32-14.93,6.39v44.02H791.1v-63.89h17.89v7.74c6.43-6.28,14.42-9.53,21.83-9.53c7.58,0,14.41,3.32,18.09,10.51
C856.07,398.48,865.17,394.75,873.48,394.75L873.48,394.75z"/>
<path class="st0" d="M943.7,394.75c16.66-0.06,27.89,14.95,27.92,33.74c-0.03,20.16-12.31,33.76-28.11,33.74
c-6.7,0.02-13.99-2.76-20.17-8.39v32.15h-17.89v-89.45h17.89v6.95C929.44,397.73,936.74,394.75,943.7,394.75L943.7,394.75z
M953.52,428.48c0.04-10.93-4.91-18.63-13.41-18.63c-5.15,0-11.59,2.5-16.77,7.67v21.58c5.25,5.21,11.39,8.21,16.75,8.17
C947.93,447.2,953.56,440.56,953.52,428.48z"/>
<path class="st0" d="M1025.15,457.85c-5.39,2.7-11.69,4.34-17.61,4.35c-11.07,0.03-20.8-5.61-20.8-20.61v-31.22h-12.28v-11.22
l11.88-2.62h0.39v-17.28h17.89v17.28h17.19v13.84h-17.19v28.9c0,6.16,3.45,8.25,8.23,8.24c2.72,0,5.8-0.69,8.69-1.6
L1025.15,457.85z"/>
<path class="st0" d="M1095.19,428.48c0,18.66-13.41,33.74-34.07,33.74c-20.53,0-34.07-15.08-34.07-33.74
c0-18.78,13.55-33.86,34.07-33.73C1081.78,394.75,1095.19,409.82,1095.19,428.48z M1045.18,428.48c0,10.8,6.17,18.41,15.94,18.41
c9.87,0,15.94-7.51,15.94-18.41c0-10.9-6.07-18.41-15.94-18.41C1051.14,410.07,1045.07,417.68,1045.18,428.48z"/>
<path class="st0" d="M1142.79,394.75c11.72,0,21.88,7.54,21.88,24.02v41.66h-17.89l0-39.41c0-7.62-4.48-11.01-10.35-11
c-4.91,0-11.17,2.36-16.43,6.62v43.79h-17.89v-63.89h17.89v7.79C1126.84,397.9,1135.31,394.75,1142.79,394.75L1142.79,394.75z"/>
</g>
<g>
<path class="st0" d="M216.55,310.32c0.15,0.05,0.29,0.1,0.43,0.16c-0.01-0.15-0.02-0.3-0.02-0.46c0-0.97,0.24-1.88,0.65-2.69
c-1.22-0.44-2.61-0.54-3.32-0.56c-0.2,0.69-0.52,2.03-0.48,3.33C214.71,309.96,215.65,310.03,216.55,310.32z"/>
<path class="st0" d="M220.9,314.47c0.4-0.19,0.83-0.33,1.28-0.4v-1.78c0-0.38,0.31-0.69,0.69-0.69s0.69,0.31,0.69,0.69v1.79
c0.45,0.07,0.88,0.21,1.28,0.4l1.81-2.49c0.02-0.03,0.48-0.69,0.48-1.96c0-2.34-1.91-4.25-4.25-4.25s-4.25,1.91-4.25,4.25
c0,1.27,0.46,1.94,0.48,1.96L220.9,314.47z"/>
<path class="st0" d="M213.41,319.99c1.21,0.39,1.98,0.16,2.02,0.15l2.95-0.96c-0.03-0.2-0.04-0.41-0.04-0.62
c0-0.24,0.02-0.47,0.05-0.7l-1.72-0.56c-0.36-0.12-0.56-0.51-0.44-0.87c0.12-0.36,0.51-0.56,0.87-0.44l1.71,0.56
c0.2-0.4,0.46-0.77,0.76-1.09l-1.81-2.49c-0.02-0.03-0.51-0.67-1.72-1.06c-0.43-0.14-0.88-0.21-1.32-0.21
c-0.66,0-1.32,0.16-1.93,0.47c-1.01,0.52-1.76,1.39-2.11,2.48C209.95,316.86,211.18,319.26,213.41,319.99z"/>
<path class="st0" d="M228.76,310.48c0.14-0.06,0.28-0.11,0.43-0.16c0.9-0.29,1.84-0.36,2.76-0.22c0.04-1.29-0.3-2.64-0.5-3.33
c-0.71,0.02-2.1,0.13-3.32,0.57c0.41,0.8,0.64,1.71,0.64,2.67C228.77,310.18,228.77,310.33,228.76,310.48z"/>
<path class="st0" d="M226.93,316.54l1.72-0.56c0.36-0.12,0.75,0.08,0.87,0.44s-0.08,0.75-0.44,0.87l-1.73,0.56
c0.04,0.23,0.05,0.46,0.05,0.7c0,0.21-0.02,0.42-0.04,0.62l2.96,0.96c0.03,0.01,0.81,0.24,2.01-0.15
c2.23-0.72,3.46-3.13,2.73-5.36c-0.35-1.08-1.1-1.96-2.11-2.48c-1.01-0.52-2.16-0.61-3.24-0.26c-1.21,0.39-1.7,1.03-1.72,1.06
l-1.81,2.5C226.47,315.78,226.73,316.14,226.93,316.54z"/>
<path class="st0" d="M232.84,321.56c-0.15,0.05-0.3,0.09-0.44,0.13c0.1,0.11,0.19,0.23,0.28,0.36c0.57,0.78,0.92,1.66,1.05,2.55
c1.25-0.36,2.43-1.1,3.02-1.5c-0.24-0.67-0.77-1.95-1.57-2.98C234.55,320.76,233.75,321.26,232.84,321.56z"/>
<path class="st0" d="M221.27,328.02c0.75-1.03,0.77-1.84,0.77-1.87v-3.13c-0.44-0.08-0.85-0.22-1.23-0.42l-1.08,1.49
c-0.13,0.19-0.34,0.28-0.56,0.28c-0.14,0-0.28-0.04-0.4-0.13c-0.31-0.22-0.38-0.65-0.15-0.96l1.08-1.49
c-0.31-0.31-0.58-0.66-0.79-1.04l-2.96,0.96c-0.03,0.01-0.79,0.28-1.54,1.31c-1.38,1.9-0.96,4.56,0.94,5.94
C217.23,330.34,219.9,329.91,221.27,328.02z"/>
<path class="st0" d="M295.4,332.66c11.72-1.36,12.02-1.18,13.74-2.59v-35.69c0,0-2.92,3.02-13.08,4.43s-14.6,4.48-14.6,5.37v33.16
C281.46,337.34,283.3,334.06,295.4,332.66z"/>
<path class="st0" d="M277.97,337.34v-33.16c0-0.89-4.44-3.96-14.6-5.37s-13.08-4.43-13.08-4.43v35.69
c1.72,1.41,2.02,1.23,13.74,2.59C276.13,334.06,277.97,337.34,277.97,337.34z"/>
<path class="st0" d="M222.87,322.06c1.93,0,3.51-1.57,3.51-3.51c0-1.93-1.57-3.51-3.51-3.51c-1.93,0-3.51,1.57-3.51,3.51
C219.36,320.49,220.93,322.06,222.87,322.06z"/>
<path class="st0" d="M229.81,321.71c0,0-0.01,0-0.01,0l-2.96-0.96c-0.21,0.38-0.48,0.74-0.79,1.04l1.08,1.49
c0.22,0.31,0.16,0.74-0.15,0.96c-0.12,0.09-0.26,0.13-0.4,0.13c-0.21,0-0.42-0.1-0.56-0.28l-1.09-1.49
c-0.38,0.2-0.8,0.34-1.23,0.42v3.13c0,0.03,0.02,0.84,0.77,1.87c1.38,1.9,4.04,2.32,5.94,0.94c1.9-1.38,2.32-4.04,0.94-5.94
C230.6,322,229.85,321.72,229.81,321.71z"/>
<path class="st0" d="M223.12,328.99c-0.09-0.13-0.18-0.26-0.26-0.38c-0.08,0.13-0.16,0.25-0.26,0.38
c-0.57,0.78-1.29,1.38-2.1,1.79c0.73,1.07,1.79,1.97,2.36,2.4c0.56-0.44,1.62-1.34,2.35-2.41
C224.41,330.36,223.69,329.77,223.12,328.99z"/>
<path class="st0" d="M213.06,322.05c0.09-0.13,0.19-0.25,0.28-0.36c-0.14-0.04-0.29-0.08-0.44-0.13c-0.92-0.3-1.71-0.8-2.35-1.45
c-0.79,1.03-1.32,2.31-1.56,2.99c0.59,0.4,1.77,1.13,3.02,1.49C212.14,323.69,212.49,322.82,213.06,322.05z"/>
<path class="st0" d="M336.79,328.99c-0.09-0.13-0.18-0.26-0.26-0.38c-0.08,0.13-0.16,0.25-0.26,0.38
c-0.57,0.78-1.29,1.38-2.1,1.79c0.73,1.07,1.79,1.97,2.36,2.4c0.56-0.44,1.62-1.34,2.35-2.41
C338.08,330.36,337.36,329.77,336.79,328.99z"/>
<path class="st0" d="M334.94,328.02c0.75-1.03,0.77-1.84,0.77-1.87v-3.13c-0.44-0.08-0.85-0.22-1.23-0.42l-1.08,1.49
c-0.13,0.19-0.34,0.28-0.56,0.28c-0.14,0-0.28-0.04-0.4-0.13c-0.31-0.22-0.38-0.65-0.15-0.96l1.08-1.49
c-0.31-0.31-0.58-0.66-0.79-1.04l-2.96,0.96c-0.03,0.01-0.79,0.28-1.54,1.31c-1.38,1.9-0.96,4.56,0.94,5.94
C330.9,330.34,333.56,329.91,334.94,328.02z"/>
<path class="st0" d="M343.47,321.71c0,0-0.01,0-0.01,0l-2.96-0.96c-0.21,0.38-0.48,0.74-0.79,1.04l1.08,1.49
c0.22,0.31,0.16,0.74-0.15,0.96c-0.12,0.09-0.26,0.13-0.4,0.13c-0.21,0-0.42-0.1-0.56-0.28l-1.09-1.49
c-0.38,0.2-0.8,0.34-1.23,0.42v3.13c0,0.03,0.02,0.84,0.77,1.87c1.38,1.9,4.04,2.32,5.94,0.94c1.9-1.38,2.32-4.04,0.94-5.94
C344.27,322,343.51,321.72,343.47,321.71z"/>
<path class="st0" d="M348.73,314.63c-0.35-1.08-1.1-1.96-2.11-2.48c-1.01-0.52-2.17-0.61-3.25-0.26c-1.21,0.39-1.7,1.03-1.72,1.06
l-1.81,2.5c0.3,0.32,0.56,0.69,0.76,1.09l1.72-0.56c0.36-0.12,0.75,0.08,0.87,0.44c0.12,0.36-0.08,0.75-0.44,0.87l-1.73,0.56
c0.04,0.23,0.05,0.46,0.05,0.7c0,0.21-0.02,0.42-0.04,0.62l2.96,0.96c0.03,0.01,0.81,0.24,2.01-0.15
C348.23,319.26,349.45,316.86,348.73,314.63z"/>
<path class="st0" d="M346.51,321.56c-0.15,0.05-0.3,0.09-0.44,0.13c0.1,0.11,0.19,0.23,0.28,0.36c0.57,0.78,0.91,1.66,1.05,2.55
c1.25-0.36,2.43-1.1,3.02-1.5c-0.24-0.67-0.77-1.95-1.57-2.98C348.21,320.76,347.42,321.26,346.51,321.56z"/>
<path class="st0" d="M329.09,320.14l2.95-0.96c-0.03-0.2-0.04-0.41-0.04-0.62c0-0.24,0.02-0.47,0.05-0.7l-1.72-0.56
c-0.36-0.12-0.56-0.51-0.44-0.87c0.12-0.36,0.51-0.56,0.87-0.44l1.71,0.56c0.2-0.4,0.46-0.77,0.76-1.09l-1.81-2.49
c-0.02-0.03-0.51-0.67-1.72-1.06c-0.43-0.14-0.88-0.21-1.32-0.21c-0.66,0-1.32,0.16-1.93,0.47c-1.01,0.52-1.76,1.39-2.11,2.48
c-0.72,2.23,0.5,4.63,2.73,5.36C328.28,320.38,329.06,320.15,329.09,320.14z"/>
<path class="st0" d="M356.42,297.33c-1.36-0.64-34.08-15.54-76.71-15.54c-42.61,0-75.32,14.9-76.7,15.53l-2.64,1.21l0,68.83
l0.04-0.02c0.31,9.26,1.81,26.35,7.97,45.15c12.05,36.76,36.35,62.15,70.26,73.43c0.45,0.15,0.92,0.22,1.39,0.22
c0.47,0,0.94-0.07,1.39-0.22c33.92-11.28,58.11-36.71,69.93-73.52c6-18.67,7.4-35.65,7.67-44.97l0.01,0v-0.21v-68.67
L356.42,297.33z M243.09,301.5c0-0.24,0.1-0.46,0.28-0.62c0.18-0.15,0.42-0.22,0.65-0.19l1.85,0.28v-3.62
c0-0.26,0.12-0.51,0.34-0.66c0.21-0.15,0.48-0.19,0.73-0.11l1.59,0.52v-2.71c0-0.63,0.34-1.22,0.89-1.53
c0.27-0.16,0.57-0.23,0.88-0.23c0.31,0,0.62,0.08,0.89,0.24c0.27,0.16,0.53,0.32,0.8,0.5c1.22,0.78,2.73,1.75,6.88,2.75
c1.18,0.29,2.72,0.56,4.34,0.85c2.8,0.5,5.98,1.06,8.83,1.93c3.54,1.08,5.93,2.44,7.3,4.17c0.25,0.31,0.38,0.69,0.38,1.08
c0-0.39,0.14-0.77,0.38-1.08c1.38-1.73,3.76-3.09,7.3-4.17c2.86-0.87,6.03-1.43,8.83-1.93c1.62-0.29,3.15-0.56,4.34-0.85
c4.14-1,5.66-1.97,6.88-2.75c0.27-0.17,0.53-0.34,0.8-0.5s0.58-0.24,0.89-0.24c0.3,0,0.61,0.08,0.88,0.23
c0.55,0.31,0.89,0.9,0.89,1.53v2.71l1.59-0.52c0.25-0.08,0.52-0.04,0.73,0.11c0.21,0.15,0.34,0.4,0.34,0.66v3.62l1.85-0.28
c0.23-0.03,0.47,0.03,0.65,0.19c0.18,0.15,0.28,0.38,0.28,0.62c0,0,0,26.97,0,29.8c0,2.83-2.13,4.03-7.44,3.75
c-18.04-0.55-24.8,4.11-24.8,4.11c-0.04,1.67-1.71,2.71-4.39,2.71c-2.68,0-4.35-1.04-4.39-2.71c0,0-6.77-4.66-24.8-4.11
c-5.31,0.28-7.44-0.92-7.44-3.75C243.09,328.48,243.09,301.5,243.09,301.5z M278.33,359.78c1.1,0.48,4.12,2.44,4.92,4.52
c0.28,0.72-0.25,1.77-0.6,2.55c-1.05,2.33-1.9,4.14-2.02,4.41c-0.25,0.49-1.83,3.77-2,7.86c-0.12,2.8,0.4,6.33,2.83,9.55
c-0.34-0.04-0.52-0.06-0.52-0.06c-2.36-0.2-4.88,0.12-5.9,0.27c-1.07,0.06-1.64-0.42-2.11-1.09c-1.45-2.07-3.81-3.95-7.53-5.06
c-4.49-1.35-10.41-2.94-15.33-4.22c0,0-0.01,0-0.01,0c-9.41-2.65-6.89-8.19-9.15-7.97c-2.26,0.22-1.08,3.99-0.22,5.54
c-3.81-0.84-5.85-2.22-5.84-2.21c-6.94-5.56-6.62-12.38-5.07-17.24c13.08-3.52,30.72-6.9,50.26-6.9c0.23,0,0.45,0.01,0.68,0.01
c2.19,1.83,6.74,6.07,5.17,9.66c-0.11,0.25-0.21,0.51-0.32,0.77c-2.91-1.99-5.79-3.13-6.24-3.32c-1.22-0.52-2.34-0.58-2.73,0.38
C276.2,358.18,277.12,359.25,278.33,359.78z M284.91,373.43l0.05-0.09c0.14-0.29,3.38-7.2,5.37-12.12
c1.83-4.51-1.77-8.96-4.26-11.36c8.19,0.29,15.94,1.13,23.08,2.28c1.04,0.88,2.16,1.73,2.33,2.64c-6.56-0.58-10.15,0.88-9.74,3.2
c0.2,0.94,1.64,1.26,2.92,0.94c1.13-0.2,6.07-0.69,9.73,2.1c1.67,1.27,2.66,3.36,2.95,6.19c0.01,0.07,0.01,0.14,0.02,0.21
c0.02,0.26,0.04,0.52,0.05,0.79c0.16,4.52-1.87,8.47-6.06,11.76c-13.5,10.6-21.42,9.14-22.55,8.85c-3.75-2.22-5.52-5.27-5.39-9.34
C283.52,376.17,284.9,373.45,284.91,373.43z M207.75,323.91l-0.37-0.29l0.13-0.45c0.03-0.11,0.73-2.48,2.16-4.18
c-0.86-1.42-1.12-3.19-0.57-4.88c0.49-1.5,1.53-2.72,2.94-3.44c0.13-0.07,0.27-0.13,0.41-0.19c-0.17-2.21,0.65-4.53,0.69-4.64
l0.16-0.44l0.47-0.02c0.12,0,2.59-0.07,4.64,0.77c1.08-1.25,2.68-2.05,4.47-2.05c1.79,0,3.39,0.8,4.48,2.06
c2.05-0.84,4.51-0.79,4.62-0.78l0.47,0.01l0.16,0.44c0.04,0.11,0.87,2.44,0.71,4.65c0.13,0.06,0.26,0.11,0.39,0.18
c1.41,0.72,2.45,1.94,2.94,3.44c0.55,1.7,0.29,3.48-0.58,4.9c1.43,1.69,2.14,4.05,2.17,4.16l0.13,0.45l-0.37,0.29
c-0.09,0.07-2.05,1.58-4.21,2.11c-0.14,1.65-0.97,3.23-2.41,4.28c-1.05,0.76-2.26,1.13-3.46,1.13c-0.46,0-0.92-0.05-1.37-0.16
c-1.16,1.89-3.19,3.28-3.28,3.35l-0.39,0.26l-0.39-0.26c-0.1-0.06-2.14-1.46-3.3-3.35c-0.44,0.1-0.9,0.16-1.35,0.16
c-1.2,0-2.42-0.37-3.46-1.13c-1.45-1.05-2.28-2.64-2.41-4.3C209.8,325.47,207.84,323.98,207.75,323.91z M225.61,369.04
c-3.34-2.13-5.9-5.35-7.31-8.95c2.11-0.71,4.48-1.45,7.08-2.22c0,0,0,0.01,0,0.01C224.72,360.85,224.39,365.16,225.61,369.04z
M342.79,409.86c-4.88,15.07-11.96,28.13-21.05,38.8c-10.99,12.91-25.02,22.38-41.71,28.19c-16.7-5.81-30.77-15.28-41.83-28.18
c-9.14-10.66-16.3-23.71-21.27-38.77c-6.81-20.63-7.62-39.53-7.67-46.51c1.29-0.52,3.05-1.2,5.21-1.98
c1.45,4.4,4.71,8.38,10.01,12.12c7,4.93,14.63,7.15,14.95,7.24c0,0,15.45,4.46,24.6,7.2c5.83,1.86,5.56,6.18,4.63,9.15
c-0.07,0.18-0.13,0.36-0.2,0.54c-0.12,0.36-0.26,0.73-0.42,1.1c-0.01,0.02-0.01,0.03-0.02,0.05c-0.16,0.36-0.33,0.73-0.53,1.1
c-0.25-0.24-0.85-3.73-7.26-6.89s-16.11-1.72-17.2-1.19c-0.55,0.27-0.56,0.55-0.08,0.91c0.28,0.21,0.59,0.39,0.82,0.65
c1.53,1.54,1.29,5.13,5.79,9.79c1.38,1.24,2.9,2.28,4.55,3.12c6.38,2.98,9.33,1.62,10.51,1.49c-0.08,0.22-0.13,0.45-0.23,0.66
c-9.79,17.22-13.65,32.03-14.21,44.39l1.97,1.66c3.79,3.25,7.87,6.18,12.21,8.77v-0.01l3.61,2.06c3.84,2.07,7.88,3.88,12.08,5.44
c11.54-4.27,21.72-10.47,30.31-18.47c0,0,1.12-1.07,1.79-1.84c-1.24-0.12-2.49-0.23-3.78-0.29c-16.56-0.72-21.3-7.3-18.41-17.26
c0.09-0.31,0.56-1.32-0.08-1.89c-0.52-0.46-1.39-0.09-1.73,0.08c-17.04,8.09-21.83,32.11-21.83,32.11s-0.68-19.19,12.69-32.01
s24.63-10.23,25.13-10.23c5.43,1.29,6.59-1.91,6.88-4.48c0.01-0.36,0.17-0.7,0.47-0.97c2.5-1.75,5.29-8.7,2.47-11.2
c-1.38-1.29-6.94-2.68-8.3-3.13c-1.22-0.41-2.44-0.81-3.58-1.44c-0.7-0.39-1.31-0.82-1.64-1.61c-0.99-2.84-3.67-4.4-4.3-4.83
c5.63-1.27,11.74-4.46,18.18-9.52c1.96-1.54,3.56-3.23,4.8-5.04c1.22-1.38,1.3-2.97,3.49-3.9c4.59-2.19,4.45-4.59,3.66-5.39
c-0.8-0.8-3.74,0.34-4.09,0.68c0.1-1.33,0.06-2.69-0.14-4.09c-0.01-0.05-0.02-0.11-0.03-0.16c-0.02-0.1-0.03-0.21-0.05-0.31
c-0.03-0.19-0.06-0.38-0.1-0.57c-0.01-0.04-0.02-0.08-0.02-0.12c-0.93-4.71-3.56-8.68-6.26-11.56
c16.87,3.29,29.44,7.99,34.57,10.09C350.15,370.42,349.44,389.27,342.79,409.86z M351.66,323.9c-0.09,0.07-2.05,1.58-4.21,2.11
c-0.14,1.65-0.97,3.23-2.41,4.28c-1.05,0.76-2.26,1.13-3.46,1.13c-0.46,0-0.92-0.05-1.37-0.16c-1.16,1.89-3.19,3.28-3.28,3.35
l-0.39,0.26l-0.39-0.26c-0.1-0.06-2.14-1.46-3.3-3.35c-0.44,0.1-0.9,0.16-1.35,0.16c-1.2,0-2.42-0.37-3.46-1.13
c-1.45-1.05-2.27-2.64-2.41-4.3c-2.15-0.52-4.11-2.02-4.2-2.08l-0.37-0.29l0.13-0.45c0.03-0.11,0.73-2.48,2.16-4.18
c-0.86-1.42-1.12-3.19-0.57-4.88c0.49-1.5,1.53-2.72,2.94-3.44c0.13-0.07,0.27-0.13,0.41-0.19c-0.17-2.21,0.65-4.53,0.69-4.64
l0.16-0.44l0.47-0.02c0.12,0,2.59-0.07,4.64,0.77c1.08-1.25,2.68-2.05,4.47-2.05c1.79,0,3.39,0.8,4.48,2.06
c2.05-0.84,4.51-0.79,4.62-0.78l0.47,0.01l0.16,0.44c0.04,0.11,0.87,2.44,0.71,4.65c0.13,0.06,0.26,0.11,0.39,0.18
c1.41,0.72,2.45,1.94,2.94,3.44c0.55,1.7,0.29,3.48-0.58,4.9c1.44,1.69,2.14,4.05,2.17,4.16l0.13,0.45L351.66,323.9z"/>
<path class="st0" d="M342.43,310.48c0.14-0.06,0.28-0.11,0.43-0.16c0.9-0.29,1.84-0.36,2.76-0.22c0.04-1.29-0.3-2.64-0.5-3.33
c-0.71,0.02-2.1,0.13-3.31,0.57c0.41,0.8,0.64,1.71,0.64,2.67C342.44,310.18,342.44,310.33,342.43,310.48z"/>
<path class="st0" d="M334.57,314.47c0.4-0.19,0.83-0.33,1.28-0.4v-1.78c0-0.38,0.31-0.69,0.69-0.69c0.38,0,0.69,0.31,0.69,0.69
v1.79c0.45,0.07,0.88,0.21,1.28,0.4l1.81-2.49c0.02-0.03,0.48-0.69,0.48-1.96c0-2.34-1.91-4.25-4.25-4.25
c-2.34,0-4.25,1.91-4.25,4.25c0,1.27,0.46,1.94,0.48,1.96L334.57,314.47z"/>
<path class="st0" d="M324.21,320.11c-0.79,1.03-1.32,2.31-1.56,2.99c0.59,0.4,1.77,1.13,3.02,1.49c0.14-0.89,0.49-1.76,1.05-2.54
c0.09-0.13,0.19-0.25,0.28-0.36c-0.14-0.04-0.29-0.08-0.44-0.13C325.65,321.26,324.85,320.75,324.21,320.11z"/>
<path class="st0" d="M333.03,318.56c0,1.93,1.57,3.51,3.51,3.51s3.51-1.57,3.51-3.51c0-1.93-1.57-3.51-3.51-3.51
S333.03,316.62,333.03,318.56z"/>
<path class="st0" d="M330.22,310.32c0.15,0.05,0.3,0.1,0.43,0.16c-0.01-0.15-0.02-0.3-0.02-0.46c0-0.97,0.23-1.88,0.65-2.69
c-1.22-0.44-2.61-0.54-3.32-0.56c-0.2,0.69-0.52,2.03-0.48,3.33C328.38,309.96,329.32,310.03,330.22,310.32z"/>
</g>
</g>
</svg>
using Gtk 4.0;
template $GameWindow: Gtk.Window {
title: "Game";
width-request: 640;
height-request: 480;
realize => $realise();
Gtk.DrawingArea area {
}
}
#include "app.h"
#include "pins.h"
#include "window.h"
/* TYPES!!! */
struct _GameApp {
AdwApplication parent;
GameWindow* window;
};
G_DEFINE_TYPE( GameApp, game_app, ADW_TYPE_APPLICATION );
/* PROTOTYPES!!! */
static void game_app_class_init( GameAppClass* class );
static void game_app_init( GameApp* app );
static void activate( GApplication* app );
/* PUBLIC FUNK!!! */
GameApp* game_app_new() {
return g_object_new( GAME_APP_TYPE,
"application-id", "xyz.tomg.game", NULL );
}
void game_app_button_press( GameApp* app, int pin ) {
game_window_button_press( app->window, pin );
}
/* PRIVATE FUNK!!! */
static void game_app_class_init( GameAppClass* class ) {
G_APPLICATION_CLASS( class )->activate = &activate;
}
static void game_app_init( GameApp* app ) {
(void) app;
}
static void activate( GApplication* app ) {
GameWindow* window = game_window_new( GAME_APP( app ) );
GAME_APP( app )->window = window;
gtk_window_present( GTK_WINDOW( window ) );
}
#include "app.h"
#include "pins.h"
#include <adwaita.h>
#include <stdio.h>
#include <wiringPi.h>
/* BAD GLOBAL VARIABLES */
static GameApp* app = NULL;
/* PROTOTYPES!!! */
static void isr_g1();
static void isr_r1();
static void isr_g2();
static void isr_r2();
/* PUBLIC FUNK!!! */
int main( int argc, char** argv ) {
wiringPiSetupPinType( WPI_PIN_BCM );
pinMode( LED_G1, OUTPUT );
pinMode( LED_R1, OUTPUT );
pinMode( LED_G2, OUTPUT );
pinMode( LED_R2, OUTPUT );
pinMode( LED_G3, OUTPUT );
pinMode( LED_R3, OUTPUT );
pinMode( LED_G4, OUTPUT );
pinMode( LED_R4, OUTPUT );
digitalWrite( LED_G1, LOW );
digitalWrite( LED_R1, LOW );
digitalWrite( LED_G2, LOW );
digitalWrite( LED_R2, LOW );
digitalWrite( LED_G3, LOW );
digitalWrite( LED_R3, LOW );
digitalWrite( LED_G4, LOW );
digitalWrite( LED_R4, LOW );
pullUpDnControl( BUTTON_G1, PUD_UP );
pullUpDnControl( BUTTON_R1, PUD_UP );
pullUpDnControl( BUTTON_G2, PUD_UP );
pullUpDnControl( BUTTON_R2, PUD_UP );
wiringPiISR( BUTTON_G1, INT_EDGE_FALLING, &isr_g1 );
wiringPiISR( BUTTON_R1, INT_EDGE_FALLING, &isr_r1 );
wiringPiISR( BUTTON_G2, INT_EDGE_FALLING, &isr_g2 );
wiringPiISR( BUTTON_R2, INT_EDGE_FALLING, &isr_r2 );
app = game_app_new();
int ret = g_application_run( G_APPLICATION( app ), argc, argv );
digitalWrite( LED_G1, LOW );
digitalWrite( LED_R1, LOW );
digitalWrite( LED_G2, LOW );
digitalWrite( LED_R2, LOW );
digitalWrite( LED_G3, LOW );
digitalWrite( LED_R3, LOW );
digitalWrite( LED_G4, LOW );
digitalWrite( LED_R4, LOW );
return ret;
}
/* PRIVATE FUNK!!! */
static int button_cb( void* pin ) {
game_app_button_press( app, *( (int*) pin ) );
return G_SOURCE_REMOVE;
}
static void isr_g1() {
static int pin = BUTTON_G1;
g_idle_add( &button_cb, &pin );
}
static void isr_r1() {
static int pin = BUTTON_R1;
g_idle_add( &button_cb, &pin );
}
static void isr_g2() {
static int pin = BUTTON_G2;
g_idle_add( &button_cb, &pin );
}
static void isr_r2() {
static int pin = BUTTON_R2;
g_idle_add( &button_cb, &pin );
}
#include "window.h"
#include "pins.h"
#include <assert.h>
#include <librsvg/rsvg.h>
#include <pango/pangocairo.h>
#include <wiringPi.h>
/* TYPES!!! */
struct _GameWindow {
GtkWindow parent;
GtkDrawingArea* area;
RsvgHandle* logo;
enum {
SPLASH,
WAIT,
LIT,
DONE,
} state;
struct {
int team_1;
int team_2;
} score;
enum { RED, GREEN } colour;
bool g1_bouncing;
bool r1_bouncing;
bool g2_bouncing;
bool r2_bouncing;
};
G_DEFINE_TYPE(
GameWindow, game_window, GTK_TYPE_WINDOW );
enum colour {
WHITE, UNIVERSITY_BLUE,
};
/* PROTOTYPES!!! */
static void game_window_class_init( GameWindowClass* class );
static void game_window_init( GameWindow* window );
static void realise( GtkWidget* widget, void* data );
static void draw( GtkDrawingArea* area, cairo_t* cr,
int width, int height, void* data );
static void set_cario_colour( cairo_t* cr, enum colour colour );
static int bounce_reset( void* data );
static int light( void* data );
/* PUBLIC FUNK!!! */
GameWindow* game_window_new( GameApp* app ) {
return g_object_new( GAME_WINDOW_TYPE,
"application", app, NULL );
}
void game_window_button_press( GameWindow* window, int pin ) {
bool* bouncing = NULL;
switch ( pin ) {
case BUTTON_G1:
bouncing = &window->g1_bouncing;
break;
case BUTTON_R1:
bouncing = &window->r1_bouncing;
break;
case BUTTON_G2:
bouncing = &window->g2_bouncing;
break;
case BUTTON_R2:
bouncing = &window->r2_bouncing;
break;
}
assert( NULL != bouncing );
if ( *bouncing ) {
return;
}
fprintf( stderr, "Ping %d\n", pin );
*bouncing = true;
g_timeout_add( 200, bounce_reset, bouncing );
if ( !digitalRead( BUTTON_G1 ) && !digitalRead( BUTTON_R1 ) &&
!digitalRead( BUTTON_G2 ) && !digitalRead( BUTTON_R2 ) ) {
fprintf( stderr, "All pressed, reset\n" );
window->state = SPLASH;
window->score.team_1 = 0;
window->score.team_2 = 0;
gtk_widget_queue_draw( GTK_WIDGET( window->area ) );
return;
}
switch ( window->state ) {
case SPLASH: {
fprintf( stderr, "Splash -> wait\n" );
window->state = WAIT;
window->score.team_1 = 0;
window->score.team_2 = 0;
g_timeout_add( g_random_int_range( 1000, 5000 ),
light, window );
break;
}
case WAIT: {
break;
}
case LIT: {
switch ( pin ) {
case BUTTON_G1:
case BUTTON_R1: {
fprintf( stderr, "Team 1 press, " );
if ( ( GREEN == window->colour ) ==
( BUTTON_G1 == pin ) ) {
fprintf( stderr, "correct\n" );
window->score.team_1++;
digitalWrite( LED_G1, LOW );
digitalWrite( LED_R1, LOW );
digitalWrite( LED_G2, LOW );
digitalWrite( LED_R2, LOW );
digitalWrite( LED_G3, LOW );
digitalWrite( LED_R3, LOW );
digitalWrite( LED_G4, LOW );
digitalWrite( LED_R4, LOW );
window->state = WAIT;
} else {
fprintf( stderr, "wrong\n" );
}
break;
}
case BUTTON_G2:
case BUTTON_R2: {
fprintf( stderr, "Team 2 press, " );
if ( ( GREEN == window->colour ) ==
( BUTTON_G2 == pin ) ) {
fprintf( stderr, "correct\n" );
window->score.team_2++;
digitalWrite( LED_G1, LOW );
digitalWrite( LED_R1, LOW );
digitalWrite( LED_G2, LOW );
digitalWrite( LED_R2, LOW );
digitalWrite( LED_G3, LOW );
digitalWrite( LED_R3, LOW );
digitalWrite( LED_G4, LOW );
digitalWrite( LED_R4, LOW );
window->state = WAIT;
} else {
fprintf( stderr, "wrong\n" );
}
break;
}
}
if ( window->score.team_2 >= 10 ||
window->score.team_1 >= 10 ) {
window->state = DONE;
}
if ( window->state == WAIT ) {
g_timeout_add( g_random_int_range( 1000, 5000 ),
light, window );
}
break;
}
case DONE: {
break;
}
}
gtk_widget_queue_draw( GTK_WIDGET( window->area ) );
}
/* PRIVATE FUNK!!! */
static void game_window_class_init( GameWindowClass* class ) {
gtk_widget_class_set_template_from_resource(
GTK_WIDGET_CLASS( class ), "/xyz/tomg/game/res/window.ui" );
gtk_widget_class_bind_template_child(
GTK_WIDGET_CLASS( class ), GameWindow, area );
gtk_widget_class_bind_template_callback_full(
GTK_WIDGET_CLASS( class ), "realise",
G_CALLBACK( &realise ) );
}
static void game_window_init( GameWindow* window ) {
gtk_widget_init_template( GTK_WIDGET( window ) );
GBytes* logo_svg = g_resources_lookup_data(
"/xyz/tomg/game/res/logo.svg", 0, NULL );
GError* error = NULL;
const char* data = g_bytes_get_data( logo_svg, NULL );
window->logo = rsvg_handle_new_from_data(
(const unsigned char*) data, strlen( data ), &error );
if ( NULL != error ) {
fprintf( stderr, "%s\n", error->message );
}
g_bytes_unref( logo_svg );
window->state = SPLASH;
gtk_drawing_area_set_draw_func(
window->area, &draw, (void*) window, NULL );
gtk_widget_set_cursor( GTK_WIDGET( window ),
gdk_cursor_new_from_name( "none", NULL ) );
}
static void realise( GtkWidget* widget, void* data ) {
gtk_window_fullscreen( GTK_WINDOW( widget ) );
(void) data;
}
static void draw( GtkDrawingArea* area, cairo_t* cr,
int width, int height, void* data ) {
(void) area;
GameWindow* window = (GameWindow*) data;
set_cario_colour( cr, UNIVERSITY_BLUE );
cairo_paint( cr );
PangoFontDescription* desc = pango_font_description_new();
pango_font_description_set_family( desc, "Roboto" );
pango_font_description_set_absolute_size( desc, PANGO_SCALE * (
0.8 * height < 0.66 * width ? 0.8 * height : 0.66 * width ) );
switch ( window->state ) {
case SPLASH: {
rsvg_handle_render_document( window->logo,
cr, &(RsvgRectangle) { 0, 0, width, height, }, NULL );
break;
}
case WAIT:
case LIT: {
char buffer[5];
snprintf( buffer, sizeof buffer,
"%d", window->score.team_1 );
int lw, lh;
PangoLayout* layout = pango_cairo_create_layout( cr );
pango_layout_set_font_description( layout, desc );
pango_layout_set_text( layout, buffer, -1 );
pango_layout_get_pixel_size( layout, &lw, &lh );
fprintf( stderr, "Layout %s size %d, %d\n", buffer, lw, lh );
cairo_move_to( cr, 0.25 * width - lw / 2.,
0.5 * height - lh / 2. );
set_cario_colour( cr, WHITE );
pango_cairo_show_layout( cr, layout );
snprintf( buffer, sizeof buffer,
"%d", window->score.team_2 );
pango_layout_set_text( layout, buffer, -1 );
pango_layout_get_pixel_size( layout, &lw, &lh );
cairo_move_to( cr, 0.75 * width - lw / 2.,
0.5 * height - lh / 2. );
set_cario_colour( cr, WHITE );
pango_cairo_show_layout( cr, layout );
g_object_unref( G_OBJECT( layout ) );
rsvg_handle_render_document( window->logo, cr,
&(RsvgRectangle) {
0.4 * width, 0.8 * height,
0.2 * width, 0.2 * height,
}, NULL );
break;
}
case DONE: {
pango_font_description_set_absolute_size( desc,
PANGO_SCALE * ( 0.4 * height < 0.33 * width ?
0.2 * height : 0.16 * width ) );
PangoLayout* layout = pango_cairo_create_layout( cr );
pango_layout_set_font_description( layout, desc );
pango_layout_set_text( layout,
window->score.team_1 >= window->score.team_2 ?
"Team 1 Wins!" : "Team 2 Wins!", -1 );
pango_layout_set_width( layout, PANGO_SCALE* 0.8 * width );
//pango_layout_set_alignment( layout, PANGO_ALIGN_CENTER );
int lw, lh;
pango_layout_get_pixel_size( layout, &lw, &lh );
cairo_move_to( cr, 0.5 * width - lw / 2,
0.5 * height - lh / 2 );
set_cario_colour( cr, WHITE );
pango_cairo_show_layout( cr, layout );
break;
}
}
pango_font_description_free( desc );
}
static void set_cario_colour( cairo_t* cr, enum colour colour ) {
switch ( colour ) {
case WHITE:
cairo_set_source_rgba( cr, 1., 1., 1., 1. );
break;
case UNIVERSITY_BLUE:
cairo_set_source_rgba(
cr, 0, 0x5C / 255., 0x84 / 255., 1. );
break;
}
}
static int bounce_reset( void* data ) {
*( (bool*) data ) = false;
return G_SOURCE_REMOVE;
}
static int light( void* data ) {
GameWindow* window = (GameWindow*) data;
if ( WAIT != window->state ) {
return G_SOURCE_REMOVE;
}
static const int leds[] = {
LED_G1, LED_G2, LED_G3, LED_G4,
LED_R1, LED_R2, LED_R3, LED_R4,
};
int led = g_random_int_range( 0, sizeof leds / sizeof *leds );
fprintf( stderr, "Lighting led %d (pin %d)\n",
led, leds[led] );
for ( int i = 0; i < 8; i++ ) {
digitalWrite( leds[i], i == led ? HIGH : LOW );
}
window->state = LIT;
window->colour = led < 4 ? GREEN : RED;
return G_SOURCE_REMOVE;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment