Go to page 1, 2  Next  [ 24 posts ]  Reply to topicPost new topic 
Author Message
 [at]
 Post subject: DJ Coco's GML Scripts
PostPosted: Thu Dec 12, 2013 5:35 pm 
Cliax Codec X Splatoon
Member
[*]
[*]
[*]
[*]
[*]

[*]
[*]
[*]
[*]
[*]

[*]
[*]
[*]
[*]
[*]

[*]
[*]
Have some scripts.

draw_text_alt(x, y, string, col, shadow, outline, outlinecol)
More drawing options for text
Syntax: [ Download ] [ Hide ]
Using gml Syntax Highlighting
///draw_text_alt(x, y, string, col, shadow, outline, outlinecol)
//argument x: x coordinate, real
//argument y: y coordinate, real
//argument string: text to be drawn, string
//argument col: color to draw the text in, real
//argument shadow: amount of pixels for shadow, -1 for none, real
//argument outline: thickness of the outline, -1 for none, real
//argument outlinecol: color of the outline, real
//Returns: nothing

var tcol = draw_get_color(), i;
if (argument4 != -1) {
    draw_set_color(c_black);
    i = max(0, argument5);
    var tval = argument4 + i;
    while (i != tval) {
        i++;
        draw_text(argument0 + i, argument1 + i, argument2);
    }
}
   
if (argument5 != -1) {
    draw_set_color(argument6);
    for (i = -argument5; i <= argument5; i++) {
        for (var j = -argument5; j <= argument5; j++) {
            draw_text(argument0 + i, argument1 + j, argument2);
        }
    }
}
draw_set_color(argument3);
draw_text(argument0, argument1, argument2);
draw_set_color(tcol);


instance_find_top(instance)
Finds the topmost instance of what you are checking for at your position, perfect for use in 3D.
Syntax: [ Download ] [ Hide ]
Using gml Syntax Highlighting
///instance_find_top(instance)

//argument instance: id of the instance, real
//Returns: topmost instance of all instances below the object the check is performed from

var t, zlist = ds_list_create(), idlist = ds_list_create();
ds_list_add(zlist, -1);
ds_list_add(idlist, -1);
while (place_meeting(x, y, argument0)) {
    t = instance_place(x, y, argument0);
    with (t) {
        ds_list_add(zlist, z);
        ds_list_add(idlist, id);
        x += room_width;
    }
}
for (var i = 1; i < ds_list_size(idlist); i++) {
    with (ds_list_find_value(idlist, i)) {x -= room_width;}
}
var tgrid = ds_grid_create(2, ds_list_size(idlist));
for (i = 0; i < ds_list_size(zlist); i++) {
    ds_grid_set(tgrid, 0, i, ds_list_find_value(zlist, i));
    ds_grid_set(tgrid, 1, i, ds_list_find_value(idlist, i));
}
ds_grid_sort(tgrid, 0, 0);
t = ds_grid_get(tgrid, 1, 0);
ds_list_destroy(zlist);
ds_list_destroy(idlist);
ds_grid_destroy(tgrid);

return t;

_________________
Image

Cliax Codec is a combination of top-down and third-person shooter. The gameplay will blend platforming, puzzle and shmup elements together to create a unique gameplay experience. You will take control of four playable characters which rise against a team that seemingly wants to take over the world - but are their motives really that cliché, or are there deeper motives behind their actions?

Currently designing Chapter 1-6, 5%

GOTM titles
Spoiler:
Fan Art
Spoiler:
 
Top
Offline 
 User page at mfgg.net
 
 [us]
 Post subject: Re: DJane Coco's GML Scripts
PostPosted: Thu Dec 12, 2013 7:42 pm 
User avatar
Member
[*]
[*]
[*]
[*]
[*]

[*]
[*]
[*]
[*]
I think you should state what version of Game Maker you're using, so people won't slap it into Game Maker 8.1 and under and be greeted by an error. Comments would also be nice? I tried the first script and the outline part was interesting, but the shadow didn't look so nice. Being able to manipulate the text's size would have been nice.

 
Top
Offline 
 
 
 [us]
 Post subject: Re: DJane Coco's GML Scripts
