Click to See Complete Forum and Search --> : GAME MAP QUESTION
slashandburn
Mar 10th, 2000, 03:35 AM
How is it that like in starcraft map files which are
a bunch of letters be used by the game?
seanm
Mar 10th, 2000, 10:49 PM
I could be wrong on this, having never played starcraft, or taken a look at their map files, but, what you're seeing when you open a map file could be an array of information regarding what's where on the map, and its attributtes, that has been saved randomly (as opposed to sequentially). That tends to produce a somewhat less legible, but smaller data file.
slashandburn
Mar 11th, 2000, 12:20 AM
My questioin is that I was looking at Warcraft files and I know how they did that but then how could I Take that Data and use it like lets say i Had a 64 X 64 grid. Now I want that to be used like in warcraft with diffrent textures for each square which WILL BE "BIT BLITED", Now how would my Progrtam remember all that data without it slowing it DOWN?
Some prograMS i HAVE DONW ARE WHERE i make it Get a square in a STATEMENT
//EXAMPLE
Public Sub GETTILE(X AS INTeger,Y AS INTEGER)
if x = 1 and y = 5 then
GROUND=5
BLOCK=False
end if
end sub
// This works but it is to intensive because I have to Write Everything. But is there a way to import code into a program While it is runing??:)
seanm
Mar 11th, 2000, 12:37 AM
Okay, well,
The map is basically an array, either 2d or 3d, etc...
so you set it up :
private Grid(1 to 100,1 to 100)
theres a 100x100 grid
each element is given a number, either manually ie:
Grid(1,1)=1
or you can write an editor program, which is a little long to copy here
Each number represents a tile. ex 1 = grass
Then its just a matter of checking each element to find out what number it is and draw it appropriatly.
I'm working on a game (as a learning experience) which uses a similar setup.
I read/write the grid to a txt file , using a straight forward loop:
For x= 1 to 100
for y= 1 to 100
[Input/Write]#1,grid(x,y)
next y
next x
then I've got functions which compare grid(x,y) to where the player is (for terrain dependant events)
and where the players going (for impassable areas,etc)
If you want to see the whole code email me - seanm@kingston.net
the game as it is, i've got at www6.50megs.com/seanm,
I hope that helps a little...
Fox
Mar 11th, 2000, 01:56 AM
Uhm,
I just wanted to say that if u use a 1D array that you can resize it without losing data. And it's not much harder to handle.
You can download a demo project from my website: http://derzirkel.tsx.org
KENNNY
Mar 11th, 2000, 02:55 AM
I'd go for 2d arrays; easier to use
And I don't usually bother resizing arrays neway :)
seanm
Mar 11th, 2000, 03:15 AM
I have come across a neat little trick in converting from 1d to 2d arrays...
The editor i use to make maps is based on a control array of some large number of image boxes...1600, which are arrayed in a grid as in:
123
456
789
the images are set to whatever terrain tile i choose, etc...
but... I was trying to set the x,y coords of objects in the game and had to figure out how to convert the index of the long 1d array to the x,y index of the 2d array, came up with this:
x = (index + 1) Mod width
y = (((index + 1) - ((index + 1) Mod width)) / width) + 1
where width is the width of the 2d array
x is the desired x coord
y is the desired y coord
index is the index of the 1d array where the object is to be placed.
NB it doesn't always work, there are some cases, along the top and sides that screw up, but given a map with a map of two squares, it works.
If anyone knows a simpler way, pray tell.
Fox
Mar 11th, 2000, 04:08 AM
Yes, I do... or I just think so ;)
Look at my code, its an optimized function to draw a map to the screen, you should be able to know what the vars are...
Public Sub DrawMap()
On Error Resume Next
Dim A As Long
Dim B As Long
Dim Index As Long
Dim Temp As Long
Dim TempX As Single
Dim TempY As Single
TempX = (Camera.X / TileW)
TempY = (Camera.Y / TileH)
'Draw floor tiles
Index = Int(TempY) * MapW + Int(TempX)
For B = 0 To TilesY
For A = 0 To TilesX
'Draw floor
Temp = Map(Index).Floor
BitBlt BackDC, (A - (TempX - Int(TempX))) * TileW, (B - (TempY - Int(TempY))) * TileH, TileW, TileH, Tile(Temp).Picture.DC, 0, 0, vbSrcCopy
Index = Index + 1
Next
Index = Index + MapW - TilesX - 1
Next
End Sub
And it works in every case, also on very top and sides...
slashandburn
Mar 11th, 2000, 04:39 AM
Heres MY CODE THAT Makes a 640 X 480 map with 32
X 32 Bitmaps or 20 Bitmaps BY 15 bitmaps
/NOTE This uses RENDEROBJECTCOPY which is another sub I Made to us in many DIffrent programs.
//////////////////////
Public GAEGRID(-4 TO 64,-4 TO 64) AS ITEGER
Public Viewx as integer
Public Viewy as integer
Public Sub RENDER_ALL()
QX = 1 ' Current X Row
QY = 1 ' Current Y Col
QT = GRID NUMBER
Do While QY <> 16
QT = GAMEGRID(QX + VIEWX, QY + VIEWY)
RENDEROBJECTCOPY QT, ((QX) * 32) - 32, ((QY) * 32)
QX = QX + 1
If QX = 21 Then
QX = 1
QY = QY + 1
End If
Loop
Form1.Refresh
End Sub
/////////////////
slashandburn
Mar 11th, 2000, 04:41 AM
I HAD A TYPO
Public GAmEGRID(-4 TO 64,-4 TO 64) AS ITEGER
slashandburn
Mar 11th, 2000, 05:14 AM
My Map Editor Is Muck Easier With only a few drawbacks.
How it works.
0.MY VIEW AREA is a 640X480 WINDOW scale is set to PIXEL
1.Click on the tile wanted to use
2.click where to place it.
3.The block of land is set.
4.updates view area
/EXAMPLE
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbKeyLButton Then
MOUSECLICKER Int((X) / 32) + 1 + VIEWX, Int((((Y) - 480) * -1) / 32) + 1 + VIEWY
end sub
/////
/EXAMPLE
Public Sub MOUSECLICKER(X As Integer, Y As Integer)
GAMEGRID(X, Y) = CURT
'MsgBox GAMEGRID(X, Y)
Form1.Refresh
RENDER_ALL
End Sub
/////
whenever it updates this is the sub used to copy images from form2 and put them on the main form.
/Note I wanted the Y to Flip so i put Y = (Y - 480) * -1
in it
Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
Public Sub RENDEROBJECTAND(OBJECTNUMBER As Integer, X As Long, Y As Long)
Y = (Y - 480) * -1
BitBlt Form1.hDC, X, Y, Form2!IMG(OBJECTNUMBER).ScaleWidth, Form2!IMG(OBJECTNUMBER).ScaleHeight, Form2!IMG(OBJECTNUMBER).hDC, 0, 0, vbSrcAnd
End Sub
'Heres my Load/Save Level Stuff
Option Explicit
Declare Function GetPrivateProfileString Lib "Kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, lpKeyName As Any, ByVal lpDefault As String, ByVal lpRetunedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
Declare Function WritePrivateProfileString Lib "Kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lplFileName As String) As Long
Global r%
Global entry$
Global iniPath$
Dim HOLDSTRING As String
Dim TX As Integer
Dim TY As Integer
Function GetFromINI(AppName$, KeyName$, FileName$) As String
Dim RetStr As String
RetStr = String(255, Chr(0))
GetFromINI = Left(RetStr, GetPrivateProfileString(AppName$, ByVal KeyName$, "", RetStr, Len(RetStr), FileName$))
End Function
' entry$ = SCENESTUFF(CURS2)
' HJK = Format(CURS2)
' r% = WritePrivateProfileString("SCENE STUFF", HJK, entry$, iniPath$)
Public Sub LOAD_LEVEL_64()
TX = 1
TY = 0
Form3.Show
iniPath$ = App.Path + "\TEST.MAP"
Do While TY <> 65
Form3.P1.Value = TX
Form3.P2.Value = TY
HOLDSTRING = "TILE" + Format(TX) + "X" + Format(TY)
GAMEGRID(TX, TY) = GetFromINI("MAP", HOLDSTRING, iniPath$)
TX = TX + 1
If TX = 65 Then
TX = 1
TY = TY + 1
End If
DoEvents
Loop
RENDER_ALL
Unload Form3
End Sub
Public Sub WRITE_LEVEL_64()
iniPath$ = App.Path + "\TEST.MAP"
TX = 1
TY = 0
Form3.Show
Do While TY <> 65
Form3.P1.Value = TX
Form3.P2.Value = TY
entry$ = GAMEGRID(TX, TY)
HOLDSTRING = "TILE" + Format(TX) + "X" + Format(TY)
r% = WritePrivateProfileString("MAP", HOLDSTRING, entry$, iniPath$)
TX = TX + 1
If TX = 65 Then
TX = 1
TY = TY + 1
End If
DoEvents
Loop
Unload Form3
End Sub
Fox
Mar 11th, 2000, 07:44 AM
-About your typo-
You can even delete or modify your posts...
-About your code-
Please post with the [c0de] tag (the '0' should be an 'o' but that wouldn't work ;) ), it's much easier to read. See the'UBB Code is ON' link on the left (appears while you're posting a message) for more information.
slashandburn
Mar 11th, 2000, 10:00 AM
IF Anyone wants a demo file I made that is a map Maker
Please e-mail me MMGATE@AOL.com
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.