PHP Battle System for RPG game

Posted by Jay on Game Development See other posts from Game Development or by Jay
Published on 2012-10-18T02:18:13Z Indexed on 2012/10/18 5:24 UTC
Read the original article Hit count: 267

Filed under:

I posted this a while ago on stackoverflow, they thought it would be better place here, I agree.

Essentially I know what I want to accomplish, and I have something to the effect of what I want but I am not satisfied with it. Here's the problem.

Each user has some states: STR (how hard they hit), DEF (dodging/blocking attacks), SPD (when they can strike), and STAMINA (basically their endurance in game, if this runs out they can no longer fight and lose)

What I need is something like this:

UserA Stats: STR: 1,000 DEF: 2500 SPD: 2000 (HP: 1000/1000)

UserB Stats: STR: 1,500 DEF: 500 SPD: 4000 (HP: 1000/1000)

Because the second user has double the speed, he lands twice the amount of hits on the first user, before he gets hit. Because he has less strength than the first users defence, he will do no, to little damage. This is how the battle would theoretically go:

UserB strikes UserA for 0 damage

UserB strikes UserA for 0 damage

UserA strikes UserB for 500 damage

UserB strikes UserA for 0 damage

UserB strikes UserA for 0 damage

UserA strikes UserB for 500 damage, and sends him to the hospital!

I was using this code, which is buggy, and not efficient, I just need a better way to do this: http://pastebin.com/15LiQQuJ

Oh, and if anyone has some good ideas on how to improve the concept that would be cool too! It's not that elaborate so I'll be thinking of all sorts of things to make it more dynamic.

Thanks.

© Game Development or respective owner

Related posts about php