2 Replies - 538 Views - Last Post: 02 November 2012 - 06:37 AM Rate Topic: -----

#1 grivcon  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 01-November 12

Basics of PHP&JS&AJAX

Posted 01 November 2012 - 05:12 PM

Hi dudes! Im starting in this world of game programming and I wanna make a simle web based one with PHP & JS and AJAX. I know how to do a basic JS game, and a PHP one but the problem is when i want to unifiy both of them to make a "complex" game client-server, the fastest answer is AJAX, ok, i have the action in JS, and when I wanna make the movs/whatever real, I send a AJAX request to a PHP web, client sends a menssage to server and server returns another message, but there I get a little confused, dunno how to organize the scripts accordin to that way-to-do the game.

Anyone can illuminate me? Any tutorial or a own answer would be great!.

Is This A Good Question/Topic? 0
  • +

Replies To: Basics of PHP&JS&AJAX

#2 Kruithne  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 99
  • View blog
  • Posts: 442
  • Joined: 28-July 09

Re: Basics of PHP&JS&AJAX

Posted 02 November 2012 - 05:08 AM

Hello,

I'm not sure I 100% follow what your question is? But heck, let's take a shot at answering it anyway.

The client
The client, which you will be using jQuery/AJAX/Javascript (whichever) for should contain all of your visual manipulation scripts. Anything that moves on the users screen, anything they can click, all the elements rendered in front of them are controlled here. Bare in mind that the user CAN and if they have malicious intent, WILL alter these scripts, so obviously you need to be very careful that they cannot be abused.

The server
The server, which you will use PHP for, should control all of the game logic and other such computing. You obviously don't want to be sending image paths from the server to the client, rather an ID of an entity which the client will then know to show X image for, and so on. If everything is done correctly, the user should not be able to manipulate things such as score on the server.

When the user 'scores' (using scoring as a very basic example) the client should not tell the server that they have scored. It shouldn't even tell the server that they did something to make them score. Rather, the client should tell the server that the user clicked X. The server should then calculate that clicking X will cause Y, and tell the client this, the client then shows the user the result of Y happening.
Was This Post Helpful? 1
  • +
  • -

#3 grivcon  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 01-November 12

Re: Basics of PHP&JS&AJAX

Posted 02 November 2012 - 06:37 AM

View PostKruithne, on 02 November 2012 - 05:08 AM, said:

Hello,

I'm not sure I 100% follow what your question is? But heck, let's take a shot at answering it anyway.

The client
The client, which you will be using jQuery/AJAX/Javascript (whichever) for should contain all of your visual manipulation scripts. Anything that moves on the users screen, anything they can click, all the elements rendered in front of them are controlled here. Bare in mind that the user CAN and if they have malicious intent, WILL alter these scripts, so obviously you need to be very careful that they cannot be abused.

The server
The server, which you will use PHP for, should control all of the game logic and other such computing. You obviously don't want to be sending image paths from the server to the client, rather an ID of an entity which the client will then know to show X image for, and so on. If everything is done correctly, the user should not be able to manipulate things such as score on the server.

When the user 'scores' (using scoring as a very basic example) the client should not tell the server that they have scored. It shouldn't even tell the server that they did something to make them score. Rather, the client should tell the server that the user clicked X. The server should then calculate that clicking X will cause Y, and tell the client this, the client then shows the user the result of Y happening.

Hi! Thank you for your answer. Your reply resolved one of my problem. The main question is how to connect visual game (js, html5...) with server (php). I will try with an example:


.....
Js.js

......
Render(){

.......
}
Update(){


// here the character can move
// the script gets input like "arrows" and other "keys"
//?ajax call to a php script to send message
//to server?

}
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1