From f0470869a94b1894c970ab8af627f471e5d44643 Mon Sep 17 00:00:00 2001 From: Jonas 'Sortie' Termansen Date: Sun, 28 Feb 2016 22:11:39 +0100 Subject: [PATCH] Convert aquatinspitz to C. --- games/Makefile | 7 ++++++- games/{aquatinspitz.cpp => aquatinspitz.c} | 22 +++++++++++----------- 2 files changed, 17 insertions(+), 12 deletions(-) rename games/{aquatinspitz.cpp => aquatinspitz.c} (96%) diff --git a/games/Makefile b/games/Makefile index 0bc2eca4..ab3252de 100644 --- a/games/Makefile +++ b/games/Makefile @@ -5,8 +5,10 @@ include ../build-aux/version.mak include ../build-aux/dirs.mak OPTLEVEL?=$(DEFAULT_OPTLEVEL) +CFLAGS?=$(OPTLEVEL) CXXFLAGS?=$(OPTLEVEL) +CFLAGS:=$(CFLAGS) -Wall -Wextra CXXFLAGS:=$(CXXFLAGS) -Wall -Wextra -fno-exceptions -fno-rtti BINARIES:=\ @@ -23,8 +25,11 @@ install: all mkdir -p $(DESTDIR)$(BINDIR) install $(BINARIES) $(DESTDIR)$(BINDIR) +%: %.c + $(CC) -std=gnu11 $(CFLAGS) $(CPPFLAGS) $< -o $@ $(LIBS) + %: %.cpp - $(CXX) -std=gnu++11 $(CPPFLAGS) $(CXXFLAGS) $< -o $@ $(LIBS) + $(CXX) -std=gnu++11 $(CXXFLAGS) $(CPPFLAGS) $< -o $@ $(LIBS) clean: rm -f $(BINARIES) *.o diff --git a/games/aquatinspitz.cpp b/games/aquatinspitz.c similarity index 96% rename from games/aquatinspitz.cpp rename to games/aquatinspitz.c index d850e13c..1383400a 100644 --- a/games/aquatinspitz.cpp +++ b/games/aquatinspitz.c @@ -15,7 +15,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . - aquatinspitz.cpp + aquatinspitz.c Aqua tin spitz! *******************************************************************************/ @@ -40,13 +40,13 @@ #include // Utility global variables every game will need. -bool game_running = true; -size_t game_width = 1280; -size_t game_height = 720; -const size_t MAX_KEY_NUMBER = 512UL; -bool keys_down[MAX_KEY_NUMBER] = { false }; -bool keys_pending[MAX_KEY_NUMBER] = { false }; -struct timespec key_handled_last[MAX_KEY_NUMBER]; +static bool game_running = true; +static size_t game_width = 1280; +static size_t game_height = 720; +#define MAX_KEY_NUMBER 512 +static bool keys_down[MAX_KEY_NUMBER]; +static bool keys_pending[MAX_KEY_NUMBER]; +static struct timespec key_handled_last[MAX_KEY_NUMBER]; // Utility functions every game will need. bool pop_is_key_just_down(int abskbkey); @@ -74,10 +74,10 @@ struct enemy }; #define NUM_ENEMIES 256 -struct enemy enemies[NUM_ENEMIES]; +static struct enemy enemies[NUM_ENEMIES]; // Prepare the game state for the first round. -void init() +void init(void) { player.x = game_width / 2; player.y = game_height / 2; @@ -314,7 +314,7 @@ bool pop_is_key_just_down(int abskbkey) } // Read input from the keyboard. -void input() +void input(void) { // Read the keyboard input from the user. unsigned termmode = TERMMODE_KBKEY | TERMMODE_SIGNAL | TERMMODE_NONBLOCK;