Real time attack?

Post all your tuts or request for tuts here.
Achilles
Posts: 14
Joined: Wed Jun 09, 2010 10:46 pm

Real time attack?

Post by Achilles »

With regards to PHP
Is it possible to construct a battle system that causes player and environment to act on a timer?
For example, player is instructed to attack every 3 seconds and keeps attacking until enemy is dead.
Each action is updated on some kind of dialogue screen and displaying what is done.

Is this possible with PHP? or is javascript the solution?
Does anyone know how to do this?
Rastan
Posts: 126
Joined: Tue Apr 13, 2010 1:48 am

Re: Real time attack?

Post by Rastan »

Do you mean sort of like an autoattack? like player swing enemy swing player swing enemy swing till one is dead? If so I'm working on one right now. I have been getting some help with a bug I'm having with it in the coding section. If you're looking for more of a timed feature I'm probably not the best to help you.
User avatar
Callan S.
Posts: 2042
Joined: Sun Jan 24, 2010 5:43 am

Re: Real time attack?

Post by Callan S. »

From my knowledge it kind of is. But it's not so much running in real time - what you'd have is when the page refreshes the code looks at the last time stamp and thinks 'Hey, it's been nine seconds so far, and each attack is done after three seconds, so I'll run three combat rounds quickly right now!'. It's also possible to make the page refresh after X number of seconds, to help show the action 'as it happens'. Currently I'm using a rest code which is kinda similar, as in the guy cannot battle further until X number of seconds have passed, then it changes a value or two - same principle.

What your talking about so far doesn't strictly need real time passing during it.
Fight Cycle : My latest Browser game WIP
Driftwurld : My Browser Game WIP
Philosopher Gamer : My Blog
User avatar
PaxBritannia
Posts: 680
Joined: Sun Apr 18, 2010 1:54 pm

Re: Real time attack?

Post by PaxBritannia »

From what I understand, you are asking if you can have:

A page with a sort of animation thing in which the player is set to attack every 3 seconds until the enemy is dead.


The short answer is no you cannot do it in php, you would have to use javascript or another client-side script.

Pax.
User avatar
Chris
Posts: 1581
Joined: Wed Sep 30, 2009 7:22 pm

Re: Real time attack?

Post by Chris »

You could actually do it with PHP. Simply put a timed refresh header in your PHP battle script. And the have the battle script a frame of some sort. However if I were to do it I'd use JavaScript to make the reloading go seamless with Ajax.
Fighting for peace is declaring war on war. If you want peace be peaceful.
Achilles
Posts: 14
Joined: Wed Jun 09, 2010 10:46 pm

Re: Real time attack?

Post by Achilles »

Yes, you are all on the right track.

Timer will count from 0 to 300 (the count will speed through this instead of actually 300 seconds)
A users character is set to attack every 3rd count (3, 6, 9, 12, 15, all the way to 300 if necessary), enemy is set to attack every 12 count (12, 24, 36, etc.)
Each class has its own 'time' to attack.

So I understand javascript may be the solution, I was just wondering if PHP was capable of this.
Thanks for the comments thus far.
User avatar
Callan S.
Posts: 2042
Joined: Sun Jan 24, 2010 5:43 am

Re: Real time attack?

Post by Callan S. »

I'd say php is capable of this, yeah. I mean, if your capable of programming this in another language, you can do it in PHP.

The only thing is the data only changes on a query from a browser. But you have the html refresh command and php time() commands to mess around with for various effects.
Fight Cycle : My latest Browser game WIP
Driftwurld : My Browser Game WIP
Philosopher Gamer : My Blog
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Real time attack?

Post by Jackolantern »

Chris wrote:You could actually do it with PHP. Simply put a timed refresh header in your PHP battle script. And the have the battle script a frame of some sort. However if I were to do it I'd use JavaScript to make the reloading go seamless with Ajax.
This pretty much sums it up. You can do it in PHP, but to make it more elegant and to create a better user experience, you should use AJAX.
The indelible lord of tl;dr
Achilles
Posts: 14
Joined: Wed Jun 09, 2010 10:46 pm

Re: Real time attack?

Post by Achilles »

Excellent feedback.
I'll look into developing this battle system in javascript. I WILL be able to convert that to AJAX though, correct?
User avatar
hallsofvallhalla
Site Admin
Posts: 12026
Joined: Wed Apr 22, 2009 11:29 pm

Re: Real time attack?

Post by hallsofvallhalla »

no conversion needed, Ajax is all JS functions, so you will just pass your current data to those functions
Post Reply

Return to “Tutorials”