Code: Select all
#include "yaglwrapper.bi"
declare function loadimage(filename as string, w as integer, h as integer) as YaglGfxSurface
dim tile(0 to 1, 0 to 99) as YaglGfxSurface, testFile as any ptr
dim as integer x, y, x2, y2
dim mapcode(0 to 1, 0 to 22, 0 to 20) as ubyte
mapcode(0,3,1) = 1
mapcode(1,5,1) = 1
YaglGfxDevice_setScreenMode(640, 480, 32, 0)
screenres 1, 1, 32, , -1
tile(0, 0) = loadimage("dat\maps\town1\ground\Grass.bmp", 30, 30)
tile(0, 1) = loadimage("dat\maps\town1\ground\Dirt.bmp", 30, 30)
tile(1, 1) = loadimage("dat\maps\town1\air\LeavesTopLeft.bmp", 30, 30)
screen 0
x = 0
y = 0
do
if YaglKeyboard_isKeyPressed(YAGL_KEY_ESCAPE) then exit do
if YaglKeyboard_isKeyPressed(YAGL_KEY_UP) then y+=1
if YaglKeyboard_isKeyPressed(YAGL_KEY_DOWN) then y-=1
if YaglKeyboard_isKeyPressed(YAGL_KEY_LEFT) then x+=1
if YaglKeyboard_isKeyPressed(YAGL_KEY_RIGHT) then x-=1
if x > 0 then x = 0
if y > 0 then y = 0
if x < -690+640 then x = -690+640
if y < -630+480 then y = -630+480
for x2 = 0 to 22
for y2 = 0 to 20
YaglGfxDevice_blit x+(x2*30), y+(y2*30), tile(0, mapcode(0, x2,y2)), BLIT_SOLID, 1
'YaglGfxDevice_blit x+(x2*30), y+(y2*30), tile(1, mapcode(1, x2,y2)), BLIT_ALPHAMASKED, &hff00ff
next y2
next x2
YaglGfxDevice_swapBuffers
loop
YaglGfxDevice_destroyAllSurfaces
function loadimage(filename as string, w as integer, h as integer) as YaglGfxSurface
dim testFile as any ptr, x as integer, y as integer, surface as YaglGfxSurface
testFile = imagecreate(w, h)
bload filename, testFile
For x = 0 To w-1
For y = 0 To h-1
cptr(Uinteger Ptr, testFile)[1+(y*h)+x] = cptr(Uinteger Ptr, testFile)[1+(y*h)+x] + &H1000000
Next
next
surface = YaglGfxDevice_createSurface
YaglGfxSurface_loadFromMemory surface, testFile+4, w, h, BITMAP_FORMAT_ARGB32
imagedestroy testFile
return surface
end function