|
-
Jan 3rd, 2002, 10:20 PM
#1
Thread Starter
Addicted Member
General question about tiles
I haven't started programming games yet, so this is my very basic question.
When you have your level saved as a .MAP, and blit them into the screen, do you blit them directly into the screen, into a DC device, and crop them into a full image, or do you have for example an array with 100 picture boxes, and load each little image into an array, so you wnd up with the same result, but using a different method...??
Also, if the answer is the first one, load them directly into a DC(picture box), then how would you determine if ther is a collision if you can't really manage each image array separately, since it is all one cropped image.
Thanks.
-
Jan 4th, 2002, 07:12 AM
#2
the way i did it was create an array i called mapArray. then i assigned tile values to each coordinate. ex:
mapArray(0,0)=1 'grass
mapArray(0,1)=2 'tree
...or whatever. then i made a type called tileInfo where i stored the coordinates of each tile (where they were located on the source bitmap). ex:
tileInfo(1).name="Grass"
tileInfo(1).index=1
tileInfo(1).left=2 'the farthest left coordinate
tileInfo(1).right=49 'the farthest right coordinate
tileInfo(1).top=2
tileInfo(1).bottom=2
tileInfo(1).location=frmGraphics.Picture1.hdc 'this is the source of the image where all the tiles are stored and will be called on when using bitblt
ok, so now all i have to do is make a for loop where it loops like this:
Xspot = 0 ' starting spot for 1st tile
For x = 0 To MAP_WIDTH
Yspot = 0
For y = 0 To MAP_HEIGHT
BitBlt frmGame.hDC, Xspot, Yspot, TILE_WIDTH, TILE_HEIGHT, tileInfo(mapArray(x, y)).Location, tileInfo(mapArray(x, y)).Left, tileInfo(mapArray(x, y)).Top, SRCCOPY
End If
Yspot = Yspot + TILE_HEIGHT
Next y
Xspot = Xspot + TILE_WIDTH
Next x
here xspot is the starting location for the 1st tile (in pixels) and x is the starting location for the 1st tile (in mapArray). it just loops across and down and checks what the value of maparray is. then it takes those coordinates and bitblts it onto the actual form itself. btw, i put this in a timer but that is probably horribly wrong but i just wanted to see some results. do whatever you think is more appropriate. gettickcount.
-
Jan 4th, 2002, 09:21 AM
#3
Thread Starter
Addicted Member
You said you made an array like this (0, 0)...
So, you mean, you only have one set of arrays with tiles..(eg. tile(1)), where you store the pictures, and the game itself is as if it were one whole image?
-
Jan 4th, 2002, 10:58 AM
#4
PowerPoster
Exactly, what the player sees is 1 full game screen, but internally it's just a map array and say 2 or 3 different tiles drawn on different positions of the screen.
-
Jan 4th, 2002, 11:04 AM
#5
Thread Starter
Addicted Member
Hey Fox, if it's one main game screen, then how do I detect a collision?
-
Jan 5th, 2002, 01:40 PM
#6
i just saw if tileInfo(mapArray(player.x,player.y)).blocked=true . i did this inside the GetAsyncKeyState tests.
ex:
if player presses left key then
if tileInfo(mapArray(player.x,player.y)).blocked=true
player.x=player.x 'prevents the player from moving
elseif tileInfo(mapArray(player.x,player.y)).blocked=false
player.x=player.x-1 ' moves the player
end if
end if
then you also need something to check if your player moves off the edge of the map. i just made a bunch of 'invisible' tiles (just grey coloured tiles) on the edges of the map that were set to blocked=true so that the player couln't walk there....if you have any other questions, just post
-
Jan 5th, 2002, 06:33 PM
#7
PowerPoster
That won't work properly.. you need to check the new position for collisions:
VB Code:
If player presses left key Then
'If there's no collision move the player one step left
If Not Tile(Map(Player.x[color=FF0000] - 1[/color], Player.y)).Blocked Then: Player.x = Player.x-1
End If
-
Jan 6th, 2002, 09:29 AM
#8
yeah sorry that's what i meant. just a little typo.. 
my code:
'checks if the tile the player is moving to is set to "Blocked"
If GetAsyncKeyState(37) <> 0 Then ' left key
If tileInfo(mapArray(player.x - 1, player.y)).Blocked = True Then
player.x = player.x
ElseIf tileInfo(mapArray(player.x - 1, player.y)).Blocked = False Then
player.x = player.x - 1 'move player left
'tileInfo(mapArray(player.x, player.y)).Stepped = True 'player has now stepped on tile
End If
End If
yours is shorter! thanks, i'll just use that snippet of yours in my proggy if you dont mind
-
Jan 6th, 2002, 10:00 AM
#9
PowerPoster
Sure, it's the same as yours.. and well, mainly I removed this 2 lines:
VB Code:
If tileInfo(mapArray(player.x - 1, player.y)).Blocked = True Then
player.x = player.x '<-- Useless, isn't it?
-
Jan 6th, 2002, 10:05 AM
#10
yeah it is useless..thanks
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|