Dark Bit Factory & Gravity

PROGRAMMING => Other languages => Yabasic => Topic started by: rain_storm on January 09, 2007

Title: Yabasic Rocks !!!
Post by: rain_storm on January 09, 2007
This is probably a little premature but I just had to post this. I am truely proud of this one. I have been attempting to design a raytcaster for yabasic for years now with no success : (

Finally I have achieved this goal! And I think you all will agree that I have truely surpassed myself.
So with without further ado ... The moment you've all been waiting for ... Drum-roll please ... I present ...

YABASIC ROCKS !!! (woo hoo)

controls -
"arrow" keys = move around
"a" key = turn left
"s" or "o" keys = turn right
Well there isn't much in here to do yet but you have to admit that it is cool nonetheless. There is still plenty of room for fun stuff (like people 'n bullets) as well. Peace out.

Updated Version includes a map display (press enter to toggle on/off)
other features
1) faster algorythm
2) more accurate intersection with walls
3) new areas of the map are loaded into memory on the fly
4) weather effects including 3d lightning
5) The level editor I use to create the map
+ other minor additions
Title: Re: Yabasic Rocks !!!
Post by: Jim on January 09, 2007
Wow!  I love the way you've done the brick walls.  That's superb!  Have some karma for squeezing that last drop out of yabasic.

Jim
Title: Re: Yabasic Rocks !!!
Post by: benny! on January 09, 2007
@rain_storm:

Never seen anything done with Yabasic ... any chance you can add an exe
file ???
Title: Re: Yabasic Rocks !!!
Post by: rain_storm on January 09, 2007
Thanx for the karma Jim it's much appreciated  :cheers:

Sorry, Benny. But no can do on the exe, you're gonna have to run it under the emulator.
You can download it here -

      http://members.iinet.net.au/~jimshaw/Yabasic/ps2yabasic1.6b3.zip

or you could try running it under this one from Marc-Oliver Ihm but, I don't recommend it as it isn't faithful to the original language -

      http://www.yabasic.de/download/yabasic-2.763.bin.exe

anyhow... I've added a pallet (for colour look up) and increased the textures to 30x30, so everything looks alot better. Also I have incorporated the room transitions technique from my last attempt at this but i have segregated the different components such as doors, lighting, etc. so that new rooms can be built up by using pieces of previous rooms which should keep the memory footprint down to a minimum. The wheels are in motion. So stay tuned ...
Title: Re: Yabasic Rocks !!!
Post by: Shockwave on January 09, 2007
That's really really smart! Great idea with the stone textured walls! Thank or posting it, + Karma for reaching your goal!
Title: Re: Yabasic Rocks !!!
Post by: rain_storm on January 09, 2007
Thanks alot Shockwave you have no idea how long that was in the making. I guese it's true 'One foot in front of the other gets the job done.'
I'm just glad to have the oppertunity to make a contribution, and to be able to display my work to the members of this fine forum.
Title: Re: Yabasic Rocks !!!
Post by: benny! on January 09, 2007
@rain_storm:

Downloaded YaBasic Interpreter - thx for the links.

Your code is very well done. Congratulations.

