Join 307,118 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,975 people online right now. Registration is fast and FREE... Join Now!
I was without internet for 2 weeks (6 days of which I had free time) and managed to throw together a simple PHP turn-based game, I threw it up at http://thegame.no-ip.info for some people on an old forum to try out.. if enough people want me to, I'll release the source (sans my alpa/beta-phase sucky-arse forum I threw into it some weeks after making the game) along with a guide in writing it.
I guess I'll keep an eye on this thread, post here if you want me to do as I mentioned?
This post has been edited by Rechocto: 4 Jan, 2009 - 02:23 AM
I have also made a web based game (mafia/pimp game) since my first post in here. It turned out pretty good, but the attack feature is not implemented yet. If you want to see it click the link on my signature. If you like it and want to make a similar one and stumble upon problems, PM me, I may be able to help you (but only mafia/pimp style games, cause I don't know other games).
hello, is there a place where i can find a good tutorial to create a mini map or even a grid map to make my character walking through it ?
thanks for your help, eli
hrm... I once (several years ago on a computer that got fried by a lightning strike (no backup )) integrated a PHP site into a MUD.. it wasn't anywhere NEAR completion and only had a skeleton system up (hence why I didn't back it up), but I did have a minimap going. it was an smaug mud, and therefore based on vnums, making it easy enough to set up the map.. basically it set up a 7x7 square of squares (a table). the center square was the room your character was in. if there was an exit east the room to the right was added, etc, following exits until it left that 7x7 square then going back to the most recent room with an unexplored exit, and so on. it took a little while to parse but every room that existed in that 7x7 had a thick black border and any area where there wasnt a room had a light grey dashed border. if there was an exit "up" there was a blue "u" in the square and if there was an exit down there was a blue "d" in the square. I wanted to set it up so that if there was another player currently in that room (set something up with php sockets and the mud server to work together) then the background of the square would be green... however I did set it up so on mouseover you could see what monsters respawned in that room...
this is somewhat irrelevant, but I believe it is the type of system your wanting to integrate into your game, yes? how does your game work? I'm guessing you have an X and Y value in your charactor data, and a database containing room descriptions, exits, and x\y values (something like how a MUD works) or file names x-y.php dynamically created where you can create rooms easilly?
elaborate on how location data and areas are set up in your game and I may be able to help you.
This post has been edited by Rechocto: 22 Jan, 2009 - 01:19 AM
hello, you are absolutly right, since I post i manage to create a map based on x,y as each place and character have there own coordinate. I build the image with GDlibrairy, and make the character move with left right/right , up/down . preety easy at the end of the day . i forgoti have a few coffees too.
but your idea ofsocket in a MUD looks interesting though.
QUOTE(Rechocto @ 22 Jan, 2009 - 01:16 AM)
QUOTE(eliphas @ 20 Jan, 2009 - 02:04 AM)
hello, is there a place where i can find a good tutorial to create a mini map or even a grid map to make my character walking through it ?
thanks for your help, eli
hrm... I once (several years ago on a computer that got fried by a lightning strike (no backup )) integrated a PHP site into a MUD.. it wasn't anywhere NEAR completion and only had a skeleton system up (hence why I didn't back it up), but I did have a minimap going. it was an smaug mud, and therefore based on vnums, making it easy enough to set up the map.. basically it set up a 7x7 square of squares (a table). the center square was the room your character was in. if there was an exit east the room to the right was added, etc, following exits until it left that 7x7 square then going back to the most recent room with an unexplored exit, and so on. it took a little while to parse but every room that existed in that 7x7 had a thick black border and any area where there wasnt a room had a light grey dashed border. if there was an exit "up" there was a blue "u" in the square and if there was an exit down there was a blue "d" in the square. I wanted to set it up so that if there was another player currently in that room (set something up with php sockets and the mud server to work together) then the background of the square would be green... however I did set it up so on mouseover you could see what monsters respawned in that room...
this is somewhat irrelevant, but I believe it is the type of system your wanting to integrate into your game, yes? how does your game work? I'm guessing you have an X and Y value in your charactor data, and a database containing room descriptions, exits, and x\y values (something like how a MUD works) or file names x-y.php dynamically created where you can create rooms easilly?
elaborate on how location data and areas are set up in your game and I may be able to help you.
I'm in the process of programming the battle system for my web based game and one problem I ran to was that I'm not sure how to make an attack only cause damage a percent of the time.
Would this work?:
CODE
<?php $perecent = 60;
$rand = rand(1,100);
if ($rand <= $percent) { echo "The attack worked!"; } else { echo "The attack failed"; } ?>
Can anyone help me?
This post has been edited by PunkRocker277: 28 Jan, 2009 - 04:14 PM
Dream.In.Code has a policy by which we prefer to see a good faith effort on your part before providing source code for homework assignments. Please post the code you have written in an effort to resolve the problem, and our members would be happy to provide some guidance. Be sure to include a description of any errors you are encountering as well.
Please post like this:
Thank you for helping us helping you.
Google helps though and maybe you want to look up rand()
This post has been edited by Auzzie: 28 Jan, 2009 - 03:56 PM
Hey guys I'm having a problem with my battle system script. When the opponent attacks it doesn't update my hp on the database and I can't find the problem.
#set the attack number variable $num = $_GET['num'];
#set date $date = date('m-d-y h:i a');
#get the battle's info $get_battle = mysql_fetch_array(mysql_query("SELECT * FROM `Battles` WHERE `UserID` = '$_COOKIE[UserID]' AND `Active` = 'Yes'"));
#get the logged-in user's info $user = User($_COOKIE['UserID']);
#get the opponent's info $opp = User($get_battle['OpponentID']);
#set some vars for the functions $exp = $user_starter['Pkmn_Exp']; $exp2 = $user_starter['Pkmn_Exp2']; $level = $user_starter['Pkmn_Level']; $hp = $user_starter['Pkmn_HP']; $ohp = $get_battle['OppHP']; $log = $get_battle['Log'];
#check what attack the user is using if (empty($num)) { #do nothing } elseif ($num == 1) { #set attack used var $attack_used = $attack1; } elseif ($num == 2) { #set attack used var $attack_used = $attack2; } elseif ($num == 3) { #set attack used var $attack_used = $attack3; } elseif ($num == 4) { #set attack used var $attack_used = $attack4; } else { ?> <div align="left"> <h2>Error</h2> Invalid attack number.<br /> <a href="battle.php">Go back</a>. </div> <?php #exit page exit; }
#set a function that checks if the user leveled up function CheckExp() {
if ( $exp >= $exp2) {
#get new hp $new_exp = ($exp * ($level + 1)) / 2;
#update the level & experience mysql_query("UPDATE `Pokemon` SET `Pkmn_Level` + '1', `Pkmn_Exp` = '0', `Pkmn_Exp2` = '$new_exp' WHERE `OwnerID` = '$_COOKIE[UserID]' AND `Slot` = '1'");
#exit page exit; } }
#set a function that checks if anyone won yet function CheckStatus() {
#globalize vars global $hp, $get_battle, $log, $date, $ohp, $level, $exp2, $exp;
if($hp == 0) {
#you lose, add 1 to battles lost mysql_query("UPDATE `Users` SET `Battles_Lost` + '1' WHERE `User_ID` = '$_COOKIE[UserID]'"); mysql_query("UPDATE `Battles` SET `Results` = 'Lose' WHERE `BattleID` = '$get_battle[BattleID]'");
#set log message $new_log = $log . '[' . $date . ']: The Player Lost The Battle.<br />';
#change status message mysql_query("UPDATE `Battles` SET `StatusMessage` = 'You lost the battle!', `Log` = '$new_log' WHERE `BattleID` = '$get_battle[BattleID]'"); #redirect user ?> <meta http-equiv='Refresh' content='0; url=battle.php' /> <?php #exit page exit; } elseif ($ohp == 0) {
#random number $randExp = rand(2,10);
#calculate how much exp to give the pokemon $exp_received = round((($exp2 * (2 / $level)) * $randExp) / 3);
#give the pokemon the exp mysql_query("UPDATE `Pokemon` SET `Pkmn_HP` + '$exp_received' WHERE `OwnerID` = '$_COOKIE[UserID]' AND `Slot` = '1'");
#you win, add 1 to battles won mysql_query("UPDATE `Users` Set `Battles_Won` + '1' WHERE `UserID` = '$_COOKIE[UserID]'"); mysql_query("UPDATE `Battles` SET `Results` = 'Win' WHERE `BattleID` = '$get_battle[BattleID]'");
#set log message $new_log = $log . '[' . $date . ']: The Player Won The Battle.<br />';
#change status message mysql_query("UPDATE `Battles` SET `StatusMessage` = 'Congratulations! You won the battle!', `Log` = '$new_log' WHERE `BattleID` = '$get_battle[BattleID]'"); #check if the user leveled up CheckExp();
#check what the user is trying to do #if the user is attacking if ($act == "attack") {
#check which pokemon has the higher speed #the user gets to attack first if ($user_starter['Pkmn_Speed'] >= $opp_starter['Pkmn_Speed']) {
#make the user attack first $dmg = ($user_starter['Pkmn_Attack'] * $attack_used['Attack_Power'] + $user_starter['Pkmn_Level']) / $opp_starter['Pkmn_Defence'];
$accuracy = $attack_used['Accuracy'];
$rand = rand(1,100);
if ($rand <= $accuracy) { #set the "missed" variable $missed = false;
#subract damage from hp $new_ohp = $get_battle['OppHP'] - $dmg;
#check if the hp is under zero if ($new_ohp <= 0) { #set $new_ohp to zero $new_ohp = 0; }
#make the opponent take damage mysql_query("UPDATE `Battles` SET `OppHP` = '$new_ohp' WHERE `BattleID` = '$get_battle[BattleID]'");
#set log message $new_log = $log . '[' . $date . ']: The player attacked with ' . $attack_used['Attack_Name'] . ' causing <b>' . $dmg . '</b> damage to the opponent.<br />';
#change status message mysql_query("UPDATE `Battles` SET `Log` = '$new_log' WHERE `BattleID` = '$get_battle[BattleID]'");
#check if anyone won the battle yet CheckStatus();
#---- the opponent is now attacking ----#
#set up a random attack for the opponent to use $randAttack = rand(1,4);
#check what attack the user is using if ($randAttack == 1) { #set attack used var $oattack_used = $oattack1; } elseif ($randAttack == 2) { #set attack used var $oattack_used = $oattack2; } elseif ($randAttack == 3) { #set attack used var $oattack_used = $oattack3; } elseif ($randAttack == 4) { #set attack used var $oattack_used = $oattack4; }
if ($orand <= $oaccuracy) { #set the "missed" variable $omissed = false;
#subract damage from hp $new_hp = $user_starter["Pkmn_HP"] - $odmg;
#check if the hp is under zero if ($new_hp <= 0) { #set $new_ohp to zero $new_hp = 0; }
#make the user take damage mysql_query("UPDATE `Pokemon` SET `Pkmn_HP` = '$new_hp' WHERE `OwnerID` = '$_COOKIE[UserID]' AND `Slot` = '1'"); } else { #set the "missed" variable $omissed = true; }
#check if anyone won the battle yet CheckStatus();
#check if any attack missed if ($missed == true) { #your attack missed
$status_msg = 'You didn\'t cause damage to the opponent because your attack missed.<br /> Your opponent attacked with ' . $oattack_used[Attack_Name] . ' causing <b>' . $odmg . '</b> damage to the you.';
$status_msg = 'You attacked with ' . $attack_used[Attack_Name] . ' causing <b>' . $dmg . '</b> damage to the opponent.<br /> Your opponent didn\'t cause damage to the you because your attack missed.';
$status_msg = 'You didn\'t cause damage to the opponent because your attack missed.<br /> Your opponent didn\'t cause damage to the you because your attack missed.';
} else { #no attacks missed
$status_msg = 'You attacked with ' . $attack_used['Attack_Name'] . ' causing <b>' . $dmg . '</b> damage to the opponent.<br /> Your opponent attacked with ' . $oattack_used['Attack_Name'] . ' causing <b>' . $odmg . '</b> damage to the you.'; }
#change status message mysql_query("UPDATE `Battles` SET `StatusMessage` = '$status_msg' WHERE `BattleID` = '$get_battle[BattleID]'");
} #the opponent gets to attack first elseif ($user_starter["Pkmn_Speed"] < $opp_starter["Pkmn_Speed"]) {
#---- the opponent is now attacking ----#
#set up a random attack for the opponent to use $randAttack = rand(1,4);
#check what attack the user is using if ($randAttack == 1) { #set attack used var $oattack_used = $oattack1; } elseif ($randAttack == 2) { #set attack used var $oattack_used = $oattack2; } elseif ($randAttack == 3) { #set attack used var $oattack_used = $oattack3; } elseif ($randAttack == 4) { #set attack used var $oattack_used = $oattack4; }
if ($orand <= $oaccuracy) { #set the "missed" variable $omissed = false;
#subract damage from hp $new_hp = $user_starter['Pkmn_HP'] - $odmg;
#check if the hp is under zero if ($new_hp <= 0) { #set $new_ohp to zero $new_hp = 0; }
#make the user take damage mysql_query("UPDATE `Pokemon` SET `Pkmn_HP` = '$new_hp' WHERE `OwnerID` = '$_COOKIE[UserID]' AND `Slot` = '1'"); } else { #set the "missed" variable $omissed = true; }
#check if anyone won the battle yet CheckStatus();
#---- make the user attack ----# $dmg = round(($user_starter['Pkmn_Attack'] * $attack_used['Attack_Power'] + $user_starter['Pkmn_Level']) / $opp_starter['Pkmn_Defence']);
$accuracy = $attack_used['Accuracy'];
$rand = rand(1,100);
if ($rand <= $accuracy) { #set the "missed" variable $missed = false;
#subract damage from hp $new_ohp = $get_battle['OppHP'] - $dmg;
#check if the hp is under zero if ($new_ohp <= 0) { #set $new_ohp to zero $new_ohp = 0; }
#make the opponent take damage mysql_query("UPDATE `Battles` SET `OppHP` = '$new_ohp' WHERE `BattleID` = '$get_battle[BattleID]'");
#set log message $new_log = $log . '[' . $date . ']: The player attacked with ' . $attack_used['Attack_Name'] . ' causing <b>' . $dmg . '</b> damage to the opponent.<br />';
#change status message mysql_query("UPDATE `Battles` SET `Log` = '$new_log' WHERE `BattleID` = '$get_battle[BattleID]'");
#check if anyone won the battle yet CheckStatus();
#check if any attack missed if ($missed == true) { #your attack missed
$status_msg = 'Your opponent attacked with ' . $oattack_used[Attack_Name] . ' causing <b>' . $odmg . '</b> damage to the you.<br /> You didn\'t cause damage to the opponent because your attack missed.';
$status_msg = 'Your opponent didn\'t cause damage to the you because your attack missed.<br /> You attacked with ' . $attack_used[Attack_Name] . ' causing <b>' . $dmg . '</b> damage to the opponent.';
$status_msg = 'Your opponent didn\'t cause damage to the you because your attack missed.<br /> You didn\'t cause damage to the opponent because your attack missed.';
} else { #no attacks missed
$status_msg = 'Your opponent attacked with ' . $oattack_used['Attack_Name'] . ' causing <b>' . $odmg . '</b> damage to the you.<br /> You attacked with ' . $attack_used['Attack_Name'] . ' causing <b>' . $dmg . '</b> damage to the opponent.'; }
#change status message mysql_query("UPDATE `Battles` SET `StatusMessage` = '$status_msg' WHERE `BattleID` = '$get_battle[BattleID]'");
}
#redirect user ?> <meta http-equiv='Refresh' content='0; url=battle.php' /> <?php #exit page exit; } #if the user is changing his starter pokemon elseif ($act == "change") {
} #if the user is running elseif ($act == 'run') {
#set log message $new_log = $log . '[' . $date . ']: The Player Ran From The Battle.<br />';
#change status message mysql_query("UPDATE `Battles` SET `StatusMessage` = 'You successfully ran from the battle!', `Log` = '$new_log' WHERE `BattleID` = '$get_battle[BattleID]'");
#deactivate the battle mysql_query("UPDATE `Battles` SET `Run_Status` = 'Yes' WHERE `BattleID` = '$get_battle[BattleID]'");
#redirect back to the battle page ?> <meta http-equiv='Refresh' content='0; url=battle.php' /> <?php exit;
} #if the user is using an item elseif ($act == "use_item") {
} else { ?> <div align="left"> <h2>Error</h2> You shouldn't be here.<br /> <a href="index.php">Go back</a>. </div> <?php } ?>