Date post: | 20-Jul-2015 |
Category: |
Technology |
Upload: | dotblue |
View: | 86 times |
Download: | 1 times |
MMOPONGBrnoJS X - 7 April 2015
Vincent van Scherpenseel
Disclaimer
Please don’t laugh (too much)
Why?
• I wanted to learn NodeJS
• I love code related to networking
• I love retro games
• My love life was falling apart ;)
Ingredients
• NodeJS
• SOCKET.IO (v0.8.7) for networking
• jCanvas (v5.1) for simple canvas manipulation
• Webserver (Apache, Nginx, pick your poison)
• Open port 8080
“Architecture”
Server(dictator)
Player(slave)
Player(slave)
Player(slave)
Player(slave)
Server is a dictator
The server dictates:
• where the ball is
• where all players (pads) are
• when a collision has occurred
• when a goal has been scored
Player is a slave
The only thing that the player is allowed to do:
• request to move (more on that later)
• render the game
SOCKET.IO rocks
The game loopServer-Side
Collision detection
Moving the ballserver-side
client-side
client-side
The game loopClient-Side
Drawing assets
Moving the pads
Confession time
Why is network performance so horrible?
This is baaaaaaaaaaaaaaaaaaad
ServerPlayer Can I haz move?
ServerPlayer Yes, new coords:
The Right Way™
ServerPlayer
ServerPlayer DISCONNECT
My new coords:
if ( $distance > $possibleDistanceTraveledConsideringTime ) {