Skocz do zawartości

XxMichałxX

Zbanowani
  • Postów

    866
  • Dołączył

  • Ostatnia wizyta

Odpowiedzi opublikowane przez XxMichałxX

  1. Setting up the server.

    To create a multiplayer game, one person needs to host the server and the other person needs to connect.

    To set up a server using the dll you first need to create an object which controls the setting up of the server and accepting any new connection. What you will need to do is create a menu that has 2 buttons. The first button says "Host" and the second button should say "Connect". When the user selects host, make it execute this code "global.master = true;" and make the room change to a room called "rmWaiting". Create a new object and call it "objWait". In the create event of this object add this code:

     

    listen = tcplisten(14804, 2, true);

    if(listen <= 0)

    {

    show_message("Failed to listen on port 14804");

    game_end();

    }

     

    Spoko, mam tak:

    GML
    global.port=get_integer('Type port for host new game',23852)

    global.socket=tcplisten(port,30,1)

    if global.socket<=0

    {

    show_message('You can not host new game at port '+string(global.port)+'. Probably the port is not free.')

    exit;

    }

    global.hoster=1

    room_goto(rm_wait)

     

    Accepting new connections.

    To accept new connections you need to create a step event for the "objWait" object we created. In the step event add this code:

     

    client = tcpaccept(listen, true);

    if(client <= 0) exit;

    global.udpsock = udpconnect(14805, true);

    global.otherplayer = client;

    global.otherip = lastip();

    global.otherudpport = 14803;

    room_goto(rmGame);

     

    Tak, to też mam:

    GML
    var new;

    new=tcpaccept(global.socket,1)

    if new<=0 exit;

    global.udpjoiner=udpconnect(global.port,1)

    global.joiner=new

    global.joinerip=lastip()

    global.joinerport=global.port

    room_goto(rm_play)

     

     

    Connecting to the server.

    To join a multiplayer game we need to connect to a server. In the room where you have the button "Host" and the button "Connect", make it so when the player clicks connect it executes this code:

    global.master = false;

    server = tcpConnect("127.0.0.1", 14804, true);

    if(server <= 0)

    {

    show_message("Unable to connect to server");

    game_end();

    exit;

    }

    global.otherplayer = server;

    global.udp = udpconnect(14803, true);

    global.otherip = tcpip(server);

    global.otherudpport = 14805;

    room_goto(rmGame);

     

    Pewnie już się domyśliłeś - owszem to też mam.

    GML
    ip=get_string('Type ip for join to game',ip)

    port=get_integer('Type port for join to game',23852)

    serw=tcpconnect(ip,port,1)

    if serw<=0

    {

    show_message('Can not join to game with ip '+ip+' and port '+string(port)+'!')

    exit;

    }

    global.server=serw

    global.udpserver=udpconnect(port,1)

    global.serverip=tcpip(global.server)

    global.serverport=port

    global.hoster=0

    room_goto(rm_play)

     

     

    Skoro wszystko mam, to czemu gdy podłączam się do gry - joiner przechodzi do rm_play i sobie gra, a w serwerze zostaje: Waiting for joiner... ? :/

     

    edit: kur** co ja gadam! nie to co u góry, tylko jest tak że joiner pisze mi ze nie moze sie podłączyć.

  2. a patrz dobry pomysł

    GML
    if global.socket<=0

    {

    show_message('You can not host new game at port '+string(global.port)+'. Probably the port is not free.')

    exit;

    }

    Na tym sie zatrzymuje..

    edit: usunąłem ten kod i działa.. ale czemu? co w tym jest zle?

  3. GML
    if show_message_ext('Are you going to host new game?','Yes',0,'No')!=1 exit;

    port=get_integer('Type port for host new game',23852)

    global.socket=tcplisten(port,30,1)

    if global.socket<=0

    {

    show_message('You can not host new game at port '+string(global.port)+'. Probably the port is not free.')

    exit;

    }

    global.hoster=1

    room_goto(rm_wait)

     

    Czemu nie przechodzi do rm_wait ? Nie wyświetla mi You can not..

  4. a jest to topdown, platformowka czy co? bo nie wiem. widac na wprost przeciwnika przed sobą od przodu? jak tak to zrób np sprite_rana i takie coś:

    GML
    /*CREATE PRZECIWNIKA:*/

    ilosc_ran=0

    rana=0

    /* DRAW PRZECIWNIKA: */

    draw_sprite(sprite_przeciwnik,-1,x,y)

    if ilosc_ran=0 exit;

    for(i=0; i<ilosc_ran; i+=1)

    {

    draw_sprite(sprite_rana,-1,rana[i,1],rana[i,2])

    }

    /* KOLIZJA POCISKU Z PRZECIWNIKIEM */

    obj_przeciwnik.ilosc_ran+=1

    obj_przeciwnik.rana[obj_przeciwnik.ilosc_ran,1]=x

    obj_przeciwnik.rana[obj_przeciwnik.ilosc_ran,2]=y

     

    Powinno działać, ale są też bardziej zoptymalizowane i łatwiejsze sposoby, teraz mi sie nie chce kombinowac ;p

×
×
  • Dodaj nową pozycję...