Add little testing and documentation

This commit is contained in:
Aaron Mueller 2009-12-19 21:57:22 +01:00
parent e908fcdf35
commit e586f4a03e
7 changed files with 125 additions and 6 deletions

View File

@ -10,6 +10,7 @@ RM= rm -r
MKDIR= mkdir -p
####### Directories
SRCDIR= src
DOCDIR= doc
OUTDIR= bin
OBJDIR= $(OUTDIR)/objects
####### Project
@ -17,7 +18,7 @@ OBJDIR= $(OUTDIR)/objects
OBJEND= o
SRCEND= c
# name of programm (and executable)
NAME= game
NAME= adventgame
# path to executable
EXE = $(OUTDIR)/$(NAME)
@ -53,7 +54,13 @@ clean:
# start programm
run: $(OUTDIR)/$(NAME)
./$(OUTDIR)/$(NAME)
./$(OUTDIR)/$(NAME) -v
man: $(DOCDIR)/$(NAME).6
gzip $(DOCDIR)/$(NAME).6 > $(OUTDIR)/$(NAME).6.gz
man-test: $(DOCDIR)/$(NAME).6
groff -man -Tascii $(DOCDIR)/$(NAME).6
# execute clean every time
.PHONY: clean

82
doc/adventgame.6 Normal file
View File

@ -0,0 +1,82 @@
.TH adventgame 6 "December 2009" "" "version 0.1"
.SH NAME
adventgame - an interactive open source programming tutorial
.SH SYNOPSIS
.B adventgame
[-v] [-h] [--man]
.SH DESCRIPTION
The
.B adventgame
is the resulting output from the advent calendar series from the website
.I advent.aaron-mueller.de
(in the year 2009). In 12 articles Aaron Mueller
explain the basics of open source and all its activities. This game is
the working example. It represents a simple (unfinished)
.I Worms
clone.
.SH OPTIONS
.TP
.B -v
Set verbose output, so the user can see debug messages. This option is usefull
in development or if a wired bug occurs and you want to know whats going on.
.TP
.B -h
Display a short description of all options. This is nice to know what options
exists without open up this manpage and read this text.
.TP
.B --man
Open up this manpage. This option is only a notice to the user to let him
know that a manpage exists.
.SH PLAY THE GAME
The game itself is not that hard. When you start the game without a parameter
or the
.B -v
parameter to see more output, you land in the main menu. Here you can choose
if you want to start a new game or view the credits or even quit the game. If
you choose to start a new game, the next menu appears. Here you can choose the
number of players to play the game. Navigating in the menu is done by
.B j
or
.B PAGE DOWN
and
.B k
or
.B PAGE UP.
To select a menu utem just press
.B RETURN
or
.B SPACE
and you change the screen.
.PP
If you choose the number of players and continue, you see the game field.
At this time, there is not really a game, it just display the dynamically
generated landscape. If you press
.B RETURN,
you can regenerate the landscape. If you press
.B ESC
or
.B F10
, you can quit the game and return to the main menu.
.SH BUGS
There area many unfinished things in this game. If you feel a light prickle
under your thumbs, feel free to contribute some code or documentation like
this. This would be great!
.SH AUTHOR AND LINKS
The project is created by Aaron Mueller <mail@aaron-mueller.de>. If you want
to contribute, visit
.I http://advent.aaron-mueller.de/
.RS
Article page
.RE
.I http://feitel.indeedgeek.de/2009/adventskalender/
.RS
Advent calendar
.RE
.I http://github.com/aaronmueller/advent2009
.RS
Sourcecode
.RE
.SH CONTRIBUTORS
Florian Eitel, Ruben Mueller

View File

@ -3,6 +3,8 @@
#include <stdbool.h>
#include "config.h"
bool DEBUG = false;
// Initialization for the global variables
SDL_Surface *screen = NULL;
SDL_Event event;

View File

@ -22,9 +22,9 @@ enum states {
// Screen size
static const int SCREEN_WIDTH = 800;
static const int SCREEN_HEIGHT = 600;
#endif
extern bool DEBUG;
// Global variables and definitions
extern SDL_Surface *screen; // Screen to paint on

View File

@ -2,11 +2,15 @@
#include "SDL.h"
#include <math.h>
#include <stdbool.h>
#include <assert.h>
#include "draw.h"
#include "config.h"
void drawPixel(int x, int y, int color) {
assert(x < SCREEN_WIDTH && x >= 0);
assert(y < SCREEN_HEIGHT && y >= 0);
unsigned int *p = (unsigned int*)screen->pixels;
int lineOffset = y * (screen->pitch/4);
@ -18,6 +22,8 @@ int _sign(float a) {
}
float _random(float from, float to) {
assert(from < to);
return ((to-from)*((float)rand()/RAND_MAX))+from;
}
@ -73,8 +79,8 @@ void drawRect(int x1, int y1, int x2, int y2, int color, bool filled) {
}
}
// TODO: Write some code in here!
void drawCircle(int x, int y, int radius, int color, bool filled) {
// TODO: Write some code in here!
}
int* generateTerrain(float peakheight, float flatness) {
@ -83,7 +89,8 @@ int* generateTerrain(float peakheight, float flatness) {
float r2 = _random(1.0, 5.0);
float r3 = _random(1.0, 5.0);
int *yvals = (int*)malloc(SCREEN_WIDTH*sizeof(int));
printf("r1=%f, r2=%f, r3=%f\n", r1, r2, r3);
if (DEBUG) printf("Generate new terrain with randoms: r1=%f, r2=%f, r3=%f\n", r1, r2, r3);
for (int x=0; x<SCREEN_WIDTH; x++) {
float y;

View File

@ -24,7 +24,6 @@ void eventsRunninggame() {
case SDLK_RETURN:
free(terrain);
terrain = generateTerrain(150.0, 180.0);
printf("New terrain generated.\n");
break;
case SDLK_ESCAPE:
case SDLK_F10:

View File

@ -2,6 +2,7 @@
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "SDL.h"
#include "SDL_ttf.h"
@ -11,7 +12,28 @@
#include "menu.h"
/**
* This is the main file for the advent game. The adventgame is an interactive
* tutorial on aaron-mueller.de (winter 2009). YOu can read the whole list of
* articles on http://advent.aaron-mueller.de/.
*/
int main(int argc, char **argv) {
// Check input parameters
if (argc == 2) {
if (strcmp(argv[1], "-v") == 0) DEBUG = true;
if (strcmp(argv[1], "--man") == 0) {
system("man adventgame");
exit(0);
}
if (strcmp(argv[1], "-h") == 0) {
printf("Advent Game 2009\n\n \
-v Verbose output, show debug messages\n \
-h Show this lines and quit\n \
--man Open up the manpage\n\n");
exit(0);
}
}
// Initialize SDL and open up a screen
SDL_Init(SDL_INIT_VIDEO);
TTF_Init();