mysql - Enemy Movement in PHP -
i'm working on making battle simulator of sorts , i've hit big road block. i'm trying create simple ai( or close ai can ) moves closer on 5x5 grid.
the problem i'm not sure how begin script. thought if in tile "1" , enemy in tile "25" , enemy can pick surrounding tiles it's next move, 19,24 or 20 logically want pick 19 since it's lowest number of group, closing gap. realized if moving top left or bottom right there difference of 6, if moving top right or bottom left there difference of 4. has left me "coder's block". , possible solutions awesome.
thanks in advance!
edit:
i guess i'm not being specific enough, i'll try again. have php file image of overview of trees , grass , have drawn 5x5 grid on it. each cell 55x55 pixels , each cell it's own individual div overlays on top of image. in mysql database have table labeled location column id,name,and tile number. updated database put me on tile 1 , ai enemy on tile 25. combination of php , css able highlight located on map (tile 1) , enemy located on map (tile 25). idea each "player" takes turn, whether move or attack. individual player simple enough, click on adjacent tile. snag comes in when trying figure out how code "ai's movement" goal ai move close enough player ai can attack. if in tile 1 , ai in tile 25 ideal move ai move diagonally tile 19, getting closer me. on next turn i'll move , ai have figure out tile go next closer me , cycle go on , on until 1 of attacks and/or dies. thought php route go since player's tile location important have @ times, i'm or , suggestions @ point!
imagine checkers board, need figure out how have ai select next tile. making ai select random tile no problem, it's calculating tile should pick problematic.
instead of having grid numbered 1-25 want coordinate system, (row, column) way can determine both directions. easiest way implement multidimensional array. though 2 separate arrays work fine.
you didn't post code, can't specifics, math becomes easier once have actual grid system. if enemy move 1 square @ time, can check if player row/column higher or lower enemies , move depending.
i hope helps, first answer.
Comments
Post a Comment