خرید بک لینک

Vote count: 0

I have a program that currently maps tiles in a maze format. using VB graphics. I want a picturebox to detect collision with a certain tile,(i.e a 48x48 section of the map) The tiles have been mapped in a 2d array

Dim stage = {{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
             {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1},
             {1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1},
             {1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 1, 1, 0, 1},
             {1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1},
             {1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1},
             {1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 1},
             {1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 0, 1},
             {1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1},
             {1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1},
             {1, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1},
             {1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1},
             {1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 1, 1},
             {1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1},
             {1, 1, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1},
             {1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1},
             {1, 0, 1, 1, 0, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1},
             {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
              {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}}

Now, i have a picturebox moving 48px at a time, tile to tile, based on user input, and i want it to detect when it has reached a "1" tile ( a wall ).. so user Slai suggested this code

Dim playerX = 0, playerY = 3, TileSize = 48


For x = 0 to stage.GetLength(0) - 1
For y = 0 to stage.GetLength(1) - 1
    Dim image = {bmpPath, bmpWall}[stage[x, y]]   ' 0 is path, 1 is wall
    Map.DrawImage(image, x * TileSize, y * TileSize, TileSize, TileSize)
Next y
Next x

Map.DrawImage(bmpPlayer, playerX * TileSize, playerY * TileSize, TileSize,      TileSize)

Now, this code in theory will work nice, however i have an issue in my compiler with this line

Dim image = {bmpPath, bmpWall}[stage[x, y]] 

I get an error -- Error 1 Bracketed identifier is missing closing ']'. If anyone can understand what the code is trying to execute, and why it won't, please, try and help me out. I have tried adding, removing, substituting brackets etc in that line but it seems its entirely wrong syntax?

This is the future movement code if i can make it work

Sub Form1_KeyPress(sender As Object, e As KeyPressEventArgs) Handles Me.KeyPress

If e.KeyChar = Keys.Right AndAlso 
    playerX < stage.GetLength(0) - 1 AndAlso ' if not at the right most tile
    stage[playerX + 1, playerY] = 0 Then     ' if the tile on the right is path

    Map.DrawImage(bmpPath, playerX * TileSize, playerY * TileSize, TileSize, TileSize)
    playerX = playerX + 1
    Map.DrawImage(bmpPlayer, playerX * TileSize, playerY * TileSize, TileSize, TileSize)

Else If e.KeyChar = Keys.Left AndAlso playerX > 0 Then
    ' add the rest of the code for the other directions
End If
End Sub

asked 2 mins ago

برچسب: نویسنده: استخدام کار تاريخ: سه شنبه 1 تير 1395 ساعت: 8:51

صفحه بندی