Battle Formula
Moderator: General Moderators
Battle Formula
I'm working on a PHP text-based game, and I'm working on the battle formula. It will be something like
x = player agility/opponent agility
If x = 1.65, then Player would attack 1.65 times for every time the opponent attacks.
How could I put this into PHP?
x = player agility/opponent agility
If x = 1.65, then Player would attack 1.65 times for every time the opponent attacks.
How could I put this into PHP?
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Code: Select all
$your_attack = $your_agility / $opponent_agility;- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
I don't really know what you want but how about.
Code: Select all
$player1_attacks = $player1_agility / $player2_agility;
$player2_attacks = $player2_agility / $player1_agility;
$possible_offset = 0.1; //10%
$player1_offset = $possible_offset * $player1_attacks;
$plus_min_array = array(1, -1);
shuffle ($plus_min_array);
$player1_this_move = ($player1_attacks + ($player1_offset * $plus_min_array[0]));- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
So it never changes?cbrian wrote:I get it from a database.
How much have this game have you written so far? It seems that we have answered your question but you need some more help?
I'm guessing that when a player makes an attack there is some sort of calculation to deduct points from the opponent depending upon what the attack was and various other factors?? What exactly do you need help with
Are the attacks whole numbers? if so then you can do it like this (change it to php yourself
):
badguy attack
badguy attack + (random integer from -5 through 5 ) = meh
player hp - meh = new player hp
you attack
your attack power / enemy defense = moh
enemy hp - moh = new enemy hp
---
also, is it me or should this be in "PHP - Theory and Design" forum?
badguy attack
badguy attack + (random integer from -5 through 5 ) = meh
player hp - meh = new player hp
you attack
your attack power / enemy defense = moh
enemy hp - moh = new enemy hp
---
also, is it me or should this be in "PHP - Theory and Design" forum?
I would use a while statement, and keep looping it until one of the players dies.
To see whos player's turn it is, I would look at the current battle turn, and use a formula to see whos go it should be, and then let that person have his go. Once (s)he has had his/her go, the loop continues.
Too late, and tired to provide you with any sample code.
To see whos player's turn it is, I would look at the current battle turn, and use a formula to see whos go it should be, and then let that person have his go. Once (s)he has had his/her go, the loop continues.
Too late, and tired to provide you with any sample code.
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
I believe it is a turned based game...Archy wrote:I would use a while statement, and keep looping it until one of the players dies.
To see whos player's turn it is, I would look at the current battle turn, and use a formula to see whos go it should be, and then let that person have his go. Once (s)he has had his/her go, the loop continues.
Too late, and tired to provide you with any sample code.
and perhaps different attacks can be applied during the battle itself and whatnot..
so I don't think the whole fight should be automated.