We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › Tug of War sketch
Page Index Toggle Pages: 1
Tug of War sketch (Read 528 times)
Tug of War sketch
Mar 16th, 2010, 5:50pm
 
Hey, I'm new to this forum and new to Processing in general but I had an idea and I was wondering if it was possible. It seems fairly simple to me, but I don't quite know how to take care of the details.

I would like to create a very simple game that would resemble Tug of War. I'll copy and paste my code here to show you what I have already assembled.

---
imagearts.ryerson.ca/kfriedman/applet/tugOfWar.html
---

I'm not sure if it could be improved here as far as efficient coding goes but it gets the job done so far. I am also working on putting in a condition that checks to see when the ball has reached 0 or 150, those values being the left and right side of the canvas respectively.

Here is the part I'm not sure how to do, I would like to make it so that I could put it online and two players from different computers could log on and play against each other in real time, like a two player multiplayer web game. I have no idea if this is possible to do with Processing but I thought if I was going to find out I might as well try doing so here. I probably have to download some sort of networking library or something? I'm really not sure, if anyone has any ideas as to how I can get this thing online or to point me in the direction of some documentation or a book even that'll help me out, I would be very thankful.

Thanks for reading my wall of text,

Kyle

EDIT:

I have made some changes to the program to include some text and the conditional check to see if the ball has reached one side or the other to determine who is the winner and who is the loser.

I also compiled it and put it up on my website so that the post wasn't so long with all of the code there. It works on the site with the fonts and everything embedded but the code is still there to view if you choose
Re: Tug of War sketch
Reply #1 - Mar 17th, 2010, 12:17am
 
I can be wrong, but I believe that to make two players to play against each other in real time on different browsers, you have to set up a server, used as intermediate layer between the two applets: applets in browsers are very limited for security reason. Perhaps you can make two applets to communicate via sockets with signet jars, but it is tricky and another difficulty is to find the IP address of the other player...
So adding a server side allows to centralize information (what players are logged in, what is their IP address) and minimize the security issues (applets can freely communicate with the server than sent the applet's jars).
You need to know some server-side language (and your Web site host must allow them), like PHP, Python, ASP or whatever.
Page Index Toggle Pages: 1