Dark Bit Factory & Gravity
PROGRAMMING => Other languages => Blitz => Topic started by: asdflkj on June 02, 2006
-
-
-
I wouldn't mind taking a look at it for you, but there seems to be missing some code in the codebox.
-
-
-
-
-
ok, looks like you haven't gotten that far yet. I have packed up two different ways of doing a tilemap. There were going to be used for a game a few years back, but it never got anywhere besides making the tilemap work. Feel free to use and modify however you want. Post back if there is something you would like me to explain about them.
You can download the package from here: http://zac-interactive.dk/temp/tankhunt.zip
-
-
-
You can use the tiles if you like. I guess the code would have been better with comments on what the various parts does, but its something I did a long time ago and I don't really use blitz anymore. The first example draws the tiles one by one, the other draws the tiles onto a huge image and then only draws a rect out of that.
In order for you having characters walking ontop of a tilemap, you will have to draw the map each time you update the characters position and then draw the character again. There really isn't any way around that.
-
-
-
Hello Mark, :hi: to DBF / GVY forum :)
Well, looking at your code, you will need to reset tile_x and tile_y, check out the modified code:
While Not KeyDown(1)
Cls
Restore startdata
Tile_X = 0Â ; reset Tile_X
Tile_Y = 0Â ; reset Tile_Y
For t = 0 To 299
Read Tiles
If Tiles = 0 Then
DrawImage G,Tile_X,Tile_Y
Tile_X = Tile_X + 32
ElseIf Tiles = 1 Then
DrawImage W,Tile_X,Tile_Y
Tile_X = Tile_X + 32
EndIf
If Tile_X > (640-32) Then
Tile_X= 0
Tile_Y= Tile_Y + 32
EndIf
Next
Player_Move() ; Draw background first then draw player
Flip
Wend
-
-
-
No probs dude !
:cheers:
-
-
-
Check out the ImagesCollide command, there are some examples on blitz help for it.
-
-
-
Great to see you again Mark-O.
All I can add is that with LoadAnimImage, is that you need to work out the width, height, starting pos ( usually 0), followed by the amount of tiles in the image bank.
All the best with the game dude! And welcome to ze forums.
Cheers Clyde,
-
Hi Mark, welcome back :)
I have another way of detecting collisions (really fast) for you.
This will not be pixel perfect but it would be fine for things like walls and houses and water etc.
You first need to know your tile size (lets say it's 32*32) and you also need to know where your player is on the screen.
So we'll say you construct your tilemap out of data with just two block types for simplicity.
data 0,0,0,0,0,0,0,0,0,0
data 0,1,0,0,1,1,0,0,1,0
data 0,1,0,0,0,0,0,0,1,0
data 0,1,0,0,0,0,0,0,1,0
data 0,1,0,0,0,0,0,0,1,0
data 0,1,1,1,1,1,1,1,1,0
data 0,0,0,0,0,0,0,0,0,0
Where 1 is a wall and 0 is grass for example.
you may do something like this to draw the whole map on the screen;
(in pseudo code)
ypos=0
for y=1 to 8
xpos=0
for x=1 to 32
drawblock xpos,ypos,blocknum (blockmap(x,y))
xpos=xpos+32
next
ypos=ypos+32
next
blockx=(playerx/32)
blocky=(playery/32)
if blocknum (blockmap(blockx,blocky)) =1 then collision
I made an RPG engine for Yabasic using a similar method.
Here's the code, it shouldn't be too hard to adapt to Blitz, or you can visit the Yabasic forums and grab the emulator from there!
' It would be a good Idea To Make This Available.
' Please Upload.
'
' Rpg Engine V1.0 Coded By Shockwave 2002.
'This program is the property of the projects forum at
'WWW.YABASIC.CO.UK and may not be adapted or modified by
'anybody else. (C) 2002 Shockwave & www.Yabasic.co.uk
'=========================================================
gosub overall_setup:rem SET UP EVERYTHING
'=========================================================
' - -START OF GAME LOOP- -
'=========================================================
gosub drawborder:rem DRAW STATIC SCREEN ELEMENTS
gosub newlocation:rem DRAW COMPLETE DISPLAY
label main
setdrawbuf dw:rem SELECT LOGICAL SCREEN
dw=1-dw :rem TOGGLE SCREEN POINTER
setdispbuf dw:rem DISPLAY OLD LOGICAL SCREEN
gosub dialoguebox:rem CLEAR THE OLD DIALOGUE
gosub control:rem INPUT, SCROLLING, COLLISION+DISPLAY
gosub player:rem DRAW PLAYER AND DO A LIMITED REFRESH
goto main
'=========================================================
' - -END OF GAME LOOP- -
'=========================================================
exit
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
' Clear Out the Dialogue Box.
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
label dialoguebox
setrgb 1,255,255,255:rem SELECT WHITE
fill rect 20,450 to 620,510:rem DRAW BORDER
setrgb 1,0,0,0:rem SELECT BLACK
fill rect 21,451 to 619,509:rem ERASE BOX
'=========================================================
' DISCARD BELOW WHEN WORKING:
'=========================================================
setrgb 1,155,155,255
text 320,470,"TREAT THIS PART AS A NORMAL DOUBLE BUFFERED SCREEN!","cc"
text 322,490,"RPG V1.0 (C) SHOCKWAVE + RPG PROJECT FORUM WORK IN PROGRESS","cc"
return
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
' DRAW THE PLAYER'S GRAPHIC
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
label player
gosub refresh: rem REFRESH BLOCKS AROUND PLAYER
setrgb 1,255,255,255:rem DRAW PLAYER
fill rect plx-10,ply-10 to plx+10,ply+10
setrgb 1,0,0,0
if d=1 text plx-6,ply+4,"L"
if d=2 text plx-6,ply+4,"R"
if d=3 text plx-6,ply+4,"D"
if d=4 text plx-6,ply+4,"U"
return
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
' UPDATE BLOCKS THAT PLAYER IS STANDING ON
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
label refresh
xw=(plx-21) :rem CENTRAL BLOCK
yw=(ply-21)
gosub refr
xw=((plx-100)-21) :rem LEFT BLOCK
yw=(ply-21)
gosub refr
xw=((plx+100)-21) :rem RIGHT BLOCK
yw=(ply-21)
gosub refr
xw=(plx-21) :rem DOWN BLOCK
yw=((ply+100)-21)
gosub refr
xw=(plx-21) :rem UP BLOCK
yw=((ply-100)-21)
gosub refr
xw=((plx-100)-21) :rem ABOVE LEFT BLOCK
yw=((ply-100)-21)
gosub refr
xw=((plx+100)-21) :rem ABOVE RIGHT BLOCK
yw=((ply-100)-21)
gosub refr
xw=((plx-100)-21) :rem BELOW LEFT BLOCK
yw=((ply+100)-21)
gosub refr
xw=((plx+100)-21) :rem BELOW RIGHT BLOCK
yw=((ply+100)-21)
gosub refr
return
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
' This Sub Refreshes The Block At xw,xt, yw,yt
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
label refr
if xw<0 or xw>599 return:rem IF X AT EDGE DONT BOTHER
if yw<0 or yw>399 return:rem IF Y AT EDGE DONT BOTHER
xw=int(xw/100)+1:rem CALCULATE MAP X
yw=int(yw/100)+1 rem CALCULATE MAP Y
xt=((xw-1)*100)+21:rem CALCULATE BLOCK X
yt=((yw-1)*100)+21:rem CALCULATE BLOCK Y
gosub blocks:rem DRAW THE BLOCK
return
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
' Move Player And Scroll The Map.
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
label control
xo=plx:rem STORE PLAYER X IN CASE OF COLLISION
yo=ply:rem STORE PLAYER Y IN CASE OF COLLISION
c=peek("port1"):rem READ PORT 1
if and (c,32)<>0 plx=plx+2:rem MOVE RIGHT
if and (c,64)<>0 ply=ply+2 :rem MOVE DOWN
if and (c,16)<>0 ply=ply-2:rem MOVE UP
if and (c,128)<>0 plx=plx-2 :rem MOVE LEFT
if plx>xo d=2:rem SET DIRECTION TO RIGHT
if plx<xo d=1:rem SET DIRECTION TO LEFT
if ply>yo d=3:rem SET DIRECTION TO DOWN
if ply<yo d=4:rem SET DIRECTION TO UP
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
' Scenery Collisions: (any block 10+can't be walked on)
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
xw=plx-21
yw=ply-21
xw=int(xw/100)+1
yw=int(yw/100)+1
if map(xw+pgx,yw+pgy)>=10 then plx=xo:ply=yo:fi
'%%%%%%%%%%%%%%%%%%%%
'%%% SCROLL RIGHT %%%
'%%%%%%%%%%%%%%%%%%%%
if plx>610 then
if (pgx+1)/6 < dmx-1 then
plx=31
pgx=pgx+6
gosub newlocation
fi
fi
'%%%%%%%%%%%%%%%%%%%%
'%%% SCROLL LEFT %%%
'%%%%%%%%%%%%%%%%%%%%
if plx<31 then
if pgx > 0 then
plx=610
pgx=pgx-6
gosub newlocation
fi
fi
'%%%%%%%%%%%%%%%%%%%
'%%% SCROLL DOWN %%%
'%%%%%%%%%%%%%%%%%%%
if ply>410 then
if (pgy+1)/4 < dmy-1 then
ply=31
pgy=pgy+4
gosub newlocation
fi
fi
'%%%%%%%%%%%%%%%%%%%
'%%% SCROLL UP %%%
'%%%%%%%%%%%%%%%%%%%
if ply<31 then
if pgy>0 then
ply=410
pgy=pgy-4
gosub newlocation
fi
fi
if ply<31 ply=31:rem MINIMUM PERMITTED Y POS
if ply>409 ply=409:rem MAXIMUM PERMITTED Y POS
if plx>609 plx=609:rem MAXIMUM PERMITTED X POS
if plx<31 plx=31:rem MINIMUM PERMITTED X POS
return
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
' Completely Refresh Current Page
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
label newlocation
for a=1 to 2:rem UPDATE LOGICAL AND PHYSICAL SCREENS
setdrawbuf dw:rem SELECT LOGICAL SCREEN
dw=1-dw:rem TOGGLE SCREEN POINTER
setdispbuf dw:rem DISPLAY OLD LOGICAL SCREEN
setrgb 1,0,0,0:rem CLEAR LOCATION DESCRIPTION
fill rect 100,430 to 520,445:rem BOX AND THEN
setrgb 1,155,155,155:rem WRITE NEW DESCRIPTION
text 318,440,location$((pgx/6)+1,(pgy/4)+1),"cc"
setrgb 1,255,255,255
text 319,441,location$((pgx/6)+1,(pgy/4)+1),"cc"
setrgb 1,0,0,0
text 320,442,location$((pgx/6)+1,(pgy/4)+1),"cc"
xt=21:rem X BLOCK DRAWING OFFSET
yt=21:rem Y BLOCK DRAWING OFFSET
for y=1 to 4:rem 4 BLOCKS TALL
for x=1 to 6:rem 6 BLOCKS WIDE
xw=x:rem MAKE X COMPATIBLE WITH BLOCK DRAWING SUB
yw=y:rem MAKE Y COMPATIBLE WITH BLOCK DRAWING SUB
gosub blocks:rem DRAW THE NEW BLOCK
xt=xt+100 :rem MOVE ACCROSS ONE BLOCK
next x
xt=21:rem RESET X BLOCK OFFSET
yt=yt+100:rem MOVE DOWN A ROW
next y
next a
return
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
' This Subroutine Draws Scenery Blocks
' They must be 100*100 in size and start at xt,yt and end
' at xt+100,yt+100, I reccommend using triangles and
' rectangles to create them although small circles should
' be okay without harming overall speed I suppose.
' Anything up to and including number 10 the player can
' walk over, above it the player collides with it.
'
'Format:
'if map (xw+pgx,yw+pgy) = (block number) then
' Your gfx here
'fi
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
label blocks
'=========================================================
' WALKABLE BLOCK TYPES:
'=========================================================
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'%% grass1 (horizontal stripe) %%
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if map(xw+pgx,yw+pgy)=1 then
setrgb 1,10,40,10
fill rect xt,yt to xt+100,yt+100
setrgb 1,20,50,20
fill rect xt,yt to xt+100,yt+25
fill rect xt,yt+50 to xt+100,yt+75
fi
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'%% grass2 (diamond pattern) %%
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if map(xw+pgx,yw+pgy)=2 then
setrgb 1,10,40,10
fill rect xt,yt to xt+100,yt+100
setrgb 1,20,50,20
fill triangle xt,yt to xt+50,yt to xt,yt+50
fill triangle xt+50,yt to xt+100,yt to xt+100,yt+50
fill triangle xt,yt+50 to xt,yt+100 to xt+50,yt+100
fill triangle xt+100,yt+50 to xt+100,yt+100 to xt+50,yt+100
fi
'%%%%%%%%%%%%%%%%%%%%%%%
'%% Horizontal bridge %%
'%%%%%%%%%%%%%%%%%%%%%%%
if map(xw+pgx,yw+pgy)=3 then
setrgb 1,60,50,50
fill rect xt,yt to xt+100,yt+100
setrgb 1,70,50,50
fill rect xt+20,yt to xt+80,yt+100
setrgb 1,80,50,50
fill rect xt+40,yt to xt+60,yt+100
fi
'%%%%%%%%%%%%%%%%%%%%%
'%% Vertical bridge %%
'%%%%%%%%%%%%%%%%%%%%%
if map(xw+pgx,yw+pgy)=4 then
setrgb 1,60,50,50
fill rect xt,yt to xt+100,yt+100
setrgb 1,70,50,50
fill rect xt,yt+20 to xt+100,yt+80
setrgb 1,80,50,50
fill rect xt,yt+40 to xt+100,yt+60
fi
'%%%%%%%%%%
'%% Path %%
'%%%%%%%%%%
if map(xw+pgx,yw+pgy)=5 then
setrgb 1,65,65,60
fill rect xt,yt to xt+100,yt+100
fi
'=========================================================
' Non Walkable Block Types:
'=========================================================
'%%%%%%%%%%%
'%% River %%
'%%%%%%%%%%%
if map(xw+pgx,yw+pgy)=10 then
setrgb 1,15,15,50
fill rect xt,yt to xt+100,yt+100
fi
return
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'Draws All Fixed Items Of The Screen Display On Both The
'Logical And Physical Screens.
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
label drawborder
for a=1 to 2:rem LOOP TWICE TO DO BOTH SCREENS
setdrawbuf dw:rem SET DRAW SCREEN
dw=1-dw:rem TOGGLE SCREEN POINTER
setrgb 1,180,110,130:rem RGB VALUE FOR GTRI POINT
setrgb 2,130,170,110:rem RGB VALUE FOR GTRI POINT
setrgb 3,20,30,60:rem RGB VALUE FOR GTRI POINT
gtriangle 0,0 to 640,512 to 0,512:rem BACKGROUND COLS
gtriangle 0,0 to 640,512 to 640,0:rem BACKGROUND COLS
setrgb 1,155,155,255:rem RGB COLOUR FOR BORDERS
fill rect 13,13 to 628,427:rem DRAW BORDERS
fill rect 98,428 to 522,447
setrgb 1,0,0,0:rem SET TO BLACK FOR PLAY AREA
fill rect 15,15 to 626,425:rem CLEAR PLAY AREA
fill rect 102,432 to 518,443
next a
return
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
' Overall Setup For RPG
' Contains Map, Array Definitions, Dialog, Vars And Data.
' This is called at the very beginning of the program.
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
label overall_setup
open window 640,512:rem OPEN GRAPHICS SCREEN
d=1:rem DIRECTION (1=left 2=right 4=up 3=down)
plx=120:rem PLAYER X START AS A PHYSICAL SCRN POS
ply=256:rem PLAYER Y START AS A PHYSICAL SCRN POS
dmx=3 : rem MAP IS 3 SCREENS WIDE
dmy=5 : rem MAP IS 5 SCREENS TALL
dim map((dmx*6),(dmy*4)):rem STORAGE SPACE FOR MAP
dim location$(dmx,dmy):rem STORAGE SPACE FOR SCRN TITLES
pgx=0 :rem MAP DISPLAY LOCATION X
pgy=0 :rem MAP DISPLAY LOCATION Y
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
' Read In Data:
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for y=1 to dmy*4:rem < THESE NESTED LOOPS
for x=1 to dmx*6:rem READ THE MAP DATA INTO
read map(x,y):rem THE map() ARRAY WHICH
next x:rem IS TWO DIMENSIONAL.
next y:rem < END OF LOOP CYCLE.
for y=1 to dmy:rem < AND THESE NESTED LOOPS
for x=1 to dmx:rem READ THE LOCATION
read location$(x,y):rem NAMES INTO THE 2 DIM
next x:rem ARRAY "location$()"
next y:rem < END OF LOOP CYCLE.
return
'=========================================================
' DATA STATEMENTS START HERE:
'=========================================================
'Block types. Add Short descriptions next to numbers.
'Up to 10 you can walk on, 11>40 you collide with.
'Also below these you'll find the descriptions map so
'that you can give each screen a title (required).
'1:grss1 5:path 9:blank 13:blank 17:blank 21: etc..
'2:grss2 6:blank 10:river 14:blank 18:blank 22: etc..
'3:brdgh 7:blank 11:blank 15:blank 19:blank 23: etc..
'4:brdgv 8:blank 12:blank 16:blank 20:blank 24: etc..
'=========================================================
' THE SCENERY MAP:
'=========================================================
REM LOCATION 1: LOCATION 2: LOCATION 3:
data 10,10,10,2,2,2, 2,2, 2, 2,2, 2, 1,1,10,1, 1, 1
data 5, 5, 3, 5,5,5, 5,5, 5, 5,10, 2, 1,1,3, 1, 1, 1
data 2, 5,10, 2,2,2, 1,10,10,4,10, 2, 1,1,10,10,10,10
data 2, 5,10, 2,2,2, 1,1, 1, 5,2, 2, 1,1,1, 1, 1, 1
REM LOCATION 4: LOCATION 5: LOCATION 6:
data 1,5,10,1,1,1, 1,1,1,5,2,2, 1,1,1,1,1,1
data 1,5,10,1,1,1, 1,1,1,5,5,5, 5,5,5,5,5,5
data 1,5, 3,5,5,5, 5,5,5,5,2,2, 2,2,2,2,2,2
data 1,5,10,1,1,1, 1,1,1,5,2,2, 2,2,2,2,2,2
REM LOCATION 7: LOCATION 8: LOCATION 9:
data 1,5,10,1,1, 1, 2, 2, 2,5,2,2, 1,1,1,1,1,1
data 1,5,10,1,1, 1, 2, 2, 2,5,2,2, 1,1,1,1,1,1
data 1,5,10,4,10,10, 10,10,2,5,2,2, 1,1,1,1,1,1
data 1,5,1, 1,1, 1, 2, 10,2,5,2,2, 1,1,1,1,1,1
REM LOCATION 10: LOCATION 11: LOCATION 12:
data 1,5,1,1,1,1, 2,10,1,5,2,2, 2,2,2,2,2,2
data 1,5,1,1,1,1, 5,3 ,5,5,2,2, 2,2,2,2,2,2
data 1,5,1,1,1,1, 2,10,2,5,1,2, 2,2,2,2,2,2
data 1,5,1,1,1,1, 2,10,2,5,1,2, 2,2,2,2,2,2
REM LOCATION 13: LOCATION 14: LOCATION 15:
data 1,5,1,1,1,1, 2,10,2, 5, 2, 2, 1,1,1,1,1,1
data 1,5,1,1,1,1, 2,10,10,5, 5, 5, 1,1,1,1,1,1
data 5,5,5,5,5,5, 5,5, 10,4 ,10,5, 1,1,1,1,1,1
data 1,1,1,1,1,1, 1,5, 3, 5, 10,5, 5,5,5,5,5,5
'=========================================================
' The Location Description Map :
'=========================================================
data "THE PADDOCK","THE KISSING BRIDGE","THE MILL"
data "THE FARMYARD","DESERTED COTTAGE","PEDDLERS WAGGON"
data "THE FARMHOUSE","THE MINESHAFT","OLD HERMITS HUT"
data "THE TRADERS ROUTE","HUNTERS LODGE","LEAFY GLADE"
data "THE ANCIENT WALL","WEST VILLAGE","EAST VILLAGE"
Hope that helps you.
-
-
-
Take whatever you want from it mate. Glad it helps
-
-
-
-
-
-
-
Works well :) Nice one. Now add some flip screen scrolling!
-
Don't know if you are using BlitzMax or not but here is a bmax module I wrote for scrolling tile maps.
http://www.scottshaver2000.com/blitz/bmaxmods/sas.mod.zip
Here is a map editor for creating the maps.
http://www.scottshaver2000.com/blitz/sasmapeditor2/sasmapeditor2.zip
(http://www.scottshaver2000.com/blitz/sasmapeditor2/sasmaped2-1.png)
here is an example of a map in action.
'===============================================================================
'===============================================================================
' Sample4.bmx By Scott Shaver
'
' This sample displays a simple one layer LayeredTileMap and allows the user
' to move a character around the map with the cursor keys. Use the escape key
' to exit the program. The character can't go through the walls.
'
' Written: 6/23/2005
' Update 6/27/2005 -
' Added the code for detecting the wall collisions
'===============================================================================
'===============================================================================
Strict
Framework BRL.GlMax2D
Import BRL.System
Import BRL.Basic
Import BRL.pngloader
Import BRL.Retro
Import pub.igl
Import SAS.tilemaps
?Win32
SetGraphicsDriver(GLMax2DDriver())
?
' init the graphics mode
Graphics 800,600,32',85
' Load a LayeredTileMap file
Global map:LayeredTileMap = LayeredTileMap.Load("maps/Walls.smf")
' load the character image
SetMaskColor(255,255,255)
Global guy:TImage = LoadImage("maps/circleguy.png",MASKEDIMAGE)
Global charWidth:Int=30
Global charHeight:Int=30
Global halfCW:Int=charWidth/2
Global halfCH:Int=charHeight/2
' Set the viewport to the entire screen
map.ViewPort(50,50,GraphicsWidth()-100,GraphicsHeight()-100)
' some helper vars
Global halfVPW:Int = map.viewPortPixelWidth/2
Global halfVPH:Int = map.viewPortPixelHeight/2
Global centerVPX:Int = map.viewPortX + halfVPW
Global centerVPY:Int = map.viewPortY + halfVPH
Global scrollSpeed:Int=3
Global wallTileIndex=0
' set up the starting position of the character by finding a specific cell
Global sx:Float,sy:Float
map.MapCellToScreenCoords(1,1,sx,sy,0)
' blue background
SetClsColor(0,0,255)
' the main program loop
While Not KeyDown(KEY_ESCAPE)
Cls
Local lastX:Float = map.GetX()
Local lastY:Float = map.GetY()
Local cx:Float,cy:Float
Local temp:Float
' handle moving the map and character around with the cursor keys
If KeyDown(KEY_A) Or KeyDown(KEY_LEFT) Then
If sx+halfCW > centerVPX Then ' the character is right of the center of the screen
sx:-scrollSpeed
Else If lastX=0 Then ' edge of the map move the character
If sx > map.viewPortX Then sx:-scrollSpeed
If sx < map.viewPortX Then sx=map.viewPortX
Else ' character is centered move the map
map.SetPosition(lastX+scrollSpeed,lastY)
lastX = map.GetX()
EndIf
' check the characters upper left corner
map.ScreenToMapCell(sx,sy,cx,cy,0)
If map.GetCell(cx,cy,0)=wallTileIndex Then map.MapCellToScreenCoords(cx+1,cy,sx,temp,0)
' check the characters lower left corner
map.ScreenToMapCell(sx,sy+charHeight-1,cx,cy,0)
If map.GetCell(cx,cy,0)=wallTileIndex Then map.MapCellToScreenCoords(cx+1,cy,sx,temp,0)
EndIf
If KeyDown(KEY_D) Or KeyDown(KEY_RIGHT) Then
If sx+halfCW < centerVPX Then ' the character is left of the center of the screen
sx:+scrollSpeed
Else If lastX=-((map.cellPixelWidth*map.mapCellWidth) - map.viewPortPixelWidth) Then ' edge of the map move the character
If sx < map.viewPortX+map.viewPortPixelWidth-charWidth Then sx:+scrollSpeed
If sx > map.viewPortX+map.viewPortPixelWidth-charWidth Then sx=map.viewPortX+map.viewPortPixelWidth-charWidth
Else ' character is centered move the map
map.SetPosition(lastX-scrollSpeed,lastY)
lastX = map.GetX()
EndIf
' check the characters upper right corner
map.ScreenToMapCell(sx+charWidth,sy,cx,cy,0)
If map.GetCell(cx,cy,0)=wallTileIndex Then
map.MapCellToScreenCoords(cx-1,cy,sx,temp,0)
sx:+(map.cellPixelWidth-charWidth)
EndIf
' check the characters lower right corner
map.ScreenToMapCell(sx+charWidth-1,sy+charHeight-1,cx,cy,0)
If map.GetCell(cx,cy,0)=wallTileIndex Then
map.MapCellToScreenCoords(cx-1,cy,sx,temp,0)
sx:+(map.cellPixelWidth-charWidth)
EndIf
EndIf
If KeyDown(KEY_W) Or KeyDown(KEY_UP) Then
If sy+halfCH > centerVPY Then ' the character is below of the center of the screen
sy:-scrollSpeed
Else If lastY=0 Then ' edge of the map move the character
If sy > map.viewPortY Then sy:-scrollSpeed
If sy < map.viewPortY Then sy=map.viewPortY
Else ' character is centered move the map
map.SetPosition(lastX,lastY+scrollSpeed)
lastY = map.GetY()
EndIf
' check the characters upper left corner
map.ScreenToMapCell(sx,sy,cx,cy,0)
If map.GetCell(cx,cy,0)=wallTileIndex Then map.MapCellToScreenCoords(cx,cy+1,temp,sy,0)
' check the characters upper right corner
map.ScreenToMapCell(sx+charWidth-1,sy,cx,cy,0)
If map.GetCell(cx,cy,0)=wallTileIndex Then map.MapCellToScreenCoords(cx,cy+1,temp,sy,0)
EndIf
If KeyDown(KEY_S) Or KeyDown(KEY_DOWN) Then
If sy+halfCH < centerVPY Then ' the character is above of the center of the screen
sy:+scrollSpeed
Else If lastY=-((map.cellPixelHeight*map.mapCellHeight) - map.viewPortPixelHeight) Then ' edge of the map move the character
If sy < map.viewPortY+map.viewPortPixelHeight-charHeight Then sy:+scrollSpeed
If sy > map.viewPortY+map.viewPortPixelHeight-charHeight Then sy=map.viewPortY+map.viewPortPixelHeight-charHeight
Else ' character is centered move the map
map.SetPosition(lastX,lastY-scrollSpeed)
lastY = map.GetY()
EndIf
' check the characters lower left corner
map.ScreenToMapCell(sx,sy+charHeight-1,cx,cy,0)
If map.GetCell(cx,cy,0)=wallTileIndex Then
map.MapCellToScreenCoords(cx,cy-1,temp,sy,0)
sy:+(map.cellPixelHeight-charHeight)
EndIf
' check the characters lower right corner
map.ScreenToMapCell(sx+charWidth-1,sy+charHeight-1,cx,cy,0)
If map.GetCell(cx,cy,0)=wallTileIndex Then
map.MapCellToScreenCoords(cx,cy-1,temp,sy,0)
sy:+(map.cellPixelHeight-charHeight)
EndIf
EndIf
' clear the background of the map with black
SetColor(0,0,0)
DrawRect(50,50,GraphicsWidth()-100,GraphicsHeight()-100)
' draw the map
map.Draw()
' draw the character shadow
SetAlpha(.5)
SetColor(0,0,0)
DrawImage(guy,sx+3,sy+3)
' draw the character
SetAlpha(1)
SetColor(255,255,255)
DrawImage(guy,sx,sy)
Flip
' FlushMem()
Wend
(http://www.scottshaver2000.com/blitz/sasmapeditor/sample4.png)
here is a screen shot a game I'm working on using this stuff.
(http://www.scottshaver2000.com/blitz/questmaster/play_interface6.png)
-
-
-
Does anyone know if there is a way to save the data for the map in a text file, then load the data into the game? If there is a way to do this could some one please tell me how?
Thanks,
Mark-O
-
You need to look into the writefile and openfile commands etc.
It's pretty easy to save an array into a file.
If you get stuck with it, make a new thread and I'll do a quick example for you :)