1
TI-BASIC / Procedural generation part 2 / Space explorer game
« on: November 05, 2011, 01:12:55 pm »
Here is the first part:
http://www.omnimaga.org/index.php?PHPSESSID=vdu1jt4pj3g1sauc09tcsh89n2&topic=4382.msg61597#msg61597
Recap:
I've always been interested in procedural generation, more specifically the generation of an universe in space.
Last time I posted about this I posted a program that did something like that. You're a little X-spaceship that flies through a dynamically generated universe filled with asterix-stars. It was horribly inefficient/slow and needlessly complicated.
Today after reading a bit about "Movement in Maps","Making Maps" on TI-basic developer I decided to give it another go. I used this code from tibasicdev for the movement.
While the movement itself was very fluid, a great bottleneck was the generation of a new screen everytime i switched to a new sector. It took up to 7 seconds using a string as the base for my map. While I was able to optimise it up to around 3-4 seconds it was still pretty long. It was a real shame since the string consisted mostly out of empty spaces with some "*"-stars sprinkled in between. I was able to fix it by using a list filled with 0's as a base and randomly put some "*" in there. The result is the generation of new sectors is almost instant now, making the program in total very fast. I added the program in an attachment for those interested
The way it's done is very elegant and filesize is almost half of my first attempt.
The way it works is that every screen has its own seed. The calculator then uses this seed to randomly generate a level. If you move one screen to the right, the seed increases with 1, to the left decreases with 1 etc.
LIST.8xp takes care of that and then also generates the level. It makes an empty list of 128 characters(the number of characters that can fit on a calcscreen) and then randomly inserts a star into the list and displays it on the screen.
GAME.8xp is used to start the game. It uses LIST to generate the level and contains the movement loop. It can then use the list to see if the player is bumping against a star or not. When the player moves to another level the loop ends, the new seed number is stored in C and GAME.8xp is recursively opened and then uses LIST.8xp to generate a new level again.
I'm still not able to generate truly unique levels and I don't think i'm able too unless I prerender them all and compare them one by one, which is a bit too calculator intensive. You can have about 10^8 calc screens before changing the seed doesn't matter anymore. The calculator then just keeps displaying the same screen.
Enjoy!
EDIT: tried uploading it again, should work now.
http://www.omnimaga.org/index.php?PHPSESSID=vdu1jt4pj3g1sauc09tcsh89n2&topic=4382.msg61597#msg61597
Recap:
I've always been interested in procedural generation, more specifically the generation of an universe in space.
Last time I posted about this I posted a program that did something like that. You're a little X-spaceship that flies through a dynamically generated universe filled with asterix-stars. It was horribly inefficient/slow and needlessly complicated.
Today after reading a bit about "Movement in Maps","Making Maps" on TI-basic developer I decided to give it another go. I used this code from tibasicdev for the movement.
Code: [Select]
:Output(1,1,Ans
:Repeat K=21 and AB=26 //AB=26 can be changed for different exit point
:getKey→K
:If Ans
:Output(A,B,"_ //One space, checks for key press and erases
:sum(Δlist(Ans={25,34
:A+Ans(" "=sub(Str1,16(A-1+Ans)+B,1→A //If future coordinate is a space, it moves
:sum(Δlist(K={24,26
:B+Ans(" "=sub(Str1,16A-16+B+Ans,1→B
:Output(A,Ans,"X
While the movement itself was very fluid, a great bottleneck was the generation of a new screen everytime i switched to a new sector. It took up to 7 seconds using a string as the base for my map. While I was able to optimise it up to around 3-4 seconds it was still pretty long. It was a real shame since the string consisted mostly out of empty spaces with some "*"-stars sprinkled in between. I was able to fix it by using a list filled with 0's as a base and randomly put some "*" in there. The result is the generation of new sectors is almost instant now, making the program in total very fast. I added the program in an attachment for those interested
The way it's done is very elegant and filesize is almost half of my first attempt.
The way it works is that every screen has its own seed. The calculator then uses this seed to randomly generate a level. If you move one screen to the right, the seed increases with 1, to the left decreases with 1 etc.
LIST.8xp takes care of that and then also generates the level. It makes an empty list of 128 characters(the number of characters that can fit on a calcscreen) and then randomly inserts a star into the list and displays it on the screen.
GAME.8xp is used to start the game. It uses LIST to generate the level and contains the movement loop. It can then use the list to see if the player is bumping against a star or not. When the player moves to another level the loop ends, the new seed number is stored in C and GAME.8xp is recursively opened and then uses LIST.8xp to generate a new level again.
I'm still not able to generate truly unique levels and I don't think i'm able too unless I prerender them all and compare them one by one, which is a bit too calculator intensive. You can have about 10^8 calc screens before changing the seed doesn't matter anymore. The calculator then just keeps displaying the same screen.
Enjoy!
EDIT: tried uploading it again, should work now.