Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - coolsnake

Pages: [1]
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.

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.

2
TI-BASIC / Procedural generation
« on: September 08, 2010, 10:30:09 am »
I've taken an interest in procedural generation lately. More specifically for the generation of areas in space.

Here's a snippet from wikipedia:

"The earliest computer games were severely limited by memory constraints. This forced content, such as maps, to be generated algorithmically on the fly: there simply wasn't enough space to store a large amount of pre-made levels and artwork. Pseudorandom number generators were often used with predefined seed values in order to create very large game worlds that appeared premade. For example, The Sentinel supposedly had 10,000 different levels stored in only 48 or 64 kilobytes. An extreme case was Elite, which was originally planned to contain a total of 248 (approximately 282 trillion) galaxies with 256 solar systems each."
http://en.wikipedia.org/wiki/Procedural_generation

I tried to do the same thing in TI-Basic. If my math is right, the size of the universe I've created on my calculator is in the magnitude of ~10^40 calc screens.
I did this by using the pseudorandom number generator of the calculator and by using predefined seed values.
The downside is, they aren't unique.
In other words, I want my calc-universe to be made up of unique calc screens only, I don't want to come through the same screen twice.
I've been thinking of a way to make this happen, but I didn't find one. Does anyone have an idea?

I've added the universe thing as "space2d.8xp". I did a quick optimisation with sourcecoder and the code itself could probably be more optimised but that isn't my main concern right now.
I've also included the individual subroutines in source.zip

ENGIN is the main game loop.
COLLIS checks for when you reach the edge of the screen and updates the X,Y coordinates, generates new seeds
NUMBERS puts the seeds into rand and generates a pseudorandom number from which the stars are generated.
CONV converts the pseudorandom number into individual numbers. e.g 123 becomes 1, 2 and 3.
COORD uses the individual numbers to generate the coordinates for each individual star while also providing collision detection.

3
TI Z80 / TIPC-Basic
« on: September 07, 2010, 05:28:57 pm »
Description
TIPC-Basic or “Tipsy”-Basic is a library written for use with the computer programming language FreeBASIC.
When installed it allows you to program in Freebasic by using a syntax that is extremely similar to the one of TI-Basic on the TI-84+ graphing calculator while
still having access to all the commands of FreeBASIC.

List of all the commands
Spoiler For Spoiler:
Supported commands
abs(
checkTmr(
ClrDraw
ClrHome
Disp
fPart(
inString(
int(
length(
Pause
Prompt
PxlChange(
PxlOff(
PxlOn(
PxlTest(
rand
randInt(
startTmr
Stop
Text(

Renamed commands
CircleTI(
GetKeyTI(
LineTI(
OutputTI(
subTI(

New commands
BigScreen
Cursor(
CursorX
CursorY
GetMouse(
GraphScreen
HomeScreen
inStringRev(
NormalScreen
Str(
Val(

Installation instructions
First make sure that FreeBASIC is installed (http://freebasic.net/)
Also install an IDE of choice. I've used FBIDE.( found at the bottom of the downloads page)
The default directory for FreeBASIC is
Code: [Select]
C:\FreeBASIC
Place “TIPC-Basic.bi” in
Code: [Select]
C:\FreeBASIC\inc
Place “libTIPC-Basic.a” in
Code: [Select]
C:\FreeBASIC\lib\win32
Add the following line to the top of your source code in FBIde
Code: [Select]
#include "TIPC-Basic.bi"
Now you can use the same commands as in TI-Basic.
Check the User Manual for more information about the syntax.
For a complete rundown of the commands, check “commandlist.html”.
To compile and run your program press F9 or go to run->compile&run.

Feedback
How this project evolves lies in your hands now. Please give me your opinions on what new commands to add, what commands need to change etc
Reports of bugs or spelling mistakes are of course very welcome too.
Please mail them to [email protected] or post them here.

EDIT: updated install instructions in post & in zip file

4
Other Calculators / Why FreeBASIC rocks your socks.
« on: September 02, 2010, 03:45:02 pm »
I've had a craving today for a programming language on the pc which is quite similar to TI-Basic.
This craving was mostly fueled by the BasiC++ project here on omnimaga.  :P

/Insert rant about how most programming languages are hard, either in use or in syntax.

This is something I created today in TI-Basic. It's a primitive fighting engine with you being the X and the enemy being the Z. If either of you punches your respective character changes to the theta symbol.


This is a direct port in FreeBASIC, a language which I understood in less than one day with the help of one tutorial and the command list.  ;D
 
Moral of the story, you know more of programming than you think + FreeBASIC is awesome. :P

also, port to axe^^

Pages: [1]