Browse Source

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

feature/2015
Christian Kroll 14 years ago
parent
commit
2bc0260f3b
  1. 2
      animations/config.in
  2. 24
      animations/stonefly.c
  3. 2
      games/config.in

2
animations/config.in

@ -8,7 +8,7 @@ comment "Animations"
dep_bool "Feuer" ANIMATION_FEUER $RANDOM_SUPPORT dep_bool "Feuer" ANIMATION_FEUER $RANDOM_SUPPORT
dep_bool "Matrix" ANIMATION_MATRIX $RANDOM_SUPPORT dep_bool "Matrix" ANIMATION_MATRIX $RANDOM_SUPPORT
dep_bool "Random Bright" ANIMATION_RANDOM_BRIGHT $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 "Flying Dots" ANIMATION_FLYINGDOTS $RANDOM_SUPPORT
dep_bool "Game of Life" ANIMATION_GAMEOFLIFE $RANDOM_SUPPORT dep_bool "Game of Life" ANIMATION_GAMEOFLIFE $RANDOM_SUPPORT
dep_bool "Breakout Demo" ANIMATION_BREAKOUT $GAME_BREAKOUT dep_bool "Breakout Demo" ANIMATION_BREAKOUT $GAME_BREAKOUT

24
animations/stonefly.c

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

2
games/config.in

@ -1,6 +1,6 @@
mainmenu_option next_comment mainmenu_option next_comment
comment "Games" 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 "Standard Tetris" GAME_TETRIS $GAME_TETRIS_CORE
dep_bool "Bastard Tetris" GAME_BASTET $GAME_TETRIS_CORE dep_bool "Bastard Tetris" GAME_BASTET $GAME_TETRIS_CORE
dep_bool "First Person Tetris" GAME_TETRIS_FP $GAME_TETRIS_CORE dep_bool "First Person Tetris" GAME_TETRIS_FP $GAME_TETRIS_CORE

Loading…
Cancel
Save