PostPosted: Thu Dec 12, 2013 8:08 pm 
User avatar
もう帰らない
Member
[*]
[*]
[*]
[*]
You should also attach a license to them.

These scripts are fairly short, but they're also pretty heavily condensed. I suspect they are non-trivial enough to be copyrighted, which would mean that no one reliably has the right to use them without a license. Probably you would want to use a simple permissive license like the Expat License,[1] or even release them to the public domain with CC0,[2] since using a copyleft or otherwise complicated license would be overkill for something so small.

[1] http://directory.fsf.org/wiki/License:Expat
[2] http://wiki.creativecommons.org/CC0_FAQ ... ntation.3F

_________________
https://onpon4.github.io
 
Top
Offline 
 
 
 [gb]
 Post subject: Re: DJane Coco's GML Scripts
PostPosted: Thu Dec 12, 2013 10:21 pm 
I never really was on your side.
Member
[*]
[*]
[*]
[*]
[*]

[*]
[*]
[*]
[*]
This should be a topic for anyone to put in some nifty, snazzy, fancy pantsy codes.

 
Top
Offline 
 User page at mfgg.net
 
 [at]
 Post subject: Re: DJane Coco's GML Scripts
PostPosted: Fri Dec 13, 2013 12:56 pm 
Cliax Codec X Splatoon
Member
[*]
[*]
[*]
[*]
[*]

[*]
[*]
[*]
[*]
[*]

[*]
[*]
[*]
[*]
[*]

[*]
[*]
Sorry, should have stated I'm using GM:Studio. I don't think it's possible to manipulate text size ingame unless you create another font.

_________________
Image

Cliax Codec is a combination of top-down and third-person shooter. The gameplay will blend platforming, puzzle and shmup elements together to create a unique gameplay experience. You will take control of four playable characters which rise against a team that seemingly wants to take over the world - but are their motives really that cliché, or are there deeper motives behind their actions?

Currently designing Chapter 1-6, 5%

GOTM titles
Spoiler:
Fan Art
Spoiler:
 
Top
Offline 
 User page at mfgg.net
 
 [us]
 Post subject: Re: DJane Coco's GML Scripts
PostPosted: Fri Dec 13, 2013 1:36 pm 
User avatar
もう帰らない
Member
[*]
[*]
[*]
[*]
The way GM8 did fonts was it stored a big texture of all the characters pre-rendered. I'm sure it's still done this way, not because YYG is incompetent, but because it's using Windows system fonts and YYG knows the consequences of this. You can't depend on everyone to have those fonts, and font files (which are programs) are copyrighted. There's no reliable way to find out what kind of license they're under automatically, and many font programs on Windows are proprietary, so distributing them with the game would be illegal in many, if not most or all cases. However, font faces cannot be copyrighted (this has been established for more than two centuries), so if they pre-render it and distribute only image files, that's legal.

The downside to this, though, is that the image files are only simple raster graphics and can't be properly scaled the way fonts are normally scaled. Game Maker could theoretically resize them the same way it resizes sprites, but that would be rather ugly in most cases.

_________________
https://onpon4.github.io
 
Top
Offline 
 
 
 [at]
 Post subject: Re: DJane Coco's GML Scripts
PostPosted: Wed Jan 08, 2014 4:06 pm 
Cliax Codec X Splatoon
Member
[*]
[*]
[*]
[*]
[*]

[*]
[*]
[*]
[*]
[*]

[*]
[*]
[*]
[*]
[*]

[*]
[*]
string_add_zeros(string, digits)
Gives strings a fixed amount of digits. All missing digits will be zeros added at the front. Perfect for displaying scores.
Syntax: [ Download ] [ Hide ]
Using gml Syntax Highlighting
///string_add_zeros(string, digits)
//argument string: real to modify to a string, real
//argument digits: amount of digits you want to have in your string, real
//Returns: the edited string

return string_replace_all(string_format(argument0, argument1, 0), " ", "0");

_________________
Image