However, it seems Yabasic itself runs very crappy on my machine. Maybe I should
give it another try - but on the first sight - I do not tend to like it.
Title: Re: Yabasic Rocks !!!
Post by: Stonemonkey on January 09, 2007
Don't let Jim hear you say that Benny. Actually, this version of YaBasic was originally released on the demodisc that shipped with the PS2 (although not in all countries) and although it was a lot of fun to program the ps2, YaBasic wasn't particularly powerful and was a bit buggy and was just really a bit of a tax dodge by sony as they could call the PS2 a programmable computer in some places.
Someone (can't remember his name atm) had started working on an emulator so that the programs could be run on the PC and Jim continued the work on it and has got it running pretty well while keeping it faithful to the PS2 version although it runs better than that now.
Title: Re: Yabasic Rocks !!!
Post by: rain_storm on January 09, 2007
Well you can't push Yabasic like you can with most other compilers but its still a great medium if you willing to put in the work. And the emulator that Jim worked is almost identical to the original except for a few commands that no one uses (numparams). if anyone finds that it runs a bit slow simply do a search for "rays = " and bring down the value a bit... it will make things a little blocky but it will run faster.
Title: Re: Yabasic Rocks !!!
Post by: benny! on January 09, 2007
Ooops ... I am sorry. I didn't want to offfend anyone or wanted to sound respectless
of someones hard work. Just tested Yabasic 2 minutes or so ... so don't take my critism
too serious.

Furthermore, I thought it was a commercial product - and the above was just was first
came into my mind.


@Jim:

Sorry, mate. I really do respect your work and knowledge !!!
Title: Re: Yabasic Rocks !!!
Post by: Jim on January 09, 2007
Hi Benny, it's no big deal.  I'll be the first to admit it isn't perfect.  I appreciate your honesty, so have some karma.
Mind you, you should have seen it before I started work on it!  The orignal programmer is Peter Bas-IJdens.

Jim
Title: Re: Yabasic Rocks !!!
Post by: Shockwave on January 09, 2007
Is there actually any of his original program left Jim? I thought that you'd pretty much re-written all of it?
Title: Re: Yabasic Rocks !!!
Post by: Jim on January 09, 2007
Not a lot of it left, no.  Some of the OpenGL primitives are still the originals.

By the way, the license is GPL and the project is on sourceforge if anyone wants to look at it.  Latest source hasn't made it to CVS though.

Jim
Title: Re: Yabasic Rocks !!!
Post by: Shockwave on January 09, 2007
Would you like to host the emulator here too Jim? You're welcome to do that.
Title: Re: Yabasic Rocks !!!
Post by: rain_storm on January 09, 2007
Ah no offense taken Benny my man. Hope I didn't come off all defensive back there that wasn't my intention. Just wanted to write what had crossed my mind. Yabasic is a little outdated and runs a bit slow, thats what I meant to type (doh)  :whack:
Title: Re: Yabasic Rocks !!!
Post by: benny! on January 10, 2007
Hi Benny, it's no big deal.  I'll be the first to admit it isn't perfect.  I appreciate your honesty, so have some karma.
Mind you, you should have seen it before I started work on it!  The orignal programmer is Peter Bas-IJdens.

Oops again. thx for the karma.  ::)

When I have some time left, I will have a closer look at the language itself. I promise.
Title: Re: Yabasic Rocks !!!
Post by: Shockwave on January 10, 2007
It's quite challenging to write demos with no graphics except lines, triangles and filled rectangles :) It's good fun.
Title: Re: Yabasic Rocks !!!
Post by: rain_storm on January 10, 2007
Okay I wanted to pose a technical question ...
Would it be faster to draw the entire scene, then charictors then draw any walls that are between the viewer and the charictors?
Or would the best speed be found by drawing walls, stopping to draw a charictor and then some more walls?
The former simplifies the bulk of the rendering, the later makes the whole proceedure more complex for the sake of one or two walls, but everything will be drawn in paralelle so you dont have to redraw anything. Any feedback to this is appreciated.
Title: Re: Yabasic Rocks !!!
Post by: Jim on January 10, 2007
In yabasic, you might need to stop and draw the characters when necessary.  Another possibility is to keep the positions of the tops of the walls in an array and use that as a kind of primitive z buffer (a z scanline effectively) and draw the characters afterwards.

Jim
Title: Re: Yabasic Rocks !!!
Post by: rain_storm on January 10, 2007
Yeah I thought as much... Really I don't know how to do proper Z buffuring but I can alter things so that when a ray comes across a charictor I can record the first and last instances taking note of the ray number and the charictor number.
Then simply draw all rays that have also hit a charictor first, followed by all charictors that have been hit by a ray then all the remaining rays. This should work and will be much less work than trying to figure out what is between the viewer and the charictors.
Thanks Jim for showing me options that I didn't pick up on.
Title: Re: Yabasic Rocks !!!
Post by: Clanky on January 11, 2007
Nice program!
It's like the other Raycaster Engine made at the old Ezboard Forums. That one was great: cell shaded walls and ran really fast!
The only problem with your one is the speed, no offence, but the other Raycaster engine ran really smooth, sometimes abit too fast. Maybe if you tried to change some sequences to cut out some slow down? You could look at the other engine's code below to see if you could change something.
::This was coded by laurenz
I changed a few things:
  Before, you could not move with to buttons pressed.
             I modified this using
