Page 1 of 1
Crazy Tetrominoes
Posted: Sat Jun 03, 2023 11:53 pm
by DusanStrakl
Updated version of Crazy Tetrominoes, clone of Tetris is now supporting Emulator R43.
Crazy Tetrominoes is written completely in BASIC and it comes with detailed walk through the code.
Access to full source code and tutorial is on my blog at:
https://www.8bitcoding.com/p/crazy-tetrominoes.html
Program can also be downloaded here:
Or you can
Try It Now! online.
Enjoy!
Re: Crazy Tetrominoes
Posted: Tue Jun 27, 2023 8:32 pm
by TestPleaseIgnore
Hi Dušan,
a small problem here: on hardware, I always get the same 2x2 box.
See video:
https://www.youtube.com/watch?v=rd-IF31aPGk
I think this is caused by the RND(0) in the code, which always returns a constant on my machine.
RND(1) seems to work OK.
- 20230627_222703.jpg (2.48 MiB) Viewed 4374 times
What do you think?
Jaroslav.
Re: Crazy Tetrominoes
Posted: Wed Jun 28, 2023 3:31 pm
by DragWx
According to
C64 BASIC, RND(0) returns a random number based on the clock, while RND(1) returns a random number based on whatever the seed originally was, and RND(negative number) sets the seed.
It seems the common convention for doing random numbers is RND(-TI) to seed based on the jiffy timer, then RND(1) to get the next random number.
Re: Crazy Tetrominoes
Posted: Wed Jun 28, 2023 6:23 pm
by DusanStrakl
Hi Jaroslav,
thank you for the info. I went to my physical X16 and tried it. I used the game as it was shipped on SD originally with the board and it plays fine. I recreated a little loop like yours and it also seem to create random values just fine:
- random.jpg (1.2 MiB) Viewed 4325 times
Not sure what could cause different behavior. If the data is based on timer, perhaps you are missing battery on your board, but that is pure guessing...
Re: Crazy Tetrominoes
Posted: Wed Jun 28, 2023 6:32 pm
by DusanStrakl
I also just tried to replace RND(0) with RND(1) on my system and works fine.
Can you try changing these two lines of code:
130 SN=INT(RND(0)*7)
160 S=INT(RND(0)*7):CX=17:CY=13:GOSUB 2210:GOSUB 2000:SN=S
to
130 SN=INT(RND(1)*7)
160 S=INT(RND(1)*7):CX=17:CY=13:GOSUB 2210:GOSUB 2000:SN=S
and see if it works.
Re: Crazy Tetrominoes
Posted: Wed Jun 28, 2023 7:17 pm
by kelli217
It has been my personal experience that... On some versions of the emulator, neither the jiffy clock nor the real time clock will start running until you set them.
It would appear that on hardware, they both start running on powerup. And the RTC continues to keep time while the computer is off, provided you've installed a battery.
Re: Crazy Tetrominoes
Posted: Wed Jun 28, 2023 7:37 pm
by Ender
kelli217 wrote: ↑Wed Jun 28, 2023 7:17 pm
It has been my personal experience that... On some versions of the emulator, neither the jiffy clock nor the real time clock will start running until you set them.
It would appear that on hardware, they both start running on powerup. And the RTC continues to keep time while the computer is off, provided you've installed a battery.
On that note, the emulator's real time clock should start with the current time if you run with "-rtc".
Re: Crazy Tetrominoes
Posted: Wed Jun 28, 2023 9:12 pm
by TestPleaseIgnore
DusanStrakl wrote: ↑Wed Jun 28, 2023 6:32 pm
Can you try changing these two lines of code:
130 SN=INT(RND(0)*7)
160 S=INT(RND(0)*7):CX=17:CY=13:GOSUB 2210:GOSUB 2000:SN=S
to
130 SN=INT(RND(1)*7)
160 S=INT(RND(1)*7):CX=17:CY=13:GOSUB 2210:GOSUB 2000:SN=S
and see if it works.
Hi, I confirm that changing to RND(1) fixes the game.
I checked in MENU and the time is running. Also PRINT TI shows incrementing values.
But OK, I will debug this myself, at least I have something to play with
Jaroslav.
Re: Crazy Tetrominoes
Posted: Thu Jun 29, 2023 12:41 am
by kelli217
TestPleaseIgnore wrote: ↑Wed Jun 28, 2023 9:12 pm
I checked in MENU and the time is running. Also PRINT TI shows incrementing values.
But OK, I will debug this myself, at least I have something to play with
Jaroslav.
Yeah, it's been a while since I did anything on the emulator that involved trying to time things, so I could've been a few versions out of date. That's why I was careful to preface my comment with it being only my personal experience.
When I did, I was just setting a variable equal to TI, and then at the end of the program subtracting that variable from the current value of TI. Something like:
0 T0=TI
[...]
9999 ? TI-T0:END
And when I did that, it always gave me a value of 0. But if I instead did this:
0 TI=0
[...]
9999 ? TI:END
It would give me the elapsed jiffies between the start and end of the program, which is what I wanted. The same thing would happen if I checked TI$ for the current time of day. It would always be "000000" unless I set it first, then it would start running.
All that being said? I just did both of those things just now on R43, and it behaves as Jaroslav indicates.
Re: Crazy Tetrominoes
Posted: Thu Jun 29, 2023 2:47 am
by DusanStrakl
Hmm very interesting.
Of course fixing the game with RND(-TI) and then using RND(1) is trivial but I wonder why it behaves differently on different systems. I also tried the Emulator with R43 ROM and couldn't reproduce repeating of the same number.