tonma Posted November 23, 2016 Share Posted November 23, 2016 Hi, I'm beginning development on lynx and I don't find a way to get random number with cc65. I've making a flappybird 'test', and I wish to have random y position of column. Test only on emulator. Quote Link to comment Share on other sites More sharing options...
Turbo Laser Lynx Posted November 23, 2016 Share Posted November 23, 2016 (edited) This example should randomize between 0 and 15 + 1 result = ((rand() & 0xf) + 1); Hopefully we will finally get a Lynx port of this fine game Btw. I noticed if you put the number really low, say between 0 and 2 + 1 it's not very reliable and will give the same number over and over. Edited November 23, 2016 by Turbo Laser Lynx Quote Link to comment Share on other sites More sharing options...
+karri Posted November 23, 2016 Share Posted November 23, 2016 There is actually two functions to "randomize" things. void __fastcall__ srand (unsigned seed); Ths srand function sets a seed for the rand() function. int rand (void); The rand() function will return the next "random" number. The sequence is always the same. If you set srand(1) then the function rand() will always return the same random numbers. What I do to get really random numbers is to call rand() all the time from the main loop. In this way it changes by itself as the time passes. Quote Link to comment Share on other sites More sharing options...
tonma Posted November 23, 2016 Author Share Posted November 23, 2016 (edited) Thanks, It's weird, I'm pretty sure I tested rand() this morning. Anyway, it's works. Never programming with big headache. I'll use rand() in main and maybe a srand(clock()) when I die / restart a level. Thanks too for the range between two numbers Hopefully we will finally get a Lynx port of this fine game You're serious, you really interested by a flappybird version ? I'm doing it only for testing the devkit, but finish it doesn't take me too much time. Except for a music, maybe only sound effect like a roaring lynx when you die. Edited November 23, 2016 by tonma Quote Link to comment Share on other sites More sharing options...
Ninjabba Posted November 23, 2016 Share Posted November 23, 2016 As a random seed I use a counter based on pressing time of buttons and waiting time in menus and keep feeding this to srand. This will make sure that the sequence of random numbers changes over time. Quote Link to comment Share on other sites More sharing options...
Heaven/TQA Posted November 23, 2016 Share Posted November 23, 2016 how is the random done in C65? deterministic like you find it at codebase64.org? Quote Link to comment Share on other sites More sharing options...
BadPricey Posted November 23, 2016 Share Posted November 23, 2016 You're serious, you really interested by a flappybird version ? Any version of anything on the Lynx is always welcome! ? Rgds BadPricey Quote Link to comment Share on other sites More sharing options...
+karri Posted November 23, 2016 Share Posted November 23, 2016 The rand is a completely deterministic 32 bit sequence. Only 16 bits are returned. Quote Link to comment Share on other sites More sharing options...
Turbo Laser Lynx Posted November 24, 2016 Share Posted November 24, 2016 (edited) You're serious, you really interested by a flappybird version ? Well maybe I was taking it a bit too far when saying it's a *fine game*, but deep inside I've been a bit bummed that there hasn't been a version of it on the Lynx I agree with BadPricey that anything new for the Lynx is nice. Flappy Bird can be pretty fun in small doses at least. Edited November 24, 2016 by Turbo Laser Lynx Quote Link to comment Share on other sites More sharing options...
+karri Posted November 24, 2016 Share Posted November 24, 2016 (edited) From the docs. The marvellous rand() in cc65: SEED *= $01010101 SEED += $31415927 SEED = abs(SEED) return (SEED >> & $FFFF The default SEED is 1. Edited November 24, 2016 by karri Quote Link to comment Share on other sites More sharing options...
tonma Posted November 24, 2016 Author Share Posted November 24, 2016 Thanks, I'll continue the game. At least, a playable version with random columns. I can't test on real hardware now. I'm waiting for the multicard SD by Saint. The other thing I need is adding sound effect. Hum hum, because for the music I really doesn't understand anything. I mean I can't create music at all. Can we convert with a tracker music files like mod or midi ? Or maybe can we play digitized sound effect. I'm in love of "Let's play awesome golf". Quote Link to comment Share on other sites More sharing options...
LX.NET Posted November 25, 2016 Share Posted November 25, 2016 Der Luchs light be able to help out. It might be in the new year because he indicated to not code in 2016 anymore. Perhaps he can make an exception for music... Quote Link to comment Share on other sites More sharing options...
tonma Posted November 25, 2016 Author Share Posted November 25, 2016 Thank you, I will send him a PM. Without pressure. I am patient Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.