08.11.2012 Views

Designing Games with Game Maker - YoYo Games

Designing Games with Game Maker - YoYo Games

Designing Games with Game Maker - YoYo Games

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

etween these. The path will run between centers of free cells. So if the cells are large enough<br />

so that the instance placed at its center will lie completely inside it this will be successful. This<br />

path you can now give to an instance to follow.<br />

The grid-based approach is very powerful (and is used in many professional games) but it<br />

requires that you do some careful thinking. You must determine which area and cell size are<br />

good enough for solving the game. Also you must determine which objects must be avoided<br />

and whether precise checking is important. All these parameters strongly influence the<br />

efficiency of the approach.<br />

In particular the size of the cells is crucial. Remember that the cells must be large enough so<br />

that the moving object placed <strong>with</strong> its origin on the center of a cell must lie completely inside<br />

the cell. (Be careful about the position of the origin of the object. Also realize that you can<br />

shift the path if the origin of the object is not in its center!) On the other hand, the smaller the<br />

cells the more possible paths exist. If you make cells too large openings between obstacles<br />

may get closed because all cells intersect an obstacle.<br />

The actual functions for the grid-based approach are as follows:<br />

mp_grid_create(left,top,hcells,vcells,cellwidth,cellheight)<br />

This function creates the grid. It returns an index that must be used in all<br />

other calls. You can create and maintain multiple grid structures at the same<br />

moment. left and top indicate the position of the top-left corner of the grid.<br />

hcells and vcells indicate the number of horizontal and vertical cells. Finally<br />

cellwidth and cellheight indicate the size of the cells.<br />

mp_grid_destroy(id) Destroys the indicated grid structure and frees its<br />

memory. Don't forget to call this if you don't need the structure anymore.<br />

mp_grid_clear_all(id) Mark all cells in the grid to be free.<br />

mp_grid_clear_cell(id,h,v) Clears the indicated cell. Cell 0,0 is the top<br />

left cell.<br />

mp_grid_clear_rectangle(id,left,top,right,bottom) Clears all<br />

cells that intersect the indicated rectangle (in room coordinates).<br />

mp_grid_add_cell(id,h,v) Marks the indicated cell as being forbidden.<br />

Cell 0,0 is the top left cell.<br />

mp_grid_add_rectangle(id,left,top,right,bottom) Marks all cells<br />

that intersect the indicated rectangle as being forbidden.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!