From 8434cfcd46cd9217fc04ec5ea6a6cb531c3b5800 Mon Sep 17 00:00:00 2001 From: Holmes Futrell Date: Fri, 18 Jul 2008 20:51:25 +0000 Subject: [PATCH] Files used by all demos (random numbers, screen size, etc) --- XCodeiPhoneOS/Demos/src/common.c | 29 +++++++++++++++++++++++++++++ XCodeiPhoneOS/Demos/src/common.h | 12 ++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 XCodeiPhoneOS/Demos/src/common.c create mode 100644 XCodeiPhoneOS/Demos/src/common.h diff --git a/XCodeiPhoneOS/Demos/src/common.c b/XCodeiPhoneOS/Demos/src/common.c new file mode 100644 index 000000000..ee7a466d4 --- /dev/null +++ b/XCodeiPhoneOS/Demos/src/common.c @@ -0,0 +1,29 @@ +/* + * common.c + * written by Holmes Futrell + * use however you want + */ + +#include "common.h" +#include "SDL.h" +#include + +/* + Produces a random int x, min <= x <= max + following a uniform distribution +*/ +int randomInt(int min, int max) { + return min + rand() % (max - min + 1); +} +/* + Produces a random float x, min <= x <= max + following a uniform distribution + */ +float randomFloat(float min, float max) { + return rand() / (float)RAND_MAX * (max - min) + min; +} + +void fatalError(const char *string) { + printf("%s: %s\n", string, SDL_GetError()); + exit(1); +} \ No newline at end of file diff --git a/XCodeiPhoneOS/Demos/src/common.h b/XCodeiPhoneOS/Demos/src/common.h new file mode 100644 index 000000000..53f8ccc58 --- /dev/null +++ b/XCodeiPhoneOS/Demos/src/common.h @@ -0,0 +1,12 @@ +/* + * common.h + * written by Holmes Futrell + * use however you want + */ + +#define SCREEN_WIDTH 320 +#define SCREEN_HEIGHT 480 + +extern int randomInt(int min, int max); +extern float randomFloat(float min, float max); +extern void fatalError(const char *string); \ No newline at end of file