Hello everyone.
Firstly, I apologize for my English ... I use google translator to communicate.
I hope to contribute by offering a lot of features.
These functions must be placed together.
She used to have a tile-based rendering.
// Use this function first ! This function initialise SuperGenesisEngine
function InitSGE(ScreenSizeX,ScreenSizeY,TileSizeX,TileSizeY,WorldSizeX,WorldSizeY,WorldSizeOfDepth)
setvirtualresolution(ScreenSizeX,ScreenSizeY)
global dim SGE_World_Map[WorldSizeOfDepth,WorldSizeX,WorldSizeY]
global dim SGE_World_Position_X[WorldSizeOfDepth]
global dim SGE_World_Position_Y[WorldSizeOfDepth]
global dim SGE_World_Depth_Visible[WorldSizeOfDepth]
Global SGE_WorldBankImage$
global SGE_Camera_Position_X , SGE_Camera_Position_Y , SGE_W_SizeOfDepth , SGE_ScreenSizeX , SGE_ScreenSizeY , SGE_TileSizeX , SGE_TileSizeY , SGE_WorldSizeX , SGE_WorldSizeY
global SGE_Camera_Limit_X , SGE_Camera_Limit_Y
SGE_W_SizeOfDepth = WorldSizeOfDepth
SGE_ScreenSizeX = ScreenSizeX
SGE_ScreenSizeY = ScreenSizeY
SGE_TileSizeX = TileSizeX
SGE_TileSizeY = TileSizeY
SGE_WorldSizeX = WorldSizeX
SGE_WorldSizeY = WorldSizeY
SGE_Camera_Limit_X = SGE_WorldSizeX*SGE_TileSizeX-SGE_ScreenSizeX-SGE_TileSizeX
SGE_Camera_Limit_Y = SGE_WorldSizeY*SGE_TileSizeY-SGE_ScreenSizeY-SGE_TileSizeY
SizeX = ScreenSizeX / TileSizeX + 1
SizeY = ScreenSizeY / TileSizeY + 1
global dim SGE_World_SpriteID[WorldSizeOfDepth,SizeX,SizeY]
ImageDummy = getimage(0,0,TileSizeX-1,TileSizeY-1)
for Depth = 0 to WorldSizeOfDepth
for Y = 0 to SizeY
for X = 0 to SizeX
SGE_World_SpriteID[Depth,X,Y] = createsprite(ImageDummy)
setspritedepth(SGE_World_SpriteID[Depth,X,Y],10000-Depth*100)
setspriteposition(SGE_World_SpriteID[Depth,X,Y],X*TileSizeX,Y*TileSizeY)
SetSpriteSize(SGE_World_SpriteID[Depth,X,Y],TileSizeX,TileSizeY)
SetSpriteTransparency(SGE_World_SpriteID[Depth,X,Y],1)
FixSpriteToScreen(SGE_World_SpriteID[Depth,X,Y],1)
next X
next Y
next Depth
endfunction
function Draw(com$,num$)
print(com$)
print(num$)
sync()
endfunction
function LoadTileBankImage(File$,BorderLineSize)
global SGE_BorderLineSize
SGE_BorderLineSize = BorderLineSize
BankID = loadimage(File$)
SGE_WorldBankImage$ = File$
NBimageX = (getimagewidth(BankID)-BorderLineSize)/(SGE_TileSizeX+BorderLineSize)
NBimageY = (getimageheight(BankID)-BorderLineSize)/(SGE_TileSizeY+BorderLineSize)
Global SGE_MaxTileImage
SGE_MaxTileImage = NBimageX*NBimageY
global dim SGE_TileImageID[SGE_MaxTileImage]
global dim SGE_TileAnimationImageID[SGE_MaxTileImage]
global dim SGE_TileAnimationTimer[SGE_MaxTileImage]
global dim SGE_TileAnimationFrameImage[SGE_MaxTileImage,30]
global dim SGE_TileAnimationFrameTime[SGE_MaxTileImage,30]
global dim SGE_TileAnimationCurrentFrame[SGE_MaxTileImage]
for Y = 0 to NBimageY-1
for X = 0 to NBimageX-1
SGE_TileImageID[NBimage] = copyimage(BankID,X*(SGE_TileSizeX+BorderLineSize)+BorderLineSize,Y*(SGE_TileSizeY+BorderLineSize)+BorderLineSize,SGE_TileSizeX,SGE_TileSizeY)
SGE_TileAnimationImageID[NBimage] = SGE_TileImageID[NBimage]
SGE_TileAnimationFrameImage[NBimage,0] = NBimage
inc NBimage
NBI# = NBimage
NBM# = SGE_MaxTileImage
Progress# = (NBI#/NBM#)*100
Draw("Loading Tile...",str(Progress#,1)+" %")
next X
next Y
deleteimage(BankID)
endfunction
function SetTileAnimation(Animation,Frame,Tile,Time)
SGE_TileAnimationFrameTime[Animation,Frame] = Time
SGE_TileAnimationFrameImage[Animation,Frame] = Tile
endfunction
function RefreshTileAnimation()
TileTimer = getmilliseconds()
for Tile = 0 to SGE_MaxTileImage
if TileTimer-(SGE_TileAnimationTimer[Tile]+SGE_TileAnimationFrameTime[Tile,SGE_TileAnimationCurrentFrame[Tile]]) >= SGE_TileAnimationFrameTime[Tile,SGE_TileAnimationCurrentFrame[Tile]]
SGE_TileAnimationCurrentFrame[Tile] = SGE_TileAnimationCurrentFrame[Tile] + 1
if SGE_TileAnimationFrameTime[Tile,SGE_TileAnimationCurrentFrame[Tile]] = 0
SGE_TileAnimationCurrentFrame[Tile] = 0
endif
SGE_TileAnimationTimer[Tile] = TileTimer
SGE_TileAnimationImageID[Tile] = SGE_TileImageID[SGE_TileAnimationFrameImage[Tile,SGE_TileAnimationCurrentFrame[Tile]]]
endif
next Tile
endfunction
function AddTileToWorld(TileID,PositionX,PositionY,Depth)
if PositionX <= SGE_WorldSizeX and PositionX >= 0 and Depth >= 0 and Depth <= SGE_W_SizeOfDepth and PositionY <= SGE_WorldSizeY and PositionY >= 0
SGE_World_Map[Depth,PositionX,PositionY] = TileID
endif
endfunction
function SetWorldDepthVisible(Depth,Visible)
if Depth >= 0 and Depth <= SGE_W_SizeOfDepth
if Visible >=0 and Visible <= 1
SGE_World_Depth_Visible[Depth] = Visible
SizeX = SGE_ScreenSizeX / SGE_TileSizeX + 1
SizeY = SGE_ScreenSizeY / SGE_TileSizeY + 1
for Y = 0 to SizeY
for X = 0 to SizeX
setspritevisible(SGE_World_SpriteID[Depth,X,Y],Visible)
next X
next Y
endif
endif
endfunction
function SetTileCameraPosition(CameraPositionX,CameraPositionY)
SGE_Camera_Position_X = CameraPositionX
SGE_Camera_Position_Y = CameraPositionY
endfunction
function FillWorld(TileID,Depth)
for Y = 0 to SGE_WorldSizeX
for X = 0 to SGE_WorldSizeY
AddTileToWorld(TileID,X,Y,Depth)
next X
next Y
endfunction
function FillZoneWorld(TileID,TopX,TopY,Lenght,Height,Depth)
for Y = TopY to TopY+Height
for X = TopX to TopX+Lenght
AddTileToWorld(TileID,X,Y,Depth)
next X
next Y
endfunction
function SaveWorld(WorldName$)
WorldName$ = WorldName$ + ".wld"
ID_File = opentowrite(WorldName$)
writeinteger(ID_File,SGE_WorldSizeX)
writeinteger(ID_File,SGE_WorldSizeY)
writeinteger(ID_File,SGE_W_SizeOfDepth)
writeinteger(ID_File,SGE_BorderLineSize)
writestring(ID_File,SGE_WorldBankImage$)
for Depth = 0 to SGE_W_SizeOfDepth
for Y = 0 to SGE_WorldSizeY
for X = 0 to SGE_WorldSizeX
writeinteger(ID_File,SGE_World_Map[Depth,X,Y])
next X
next Y
next Depth
closefile(ID_File)
endfunction
function LoadWorld(WorldName$)
WorldName$ = WorldName$ + ".wld"
ID_File = opentoread(WorldName$)
SGE_WorldSizeX = readinteger(ID_File)
SGE_WorldSizeY = readinteger(ID_File)
SGE_W_SizeOfDepth = readinteger(ID_File)
SGE_BorderLineSize = readinteger(ID_File)
SGE_WorldBankImage$ = readstring(ID_File)
for Depth = 0 to SGE_W_SizeOfDepth
for Y = 0 to SGE_WorldSizeY
for X = 0 to SGE_WorldSizeX
SGE_World_Map[Depth,X,Y] = readinteger(ID_File)
next X
next Y
next Depth
closefile(ID_File)
LoadTileBankImage(SGE_WorldBankImage$,SGE_BorderLineSize)
endfunction
function TestInputX()
MX# = GetRawJoystickX(Joy_0_ID)
MoveX = round(MX#)
endfunction MoveX
function TestInputY()
MY# = GetRawJoystickY(Joy_0_ID)
MoveY = round(MY#)
endfunction MoveY
function RenderWorld()
RefreshTileAnimation()
if SGE_Camera_Position_X <= SGE_Camera_Limit_X and SGE_Camera_Position_Y <= SGE_Camera_Limit_Y and SGE_Camera_Position_X >=0 and SGE_Camera_Position_Y >= 0
TileStartX = SGE_Camera_Position_X / SGE_TileSizeX
TileStartY = SGE_Camera_Position_Y / SGE_TileSizeY
TileStopX = (SGE_Camera_Position_X + SGE_ScreenSizeX) / SGE_TileSizeX
TileStopY = (SGE_Camera_Position_Y + SGE_ScreenSizeY) / SGE_TileSizeY
PositionScreenX = TileStartX * SGE_TileSizeX - SGE_Camera_Position_X
PositionScreenY = TileStartY * SGE_TileSizeY - SGE_Camera_Position_Y
for Depth = 0 to SGE_W_SizeOfDepth
PosY = PositionScreenY
SprID_Y = 0
if SGE_World_Depth_Visible[Depth] = 1
for Y = TileStartY to TileStopY
PosX = PositionScreenX
SprID_X = 0
for X = TileStartX to TileStopX
setspriteposition(SGE_World_SpriteID[Depth,SprID_X,SprID_Y],PosX,PosY)
setspriteimage(SGE_World_SpriteID[Depth,SprID_X,SprID_Y],SGE_TileAnimationImageID[SGE_World_Map[Depth,X,Y]])
inc PosX,SGE_TileSizeX
inc SprID_X
next X
inc PosY,SGE_TileSizeY
inc SprID_Y
next Y
endif
next Depth
endif
endfunction
An example of usage:
function DemoSGE()
if GetJoystickExists() = 1
global Joy_0_ID
Joy_0_ID = GetRawJoystickExists(1)
endif
// InitSGE(ScreenSizeX , ScreenSizeY, TileSizeX , TileSizeY, Number of tile in world lenght , Number of tile in world height, Number of depth world)
InitSGE(320,240,16,16,400,300,0)
//charging an image containing all the tiles
// LoadTileBankImage( File Name , size of the gap between each tile)
LoadTileBankImage("GB_Tiles.png",1)
// Depth 0 with grass
FillWorld(182,0)
//FillZoneWorld(TileID,TopX,TopY,Lenght,Height,Depth)
FillZoneWorld(157,10,10,10,5,0)// water
FillZoneWorld(115,10,9,10,0,0)// border top
FillZoneWorld(199,10,16,10,0,0)// border bottom
FillZoneWorld(155,9,10,0,5,0)// border left
FillZoneWorld(159,21,10,0,5,0)// border right
AddTileToWorld(134,9,9,0)
AddTileToWorld(138,21,9,0)
AddTileToWorld(180,21,16,0)
AddTileToWorld(176,9,16,0)
FillZoneWorld(242,0,18,40,2,0)// sand
FillZoneWorld(264,0,17,19,0,0)
FillZoneWorld(264,22,17,19,0,0)
FillZoneWorld(209,0,21,40,0,0)//sea
SetTileAnimation(209,0,209,500)
SetTileAnimation(209,1,188,200)
FillZoneWorld(209,0,21,40,0,0)
SetWorldDepthVisible(0,1)
do
CamX = CamX + TestInputX()
CamY = CamY + TestInputY()
SetTileCameraPosition(CamX,CamY)
RenderWorld()
sync()
loop
endfunction
This example uses the joystick to move the view.
GB_Tiles.png file is found at
http://puu.sh/Lgq4
collisions will be easy to implement later.