Code: [Select]
if and(j,num)<>0 turn=turn+1  Before, the map was behind the shaded walls, making it invisible when you went close to the walls.
             I modified this by moving the map code after the wall drwaing code.
  I added a slowdown option, located as SLOWDOWN=0. Increase this value to slow the program's frame reat down.
NB/ The program uses Binary for the map data. Jim told me this when i asked how to change the map.
Put the value into your computers calculator and set it to BIN.

Code: [Select]
open window 640,512

slowdown=0

dim grid(42,54)
dim cs(360),sn(360)

data 66714624,66584830,34145280
data 34078858,116383736,116391819
data 10485768,77594664,130015208
data 128966563,66600,34099362
data 130088,66605310,66613288
data 66706686,34099240,34145418,112188654
data 49248171,10486914,35672104,117431534
data 49272803,35672104,34083970,60837928
data 66591998,27385070,58850304,18941058
data 42009600,123854010,50296831,4214946
data 33570816,130145518,66025455,66690
data 2688040,130302,3800104,130302,238
data 87170,130,134174595,16773307,57
data 8392872,134174603,12570795,87178
data 10506370,130286,10506494,66714760
data 62410814,34145416,34099234,101676942
data 48783331,20482,34095104,101703662
data 62422927,34078760,10485896,66584632
data 10486008,0,60947710,0,35718274
data 0,50272131,0,33558529,0,50296707
data 0,35734658,0,65142014

for y=0 to 41
read a,b
for x=0 to 26
decode=2^(26-x)
if decode>b then
grid(y,x)=0
else
grid(y,x)=1
b=b-decode
fi
decode=2^(26-x)
if decode>a then
grid(y,x+27)=0
else
grid(y,x+27)=1
a=a-decode
fi
next x
next y
factor=(atan(1)*8)/360
for a=0 to 359
ang=a*factor
sn(a)=sin(ang)*.1
cs(a)=cos(ang)*.1
next a
px=3
py=1
head=182

label main
setdispbuf db
db=1-db
setdrawbuf db
setrgb 1,0,100,130
fill rectangle 0,0 to 640,256
setrgb 1,40,40,40
fill rectangle 0,256 to 640,512

j=peek("port1")
if and(j,32)<>0 head=mod(head+5,360)
if and(j,128)<>0 head=mod(head+360-5,360)
if and(j,16)<>0 then
newpx=px-(sn(head))*3
newpy=py-(cs(head))*3
if grid(newpx,newpy)=0 then
px=newpx
py=newpy
fi
fi
if and(j,64)<>0 then
newpx=px+(sn(head))*3
newpy=py+(cs(head))*3
if grid(newpx,newpy)=0 then
px=newpx
py=newpy
fi
fi
x1=0
for sc=head-31 to head+32 step 2
ang=mod(sc,359)
if ang<0 ang=ang+359
spx=sn(ang)
spy=cs(ang)
setrgb 1,255,0,0
fill box 320+px*2,56+py*2,322+px*2,58+py*2
xx=px
yy=py
l=0
repeat
xx=xx-spx
yy=yy-spy
l=l+1
k=grid(xx,yy)
until (k>0)
dd=1024/l
h=dd+dd
dt=256-dd
setrgb 1,140-dt*.5,140-dt*.5,140-dt*.5
fill box x1,dt,x1+20,256+h*.5
setrgb 1,0,0,0
box x1+2,dt+2,x1+20-2,256+h*.05
box x1+20-2,256+h*.05,x1+2,256+h*.5
x1=x1+20
next sc
for y=0 to 53
for x=0 to 41
if grid(x,y)>0 then
setrgb 1,0,0,0
fill box 320+x*2,56+y*2 to 322+x*2,58+y*2
fi
next x
next y
wait slowdown
goto main


