![]() |
Directional Blocking (My strange way) - Printable Version +- Mirage Engine (https://mirage-engine.uk/forums) +-- Forum: Mirage Source (Nostalgia) (https://mirage-engine.uk/forums/forumdisplay.php?fid=61) +--- Forum: Archive (2006-2011) (https://mirage-engine.uk/forums/forumdisplay.php?fid=18) +---- Forum: Resources (https://mirage-engine.uk/forums/forumdisplay.php?fid=49) +---- Thread: Directional Blocking (My strange way) (/showthread.php?tid=1085) |
Directional Blocking (My strange way) - funkynut - 05-07-2007 Since this isn't up, I'll repost this aswell Directional Blocking (My way) Difficulty 3/5 Ok, this tutorial will allow each tile to have its own Blocking rules so there’s no need for TILE_TYPE_BLOCK (Although it will still be there if you want it). On Map Editor, a new option will be added to allow viewing tile Block pattern and will blt on each tile, the directions your able to walk in (If your unable to walk in a certain direction, a circle will be placed instead of an arrow) and in the center of every tile is a toggle circle that will Enable/Disable the ability to walk over the tile. Btw, I’m not sure, but I assume that this will muck up any maps you already have so you either have to redo the maps, or make a small app to convert all old maps to this new format Ok, lets Begin, first off lets change the way Tiles are read and saved, so find TileRec on both Client and Server and add to the bottom of the type: Code: WalkUp As Boolean This will be used to record which directions are walkable, if a directions walkable, it will be set to true Now, lets just add the controls we’ll be using in Map Editor, Add a Checkbox called chkDirectionView and two command buttons called cmdFillDirections and cmdClearDirections ![]() Ok, now we’ve added the controls, we need the server to send us the new Tile Records to the client so find the sub SendMap, find: Code: Packet = Packet & .Ground & SEP_CHAR & .Mask & SEP_CHAR & .Anim & SEP_CHAR & .Fringe & SEP_CHAR & .Type & SEP_CHAR & .Data1 & SEP_CHAR & .Data2 & SEP_CHAR & .Data3 & SEP_CHAR and replace it with: Code: Packet = Packet & .Ground & SEP_CHAR & .Mask & SEP_CHAR & .Anim & SEP_CHAR & .Fringe & SEP_CHAR & .Type & SEP_CHAR & .Data1 & SEP_CHAR & .Data2 & SEP_CHAR & .Data3 & SEP_CHAR & .WalkUp & SEP_CHAR & .WalkDown & SEP_CHAR & .WalkLeft & SEP_CHAR & .WalkRight & SEP_CHAR Now find SendMap in the Client and replace the same thing Now, we need the client to interpret this new data when its received so find: Code: SaveMap.Tile(x, y).Ground = Val(Parse(n)) And after SaveMap.Tile(x, y).Data3 add: Code: SaveMap.Tile(x, y).WalkUp = Parse(n + 8) And change: Code: n = n + 8 Code: n = n + 12 Now we’ve done all that, we need to make the server aware of all this malarkey that the clients sending so find: Code: Map(MapNum).Tile(x, y).Ground = Val(Parse(n)) And add: Code: Map(MapNum).Tile(x, y).WalkUp = Parse(n + 8) And again, change the n = n +8 to n = n + 12 Now the server can quite happily send and retrieve the new data, we need to allow the Client to edit this data, so let’s first make the Client Blt the arrows onto each tile by adding a new surface containing the arrows. First, save this image to your Client Gfx Folder and call it ‘Direction’ and the extension you use. http://img363.imageshack.us/img363/4606 ... ion6rn.png We want to do this neatly and as fully as possible so find Code: If FileExist(FileName & "sprites" & GFX_EXT, True) = False Or FileExist(FileName & "tiles" & GFX_EXT, True) = False Or FileExist(FileName & "items" & GFX_EXT, True) = False Then Code: If FileExist(FileName & "sprites" & GFX_EXT, True) = False Or FileExist(FileName & "tiles" & GFX_EXT, True) = False Or FileExist(FileName & "items" & GFX_EXT, True) = False Or FileExist(FileName & "Direction" & GFX_EXT, True) = False Then Now, we need to create the DirectDraw surface, so find Code: Public DDSD_Item As DDSURFACEDESC2 Code: Public DDSD_Direction As DDSURFACEDESC2 Also find: Code: Public DD_ItemSurf As DirectDrawSurface7 Code: Public DD_DirectionSurf As DirectDrawSurface7 Now we need to add the code that actually inits the surface, so find Code: ' Init items ddsd type and load the bitmap And add under it Code: ' Init Direction ddsd type and load the bitmap Lets go though this line by line, the .lFlags is telling Dx what properties to look at, so if we added, ddsd_Height, it will check the height property, in this case its checking the caps property. The .lCaps is describing how to load the surface, in this case its placed into the video memory. (Not 100% sure what the OffScreenPlain does, but you use it for any surface that’s in the background) The next line tells it to load a picture from file onto the surface using the properties we’ve just set, and the line after that just tells it what colours to make invisible. We also have to unload the surface from memory when we exit so find Code: Set DD_ItemSurf = Nothing Code: Set DD_DirectionSurf = Nothing Now we need to display the directions on the map when we choose to so, find: Code: ' Blit out attribs if in editor And replace it with Code: ' Blit out attribs if in editor Now to main part that displays the arrows, we need this to be displayed above everything including all text, so we need to place this just after the backbuffer is released when blting text, so find: Code: Call DD_BackBuffer.ReleaseDC(TexthDC) And add this Code: If InEditor Then and then add the end of modGameLogic add this sub Code: Public Sub BltDirectionArrows() All this sub does is, go though each tile, checks its walkable properties and blts the correct image, once it’s done that it blts 2 lines which will eventually create a grid. The only other thing to explain about this sub is that it blts the center shape by checking if the tile is totally blocked, and if it is, it will blt a cross, if not, it blts a circle. We still need to make use of them buttons we added earlier, so double click on cmdFillDirections and add: Code: Dim X As Long, Y As Long All this does is scan each tile and make each direction walkable Now double click cmdClearDirections and add: Code: Dim X As Long, Y As Long This also scans each tile, but this time, it cuts off all directions. Direction Blocking Part 2 Finally gotten round to starting the second half ![]() I better explain first what I’m going to do next for detecting which tile and where on the tile you’ve clicked, so far, i've split the tile into sections like this... ![]() Each section is a different clickable area, for example, the green area is for Blocking/Unblocking walking up and if the user clicks in this area then it will toggle it, the only problem now, is the corners at each side of the green section. The easiest way to solve this is to divide the whole tile into nine sections, like this… ![]() What we need the client to do now when the mouse is clicked, is to scan which section was clicked. So, open up your client, find the sub EditorMouseDown. Now at the top with the variables declaration, add these variables: Code: Dim x2 As Long, y2 As Long ' Used to record where on the tile was clicked Now, to make it look neat, indent this Code: If (Button = 1) And (x1 >= 0) And (x1 = 0) And (y1 = 0) And (x1 = 0) And (y1 .Right Then ' Right side All this section does is scan for which of the nine parts of the tile we clicked, and changes the settings respectively. If it’s a corner, it will compare x and y to tell which side of the square its on, for, if X = Y, it will create a line from one corner to the other, if X > Y, it will make a point on one side of the line, if Y > X, it will create a point on the other side of the line. Ok, right now, we have to actually restrict player movement if the tile their standing on needs to so, in the client, find sub CanMove, find: Code: ' Check to see if a npc is already on that tile Code: ' Check if the tile will let us walk onto it Now, find this, which is a bit below it (This ones the walking down version) Code: ' Check to see if a npc is already on that tile and add below it Code: ' Check if the tile will let us walk onto it And now for the left movement, find Code: ' Check to see if a npc is already on that tile And add: Code: ' Check if the tile will let us walk onto it Now the right side, find Code: ' Check to see if a npc is already on that tile Then add: Code: ' Check if the tile will let us walk onto it Now, this alone would work, but if a player is using a hacked client, or has hacked the map somehow, this could be bypassed easily, so we need to change the Player movement in the server, so find in the server, sub PlayerMove, and we basically have to do something similar here so locate: Code: If Map(GetPlayerMap(Index)).Tile(GetPlayerX(Index), GetPlayerY(Index) - 1).Type TILE_TYPE_BLOCKED Then And Change it to: Code: If Map(GetPlayerMap(Index)).Tile(GetPlayerX(Index), GetPlayerY(Index) - 1).Type TILE_TYPE_BLOCKED And Map(GetPlayerMap(Index)).Tile(GetPlayerX(Index), GetPlayerY(Index)).WalkUp Then Now do the same with: Code: If Map(GetPlayerMap(Index)).Tile(GetPlayerX(Index), GetPlayerY(Index) + 1).Type TILE_TYPE_BLOCKED Then Code: If Map(GetPlayerMap(Index)).Tile(GetPlayerX(Index), GetPlayerY(Index) + 1).Type TILE_TYPE_BLOCKED And Map(GetPlayerMap(Index)).Tile(GetPlayerX(Index), GetPlayerY(Index)).WalkDown Then Now do the same with: Code: If Map(GetPlayerMap(Index)).Tile(GetPlayerX(Index)-1, GetPlayerY(Index) ).Type TILE_TYPE_BLOCKED Then Code: If Map(GetPlayerMap(Index)).Tile(GetPlayerX(Index)-1, GetPlayerY(Index) + 1).Type TILE_TYPE_BLOCKED And Map(GetPlayerMap(Index)).Tile(GetPlayerX(Index), GetPlayerY(Index)).WalkLeft Then Now do the same with: Code: If Map(GetPlayerMap(Index)).Tile(GetPlayerX(Index)+1, GetPlayerY(Index) + 1).Type TILE_TYPE_BLOCKED Then Code: If Map(GetPlayerMap(Index)).Tile(GetPlayerX(Index)+1, GetPlayerY(Index) + 1).Type TILE_TYPE_BLOCKED And Map(GetPlayerMap(Index)).Tile(GetPlayerX(Index), GetPlayerY(Index)).WalkRight Then That should be everything, find any problems with this let me know. Btw, I wont be surprised if you dont understand it, I found it a kinda hard to explain some of the things.. Re: Directional Blocking (My strange way) - Robin - 25-07-2007 Well, no one else has bothered posting so here you go: Very nice, awesome, orgasmic. Delicious. Re: Directional Blocking (My strange way) - William - 25-07-2007 I think its because its reposted, very good tut. |