#39833 - Ultima2876 - Tue Apr 12, 2005 8:18 pm
Code: |
void scansep(void)
{ if (hspeed[REG_VCOUNT] == 0) { hspeed[REG_VCOUNT] = random(2, 6); } hoffset[REG_VCOUNT] += hspeed[REG_VCOUNT]; if (hoffset[REG_VCOUNT] > 256) { hoffset[REG_VCOUNT] = 0; hspeed[REG_VCOUNT] = 0; } REG_BG0HOFS = hoffset[REG_VCOUNT]; } |
This is my Hblank function. It works fine, apart from the fact that the hoffset seems to be resetting prematurely - the effect I'm trying to achieve is one of stars flying by at (pseudo)random speeds. Once a star goes a bit offscreen (to the left - hoffset > 256) the hoffset is reset and the speed of the "new" star is calculated.
All the REG_VCOUNT stuff is to have it so that every scanline retains its own properties (offset and speed). I have the hoffset and hspeed arrays set up with 256 elements each (I'm going to clear this up once my code is done - if I had too few elements it would cause problems but too many is easy to sort out later).
The result is that the starts scroll fine, every looks great, until stars start randomly disappearing (their hoffset is being reset to 0). I've been staring at this code for hours and really can't see what's wrong. Other relevant code bits:
RNG function:
Code: |
s32 random(s32 min, s32 max)
{ seed *= 69069; return min + ((max - min + 1) * (seed >> 16)) / 0x10000; } |
Variables:
Code: |
u16 hoffset[256] = { 0, };
u8 hspeed[256] = { 0, }; u32 seed = 122; |
If you need screenshots, just ask and I'll grab some. Thanks.