Trying to mimic the effect from an
old amiga game(starts at about 1:10). Not my cleanest code ever, but it shows how to swap between two screens using ImageKit.
Rem Project: Dark Basic Pro Project
Rem Created: Monday, November 05, 2012
Rem ***** Main Source File *****
set display mode 640, 480, 32
loadFont("font.png", 100, 32)
load image "tile1.png", 1
load image "tile3.png", 2
ik create render target 3, 640, 384
ik create render target 4, 640, 64
ik create render target 5, 640, 384
draw to image 3
for x = 0 to 9
for y = 0 to 5
paste image 1, x*64, y*64, 1
next y
next x
drawFont(320, 32, "please insert", 0, 1)
drawFont(320, 64, "blood money disk 2", 0, 1)
drawFont(320, 96, "into drive 0", 0, 1)
draw to bitmap 0
do
cls
paste image 5, 0, 0, 1
if spacekey() = 1 and flag = 0
flag = 1
hFlag = 4
row = 0
doThing = 1
endif
if spacekey() = 0 then flag = 0
if doThing = 1
if delay+20 <= timer()
ik resize image 4, 640, 64, RESIZE_NEAREST
ik copy image 4, 3, 0, row*64, 640, (row+1)*64
ik resize image 4, 640, hFlag, RESIZE_LINEAR
inc hFlag, 4
draw to image 5
paste image 4, 0, (32-hFlag/2)+row*64, 1
draw to bitmap 0
if hFlag > 64
inc row
hFlag = 4
if row > 5 then doThing = 0
endif
delay = timer()
endif
endif
if inkey$() = "1" and doThing = 0
`doThing = 1
draw to image 3
for x = 0 to 9
for y = 0 to 5
paste image 2, x*64, y*64, 1
next y
next x
drawFont(320, 0, "blood money", 0, 1)
drawFont(320, 64, "coded by dave jones", 0, 1)
drawFont(320, 96, "graphics tony smith", 0, 1)
drawFont(320, 128, "dma design", 0, 1)
drawFont(320, 192, "press f1 1 player", 0, 1)
drawFont(320, 224, "press f2 2 player", 0, 1)
drawFont(320, 256, "press f3 music on", 0, 1)
drawFont(320, 288, "press f4 patient ", 0, 1)
drawFont(320, 352, "1989 psygnosis", 0, 1)
draw to bitmap 0
endif
set cursor 0,0
print screen fps()
print doThing
print hFlag
loop
function drawFont(x, y, t$, charOffset, center)
if center = 1 then x = x-len(t$)*16
imgOffset = 100
t$ = upper$(t$)
l = len(t$)
for i = 1 to l
char = asc(mid$(t$, i))
if char < 32 then char = 32
img = imgOffset + char - 32
paste image img, x, y, 1
inc x, 32+charOffset
next i
endfunction
REM ===============================================================
REM Loads the specified image into a memblock and extracts
REM individual tiles, storing them starting with 'imgOffset'.
REM 'imgOffset' should start with 2 or higher, unless the variable
REM 'imgNoMap' at the top of the function is changed.
REM
REM Returns: Last image number used
REM ===============================================================
function loadFont(filename as string, imgOffset as integer, tileSize as integer)
rem these variables can be changed to fit your needs if these
rem numbers are already used elsewhere in your program
local memNoMap = 1
local memNoTile = 2
local imgNoMap = 1
local color as dword
rem load the tilemap image
load image filename, imgNoMap
rem Create the memblock to store the individual tiles
make memblock memNoTile, 12 + tileSize*tileSize*4
write memblock dword memNoTile, 0, tileSize
write memblock dword memNoTile, 4, tileSize
write memblock dword memNoTile, 8, 32
rem Create memlbock from the tilemap image
make memblock from image memNoMap, imgNoMap
imgWidth = memblock dword(memNoMap, 0)
imgHeight = memblock dword(memNoMap, 4)
rem determine how many tile rows and columns there are in the image
tileCols = imgWidth / tileSize
tileRows = imgHeight / tileSize
rem tile offset calculations
colTileOffset = tileSize*4
rowTileOffset = imgWidth*4*tileSize
rem loop through the tiles in the image
for y = 0 to tileRows-1
for x = 0 to tileCols-1
col = x*colTileOffset
row = y*rowTileOffset
rem tile offset within the image
tileOffset = row + col + 12
rem Extract pixel data from tilemap and store
rem a "tileSize by tileSize" image tile into
rem the other memblock
for iy = 0 to tileSize-1
for ix = 0 to tileSize*4-1 step 4
ty = iy*imgWidth*4
pos = tileOffset + ty + ix
rem extra pixel color from larger tilemap
color = memblock dword(memNoMap, pos)
tilePos = iy*tileSize*4 + ix + 12
rem write pixel color to smaller tile image
write memblock dword memNoTile, tilePos, color
next ix
next iy
rem create an image from tile memblock then repeat process
make image from memblock imgOffset, memNoTile
inc imgOffset, 1
next x
next y
rem free up memory
delete memblock memNoMap
delete memblock memNoTile
rem since DB can't handle expressions in the endfunction
dec imgOffset, 1
endfunction imgOffset
"You're not going crazy. You're going sane in a crazy world!" ~Tick