00:00
00:00
Newgrounds Background Image Theme

Someone gifted MetalSlayer69 supporter status!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

(flash 8, as2) how can i make a multiplayer game using actionscript 2.0?

370 Views | 8 Replies
New Topic Respond to this Topic

can anyone tell me how i can make a multiplayer flash game using actionscript 2.0? im thinking of making a game similar to club penguin but except the camera moves around your player, and you move using arrow keys, how can i make a game like that?


You need a server to synchronize all of the players, and then the trouble only increases from there.


Multiplayer games are hell.


Slint approves of me! | "This is Newgrounds.com, not Disney.com" - WadeFulp

"Sit look rub panda" - Alan Davies

BBS Signature

It's better to use as3 for multiplayer games but it won't work in ruffle, if you want to use as2 then here's what you need:

1) this is a remote server (www.000webhost.com)

2) these are files that the server can process (for example php)

3) connection code and data transfer


minuses:

1) you need an internet connection

2) ruffle may not process them

3) it's very slow, very very slow


if you want, I can do all this for you, but for a fee


interesting, also im using something called "SmartFoxServer Pro" which is a tool that can make a multiplayer game in flash, but however i have a problem: theres an error that keeps happening when i try to connect to the ip, this is the error:

127.0.0.1
** Socket connection failed. Trying BlueBox **
[ Send ]: connect
Error opening URL "http://127.0.0.1:8080/BlueBox/HttpBox.do"

Here's something, it just displays the list of players and their cords. Ill update the code more later to get movable characters around on the screen but I have work in the morning.


// Client-side code (Flash/AS2)
var serverURL:String = "http://127.0.0.1:5000/";
var variables:LoadVars = new LoadVars();
var lblMessages:TextField = this.createTextField("lblMessages", this.getNextHighestDepth(), 0, 0,550,400);


variables.id = String(_xmouse + _ymouse); // Unique id can anything, mouse position can be a good chaos
variables.username = "Johnathan";
variables.xCoord = 1; 
variables.yCoord = 12; 


variables.onLoad = function(success:Boolean):Void {
    if (success) {
        trace("Data sent successfully");
    } else {
        trace("Error connecting to the server.");
    }
};


variables.onData = function(data:String):Void {
	var message:LoadVars = new LoadVars(); 
	message.decode(data);
	
	trace(data);
	
	lblMessages.text = "";
	for (var prop in message) {
    	var debug = prop + " -> "+message[prop];
		trace(debug); 
		lblMessages.text += debug + "\n";
	}
	
	variables.sendAndLoad(serverURL, variables, "POST");
}


stop(); 
variables.sendAndLoad(serverURL, variables, "POST");
# Server-side code (Python/Flask)
from flask import Flask, request, make_response
import time
import urllib.parse


app = Flask(__name__)


# Dictionary to store connected users and their coordinates
connected_users = {}


@app.route('/', methods=['POST'])
def handle_data():
    user_id = request.form.get('id', '')
    username = request.form.get('username', '')  # Include username
    x_coord = request.form.get('xCoord', '')
    y_coord = request.form.get('yCoord', '')
    
    # Process the data as needed
    print("Received data - User ID:", user_id, "Username:", username, "X:", x_coord, "Y:", y_coord)


    # Update the dictionary with the user's coordinates
    connected_users[user_id] = {'username': username, 'x': x_coord, 'y': y_coord}


    # Construct the response in the specified format
    response_content = '&'.join([f'id.{index}={urllib.parse.quote(user_id)}&username.{index}={user_data["username"]}&xCoord.{index}={user_data["x"]}&yCoord.{index}={user_data["y"]}' 
                             for index, (user_id, user_data) in enumerate(connected_users.items())])


    # Create the response object with the desired content type
    response = make_response(response_content)
    response.headers['Content-Type'] = 'application/x-www-form-urlencoded'


    print("Response - " + response_content)


    print("Users -  " + str(len(connected_users)))


    # Wait for 1/10 of a second before sending the next response
    time.sleep(1 / 10.0)


    return response


if __name__ == '__main__':
    app.run(debug=True)

I don't ever think I looked too much into networking with flash and as2 back then.

My best guess would be to convert the users into arrays (either by username.# and splitting the '.' or by username=name1,name2,name3 and encode the names in base64 or some encodeUriComponent equivalent) then create the game objects when and where you wish.


thanks, also which frame do i need to add that code in? maybe you can make an example fla file (the fla must work in flash 8)


At 11/18/23 04:29 PM, Gimmick wrote: Multiplayer games are hell.


fuck u ez took a week


At 11/22/23 07:42 PM, SuperGibaLogan wrote: thanks, also which frame do i need to add that code in? maybe you can make an example fla file (the fla must work in flash 8)


Sorry I should have been WAY more specific.

In order to get "multiplayer". You need to write ActionScript 2 code to request a specific webpage over and over, a method called HTTP polling. For the last examples I gave I used python for the server code, when you can write php code as well you must return application/x-www-form-urlencoded no matter what.

In my previous post there are two code snippets that are important, the python code and the ActionScript code. You can put the ActionScript code anywhere as long as its executed it should POST to the server.

In the current example I put all of my source code into one project to see if it works (and it did :D). The example uses a login scene and a room scene so all the networking code is separated. You can go ahead and run server2.py and then run local.swf or .fla to get started.


I can comment out the code to make it more verbose, Im tired right now lol.



At 11/28/23 03:29 AM, FlashBacks1998 wrote:
At 11/18/23 04:29 PM, Gimmick wrote: Multiplayer games are hell.
fuck u ez took a week

At 11/22/23 07:42 PM, SuperGibaLogan wrote: thanks, also which frame do i need to add that code in? maybe you can make an example fla file (the fla must work in flash 8)
Sorry I should have been WAY more specific.
In order to get "multiplayer". You need to write ActionScript 2 code to request a specific webpage over and over, a method called HTTP polling. For the last examples I gave I used python for the server code, when you can write php code as well you must return application/x-www-form-urlencoded no matter what.
In my previous post there are two code snippets that are important, the python code and the ActionScript code. You can put the ActionScript code anywhere as long as its executed it should POST to the server.
In the current example I put all of my source code into one project to see if it works (and it did :D). The example uses a login scene and a room scene so all the networking code is separated. You can go ahead and run server2.py and then run local.swf or .fla to get started.

I can comment out the code to make it more verbose, Im tired right now lol.

https://www.newgrounds.com/portal/view/908368

thanks, ill try it out soon