Media Loader by Northern Lights7th May 2005 14:11
|
---|
Summary Automatically load all supported picture files in a folder. Description I don't know how useful this is to anyone, but it seems like it should save a little time with some slight modifications. It loads all media in a "media" folder that must be in the same directory as the executable. Code ` This code was downloaded from The Game Creators ` It is reproduced here with full permission ` http://www.thegamecreators.com REM Project: Main Project File REM Created: 5/5/2005 9:59:50 PM REM REM ***** Main Source File ***** REM loadMedia() sleep 50 s# = getSIndex() e# = getEIndex() do if returnkey() = 1 cls print "Valid Choices: " for x = 1 to array count(imgIndex(0)) `this checks if array count is > 0 and if imgIndex(x)>0 `then if the image is loaded. then tells user if image exist(imgIndex(x)) = 1 print str$(imgIndex(x)) endif endif next x endif Input "Choice: ",I# if I# < s# or I# > e# `basic error checking to make sure the user hasn't put in a bad value I# = 0 cls endif if I# <> 0 if image exist(I#) = 1 create bitmap 1,1024,768 `next set of lines get sprites width and height and set current bitmap 1 `centers it on the screen. Assuming you run in 1024x768 sprite 1,0,0,I# w# = sprite width(1) h# = sprite height(1) set current bitmap 0 delete bitmap 1 sprite 1,(512-(w#/2)),(384-(h#/2)),I# else `if image doesn't exist, return error Print "Image "+str$(I#)+" not loadable" endif endif sync loop function loadMedia() Sync on : sync rate 60 gosub initFileArrays set dir "media\" load dll "user32.dll",1 ` this will enable me to have message boxes if I need them perform checklist for files `scans media folder for all files q# = checklist quantity() W = call dll(1,"GetActiveWindow") `used to make messagebox if q# <= 2 `there are two files in every folder that you can't see if there are only those two - make error box msgBox("You need to put some media into the media folder","Error") end endif for x = 3 to q# l# = len(checklist string$(x)) `get length of file name print "Length of File Name: "+ str$(l#) if mid$(checklist string$(x), (l#-3)) = "." `search for "." in file name print "Checking file: "+ checklist string$(x) for y = 0 to 4 if lower$(right$(checklist string$(x),3)) = right$(supportedFiles$(y),3) `takes the last 3 digits of file file_names$(x+1) = checklist string$(x) `name and compares to supportedFiles$() numFiles# = numFiles#+1 `increments the number of valid files I have print "Valid file found: "+ file_names$(x+1) print " " endif next y endif next x print str$(numFiles#)+" = NumFiles" print "file names " + file_names$(3) print " " for a = 1 to numFiles#+3 `numFiles#+3 because in the loop NumFiles# was made it starts at 3 `(line 31)^ f$ = file_names$(a) print "Attempting to Load " + f$ `loads the valid image name if file exist(f$) = 1 then load image f$,a if image exist(a) = 1 then print str$(a)+" loaded":imgIndex(a) = a `stores the valid images # into imgIndex if image exist(a) = 0 then print str$(a) + " not loaded" print " " next a `this will paste the loaded image as a reference for a = 3 to numFiles#+3 if image exist(a) = 1 then paste image a,(a*30)+100,400:else:print "image doesn't exist" next a endIndex# = numFiles#+3 startIndex# = 4 endfunction function getSIndex() `both functions are used to determine choices that a user a# = startIndex# `may choose to display an image endfunction a# function getEIndex() a# = endIndex# endfunction a# function msgBox(message$,title$) call dll 1,"MessageBoxA",W,message$,title$,48 endfunction initFileArrays: dim file_names$(250) `stores all valid file names ` dim file_string$(20) dim supportedFiles$(4) ` stores list of supported files to compare to global dim imgIndex(250) `will store every valid image's index number for choosing image supportedFiles$(0) = "dds" supportedFiles$(1) = "jpg" supportedFiles$(2) = "bmp" supportedFiles$(3) = "tga" supportedFiles$(4) = "png" global startIndex# `used to determine what can be chosen by the user global endIndex# return |