PHP Strategy Game BattleNow (a few updates)
Battle now is going to be our first attempt at a strategy style game. After today we have developed a simple tile system. Here is some of the code below.
For you who haven’t heard or forgotten, Battlenow is going to serve at the base level for a open source battle simulator. The plan is to have Generals with various rank, movement, intelligence, charm, war. There is also going to be hopefully some various weapon or military classes such as arterial (probably catapults), mounted units (probably rangers) and foot units (probably knights).
Turn based php game is what we will be shooting for, however it’s going to have the initiative system much like the older final fantasy tactics. You will have a queue and depending on your wait time will determine when your general will have his turn.
Forts, Castles, and different terrain all over different stats such as defense and movement. There is plans between levels to have a down/upgrade time for the next battle as well as in-game upgrades. Some code is below.
[code]
<?php
// Battlenow
// by hawk enterprises (http://www.hawkenterprises.org)
// 0 1 2 3 4 5 6 7
$terrain_map = array( 0 => array ( ‘M’,'M’,'M’,'F’,'F’,'G’,'G’,'G’),
1 => array ( ‘M’,'C’,'F’,'G’,'G’,'G’,'G’,'G’),
2 => array ( ‘M’,'H’,'H’,'H’,'F’,'G’,'G’,'G’),
3 => array ( ‘M’,'M’,'M’,'H’,'F’,'G’,'G’,'G’),
4 => array ( ‘W’,'W’,'W’,'W’,'W’,'G’,'G’,'G’),
5 => array ( ‘G’,'G’,'G’,'G’,'G’,'G’,'G’,'G’),
6 => array ( ‘G’,'F’,'G’,'G’,'G’,'G’,'G’,'G’),
7 => array ( ‘G’,'G’,'G’,'G’,'G’,'G’,'G’,'G’));
define(’ROWS’,8);
define(’COLS’,8);
$terrain_movement = array (’M’ => 100,
‘C’ => 0,
‘G’ => 1,
‘W’ => 6,
‘F’ => 3,
‘H’ => 4);
$cp_generals = array (0=> array(’flag’=>’CX’,'units’=>100,’rank’=>100,’x'=>1,’y'=>1),
1=> array(’flag’=>’X1′,’units’=>10,’rank’=>50,’x'=>5,’y'=>6));
$pc_generals = array (0=> array(’flag’=>’PX’, ‘units’=>100,’rank’=>100,’x'=>0,’y'=>6));
function display_map($c_generals, $p_generals, $map){
for($y=0;$y<ROWS;$y++){
for($x=0;$x<COLS;$x++){
$flag = false;
echo ‘<div id=”grid_’.$x.$y.’” class=”‘.$map[$y][$x].’”>
<img width=”64″ height=”64″ src=”image_tile.php?cost=’.movecost($y,$x).’&flag=’;
//check if anyone occupies this spot
foreach($c_generals as $k=>$v){ // computer first
if($v['x'] == $x && $v['y'] == $y){
echo $v['flag'];
$flag = true;
}
}
foreach($p_generals as $k=>$v){ // then player
if($v['x'] == $x && $v['y'] == $y){
echo $v['flag'];
$flag = true;
}
}
if(!$flag) echo $map[$y][$x]; // then bare terrain
echo ‘” alt=”tile” /></div>’;
}
echo ‘<br/>’; // next row
}
}
function movecost($x,$y){
global $terrain_map;
global $terrain_movement;
return $terrain_movement[$terrain_map[$x][$y]];
}
function distancecost($x,$y,$gx,$gy){
$cost = 0;
}
function movement_range($x,$y,$movepoints=6){
}
display_map($cp_generals,$pc_generals,$terrain_map);
?>
<style type=”text/css”>
.M,.G,.C,.W,.F,.H {width:64px;height:64px;display:inline;border:1px solid black;}
</style>
[/code]
PHP Game developers please contact us if you would like to get in on this project. We can use programmers but would also love a designer. Right now our tiles look like this click here to see our tiles
No Comments yet »
RSS feed for comments on this post. TrackBack URI
Leave a comment
You must be logged in to post a comment.















