Results 1 to 10 of 10

Thread: General question about tiles

  1. #1

    Thread Starter
    Addicted Member kikelinus's Avatar
    Join Date
    Nov 2000
    Posts
    219

    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.

  2. #2
    vshammas
    Guest
    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.

  3. #3

    Thread Starter
    Addicted Member kikelinus's Avatar
    Join Date
    Nov 2000
    Posts
    219
    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?

  4. #4
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    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.

  5. #5

    Thread Starter
    Addicted Member kikelinus's Avatar
    Join Date
    Nov 2000
    Posts
    219
    Hey Fox, if it's one main game screen, then how do I detect a collision?

  6. #6
    vshammas
    Guest
    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

  7. #7
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    That won't work properly.. you need to check the new position for collisions:

    VB Code:
    1. If player presses left key Then
    2.     'If there's no collision move the player one step left
    3.     If Not Tile(Map(Player.x[color=FF0000] - 1[/color], Player.y)).Blocked Then: Player.x = Player.x-1
    4. End If

  8. #8
    vshammas
    Guest
    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

  9. #9
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    Sure, it's the same as yours.. and well, mainly I removed this 2 lines:

    VB Code:
    1. If tileInfo(mapArray(player.x - 1, player.y)).Blocked = True Then
    2.     player.x = player.x  '<-- Useless, isn't it?

  10. #10
    vshammas
    Guest
    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
  •  



Click Here to Expand Forum to Full Width