CodeBase - Event Triggering Method
Uploaded: 14th Jan 2004 12:57
Modified: 1st Jan 1970 01:00
This is a method I use to find a players general location. It converts a characters X Y coordinate location in to a tile location. What it does is saves you from using a million if statements to see what location a player is in.
Here is a system I use to identify the location of a player. This method is really for triggering events in your games. Dunno if anybody wants to use this, but hey its easy to understand and usuable under the right conditions. <br /> <br /> <br /> What it does:<br /> <br /> The first step is to convert your characters location in to a row and column. This is done by dividing your avatars current location by a tile size that you determine.<br /> <br /> column = (xlocation / xtilesize) + 1<br /> row = (ylocation(or zlocation) / y( z tile size)) + 1<br /> <br /> From the row and column it determines which tile you are in. <br /> Tile = ((Current Row - 1) * the number of tiles across/down + Current Column<br /> <br /> In a nutshell it converts your x, y or z coordinate in to a integer value. <br /> <br /> Why would you do this:<br /> Well its better than doing something like...<br /> if x > 10 and x < 100 <br /> if y > 10 and y < 100<br /> blah blah<br /> endif<br /> endif<br /> <br /> Its great for event based triggering. You can use this method from matrix sized areas where you have multiple matrices, down to the tiles on the matrices. It doesn't even have to be a visible grid. You could make up a virtual tile system not determined by visible boundries. <br /> <br /> This can even be down for space type games. Basically all you do is <br /> find your XZ tile, then your XY tile. You can actually specify a position in 3d space using two numbers. <br /> <br /> <br /> Limitations:<br /> <br /> This method only works in a finite universe. <br /> <br /> The number of tiles is determined by Total area / tile size of course. Your tiles can not scale differant than your area size. Basically if you have 16 rows you have to have 16 columns. <br /> <br /> <br /> Example:<br /> I've attached an example. The are displayed is 16 x 12. Don't let that confuse you, because if they resulation were 1024 x 1024 instead of 1024 x 768 there would be a 16 x 16 grid displayed<br /> <br /> Anyways see the attached source. The source will randomly generate a number between 1 and 192 because there are 192 tiles on a 16 x 12 grid. Simply move the mouse curser to the grid square and it will choose another. That part of the example is just to show this method in action. <br /> <br /> <br /> Workarounds:<br /> This system does have limitations but there are work arounds. If you have irregular shaped areas. Lets say a T shaped area all you would have to do is like down 1 'virtual' grid over the entire area. <br /> This is a great method for MMORPGs as it makes it easy to determine if somebody got in to an area they were supposed to. In a T shaped area you would have a 3 x 3 over all grid. 1 2 3 5 8 are the tiles the player can be in 4 6 7 9 are where the player isn't supposed to be able to get to. So its simply one If statement<br /> <br /> If pTile = 4 <br /> kill player<br /> endif<br />
No comments yet.