Overall, a great piece of code. Very nice graphical effects with the bricks!
Title: Re: Yabasic Rocks !!!
Post by: rain_storm on January 11, 2007
Thanks a million Clanky, this is excellent. Would it be possible if I could get a link to the original one? You're right it is fast, damn fast. Oh and that technique for using binary for the map, that's called packed data feilds its commonly used in assembler I already use it in all my code I found that on the PS2 any game that used whole bytes might take up to a minute to parse (very painful when testing a near complete game) but by switching to packed data those same games parsed in seconds. I've been using it ever since I recommend it to anyone. Thanks again for the code bud. I'm gonna have fun rippin this apart.
Title: Re: Yabasic Rocks !!!
Post by: rain_storm on January 11, 2007
True this raycaster runs faster, but it is not a faster algorithm. It casts only 33 rays and I clocked the fps for the above at just under 80 fps on my celeron. My own caster uses 160 rays by default and I was surprised that it only reached 30 odd fps so I turned down the amount of rays to 33 and the fps shot up to about 100 and it reached between 125 and 140 fps without the texture maps (depending on wether you spend that time looking across an open space or staring at a wall) Still you're right 30 odd frames per second is is pretty slow I'll make sure that the final release has this fixed.
Title: Re: Yabasic Rocks !!!
Post by: Jim on January 11, 2007
I think your routine also scans correctly, whereas this one takes baby steps across the map so as to avoid missing walls.  It still doesn't always work.

Jim
Title: Re: Yabasic Rocks !!!
Post by: rain_storm on January 11, 2007
I know that one. I had that problem too, mine still misses the edges of  the walls. When the ray travels beyond the target tyle and enters the next one. Had to decrease the distance rays traveled in one jump to 0.1 meter when it was 0.5 meter sharp corners simply didn't exist. Still I can't see myself getting even 50 fps and still hold on to the textures. It just aint gonna happen. An I aint letting them go. Must be another way to find some speed maybe by reworking the intersections... Ah well back to the drawing board.
Title: Re: Yabasic Rocks !!!
Post by: Jim on January 11, 2007
There are some good tutorials on the net that show how to jump a whole grid square at a time without missing anything.  Try googling while I see if I can find the link again.

Jim
Title: Re: Yabasic Rocks !!!
Post by: rain_storm on January 11, 2007
is this it?
http://www.properbostin.co.uk/notes/notes004.html
Title: Re: Yabasic Rocks !!!
Post by: Clanky on January 12, 2007
Heres the link to the code I posted:
http://p205.ezboard.com/fyabasicprogrammingfrm2.showMessage?topicID=294.topic

It's at the eeky Ezboard Forums... you can have a look around, some really good toutorials and codes at that board.
Yes, I guess this one is simplier - no textured walls. But it is still a nice base for a 3D shooter engine.
Title: Re: Yabasic Rocks !!!
Post by: rain_storm on January 12, 2007
Indeed it is thanks for the link bud, I think I might be able to squeze some more frames out by casting the first ray to both nearest longitudal and lateral grid lines so that I can then simply project on to the next lines instead of increasing the rays distance at the same steady rate this way I will know the right face Im dealin with from the get go instead of havin to calculate intersection points for faces that need not be considered thus eliminating two for - next loops (one for plotting intersection the other checking for distance) This is still on the writing pad though. Thank you
Title: Re: Yabasic Rocks !!!
Post by: Jim on January 16, 2007
Here's the link I was thinking of.
http://www.permadi.com/tutorial/raycast/index.html (http://www.permadi.com/tutorial/raycast/index.html)

Jim
Title: Re: Yabasic Rocks !!!
Post by: rain_storm on January 16, 2007
Karma for that, Jim. This is better than source code, it actually explains the technique very clearly and the part about looking up/down never thought it could be done in a raycaster btw got the rays projectin straight to lines now loads faster and always hits the right targets think I will go over the link a few more times to see what else I'm missin. Best tutorial I ever saw for rayscastin

Edit -

My textures are done the same as in the tutorial thats excellent one less thing to fix. One thing I didnt do the same is I use only angles, no projection plane maybe I should change that, the plane seems more versatile lets the camera move vertically as well as look up/down thanks again
Title: Re: Yabasic Rocks !!!
Post by: rain_storm on January 21, 2007
I have updated this code and have zipped the original post. Its alot better now running at 80 fps with weather effects and some minor alterations / additions. Thanks for the tutorial Jim it has really made a big difference. Hope you all like the changes. The new version can be found on the first post of this thread.
Title: Re: Yabasic Rocks !!!
Post by: lilw4t3rdr0p on January 21, 2007
Very cool!