Cliax Codec is a combination of top-down and third-person shooter. The gameplay will blend platforming, puzzle and shmup elements together to create a unique gameplay experience. You will take control of four playable characters which rise against a team that seemingly wants to take over the world - but are their motives really that cliché, or are there deeper motives behind their actions?

Currently designing Chapter 1-6, 5%

GOTM titles
Spoiler:
Fan Art
Spoiler:
 
Top
Offline 
 User page at mfgg.net
 
 [at]
 Post subject: Re: DJane Coco's GML Scripts
PostPosted: Sat Jan 11, 2014 3:50 pm 
Cliax Codec X Splatoon
Member
[*]
[*]
[*]
[*]
[*]

[*]
[*]
[*]
[*]
[*]

[*]
[*]
[*]
[*]
[*]

[*]
[*]
Fixed some wrong information in my latest script: argument string has got to be real, it will only be returned as a string.

_________________
Image

Cliax Codec is a combination of top-down and third-person shooter. The gameplay will blend platforming, puzzle and shmup elements together to create a unique gameplay experience. You will take control of four playable characters which rise against a team that seemingly wants to take over the world - but are their motives really that cliché, or are there deeper motives behind their actions?

Currently designing Chapter 1-6, 5%

GOTM titles
Spoiler:
Fan Art
Spoiler:
 
Top
Offline 
 User page at mfgg.net
 
 [at]
 Post subject: Re: DJane Coco's GML Scripts
PostPosted: Thu Jan 16, 2014 12:36 pm 
Cliax Codec X Splatoon
Member
[*]
[*]
[*]
[*]
[*]

[*]
[*]
[*]
[*]
[*]

[*]
[*]
[*]
[*]
[*]

[*]
[*]
d3d_floor_create_from_tile(x, y, w, h, tilelayer)
Returns a flat floor where you can use a specific tileset as its texture. If a tile from that tileset is found at the location you check from, the texture will be shown as that tile.
Syntax: [ Download ] [ Hide ]
Using gml Syntax Highlighting
///d3d_floor_create_from_tile(x, y, w, h, tilelayer)
//Argument x: x coordinate to check from
//Argument y: y coordinate to check from
//Argument w: width of the tile
//Argument h: height of the tile
//Argument tilelayer: tile layer you check on
//Returns: 3D Model as flat floor (use the tileset as its texture), -4 when no tile is found

var tile = tile_layer_find(argument4, argument0, argument1);
if (tile) {
    var xx, yy, bg, hsize, vsize;
    xx = tile_get_left(tile);
    yy = tile_get_top(tile);
    bg = tile_get_background(tile);
    hsize = background_get_width(bg);
    vsize = background_get_height(bg);

    var model = d3d_model_create();
    d3d_model_primitive_begin(model, pr_trianglelist);

    d3d_model_vertex_normal_texture(model, x, y, z, 0, 0, 1, xx / hsize, yy / vsize);
    d3d_model_vertex_normal_texture(model, x + argument2, y, z, 0, 0, 1, (xx + argument2) / hsize, yy / vsize);
    d3d_model_vertex_normal_texture(model, x, y + argument3, z, 0, 0, 1, xx / hsize, (yy + argument3) / vsize);

    d3d_model_vertex_normal_texture(model, x + argument2, y, z, 0, 0, 1, (xx + argument2) / hsize, yy / vsize);
    d3d_model_vertex_normal_texture(model, x, y + argument3, z, 0, 0, 1, xx / hsize, (yy + argument3) / vsize);
    d3d_model_vertex_normal_texture(model, x + argument2, y + argument3, z, 0, 0, 1, (xx + argument2) / hsize, (yy + argument3) / vsize);

    d3d_model_primitive_end(model);

    return model;
}
return -4;


If you have trouble knowing which tileset you use, check with tile_get_background, like it was done in the script.
EDIT: When you draw the model, it is crucial you draw it at 0, 0, 0 and not x, y, z! Also, the script requires that the z variable has been initialized.

_________________
Image

Cliax Codec is a combination of top-down and third-person shooter. The gameplay will blend platforming, puzzle and shmup elements together to create a unique gameplay experience. You will take control of four playable characters which rise against a team that seemingly wants to take over the world - but are their motives really that cliché, or are there deeper motives behind their actions?

Currently designing Chapter 1-6, 5%

GOTM titles
Spoiler:
Fan Art
Spoiler:
 
Top
Offline 
 User page at mfgg.net
 
 [es]
 Post subject: Re: DJane Coco's GML Scripts
PostPosted: Mon Jan 20, 2014 4:37 am 
User avatar
I'm just a little adorable kitty :3
Member
[*]
[*]
[*]
[*]
[*]

[*]
[*]
[*]
[*]
[*]

Do you mind if I add these scripts on this topic?

_________________
Image ImageImageImageImageImageImage Image
~ Supernova / Drawerkirby (2) / Gato / Neweegee (2) (3) ~
"shy guys are wall plugs confirmed" - Vitiman on Club Saturn Ex
Image
 
Top
Offline 
 User page at mfgg.net
 
 [at]
 Post subject: Re: DJane Coco's GML Scripts
PostPosted: Mon Jan 20, 2014 5:56 am 
Cliax Codec X Splatoon
Member
[*]
[*]
[*]
[*]
[*]

[*]
[*]
[*]
[*]
[*]

[*]
[*]
[*]
[*]
[*]

[*]
[*]
You're free to do with them whatever you want.

_________________
Image

Cliax Codec is a combination of top-down and third-person shooter. The gameplay will blend platforming, puzzle and shmup elements together to create a unique gameplay experience. You will take control of four playable characters which rise against a team that seemingly wants to take over the world - but are their motives really that cliché, or are there deeper motives behind their actions?

Currently designing Chapter 1-6, 5%

GOTM titles
Spoiler:
Fan Art
Spoiler:
 
Top
Offline 
 User page at mfgg.net
 
 [at]
 Post subject: Re: DJane Coco's GML Scripts
PostPosted: Sun Apr 20, 2014 9:30 pm 
Cliax Codec X Splatoon
Member
[*]
[*]
[*]
[*]
[*]

[*]
[*]
[*]
[*]
[*]

[*]
[*]
[*]
[*]
[*]

[*]
[*]
d3d_draw_cylinder_hexagon(radius, z, height, col)
Returns nothing, use in draw event. Pretty useless script, but in case you ever need a hexagonal switch or something, here you go.

Syntax: [ Download ] [ Hide ]
Using gml Syntax Highlighting
///d3d_draw_cylinder_hexagon(radius, z, height, col)

var len = argument0, z = argument1, height = argument2, col = argument3, tcol = draw_get_color();

draw_set_color(c_black);

d3d_primitive_begin(pr_linestrip);
for (var i = 0; i < 7; i++) {
    d3d_vertex(x + lengthdir_x(len, i * 60), y + lengthdir_y(len, i * 60), z + height);
}
d3d_primitive_end();

for (var i = 0; i < 7; i++) {
    d3d_primitive_begin(pr_linestrip);
    d3d_vertex(x + lengthdir_x(len, i * 60), y + lengthdir_y(len, i * 60), z + height);
    d3d_vertex(x + lengthdir_x(len, i * 60), y + lengthdir_y(len, i * 60), z);
    d3d_primitive_end();
}

draw_set_color(col);

d3d_primitive_begin(pr_trianglefan);
for (var i = 0; i < 7; i++) {
    d3d_vertex(x + lengthdir_x(len, i * 60), y + lengthdir_y(len, i * 60), z + height);
}
d3d_primitive_end();

d3d_primitive_begin(pr_trianglefan);
for (var i = 0; i < 7; i++) {
    d3d_vertex(x + lengthdir_x(len, i * 60), y + lengthdir_y(len, i * 60), z + height);
    d3d_vertex(x + lengthdir_x(len, i * 60), y + lengthdir_y(len, i * 60), z);
    d3d_vertex(x + lengthdir_x(len, (i + 1) * 60), y + lengthdir_y(len, (i + 1) * 60), z);
}
d3d_primitive_end();

draw_set_color(tcol);

_________________
Image

Cliax Codec is a combination of top-down and third-person shooter. The gameplay will blend platforming, puzzle and shmup elements together to create a unique gameplay experience. You will take control of four playable characters which rise against a team that seemingly wants to take over the world - but are their motives really that cliché, or are there deeper motives behind their actions?

Currently designing Chapter 1-6, 5%

GOTM titles
Spoiler:
Fan Art
Spoiler:
 
Top
Offline 
 User page at mfgg.net
 
 [at]
 Post subject: Re: DJane Coco's GML Scripts
PostPosted: Fri Jan 30, 2015 9:03 am 
Cliax Codec X Splatoon
Member
[*]
[*]
[*]
[*]
[*]

[*]
[*]
[*]
[*]
[*]

[*]
[*]
[*]
[*]
[*]

[*]
[*]
draw_line_dotted_width(x1,y1,x2,y2,w)
You can easily rewrite it to have a version without the width parameter. Anyway, I think it's pretty useful. Maybe I should have made the 0.05 a parameter instead of a hardcoded value, but you should be able to edit that yourself in case you need it.
Syntax: [ Download ] [ Hide ]
Using gml Syntax Highlighting
///draw_line_dotted_width(x1,y1,x2,y2,w)

var x1 = argument0, y1 = argument1, x2 = argument2, y2 = argument3, w = argument4;
var dist = point_distance(x1, y1, x2, y2) * 0.05; //Random factor to scale it to an appropriate length

for (var i = 0; i < dist; i++) {
    xx[i] = x1 + (x2 - x1) * (i / dist);
    yy[i] = y1 + (y2 - y1) * (i / dist);
}

for (var i = 0; i < dist - 1; i += 2) {
    draw_line_width(xx[i], yy[i], xx[i+1], yy[i+1], w);
}

_________________
Image

Cliax Codec is a combination of top-down and third-person shooter. The gameplay will blend platforming, puzzle and shmup elements together to create a unique gameplay experience. You will take control of four playable characters which rise against a team that seemingly wants to take over the world - but are their motives really that cliché, or are there deeper motives behind their actions?

Currently designing Chapter 1-6, 5%

GOTM titles
Spoiler:
Fan Art
Spoiler:
 
Top
Offline 
 User page at mfgg.net
 
 [tr]
 Post subject: Re: DJane Coco's GML Scripts
PostPosted: Fri Jan 30, 2015 9:57 am 
User avatar
Thanks DonnieTheGuy!
Administrator
[A]
[*]
[*]
[*]
[*]

[*]
[*]
[*]
[*]
[*]

[*]
[*]
[*]
[*]
[*]

[*]
[*]
[*]
[*]
[*]

[*]
This code is really useful.

_________________
Image
 
Top
Offline 
 
 
 [at]
 Post subject: Re: DJane Coco's GML Scripts
PostPosted: Thu Jun 30, 2016 1:39 pm 
Cliax Codec X Splatoon
Member
[*]
[*]
[*]
[*]
[*]

[*]
[*]
[*]
[*]
[*]

[*]
[*]
[*]
[*]
[*]

[*]
[*]
Haven't posted here in ages. Bleh, I didn't miss GML at all. I keep trying to do C#-y things in Game Maker.
Anywho, here's a new code snippet I came up with which can be useful for platformers. It lets you basically have an object jump so it lands exactly on a desired spot - all you need to pass to the function is the jumping object's origin, the impact point and the desired yspeed and gravity. You get the xspeed back which is the only missing variable needed. It's useful for having enemies fire projectiles at the player in an arc, for instance, or having a boss enemy jump towards a specific position in his pattern.

***This code wasn't thoroughly tested. If you encounter bugs with it, please report, and I'll fix them***

arc_calc_xspeed(yspeed, gravity, spawn_x, spawn_y, impact_x, impact_y)

Syntax: [ Download ] [ Hide ]
Using gml Syntax Highlighting
///arc_calc_xspeed(yspeed, gravity, spawn_x, spawn_y, impact_x, impact_y)
var t_yspeed = argument0, t_grav = argument1, t_spawn_x = argument2, t_spawn_y = argument3, t_impact_x = argument4, t_impact_y = argument5;

var t_y = t_spawn_y, t_yprev = t_y, time = 0;
do {
    time++;
    t_yprev = t_y;
    t_y += t_yspeed;
    t_yspeed += t_grav;
}
until (t_y >= t_impact_y && t_yprev < t_impact_y) || (t_yspeed > 0 && t_y > t_impact_y);

return (t_impact_x - t_spawn_x) / time;

_________________
Image

Cliax Codec is a combination of top-down and third-person shooter. The gameplay will blend platforming, puzzle and shmup elements together to create a unique gameplay experience. You will take control of four playable characters which rise against a team that seemingly wants to take over the world - but are their motives really that cliché, or are there deeper motives behind their actions?

Currently designing Chapter 1-6, 5%

GOTM titles
Spoiler:
Fan Art
Spoiler:
 
Top
Offline 
 User page at mfgg.net
 
 [us]
 Post subject: Re: DJ Coco's GML Scripts
PostPosted: Mon Jul 18, 2016 12:48 pm 
User avatar
C# Programmer
Member
[*]
[*]
[*]
[*]
You could instead just solve for the total time and xspeed:

http://stackoverflow.com/questions/1670 ... trajectory

The above gives you the equations for determining the total time and initial yspeed, given the initial xspeed and x distance.

_________________
MFGG TKO (scrapped) - Animations
Image
"It feels that time is better spent on original creations" - Konjak
Focus on the performance, the idea, not the technical bits or details - Milt Kahl
 
Top
Offline 
 
 
 [at]
 Post subject: Re: DJ Coco's GML Scripts
PostPosted: Tue Sep 13, 2016 6:52 am 
Cliax Codec X Splatoon
Member
[*]
[*]
[*]
[*]
[*]

[*]
[*]
[*]
[*]
[*]

[*]
[*]
[*]
[*]
[*]

[*]
[*]
collision_raycast(x1, y1, x2, y2, obj, prec, notme, [max_dist])
I have no idea why this isn't a built-in function in GM.
Anywho, this function casts a ray and returns the instance the ray collides with. It also outputs the impact position in two variables, titled "raycast_hit_x" and "raycast_hit_y"

Function could probably be nicer, but eh, I wrote it in 5 minutes and it gets the job done. I assume it's rather slow though, so use collision_line instead if you can.

EDIT: Made it nicer.

Syntax: [ Download ] [ Hide ]
Using gml Syntax Highlighting
///collision_raycast(x1, y1, x2, y2, obj, prec, notme, [max_dist])

//x1, real: X-position of the ray origin
//y1, real: Y-position of the ray origin
//x2, real: X-position of where to aim the ray at
//y2, real: Y-position of where to aim the ray at
//obj, real: The object index to check for
//prec, real: Whether to check using precise collisions
//notme, real: Whether to ignore self
//max_dist, real: Maximum distance the ray can reach (optional parameter)

//Returns id of collision hit ("noone" if no collision)
//Saves impact coordinates in "raycast_hit_x" and "raycast_hit_y" (saves "noone" if no collision)

raycast_hit_x = noone;
raycast_hit_y = noone;

var x1, y1, x2, y2, obj, prec, notme, max_dist, tdir, tdist, ret_val;
x1 = argument[0];
y1 = argument[1];
x2 = argument[2];
y2 = argument[3];
obj = argument[4];
prec = argument[5];
notme = argument[6];
tdir = point_direction(x1, y1, x2, y2);
tdist = point_distance(x1, y1, x2, y2);
ret_val = noone;

max_dist = tdist;
if (argument_count > 7) {
    max_dist = argument[7];
    if (max_dist > tdist) {max_dist = tdist;}
}

var xx, yy, xx_add, yy_add;
xx = x1;
yy = y1;
xx_add = lengthdir_x(1, tdir);
yy_add = lengthdir_y(1, tdir);
for (var i = 0; i < max_dist; i++) {
    var col = collision_point(xx, yy, obj, prec, notme);
    if (col) {
        ret_val = col;
        other.raycast_hit_x = xx;
        other.raycast_hit_y = yy;
        break;
    }
    xx += xx_add;
    yy += yy_add;
}

return ret_val;

_________________
Image

