[Thảo Luận] Topic thảo luận GameMaker Engine

189111314

Comments

  • bate7a1bate7a1 Posts: 317Registered
    không phải lỗi mà script nó chỉ draw text thoi e cần có cái khung bao quanh text
  • VistrifaVistrifa Posts: 87Registered
    @bate7a1
    Sao mà cứ chạy từa lưa vậy!

    Xem cái này dc ko

    draw_text_special(mouse_x-80,mouse_y-20,"Text",font0,c_black,18,250,1,sp_bap,0,0,0,c_background,Màu viền,Độ dày);

    [php]var list_char;list_char=ds_list_create();
    var list_line;list_line=ds_list_create(); //list members are other lists containing the line's characters
    var list_alignmentapplies;list_alignmentapplies=ds_list_create();
    var list_linewidth;list_linewidth=ds_list_create();
    var i,j,k,m,p,t,z,c,a,changeline;
    var cred,cgreen,cblue;
    var numspaces;
    var forcealign;
    var symbolsize;
    var txtwidth;txtwidth=argument6;
    if argument6=-1 then txtwidth=99999;
    var tspac;tspac=argument5;
    var wordspace;
    var spacewidth;
    var diesiwidth;
    var offx,offy,w,h;

    //draw_rectangle(argument0, argument1,)

    draw_set_font(argument3);
    symbolsize=string_height("0");
    if argument5=-1 then tspac=symbolsize;
    spacewidth=string_width(" ");
    diesiwidth=string_width("\#");
    //insert all chars into the list and transform symbols
    i=0;
    do
    {
    i+=1;
    k=0;
    if string_char_at(argument2,i)="\" then
    {
    //if i<string_length(argument2)-5 then
    //{
    if string_copy(argument2,i,5)="\sym{" then
    {
    i+=5;j=i;do j+=1 until string_char_at(argument2,j)="}";
    ds_list_add(list_char,"sym"+string_copy(argument2,i,j-i));
    i=j;k=1; //special symbol found
    }

    if string_copy(argument2,i,5)="\col{" then
    {
    i+=5;j=i;do j+=1 until string_char_at(argument2,j)="}";
    ds_list_add(list_char,"col"+string_copy(argument2,i,j-i));
    i=j+1;
    j=i;do {ds_list_add(list_char,string_char_at(argument2,j));j+=1} until string_char_at(argument2,j)="/";
    ds_list_add(list_char,"col"+string(color_get_red(argument4))+","+string(color_get_green(argument4))+","+string(color_get_blue(argument4)));
    i=j;k=1; //special symbol found
    }

    if string_copy(argument2,i,2)="\#" then
    {
    i+=1;
    ds_list_add(list_char,"pr#");
    k=1; //special symbol found
    }
    //}
    }
    if k=0 then ds_list_add(list_char,string_char_at(argument2,i));
    }
    until i=string_length(argument2);

    //create lines
    i=-1;
    t=-1; //tracks start of line relative to list_char
    j=0; //text width
    changeline=0; //if line changes then it is set to 1
    do
    {
    i+=1;
    k=ds_list_find_value(list_char,i);
    if string_length(k)=1 then j+=string_width(k) else {if string_copy(k,1,3)="sym" then j+=symbolsize;if string_copy(k,1,3)="pr#" then j+=diesiwidth;}

    if k<>"#" then
    {
    if j>=txtwidth then
    {
    changeline=1;forcealign=argument7;
    i+=1;m=j;do
    {
    i+=-1;
    z=ds_list_find_value(list_char,i);
    if string_length(z)=1 then m+=-string_width(z) else {if string_copy(k,1,3)="sym" then m+=-symbolsize;if string_copy(k,1,3)="pr#" then m+=-diesiwidth;}
    }
    until ds_list_find_value(list_char,i)=" ";
    ds_list_add(list_linewidth,m);
    }
    }
    else
    {
    changeline=1;forcealign=false;ds_list_add(list_linewidth,j);
    }

    if changeline=1 then //line change
    {
    j=0; //text width resets to 0
    changeline=0; //line change resets to 0
    p=ds_list_create();
    ds_list_add(list_line,p);
    ds_list_add(list_alignmentapplies,forcealign);
    repeat i-t
    {
    t+=1;
    ds_list_add(p,ds_list_find_value(list_char,t));
    }
    }
    }
    until i=ds_list_size(list_char)-1;

    //add last line
    p=ds_list_create();
    ds_list_add(list_line,p);
    ds_list_add(list_alignmentapplies,false);
    repeat i-t+1
    {
    t+=1;
    ds_list_add(p,ds_list_find_value(list_char,t));
    }
    ds_list_add(list_linewidth,j);

    switch argument9
    {
    case 0: //draw text normally
    {

    break;
    }

    case 1: //return width
    {
    ds_list_sort(list_linewidth,0);
    j=ds_list_find_value(list_linewidth,0);

    ds_list_destroy(list_char);
    i=-1;
    repeat ds_list_size(list_line)
    {
    i+=1;
    ds_list_destroy((ds_list_find_value(list_line,i)));
    }
    ds_list_destroy(list_line);
    ds_list_destroy(list_alignmentapplies);
    ds_list_destroy(list_linewidth);
    return j;
    break;
    }

    case 2: //return height
    {
    j=ds_list_size(list_line)*tspac;

    ds_list_destroy(list_char);
    i=-1;
    repeat ds_list_size(list_line)
    {
    i+=1;
    ds_list_destroy((ds_list_find_value(list_line,i)));
    }
    ds_list_destroy(list_line);
    ds_list_destroy(list_alignmentapplies);
    ds_list_destroy(list_linewidth);
    return j;
    break;
    }
    }
    ds_list_sort(list_linewidth,0);
    w=ds_list_find_value(list_linewidth,0);
    h=ds_list_size(list_line)*tspac;
    draw_set_color(argument12);
    draw_rectangle(argument0-8, argument1-8,mouse_x-80+w+8,mouse_y-20+h+8, false);
    draw_set_color(argument13);
    for (ii=0;ii<argument14;ii+=1) {
    draw_rectangle(argument0-8-ii, argument1-8-ii,mouse_x-80+w+8+ii,mouse_y-20+h+8+ii, true);
    };
    //draw text
    draw_set_color(argument4);
    i=-1;
    repeat ds_list_size(list_line)
    {
    i+=1;
    j=-1;
    k=0;
    a=0; //because wordspace=floor((txtwidth-c)/numspaces),due to the floor() some space will be lost. 'a' stores that extra space.
    p=ds_list_find_value(list_line,i);
    wordspace=spacewidth;
    switch argument10
    {
    case 0:{offx=0;break;}
    case 1:{offx=-round(ds_list_find_value(list_linewidth,i)/2);break;}
    case 2:{offx=-ds_list_find_value(list_linewidth,i);break;}
    }

    switch argument11
    {
    case 0:{offy=0;break;}
    case 1:{offy=-round(0.5*ds_list_size(list_line)*tspac);break;}
    case 2:{offy=-ds_list_size(list_line)*tspac;break;}
    }

    if argument7=1 then //find number of spaces in line
    {
    if ds_list_size(list_line)>1 then
    {
    if ds_list_find_value(list_alignmentapplies,i)=true then
    {
    numspaces=0;t=-1;c=0;
    repeat ds_list_size(p)-1
    {
    t+=1;
    m=ds_list_find_value(p,t);
    if string_length(m)=1 then {if m<>" " then c+=string_width(m) else numspaces+=1;} else {if string_copy(m,1,3)="sym" then c+=symbolsize;if string_copy(m,1,3)="pr#" then c+=diesiwidth;}
    }
    if numspaces>0 then
    {
    wordspace=floor((txtwidth-c)/numspaces);
    a=txtwidth-c-numspaces*wordspace;
    }
    }
    }
    switch argument10
    {
    case 0:{offx=0;break;}
    case 1:{offx=-round((argument6)/2);break;}
    case 2:{offx=-argument6;break;}
    }
    }

    repeat ds_list_size(p)
    {
    j+=1;
    m=ds_list_find_value(p,j);
    if string_length(m)=1 then
    {
    draw_text(argument0+k+offx,argument1+offy+tspac*i,m);
    if m=" " then {k+=wordspace;if a>0 then {a+=-1;k+=1;}} else k+=string_width(m);
    }
    else
    {
    if string_copy(m,1,3)="col" then
    {
    t=3;z=3;do z+=1 until string_char_at(m,z)=",";cred=string_copy(m,t+1,z-t-1);z+=1;t=z;
    do z+=1 until string_char_at(m,z)=",";cgreen=string_copy(m,t,z-t);t=z;
    cblue=string_copy(m,t+1,string_length(m)-z);
    draw_set_color(make_color_rgb(real(cred),real(cgreen),real(cblue)));
    }

    if string_copy(m,1,3)="sym" then
    {
    draw_sprite_ext(argument8,real(string_digits(m)),argument0+k+offx+symbolsize/2,argument1+offy+tspac*i+(symbolsize/2),symbolsize/sprite_get_width(argument8),symbolsize/sprite_get_width(argument8),0,c_white,1);
    k+=symbolsize;
    }

    if string_copy(m,1,3)="pr#" then
    {
    draw_text(argument0+k+offx,argument1+offy+tspac*i,"\#");
    k+=diesiwidth;
    }
    }
    }
    }

    ds_list_destroy(list_char);
    i=-1;
    repeat ds_list_size(list_line)
    {
    i+=1;
    ds_list_destroy((ds_list_find_value(list_line,i)));
    }
    ds_list_destroy(list_line);
    ds_list_destroy(list_alignmentapplies);
    ds_list_destroy(list_linewidth); [/php]
  • Focker_cFocker_c Posts: 1,577Registered
    Cái của Vistrifa là draw_text có outline.
    Còn chắc bạn @bate7a1 đang muốn vẽ cái khung vuông bọc dòng chữ đúng ko ?

    Cơ bản thì draw 1 hình chữ nhật có chiều rộng là string_length(text) , chiều dài là string_height(text).
    Trong đó, text là đoạn chữ
    Còn vụ xuống dòng thì bạn hãy tùy cơ ứng biến theo.

    Chúc thành công :D
  • bate7a1bate7a1 Posts: 317Registered
    anh ơi,có thể giúp em làm 1 cái kho không,nó có nhiều trang,có thể qua trang khác nếu đày kho
    vd:cái kho nó ntn nek`
    vật phẩm 1 ở vị trí 1
    vật phẩm 2 ở vị trí 2
    nếu
    vật phẩm 1 hết
    thì vật phẩm 2 ở vị trí 1
  • bate7a1bate7a1 Posts: 317Registered
    ai giúp cái
  • MeoDenLuoiMeoDenLuoi Posts: 1,425Registered
    focker dạo này vắng chẳng thấy đâu nên để @Vistrifa 1 mình cân tất luôn :3
  • Focker_cFocker_c Posts: 1,577Registered
    Đây đây, dạo này đang "bị" thi :D
    anh ơi

    Ơi :D !
    có thể giúp em làm 1 cái kho không,nó có nhiều trang,có thể qua trang khác nếu đày kho

    Kho à ? hmm..
    vd:cái kho nó ntn nek`
    vật phẩm 1 ở vị trí 1
    vật phẩm 2 ở vị trí 2
    nếu
    vật phẩm 1 hết
    thì vật phẩm 2 ở vị trí 1

    Ok, so... bạn xài biến array để làm inventory đúng ko ?
    kiểu như
    slot[1,1] = ID của item tại slot này
    slot[1,2] = hình ảnh tương ứng theo ID
    slot[1,3] = số lượng

    Và vì vậy, ta check xem tất cả các ô có còn ô nào trống ko. Nếu ko thì chuyển qua trang 2.

    [php]for (n=1; n<=10; n+=1) // trang inventory này có 10 slot chẳng hạn.
    {
    if slot[n,1] = 0
    {
    n = 11; // để kết thúc cái chuỗi này vì đã tìm ra slot trống.
    //thêm các câu lệnh thêm item gì đó ở đây
    }
    else // đến đây thì tức là ô này ko còn trống
    if n = 10 // mà nếu ô này là ô cuối cùng thì ...
    {
    // qua trang 2
    }
    }[/php]

    Chúc bạn thành công nhé :D !
  • bate7a1bate7a1 Posts: 317Registered
    em làm được phần trên rồi,còn phần qua trang pó tay,làm sao để trang 1 đầy thì vp wa trang 2,tj nữa trang 1 lại trống thì vp trang 2 qua trang 1 vậy anh
  • David ChaseDavid Chase Posts: 1,766Registered
    nhìn script nhìn đọc chẳng hiểu cái đếch gì cả
    há há
  • Focker_cFocker_c Posts: 1,577Registered
    làm sao để trang 1 đầy thì vp wa trang 2,tj nữa trang 1 lại trống thì vp trang 2 qua trang 1 vậy anh
    Ý tưởng hay đấy :) , nhưng làm cũng ko hề dễ đâu :)
    Nhưng vẫn muốn "làm tới" thì đi theo hướng như thế này nhé :

    Trang 1 có 10 slot chẳng hạn thì trang 2 thực ra là các slot thứ 11, 12, 13, ... trở đi.
    Đó giải thích cho "trang 2"

    Còn vấn đề mà item biết tự đùn lên ô trước nếu ô đằng trước đang trống ( mà trang 2 thực ra là các slot 11 trở đi, cho nên cũng sẽ đùn về trang 1 nếu trang 1 trống) thì phương hướng thế này :

    Chắc chắn rằng sẽ ko có các ô trống đan xen giữa các ô đã có item.
    Lại thực hiện lệnh đếm for để tìm ra ô còn trống ,
    ví dụ ô trống đó là n, thì kiểm ô phía sau (ô n+1 đấy) có item ko .
    Nếu ô đó có item thì chuyển nó lấp đầy ô n .
    Kiểu như sau:

    [php]for (n=1; n<=10; n+=1)
    {
    if slot[n,1] = 0 // tìm ra ô trống
    {
    // đến đây thì ô trống là ô số "n"
    if slot[n+1,1] <> 0 // kiểm tra xem ô ngay phía sau có trống ko.
    {
    // Nếu không trống và có item thì :
    // Viết các câu lệnh chuyển item từ ô "n" sang ô "n+1" , tức là ô ngay phía sau.
    // Việc này sẽ giúp các item lấp đầy các ô trống phía trước và như vậy chúng sẽ đùn lại gần nhau về phía trước.
    }
    }
    } [/php]

    Nói chung là sẽ ko dễ dàng nếu bạn chưa cứng về phần script :)
    Nhưng mình khuyến cáo là bạn nên tiếp tục, kể cả ko đi đến đâu thì cũng thêm hiểu biết ^^
    Chúc bạn thành công ! :D
  • StupidDonutStupidDonut Posts: 1,196Registered
    Nói chung cũng ko dễ vs bác bate7a1 và nói riêng thì em chả hiểu con khỉ gì cả :D
  • bate7a1bate7a1 Posts: 317Registered
    làm được oy` :)
    thành quả
    if argument0>=1
    {for (n=1; n<=argument1; n+=1)
    {
    if global.slot[n,1] = 0 or  global.slot[n,1] >argument1 
        {
        global.slot[n,1]=argument1
        for (i=n+1; n<=argument1-1; n+=1)
        {if global.slot[i,1]=argument1
        global.slot[i,1]=0
        }
        n = 100;  
         }
    else
    {if global.slot[n,1] =argument1
    n = 100;}
    }}
    else
    for (n=1; n<=argument1; n+=1)
    {
    if global.slot[n,1] = argument1
    {global.slot[n,1]=0
    n = 100;}
    } 
    for (n=1; n<=argument1; n+=1)
    {if n<=8
    {if global.slot[n,1]=argument1
    {
    x=64-global.trang+80*(n-1)
    y=488;
    n = 100;}
    }
    else
    {if n<=16
    if global.slot[n,1]=argument1
    {x=1064-global.trang+80*(n-9)
    y=488
    n = 100;}
    else
    {
    if global.slot[n,1]=argument1
    {x=2064-global.trang+80*(n-17)
    y=488
    n = 100;}
    }}}
    
  • Focker_cFocker_c Posts: 1,577Registered
    Chúc mừng chú @bate7a1 :)
    Dạo này a hơi bị bận, có post request ở đây thì lên facebook p.m cho a một tiếng :D
  • dsiver144dsiver144 Posts: 1,064Registered
    @! pác bate7a1 giỏi khoản script ghê :)
Sign In or Register to comment.