Monkuar Posted December 2, 2014 Share Posted December 2, 2014 Just curious, how would you go about rendering and storing this in a database. For example a simple small maze. With each keypress, the user is moved up,down,left,right like 1 inch. (1 block). Which is easy to do with jquery, etc. But how would go about storing the data in a databse (can update the position per update or using websockets), but essentially so maphacks are impossible and everything is saved/read from the server. Would the storage data be something like [0,0,0,1,0,0,1,1,1,1,0,1] I imagine or what? Link to comment https://forums.phpfreaks.com/topic/292835-maze-map-with-php-serverside-storage/ Share on other sites More sharing options...
requinix Posted December 2, 2014 Share Posted December 2, 2014 Storage space efficiency aside, my first thought would be that each cell is a number 0-15 indicating where there are not walls. A bitmask. WSEN 0 0000 1 0001 2 0010 3 0011 4 0100 5 0101 6 0110 7 0111 8 1000 9 1001 10 1010 11 1011 12 1100 13 1101 14 1110 15 1111The cell with the ◄ would be a 12: N=0 (0), E=0 (0), S=1 (2**2=4), W=1 (2**3=8 ). Moving S brings you to a 3 cell (N+E). In MySQL you can do that with a SET automatically. Link to comment https://forums.phpfreaks.com/topic/292835-maze-map-with-php-serverside-storage/#findComment-1498254 Share on other sites More sharing options...
Barand Posted December 2, 2014 Share Posted December 2, 2014 When I created a maze program I used an image to define the maze. Samples attached. Not very complex, I was using it to experiment with the mathematics of creating 3D maze with perspective views. Link to comment https://forums.phpfreaks.com/topic/292835-maze-map-with-php-serverside-storage/#findComment-1498263 Share on other sites More sharing options...
requinix Posted December 2, 2014 Share Posted December 2, 2014 That's a clever idea. If the maze is drawn to specific, known constraints, you can use basic image reading functions to "parse" it. If each square is a cell or wall with a fixed size then you can pull the color of a specific pixel to determine the contents. If walls are not the same size, like they're borders, then it's a little trickier but you can still do some simple math to determine which pixel to look at for what. Link to comment https://forums.phpfreaks.com/topic/292835-maze-map-with-php-serverside-storage/#findComment-1498266 Share on other sites More sharing options...
Monkuar Posted December 2, 2014 Author Share Posted December 2, 2014 On 12/2/2014 at 2:48 AM, requinix said: Storage space efficiency aside, my first thought would be that each cell is a number 0-15 indicating where there are not walls. A bitmask. WSEN 0 0000 1 0001 2 0010 3 0011 4 0100 5 0101 6 0110 7 0111 8 1000 9 1001 10 1010 11 1011 12 1100 13 1101 14 1110 15 1111The cell with the ◄ would be a 12: N=0 (0), E=0 (0), S=1 (2**2=4), W=1 (2**3=8 ). Moving S brings you to a 3 cell (N+E). In MySQL you can do that with a SET automatically. When you say each cell, you mean each number in the row right? That makes sense, so I would just need to create a function that checks it serverside to make sure the player can only move away one block at a time? (e.g: No flying or moving from block 1 to 15). That will be a bit tricky for me, but I understand the process now. Thank you. This system would also be used as data to be sent from the client to the websocket for a serverside mmorpg I assume. (For serverside storage of characters positions and whatnot and preventing speed hackers and teleporters). Although, this would be very CPU intensive? Doesn't quite look that bad. Link to comment https://forums.phpfreaks.com/topic/292835-maze-map-with-php-serverside-storage/#findComment-1498269 Share on other sites More sharing options...
requinix Posted December 2, 2014 Share Posted December 2, 2014 On 12/2/2014 at 9:47 AM, Monkuar said: When you say each cell, you mean each number in the row right?Each row itself, yes. The table has columns for the X and Y coordinates, the type of cell (potentially), and the bitmask of where the walls are. But I'm liking Barand's idea more now. On 12/2/2014 at 9:47 AM, Monkuar said: That makes sense, so I would just need to create a function that checks it serverside to make sure the player can only move away one block at a time? (e.g: No flying or moving from block 1 to 15).Have the client tell you the direction they want to move. That way all you have to validate is the direction (only four possible) and whether it's allowed (based on walls). On 12/2/2014 at 9:47 AM, Monkuar said: This system would also be used as data to be sent from the client to the websocket for a serverside mmorpg I assume. (For serverside storage of characters positions and whatnot and preventing speed hackers and teleporters). Although, this would be very CPU intensive? Doesn't quite look that bad.Wouldn't expect it to be CPU intensive - most of the time would be spent waiting for the client to act. But it will use a lot of connections on the server. Link to comment https://forums.phpfreaks.com/topic/292835-maze-map-with-php-serverside-storage/#findComment-1498298 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.