mirror of
https://gitlab.com/sortix/sortix.git
synced 2023-02-13 20:55:38 -05:00
Fixed randomness-related crash in snake.
This commit is contained in:
parent
a7de7b4905
commit
5bde040295
2 changed files with 8 additions and 6 deletions
|
@ -56,8 +56,8 @@ void Reset()
|
||||||
case 3: velx = 0; vely = -1; break;
|
case 3: velx = 0; vely = -1; break;
|
||||||
}
|
}
|
||||||
|
|
||||||
animalx = 2 + (rand() % width-4);
|
animalx = 2 + (rand() % (width-4));
|
||||||
animaly = 2 + (rand() % height-4);
|
animaly = 2 + (rand() % (height-4));
|
||||||
|
|
||||||
taillen = 0;
|
taillen = 0;
|
||||||
tailmax = 3;
|
tailmax = 3;
|
||||||
|
@ -141,8 +141,10 @@ void Update()
|
||||||
if ( newx == animalx && newy == animaly )
|
if ( newx == animalx && newy == animaly )
|
||||||
{
|
{
|
||||||
tailmax++;
|
tailmax++;
|
||||||
animalx = 2 + (rand() % width-4);
|
animalx = 2 + (rand() % (width-4));
|
||||||
animaly = 2 + (rand() % height-4);
|
animaly = 2 + (rand() % (height-4));
|
||||||
|
ASSERT(0 <= animalx && animalx < width);
|
||||||
|
ASSERT(0 <= animaly && animaly < height);
|
||||||
if ( maxspeed < speed ) { speed += speedincrease; }
|
if ( maxspeed < speed ) { speed += speedincrease; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,11 +28,11 @@ namespace Maxsi
|
||||||
{
|
{
|
||||||
namespace Random
|
namespace Random
|
||||||
{
|
{
|
||||||
int random_seed=1337;
|
unsigned random_seed = 1337;
|
||||||
extern "C" int rand()
|
extern "C" int rand()
|
||||||
{
|
{
|
||||||
random_seed = random_seed + 37 * 1103515245 + 12345;
|
random_seed = random_seed + 37 * 1103515245 + 12345;
|
||||||
return random_seed / 65536;
|
return random_seed >> 16;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue