#!/usr/local/bin/yabasic rem
goto Main : rem
label CopyLeft print "YaSokoban r1.2, Copyright (C) 1998,1999 by Hermang Mansilla" print "E-mail: hmansilla@usa.net" ? "This is a clone of a puzzle in which you move in a maze pushing " ? "blocks, to put them in the grid regions of the maze" print "For more information visit my Web Page" print "www.oocities.org/SunsetStrip/Palms/1624/yabasic/" print "This program is free software; you can redistribute it and or" print "modify it under the terms of the GNU General Public License as" print "published by the Free Software Foundation." print "This Program is distributed in the hope that it will be useful," print "but WITHOUT ANY WARRANTY" print " :-) :-> " print "Developed and tested in Linux 2.0.27, should work in windows too" print "Yabasic version 2.45 or later recommended" print "Tip: arrange the position of this window so it does not " print "cover the graphic window" print "To move in the maze or push blocks press the cursor keys" return : rem CopyLeft rem
rem
rem
LABEL Initialize saving=0 nmovs=0 npush=0 SokobanPATH$="." if peek$("os")="unix" then SCREENPATH$=SokobanPATH$+"/screens/" BitmapPATH$=SokobanPATH$+"/ybitmaps/" else SCREENPATH$=SokobanPATH$+"\\screens\\" BitmapPATH$=SokobanPATH$+"\\ybitmaps\\" print "This program has not been tested with windows " print "if it works on your system, please, send me an E-mail message" input "press enter to continue",dummy$ fi nivel=1 MAXROW=21 MAXCOL=21 sizetile=30 WidthScreen=sizetile*(MAXCOL-1) HeightScreen=sizetile*(MAXROW-1) tsprites=6 dim Sprites$(tsprites,40) dim SpriteName$(tsprites) dim height(tsprites),width(tsprites) dim DirtyX(tsprites,35,35), DirtyY(tsprites,35,35), tpoints(tsprites,35) for i=1 to tsprites read SpriteName$(i) next i data "man.ybm", "goal.ybm", "wall.ybm", "object.ybm" data "saveman.ybm","treasure.ybm" valid$="@.#$+* " retError$="ok" dim Mapa$(MAXROW,MAXCOL) dim Dirty(MAXROW,MAXCOL) Ground$=" ":player$="@" store$=".":playerstore$="+" packet$="$":save$="*" wall$="#" newline$=chr$(10) return rem Initialize
rem
label Main gosub CopyLeft gosub Initialize gosub LoadSprites print "\n ... Sprites loaded in Memory" input "Press Enter to continue ",dummy$ clear screen input "Indicate which level to play (1-90)", nivel label innerloop gosub ReadLevel gosub GeneraMapa if retError$="ok" then clear screen gosub ShowStatus WidthScreen=cols*sizetile HeightScreen=rows*sizetile open window WidthScreen,HeightScreen gosub DrawMap gosub playit else print "Errors Reading this Level : ",retError$ beep k$=inkey$ if k$="q" then CLOSE WINDOW end fi fi Print "\n Changing level\n" rem k$=inkey$ close window if k$="q" then end fi nivel=nivel+1 goto innerloop rem Main
rem
label ReadYBitmap FileName$="" FileName$=BitmapPATH$+SpriteName$(sprite) open 1,FileName$,"r" input #1 tem$,title$ input #1 tem$,ancho$,coma$,alto$ height(sprite)=val(alto$) width(sprite)=val(ancho$) for ybmrow=1 to height(sprite) if (not eof(1)) then input #1 tem$, Sprites$(sprite,ybmrow) fi next ybmrow close 1 for ybmrow=1 to height(sprite) point=0 for ybmcol=1 to width(sprite) tmp$=mid$(Sprites$(sprite,ybmrow),ybmcol,1) if tmp$="1" then point=point+1 DirtyX(sprite,point,ybmrow)=ybmcol DirtyY(sprite,point,ybmrow)=ybmrow fi next ybmcol tpoints(sprite,ybmrow)=point next ybmrow return :rem ReadYBitmap
rem
Label ShowYbm for ybmrow=1 to height(sprite) for point=1 to tpoints(sprite,ybmrow) dot DirtyX(sprite,point,ybmrow)+offsetx,DirtyY(sprite,point,ybmrow)+offsety next point next ybmrow return :rem
rem
label LoadSprites for sprite=1 to tsprites gosub ReadYBitmap next sprite return :rem
rem
LABEL ReadLevel MapFile$="" MapFile$=SCREENPATH$+"screen."+str$(nivel,"%1.0f") rem comando$="" rem comando$="cat "+MapFile$ niveldata$="" rem niveldata$=system$(comando$) open 1,MapFile$,"r" label loopLeeNivel if (not eof(1)) then line input #1 buflinea$ niveldata$=niveldata$+buflinea$+newline$ else close 1 goto SalirLeeNivel endif goto loopLeeNivel label SalirLeeNivel nmovs=0 : npush=0 return : rem ReadLevel rem
rem
LABEL GeneraMapa for y=1 to MAXROW for x=1 to MAXCOL Mapa$(y,x)=Ground$ Dirty(y,x)=1 next x:next y j=1:cols=1:rows=1:packets=0:savepack=0 playerposx=-1:playerposy=-1 for index=1 to len(niveldata$) temp$=mid$(niveldata$,index,1) if temp$=newline$ then rows=rows+1 if rows > MAXROW then retError$="ErrTOMUCHROWS" else if j> cols then cols=j fi j=1 fi else opt=instr(valid$,temp$) if opt>0 then if temp$=player$ or temp$=playerstore$ then playerposy=rows playerposx=j fi if temp$=save$ then savepack=savepack+1 packets=packets+1 fi if temp$=packet$ then packets=packets+1 fi Mapa$(rows,j)=temp$ j=j+1 if j>MAXCOL then retError$="ErrTOMUCHCOLS" fi else retError$="ErrILLCHAR" fi fi next index return : rem GeneraMapa rem
rem
label ShowStatus MapRows=rows-1 MapCols=cols-1 print @(1,5) "Level = ",nivel; rem print @(1,2) "Rows = ",MapRows; rem print @(1,3) "Columns = ",MapCols; print @(1,6) "Packets = ",packets; print @(1,7) "Saved Packets = (in development)"; rem savepack; print @(1,8) "Movements = ",nmovs; print @(1,9) "Pushes = ",npush; print "\nlet's play \n"," Press q to Quit the Game" ? " Arrows to Move, n for next Level" ? " r to restart current level" ? " t to redraw the screen (if needed)" return : rem ShowStatus
rem
label DrawMap for tiley=1 to rows for tilex=1 to cols sprite=0 if Mapa$(tiley,tilex)=wall$ then sprite=3 fi if Mapa$(tiley,tilex)=player$ then sprite=1 fi if Mapa$(tiley,tilex)=store$ then sprite=2 fi if Mapa$(tiley,tilex)=packet$ then sprite=4 fi if Mapa$(tiley,tilex)=playerstore$ then sprite=5 fi if Mapa$(tiley,tilex)=save$ then sprite=6 fi if Mapa$(tiley,tilex)=Ground$ then sprite=7 fi if Dirty(tiley,tilex)=1 then box (tilex-1)*sizetile,(tiley-1)*sizetile to tilex*sizetile,tiley*sizetile if sprite>0 then if sprite=7 then rem nothing :-) else offsetx=sizetile*(tilex-1)-1 offsety=sizetile*(tiley-1) gosub ShowYbm fi fi Dirty(tiley,tilex)=0 fi next tilex : next tiley return : rem DrawMap
rem
rem This was used to create new rem levels for the next release Label SaveMap saveas$="" saveas$="./levels/level."+str$(nivel,"%1.0f") estenivel$="level"+str$(nivel,"%1.0f") open 1,saveas$,"w" print #1 "Label ",estenivel$ print #1 "data ",MapRows," , ",MapCols for tiley=1 to MapRows bl$="" for tilex=1 to MapCols bl$=bl$+Mapa$(tiley,tilex) next tilex print #1 "data ", "\"",bl$,"\"" next tiley close 1 if nivel=90 then end fi return : rem SaveMap
rem
label playit label KeepPlaying dx=0:dy=0 if saving=1 then k$="s" else k$=inkey$ fi desde$=Mapa$(playerposy,playerposx) if k$="up" then dy=-1 fi if k$="down" then dy=1 fi if k$="left" then dx=-1 fi if k$="right" then dx=1 fi hacia$=Mapa$(playerposy+dy,playerposx+dx) if hacia$=Ground$ or hacia$=store$ then gosub Movedxdy fi if hacia$=packet$ or hacia$=save$ then atras$=Mapa$(playerposy+2*dy,playerposx+2*dx) if atras$=Ground$ or atras$=store$ then gosub Pushdxdy fi fi clear screen gosub ShowStatus gosub DrawMap if k$="q" then end fi if k$="t" then for tiley=1 to rows for tilex=1 to cols Dirty(tiley,tilex)=1 next tilex next tiley gosub DrawMap fi if k$="s" then saving=1 gosub SaveMap k$="n" print "Wait ! Creating new Levels on ./levels" fi if k$="r" then nivel=nivel-1 k$="n" fi if k$<>"n" then goto KeepPlaying fi return : rem playit
rem
Label Pushdxdy if desde$=player$ then Mapa$(playerposy,playerposx)=Ground$ else Mapa$(playerposy,playerposx)=store$ fi if hacia$=packet$ then Mapa$(playerposy+dy,playerposx+dx)=player$ else Mapa$(playerposy+dy,playerposx+dx)=playerstore$ fi if atras$=Ground$ then Mapa$(playerposy+2*dy,playerposx+2*dx)=packet$ else Mapa$(playerposy+2*dy,playerposx+2*dx)=save$ fi Dirty(playerposy,playerposx)=1 Dirty(playerposy+dy,playerposx+dx)=1 Dirty(playerposy+2*dy,playerposx+2*dx)=1 playerposx=playerposx+dx playerposy=playerposy+dy npush=npush+1 return : rem Pushdxdy
rem
Label Movedxdy if desde$=player$ then Mapa$(playerposy,playerposx)=Ground$ else Mapa$(playerposy,playerposx)=store$ fi if hacia$=Ground$ then Mapa$(playerposy+dy,playerposx+dx)=player$ else Mapa$(playerposy+dy,playerposx+dx)=playerstore$ fi Dirty(playerposy,playerposx)=1 Dirty(playerposy+dy,playerposx+dx)=1 playerposx=playerposx+dx playerposy=playerposy+dy nmovs=nmovs+1 return : rem Movedxdy rem
rem