Ok, started this tile scroller so I wouldnt have to use a lot of video ram for a large map. This uses an Array and it can be as big as you want.
For each tile image, as in a piece of grass, you need one sprite. each array element will be valued at 1,2 or 3 in this one.
I use 3 sprites here, 1 for grass, another for water , and the last for Mountains, or sand if you wish it to be. The graphics are awful. its just there for me to test this thing out before I start hand drawing ,map tiles. Plus this way I dont have to upload media, just the code.
if you find things wrong, or see a faster way, let me know.
// Project: MyMapScroller1
// Created: 2014-11-28
//
// My Map scroller in progress , havent had a lot of time lately to mess with it so
// releasing whats here so people who might need it, or wanna check out bugs can.
// Tiles are made with AGK drawing functions as to not need hand drawn tiles at this time.
// each tile uses one sprite to contain the image, so I have 3 sprites in use here
// Grass land, Water , and Moutain or sand, take your pick
//
// just easier to post the code that way.
//
// only one layer scrolling at the moment, mainly was workin towards a dragon quest clone
//Oh and some of the variables may not get used yet, they are there for later code.
// now the codes a mess, but I got a lot goin, so as I said, work in progress.
//
// I still need to work on tile to sprite collision when I put a walking character up
SetWindowTitle( "MyMapScroller1" )
SetWindowSize( 800, 480, 0 )
SetVirtualResolution( 800,480 )
SetOrientationAllowed( 0, 0, 1, 1 )
SetSyncRate(0,0)
Global lotw=100
Global loth=80
Global Mapscrnx=150
Global mapscrny=40
// Global SetColor Variables
Global dred=255
Global dgreen=255
Global dblue=255
Global starangle=53
Global starstep=144
Global Stdia
Global spr1
Global Dim mainmap[128+1,64+1]
Global Dim savedimages[64]
Global mapdataw=128
Global mapdatah=64
Global realmapw=12
Global realmaph=7
Global testvar
Global gmapx,gmapy
// #Include "AGKGraphicsSub1.agc"
SetColor(128,128,128)
Render2DFront()
// Make land tiles in code for demo purposes
MakeGrassTile(1)
MakeWaterTile(2)
MakeMountainTile(3)
SetMapData(0,0,mapdataw,mapdatah) // fill map array with random land
//plant mountains at two corners to test if map works right
mainmap[12,7]=3
mainmap[0,7]=3
// here we go
do
print("Use arrow keys")
Print( "fps="+str(floor( ScreenFPS()) ))
CheckInput()
DrawmaptoScreen(gmapx,gmapy,realmapw,realmaph)
Sync()
loop
Function CheckInput()
if GetRawKeystate(37) // left
gmapx=gmapx-1
if gmapx<0
gmapx=0
endif
endif
if GetRawKeystate(39) // right
gmapx=gmapx+1
if gmapx>(mapdataw-realmapw)*64
gmapx=(mapdataw-realmapw)*64
endif
endif
if GetRawKeystate(38) // Up
gmapy=gmapy-1
if gmapy<0
gmapy=0
endif
endif
if GetRawKeystate(40) // down
gmapy=gmapy+1
if gmapy>(mapdatah-realmaph)*64
gmapy=(mapdatah-realmaph)*64
endif
endif
if getrawkeystate(27) // stop , end , exit , outta here
end
endif
EndFunction
// Fill Map array with random tiles, each being 1,2 or 3 for this example
function SetmapData(mx,my,mw,mh)
for mapy=my to mh-1
for mapx=mx to mw-1
rr=random(0,2)
mnt=random(0,100)
if mnt>95 and rr=2 // make less mountians /gray sand tiles than grass or water
rr=2
elseif rr=2
rr=0
endif
MainMap[mapx,mapy]=rr+1
next mapx
next mapy
endfunction
// this is the puppy that does all the moving the tiles around
function DrawMaptoScreen(mx,my,mw,mh)
mx64=mx/64
my64=my/64
mxmod64=mod(mx,64)
mxmod64=-mxmod64
mymod64=mod(my,64)
mymod64=-mymod64
testvar=mymod64
Print("Mapx="+str(mx))
print("Mapy="+str(my))
mapinXX=mx64
// mapinY=my64*mapdataw
mapinY=my64
for mapy=0 to mh+1
mapinX=mapinXX
for mapx=0 to mw+1
rr=mainmap[mapinX,mapinY]
mapinX=mapinX+1
setspriteposition(rr,(mapx*64)+mxmod64,(mapy*64)+mymod64)
drawsprite(rr)
next mapx
mapinY=mapinY+1
next mapy
endfunction
// Simple draw Tile functions for testing purposes only
Function MakeGrassTile(spnum)
Render2DFront()
SetColor(40,180,40)
SBox(0,0,64,64)
For l= 0 To 130
gx=Random(0,63)
gy=Random(0,63)
DrawLine(gx,gy,gx+1,gy+1,20,220,20)
gx=Random(0,63)
gy=Random(0,63)
DrawLine(gx,gy,gx,gy,10,120,10)
Next l
spr1=GetImage(0,0,64,64)
CreateSprite(spnum,spr1)
SetSpriteSize(spnum,64,64)
savedimages[spnum]=spr1 // save image made for later use , maybe
EndFunction
Function MakeWaterTile(spnum)
render2dfront()
Setcolor(60,60,220)
Sbox(0,0,64,64)
for l= 0 to 130
gx=random(0,63)
gy=random(0,63)
drawline(gx,gy,gx+1,gy+1,80,80,250)
gx=random(0,63)
gy=random(0,63)
drawline(gx,gy,gx,gy,10,10,120)
next l
spr1=getimage(0,0,64,64)
createsprite(spnum,spr1)
setspritesize(spnum,64,64)
savedimages[spnum]=spr1
endfunction
function MakeMountainTile(spnum)
render2dfront()
Setcolor(160,160,160)
Sbox(0,0,64,64)
for l= 0 to 130
gx=random(0,63)
gy=random(0,63)
drawline(gx,gy,gx+1,gy+1,80,80,80)
gx=random(0,63)
gy=random(0,63)
drawline(gx,gy,gx,gy,220,220,220)
next l
spr1=getimage(0,0,64,64)
createsprite(spnum,spr1)
setspritesize(spnum,64,64)
savedimages[spnum]=spr1
endfunction
Function SBox(sbx,sby,sbx2,sby2)
crn1=makecolor(dred,dgreen,dblue)
crn2=makecolor(dred,dgreen,dblue)
crn3=makecolor(dred,dgreen,dblue)
crn4=makecolor(dred,dgreen,dblue)
drawbox(0,0,64,64,crn1,crn2,crn3,crn4,1)
endfunction
// sets color variables for later use by my own drawing functions
function SetColor(sred,sgreen,sblue)
dred=sred
dgreen=sgreen
dblue=sblue
endfunction
It's Bird! , It's Plane!, No its a rocket powered Squirrel holding some acorns and a smile!