make prng support optional for all tetris related routines (useful for the limited ATmega8 flash mem)

This commit is contained in:
Christian Kroll 2011-03-07 02:31:19 +00:00
parent c1b55278cd
commit 2bc0260f3b
3 changed files with 18 additions and 10 deletions

View File

@ -8,7 +8,7 @@ comment "Animations"
dep_bool "Feuer" ANIMATION_FEUER $RANDOM_SUPPORT
dep_bool "Matrix" ANIMATION_MATRIX $RANDOM_SUPPORT
dep_bool "Random Bright" ANIMATION_RANDOM_BRIGHT $RANDOM_SUPPORT
dep_bool "Stonefly" ANIMATION_STONEFLY $RANDOM_SUPPORT $GAME_TETRIS_CORE
dep_bool "Stonefly" ANIMATION_STONEFLY $GAME_TETRIS_CORE
dep_bool "Flying Dots" ANIMATION_FLYINGDOTS $RANDOM_SUPPORT
dep_bool "Game of Life" ANIMATION_GAMEOFLIFE $RANDOM_SUPPORT
dep_bool "Breakout Demo" ANIMATION_BREAKOUT $GAME_BREAKOUT

View File

@ -7,6 +7,14 @@
#include "../games/tetris/piece.h"
#include "../util.h"
#ifdef RANDOM_SUPPORT
#define RANDOM8() random8()
#else
#define RANDOM8() rand()
#endif
#define MAX_STONES 8
#define YSCALE 2 //y axis is scaled up, this allows for YSCALE different falling speeds
@ -46,17 +54,17 @@ static void create_stone(stone_t *stone)
//random x
//4 is piece width
stone->x = random8() % (NUM_COLS - 4);
stone->x = RANDOM8() % (NUM_COLS - 4);
//random shape at random angle (untyped enums rock! yay!)
stone->piece.shape = random8() % 7;
stone->piece.angle = random8() % 4;
stone->piece.shape = RANDOM8() % 7;
stone->piece.angle = RANDOM8() % 4;
//chose a random speed from 1-2
stone->speed = (random8() % YSCALE) + 1;
stone->speed = (RANDOM8() % YSCALE) + 1;
//chose a random color
stone->color = (random8() % NUMPLANE) + 1;
stone->color = (RANDOM8() % NUMPLANE) + 1;
}
@ -196,16 +204,16 @@ void stonefly(void)
//if there are less than max_stones flying, there's a chance to spawn one
if((stoneCount < MAX_STONES) && (counter > 0))
{
if(random8() < 48)
if((RANDOM8() % (UINT8_MAX + 1)) < 48)
{
create_stone(&stones[stoneCount++]);
}
//invasion time!!!
if((random8() < 8) && (invasion == 0))
if((RANDOM8() < 8) && (invasion == 0))
{
//9 is invader width
invax = random8() % (NUM_COLS - 9);
invax = RANDOM8() % (NUM_COLS - 9);
invay = 0;
invasion = 1;
}

View File

@ -1,6 +1,6 @@
mainmenu_option next_comment
comment "Games"
dep_bool_menu "Tetris" GAME_TETRIS_CORE y $JOYSTICK_SUPPORT $RANDOM_SUPPORT
dep_bool_menu "Tetris" GAME_TETRIS_CORE y $JOYSTICK_SUPPORT
dep_bool "Standard Tetris" GAME_TETRIS $GAME_TETRIS_CORE
dep_bool "Bastard Tetris" GAME_BASTET $GAME_TETRIS_CORE
dep_bool "First Person Tetris" GAME_TETRIS_FP $GAME_TETRIS_CORE