Karma up!
Title: Re: Yabasic Rocks !!!
Post by: rain_storm on January 21, 2007
Thanks Lilly I appreciate that
Title: Re: Yabasic Rocks !!!
Post by: Clanky on January 21, 2007
Geez! That's awesome!!! Never knew YaBASIC could create such good programs!
Nice updates by the way... runs really smooth... and I like the way you have made the keyboard keys the defaults in the game, instead of using the X,O etc yab defaults - karma!

Although, the drawback is the wheather, it seems that there is too much rain falling, because the rects are thick, it doesn't guite give the feeling of real rain? Maybe tone it down abit, but it's up to you!

Nice progress on the program...

I have just been mucking around with the other RayCaster program, lol... never could ray cast myself! lol...

Cheers
Title: Re: Yabasic Rocks !!!
Post by: rain_storm on January 21, 2007
Ya like that! (Thanks)
I know what you mean about the rain but I added a slight wind effect so they drawn as lines not rects thats as thin as it goes I will be reducing the number of raindrops when I get around to adding splashes and ripples but this is coming along nicely! thanks for the Karma buddy
Title: Re: Yabasic Rocks !!!
Post by: Yaloopy on January 21, 2007
That's lookinh great, man!
Title: Re: Yabasic Rocks !!!
Post by: rain_storm on January 21, 2007
Thanks Loopy great to see you still check out Yabasic stuff

Edit -

I just put a picture in below the download and every surface has a splash now too. I reackon this one is done and dusted, now I haven't the foggiest what to do next. Maybe a graphics demo.
Title: Re: Yabasic Rocks !!!
Post by: Shockwave on January 21, 2007
I just had to press your Karma button :) That is one of the nicest raycasters I've ever seen in Yabasic and I've seen quite a few. The lightning and rain is a really nice touch. Textures are good as well. Nice stuff!

Title: Re: Yabasic Rocks !!!
Post by: rain_storm on January 21, 2007
Thanks, I aim to please
Title: Re: Yabasic Rocks !!!
Post by: Jim on January 22, 2007
Pretty amazing.  Good effort at interpreting the web site and putting it into code.

Jim
Title: Re: Yabasic Rocks !!!
Post by: lilw4t3rdr0p on January 22, 2007
Agrred. I like the rain and lighting. The map was handy as well! ;)
Title: Re: Yabasic Rocks !!!
Post by: rain_storm on January 22, 2007
I'm proud of this one its my baby I still dont know what to do next. Maybe I will hit up one of my other hobbies til something comes along
Title: Re: Yabasic Rocks !!!
Post by: lilw4t3rdr0p on January 22, 2007
ENTER in the INTRO-INFERNO compo!!!!!!! You still have plenty of time!

 :goodpost: karma up!
Title: Re: Yabasic Rocks !!!
Post by: rain_storm on January 27, 2007
Okay I have run some optimisations on this raycaster and I have removed the bugs and bug-fixes. I am confident that I can get 640 rays working at decent speed, at the moment the frame rate is 170+ when doing nothing 150+ when rotating but only a measly 50+ when walking.
I am trying to avoid casting rays if at all possible for example when the camera is rotating I have scrolled the distance values through the array and only cast rays that will hit new areas of the map. This works perfectly. I am trying to cheat when moving too by simply sliding the rays along the walls and only casting those rays that are near an edge or beyond the visible range. But this has proven to be a royal pain. I know it can be done. But I am constantly running into the same brick wall.
Things I have noted though are walls need to be altered according to the angle of the ray multiplied by direction of travel and not simply the direction the camera is moving at. Sometimes the alterations need to be applied as the cosine other walls require it to be the sine. The first file below does not include the movement cheat the other one does, the problem is in the move_rays() subroutine. I will trade karma for advise. Any suggestions will be appreciated.
Title: Re: Yabasic Rocks !!!
Post by: Clanky on January 28, 2007
RayCaster Optimised is really good!
Nice effort.
Title: Re: Yabasic Rocks !!!
Post by: rain_storm on January 30, 2007
The movement routine is a disaster, that sliding the rays along the wall cant be done directly I tried casting directly to the wall bypassing the firing the ray stage that works alright but finding the edges of the wall is killing the speed. You need to know exactly where the edge is and you need to leave a tolerence to either side of it. I have pulled it off but the camera moves at a snails pace and still miss the odd edge I need a better approach. the best thing is to play it safe for now and leave this one on the backburner til I can get my head around it.