1

I just started learning HTML5 canvas and Google App Engine's Channel API.

I build a simple game demo based on a isometric map. Right now I want to implement character movement, but I am wondering how I should implement it.

current demo: http://cheukalex.appspot.com

This is how I think it would be implemented:

The client will handle the movement. Once the arrow keys are pressed, the client will do the movement, then sends the new coordination to the server which then will be broadcast to other users on the server to update the location of your character.

Problems I thought of:

  1. What if I want to implement "movement speed", as in how fast can the user walk five squares for example. The delay between each movement will be done on the client side. But will that be safe? since javascripts are easily edited.

  2. How do I deal with latency? If i built a simple chase-tag game, how would I sync up the users so situations where, one person looks like they "tag" another user, but the other user see him 1-2 squares behind, wont happen?


EDIT: @nycynik, you are right, the latency is around 200ms. I have tested it here.

Latency Test: http://cheukalex.appspot.com/latency

Thats is the smallest latency it will ever get. 200ms is pretty fast. Then it might be my code that is slow?

How i implemented the whole game is.

  1. Client enters website
  2. Server creates token, open channel, store client data ( channel id ) in DB
  3. .... some logic
  4. When Client press arrow keys, it notifies the server which client moved and what direction
  5. Server recieve movement, does logic, loops through database (only currently online clients), broadcast message to all clients the position of every client on the map in json. Client then "moves".

Something wrong with this?

AlexCheuk
  • 5,595
  • 6
  • 30
  • 35
  • As for hacking the movement speed, the server can just keep their last position and check it against a maxspeed delta variable - if its too high over a given time difference, HAXX. –  Apr 17 '12 at 20:45
  • can you share more of how your doing it? The channel should work very similar to a socket, and that should be fast enough for this. – nycynik Apr 17 '12 at 22:58

2 Answers2

2

This was supposed to be a comment to the first answer, but it won't fit.

There might not be much you can do with the response time, because network latency will really be an issue for now. Perhaps you can just work on the user experience side. To make the delay "acceptable" to the user, why don't you add an animation?

For example, when the user hits an arrow key, the horse can look like it's pulling back slowly and getting ready to jump (behind the scenes you're sending a request through the Channel API). When you get the response from the server, the horse can then complete the jump and land on another position.

Though there will still be an issue of latency, your users might find it "acceptable" if the latency isn't that obvious.

Albert
  • 3,611
  • 3
  • 28
  • 52
1

What if I want to implement "movement speed"

I would recommend sending your move to the server, and having the server refresh the board. That would keep each player in sync.

How do I deal with latency?

If you wanted to, you could require that all clients report in, before the server sends out the refresh of position, this would enforce consistency, but would be a LCD approach. I think for this type of game, should work fine.

EDIT: Originally I thought it would work like a network socket worked, but it seems your results are much, much slower then that. It might be something in the code, or it might be the technology itself, but it does not seem fast enough for what you are trying to do. If this were a game of chess, you would be fine. But for this type of game you need a faster round trip to work.

This post refers to the time expectations

Channel API deliver speed is on the order of 100-200ms;

working with new channel creation limits

That should be faster then what you are getting.

Community
  • 1
  • 1
nycynik
  • 7,371
  • 8
  • 62
  • 87