hi...
here is 3 .bas files for a base to a text game using sound/music with Bass lib and images and text files for text... and with library FBTrueType for the opening.
1. file "fb_main.bas"
#include "fbgfx.bi"
#include "FBTrueType.bi"
'#include Once "bass.bi"
#undef Boolean
type Boolean as byte
#define IsNot 0=
const screen_w = 800 , screen_h = 600
SCREENRES screen_w , screen_h , 32
windowtitle("Finel Days Game By Ron77")
width screen_w\8,screen_h\16
#include "fb_samples_init.bas"
#include "fb_images_init.bas"
const MUSIC_INTRO = "sound/opening_theme.mp3"
const MUSIC_INTRO2 = "sound/opening_theme2.mp3"
const MUSIC_FREE_MADE = "sound/growing up pains.mp3"
const BACK_OLDMAN = "img/final_days1.bmp"
const BACK_REINCARNATION = "img/reincarnation.bmp"
'improve print of whole text file on screen
SUB txtfile( TextFile AS STRING)
'CLS
/'
DIM AS STRING buffer
DIM h AS LONG = FREEFILE()
if OPEN(TextFile FOR BINARY access read AS #h) then
print "file could not be opened!"
elseif (lof(h) < 1) then
print "file could not be read!"
else
buffer = SPACE(LOF(h))
GET #h , , buffer
CLOSE #h
PRINT buffer
end if
'/
var f = FREEFILE()
if OPEN(TextFile FOR input AS #f) then
print TextFile & " file could not be opened!"
exit sub
EndIf
dim as string sLine
dim as long PosY = 0
while not eof(f)
line input #f, sLine
for Y as long = -1 to 1 step 2
for X as long = -1 to 1 step 2
Draw String (X+0,Y+PosY),sLine,rgb(0,0,0)
Next
Next
Draw String (0,PosY),sLine,rgb(255,255,255)
PosY += 16
Wend
close #f
End SUB
sub theme( textfile as string, music as string, BackgroundImageFile as string)
var imgBack = LoadImage1( BackgroundImageFile )
ShowImage( imgBack )
playMusic( music )
txtfile(textfile)
sleep
stopMusic()
DestroyImage( imgBack )
End Sub
SUB opening()
var imgBack = LoadImage1(BACK_OLDMAN)
Showimage( imgBack )
playMusic( MUSIC_INTRO )
VAR Font = FontLoad("NaKaDai Italic.ttf")
DIM AS STRING WORD = "A GAME BY RON77"
DIM s AS STRING = "Final Days"
TTPrint Font , 300 , 150 , s , RGB(255 , 0 , 0) , 50
ttprint Font , 100 , 200 , WORD , RGB(0 , 255 , 80) , 50
sleep
StopMusic()
Destroyimage( imgBack )
FontFree( Font )
END SUB
opening()
theme( "data/test1.txt" , MUSIC_INTRO2 , BACK_REINCARNATION )
sleep
2. file "fb_sample_init.bas" (for the sound/music using Bass library
#include "bass.bi"
'' Call this once at the beginning of the program
If (BASS_GetVersion() < MAKELONG(2,2)) Then
Print "BASS version 2.2 or above required!"
End 1
End If
If (BASS_Init(-1, 44100, 0, 0, 0) = 0) Then
Print "Could not initialize BASS"
End 1
End If
dim shared as HMUSIC g_BackgroundMusic
sub stopMusic( music as HMUSIC = NULL )
if music = NULL then music = g_BackgroundMusic
if music then BASS_ChannelStop( music )
end sub
sub freeMusic( music as HMUSIC = NULL )
if music = NULL then music = g_BackgroundMusic : g_BackgroundMusic = NULL
if music then BASS_MusicFree( music )
end sub
function playMusic( soundfile as string ) as HMUSIC
if g_BackgroundmUsic then
stopMusic(g_BackgroundMusic)
freeMusic(g_BackgroundMusic)
g_BackgroundMusic = NULL
EndIf
var music = BASS_StreamCreateFile( 0, strptr( soundfile ), 0, 0, 0 )
if music then
g_BackgroundMusic = music
BASS_ChannelPlay( music, 0 )
end if
return music
end Function
3. file "fb_image_init.bas" (for images on graphic screen)
function loadImage1( imagefile as string ) as fb.image ptr
DIM AS fb.image ptr image
dim as long ImageWid , ImageHei
var f = freefile()
if open( imagefile for binary access read as #f) then
return NULL
EndIf
get #f,19,ImageWid : get #f,,ImageHei
close #f
image = IMAGECREATE(ImageWid , ImageHei , 0)
bload imagefile, image
return image
end function
sub ShowImage( image as fb.image ptr )
put(0,0), image, pset
End Sub
sub destroyImage( image as fb.image ptr )
if image then ImageDestroy(image)
End Sub