Cliax Codec is a combination of top-down and third-person shooter. The gameplay will blend platforming, puzzle and shmup elements together to create a unique gameplay experience. You will take control of four playable characters which rise against a team that seemingly wants to take over the world - but are their motives really that cliché, or are there deeper motives behind their actions?

Currently designing Chapter 1-6, 5%

GOTM titles
Spoiler:
Fan Art
Spoiler:
 
Top
Offline 
 User page at mfgg.net
 
 [us]
 Post subject: Re: DJ Coco's GML Scripts
PostPosted: Tue Sep 13, 2016 9:24 am 
Always have Jason Voorhees in your sig
Member
[*]
[*]
[*]
[*]
[*]

DJ Coco wrote:
draw_line_dotted_width(x1,y1,x2,y2,w)
You can easily rewrite it to have a version without the width parameter. Anyway, I think it's pretty useful. Maybe I should have made the 0.05 a parameter instead of a hardcoded value, but you should be able to edit that yourself in case you need it.
Syntax: [ Download ] [ Hide ]
Using gml Syntax Highlighting
///draw_line_dotted_width(x1,y1,x2,y2,w)

var x1 = argument0, y1 = argument1, x2 = argument2, y2 = argument3, w = argument4;
var dist = point_distance(x1, y1, x2, y2) * 0.05; //Random factor to scale it to an appropriate length

for (var i = 0; i < dist; i++) {
    xx[i] = x1 + (x2 - x1) * (i / dist);
    yy[i] = y1 + (y2 - y1) * (i / dist);
}

for (var i = 0; i < dist - 1; i += 2) {
    draw_line_width(xx[i], yy[i], xx[i+1], yy[i+1], w);
}

About the parameters: is it possible in GML to have default parameter values? like:

Code:
draw_line_dotted_width(x1,y1,x2,y2,w=1)


So that you can leave off the w if you want when you call it, and it will default to 1?

_________________
Image

Image Image
Bibby Team | MFGG3 Github
 
Top
Offline 
 User page at mfgg.net
 
 [at]
 Post subject: Re: DJ Coco's GML Scripts
PostPosted: Tue Sep 13, 2016 10:29 am 
Cliax Codec X Splatoon
Member
[*]
[*]
[*]
[*]
[*]

[*]
[*]
[*]
[*]
[*]

[*]
[*]
[*]
[*]
[*]

[*]
[*]
You can have default parameters in GM, but it's a bit inconveniently done as opposed to other languages.
If you take a look at collision_raycast, I included an optional parameter there.

I'm not entirely sure as I didn't try it myself, but to my knowledge instead of using the fixed variables like argument0, argument1, ... you need to use the array (argument[0], argument[1], ...).
Then you can check the parameter count and assign values as needed.

Example:
if (argument_count > 2) { variable = argument[2]; }
else { variable = 0; }

_________________
Image

Cliax Codec is a combination of top-down and third-person shooter. The gameplay will blend platforming, puzzle and shmup elements together to create a unique gameplay experience. You will take control of four playable characters which rise against a team that seemingly wants to take over the world - but are their motives really that cliché, or are there deeper motives behind their actions?

Currently designing Chapter 1-6, 5%

GOTM titles
Spoiler:
Fan Art
Spoiler:
 
Top
Offline 
 User page at mfgg.net
 
 [us]
 Post subject: Re: DJ Coco's GML Scripts
PostPosted: Tue Sep 13, 2016 9:27 pm 
User avatar
Lawful Evil
Member
[*]
[*]
[*]
[*]
[*]

[*]
Wouldn't the raycast be a bit faster if you calculated lengthdir_x and lengthdir_y outside of the for loop and saved it as a constant? It's generally best to use as few sin/cos operations as you can.

_________________
Image
Magikoopa Security Force, the Mario Action-Strategy game!
  It's time to fight for Bowser!
 
Top
Offline 
 User page at mfgg.net
 
« Previous topic | Next topic »
Display posts from previous:  Sort by  
Go to page 1, 2  Next  [ 24 posts ]  Reply to topicPost new topic 


Who is online

Users browsing this topic: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group