GMLscripts.com

Discuss and collaborate on GML scripts
Invert

You are not logged in.

#1 Re: Script Submission » Precise Tile Collision » 2020-09-20 10:52:11

While we're at it here are a few others I made based off the same code.

Expand///@description tile_point_precise(x,y,layer)
///@param x
///@param y
///@param layer

var _layer = argument2;

_checker = obj_precise_tile_checker;
if(!instance_exists(_checker)) instance_create(0,0,_checker); 

var _x = argument0,
    _y = argument1;

var _tile = tile_layer_find(_layer, _x, _y);
if(_tile){
  var bg = tile_get_background(_tile),
      bg_ww = background_get_width(bg),
      ww = tile_get_width(_tile),
      hh = tile_get_height(_tile),
      ll = (tile_get_left(_tile) / ww),
      tt = (tile_get_top(_tile) / hh);
  
  var pos = ll + tt*(bg_ww div ww);
  
  if(pos == 0) return true;
  
 _checker.x = _x - (_x mod tile_get_width(_tile));
 _checker.y = _y - (_y mod tile_get_height(_tile));
 _checker.image_index = pos;
  
 
 if(collision_point(argument0,argument1,_checker, true, true)) return true;
}

return false;
Expand/// tile_collision_normal(x, y, radius, resolution, prec)

// x
// y
// radius
// resolution - how many pixels of the radius to draw
// prec - (false) = outerring check only; (true) = entire circle check

var cx, cy, xx, yy, radius, res, prec, radius_i, degrees, degrees_i, rads, nx, ny;

cx = argument0
cy = argument1
xx = cx
yy = cy
radius = argument2
radius_i = radius
res = argument3
prec = argument4
degrees = 0
nx = 0
ny = 0

//draw_set_color(c_dkgray)
//draw_set_alpha(0.25)
if (res > radius*2){
  res = radius*2;
  show_debug_message("Error: resolution is larger then the circle")
}

while (radius_i > 0)
{
  //pi method
  degrees_i = (res/((radius_i*2)*pi))*360
  degrees_i =  360/round(360/degrees_i)
  
  while (degrees < 360)
  {
    rads = degtorad(degrees)
    xx = cos(rads) * radius_i;
    yy = sin(rads) * radius_i ;
    
    if !tile_point_precise(cx+xx,cy+yy,TileLayerBottom,){
      nx += xx
      ny += yy
    }
    
    degrees += degrees_i
  }
  degrees = 0
  radius_i -= res
  if (!prec) radius_i = 0;
}

if (nx == 0 && ny == 0) return (-1);
return point_direction(0,0,nx,ny);

#2 Re: Community » GMS 2.3.x compatibility ? » 2020-09-20 10:50:45

Aw man... gms1 is gonna be loosing support? that's a real shame honestly. I've been porting things back just so they have support for gms 1.4 and posting them here. I'm like half finished with a neural network framework for gms 1.4.999. If there is anything I can do to assist feel free to get in contact with me on discord.

#3 Script Submission » Precise Tile Collision » 2020-09-20 10:46:19

redeyesmaster
Replies: 2
Expand///@description tile_meeting_precise(x,y,layer)
///@param x
///@param y
///@param layer
/*
  Returns true or false
  
  place_meeting() for use with tiles.
  [Requires] obj_precise_tile_checker
  more information can be found here:
  https://www.yoyogames.com/blog/577/precise-tile-collisions-by-pixelated-pope

  make a sprite sheet with the exact same tiles. and for gms 1.4.9999 you may
  wish to expand the mask 1 in every direction (assists with sub pixel movement)
  
  Ported by Red#9475
*/
/// GMLscripts.com/license
var _layer = argument2;

_checker = obj_precise_tile_checker;
if(!instance_exists(_checker)) instance_create(0,0,_checker); 

var _x1 = bbox_left + (argument0 - x),
    _y1 = bbox_top + (argument1 - y),
    _x2 = bbox_right + (argument0 - x),
    _y2 = bbox_bottom + (argument1 - y),
    
for(var _x = _x1; _x <= _x2; _x++){
  for(var _y = _y1; _y <= _y2; _y++){
    var _tile = tile_layer_find(_layer, _x, _y);
    if(_tile){
      var bg = tile_get_background(_tile),
          bg_ww = background_get_width(bg),
          ww = tile_get_width(_tile),
          hh = tile_get_height(_tile),
          ll = (tile_get_left(_tile) / ww),
          tt = (tile_get_top(_tile) / hh);
      
      var pos = ll + tt*(bg_ww div ww);
      
     _checker.x = _x - (_x mod tile_get_width(_tile));
     _checker.y = _y - (_y mod tile_get_height(_tile));
     _checker.image_index = pos;

     if(place_meeting(argument0,argument1,_checker)) return true;
    }
 }
}

return false;

Original code base:   https://www.yoyogames.com/blog/577/prec … lated-pope

I was expressly given permission by Pixelated Pope to share this port, and he will direct people to it when they need assistance for gms 1.4.999

#4 Re: GML Creations » Recurrent Neural Network Example » 2020-09-12 21:16:38

I've added a bunch of functions and difference memory gates already. When the final version is complete I'll be posting a github release.

#5 GML Creations » Recurrent Neural Network Example » 2020-09-04 23:09:22

redeyesmaster
Replies: 1

This is not my code, but I remade it from the original blog post for an easy download. Until some vast changes are made I wont be officially submitting this.

Blog Post:
https://highleapstudios.wordpress.com/2 … -studio-1/

My Git:
https://github.com/dsk80004/Gamemaker-S … al-Network

If anyone has any questions on integrating it into a project feel free to ask.

Some of the changes made are things like only drawing 1/10 of the simulations, and some scaling to view more arrows at once. Thinking about incorporating a save system for the project, so your neurons can be loaded from the last test. Allowing for you to send the program to a stronger computer to train on, then return the neuron information back to your testing computer. Also a few quality of life improvements for the structuring of code.

If anyone is more experience with RNNs I could use some help adding other learning methods such as Q learning systems as a scripted function.

#6 Re: Script Submission » generate a random cave for a ds_grid (Update 9/2/20) » 2020-09-04 23:00:26

Awesome looking forward to it. The other generation codes would be great to see too.

#7 Script Submission » anim_rotate - Paper Mario Rotate Animation » 2020-08-28 14:25:26

redeyesmaster
Replies: 0

This script is the isometric equivalent to Paper Mario animations. If you want a true Paper Mario rotate animation you will just need to change the top right, and bottom left corners that way on a platformer 2D plane the players front side will expand.

Examples:
Video: https://i.gyazo.com/ccdbf7a781866e663f9 … b91f86.mp4
unknown.png

[NOTE]: This may not work as intended when your texture pages are set to automatic cropping.

To effectively use this script, the calling instance must call it every frame, once the direction variable has been changed. So on the first frame you are looking left, the animation should be called, the player will still be facing right, when the animation finishes you can use the returned true as a reference to flip the player's image_xscale.

Expand///anim_rotate()

/* This script is used to animate the sprite rotation mimicing
     the paper mario style with out the need for seperate arm
     or leg sprites
   
   Make sure to account for player direction as the sprite will
     rotate in different styles based on the direction it rotated
     to, for instance when the player walks right, then up, then
     left. the front side (right) of the sprite will shrink at 
     it rotates to give the illusion it is further away from the 
     camera.
     
   Returns: Bool (True when animation is finished, False for any other state)
*/

/// GMLscripts.com/license

returned = false


if !variable_instance_exists(self.id, "anim_rotate_start") {anim_rotate_start = true}


//set the animation variables
if (anim_rotate_start)
{
  anim_time = floor(room_speed*0.25)
  anim_timer = anim_time
  anim_flip_frame = floor(anim_time*0.5)
  //anim_ideal_delta_time = 1/room_speed * 1000000; //typically 33333 or 16666
  anim_travel_dis = sprite_width/anim_time
  pi_time = pi / anim_time
  //this variable is used to keep track of the last view we did. 9 is a view which doesnt exist so it will think it's a new frame
  view_loop = 9
  
  //if turning prefered up  
  if (direction > 0) && (direction < 180) {anim_face_dir = -1}
  //if turning prefered down or instant turn
  if (direction = 0) || ((direction < 360) && (direction >= 180)) {anim_face_dir = 1}
  
  //if turning left
  if (direction > 90) && (direction < 270) {anim_rotate_dir = -1}
  //if turning right
  if (direction < 90) || (direction > 270) {anim_rotate_dir = 1}
  //anim_rotate_dir = sign(image_xscale)
  
  max_y_multiplier = abs(sprite_height)*0.2 //20 percent of the height
  
  anim_rotate_start = false
}

var lag = delta_time * room_speed * 0.000001

/// tris will multiply variables by 1 or -1 fepending on the flip
var flip_multiplier = sign(anim_timer - anim_flip_frame)


// the x distance the flip needs to travel, acounting delta time
var trav_dis = anim_travel_dis * lag

/// a negative number means we were right, and we're turning left
var trav_dis_x = cos(anim_timer * pi_time) * (sprite_width/2) - abs(sprite_width/2)*anim_rotate_dir

// how much we skew the y for either the front of back of the player
var y_miltiplier = cos((anim_timer-anim_flip_frame)  * pi_time)*max_y_multiplier


draw_sprite_pos(sprite_index,
                image_index, 
                
                //top left
                x-(sprite_xoffset)+trav_dis_x, 
                y-(sprite_yoffset)-(y_miltiplier*anim_face_dir), 
                
                //top right
                x+(sprite_width-sprite_xoffset)-trav_dis_x, 
                y-(sprite_yoffset)+(y_miltiplier*anim_face_dir), 
                
                //bottom right
                x+(sprite_width-sprite_xoffset)-trav_dis_x, 
                y+(sprite_height-sprite_yoffset)+(y_miltiplier*anim_face_dir), 
                
                //bottom left
                x-(sprite_xoffset)+trav_dis_x, 
                y+(sprite_height-sprite_yoffset)-(y_miltiplier*anim_face_dir), 
                
                image_alpha);

//this will keep track of the view ports we've iterated through, that way we never count down the anim timer more then once each frame
if (view_current < view_loop){
  view_loop = view_current
  anim_timer -= 1*lag
}else if (view_current > view_loop){
  view_loop = view_current
}

if (anim_timer <= 0)
{
  returned = true
  anim_rotate_start = true
}



return returned

[EDIT] There were an absolute ton of errors in the code, updated to the new system. It also now supports image scale flipping. Although you should set the flip after this script returns true.

[EDIT 2] It's amazing this code works at all from how I wrote it, I'm rewriting the system now to vastly improve this. I have no idea why I have unused variables, and why some of the math is done the way i did it. I guess I was just excited to have this finished.

#8 Script Submission » lag() - A delta_time optimization. » 2020-08-28 14:14:08

redeyesmaster
Replies: 0

I made this code for myself, honestly the code could be made by pretty much anyone, but the reason I'm posting it is because the ability to shrink your code a bit, and have optimized code really helps.

For those of you that didn't know multiplying takes less cpu then dividing, it's not that important but it's something to keep in mind for large projects.

Also, personally I named the code dt() since it's easier and faster to type on a qwarty keyboard, but just named it lag for memory sake.

Expand/// lag();
//
//  this function is simply the most optimal way to calculate lag
//  since computers multiply with fewer cpu instructions than they can divide
//
//  Returns: real
//
//  The returned is a multiplier value for lost frames,
//    this function is really only to server as a
//    replacement for dividing by delta_time by ideal_delta.
//
//  The function also helps clean up the code a bit in my opinion
//
/// GMLscripts.com/license


//returning this multiple allows for simple equasions like:   speed * lag()
return delta_time * room_speed * 0.000001

#9 Re: GML Code Help » Xot's Collision normal [optimizing] » 2020-08-26 03:10:21

I had an amazing idea, why not make use of ds_grid_disk() and mp_grid. through the mp_grid_to_ds_grid(), then we could copy the section, cull that section down to a circle, then find the center of that circle and normal from that. It would require no collision event, and simply setting the precision or mp_grid, where everything else would be handled for us.

#10 Re: GML Code Help » Rectangle Point Direction [unfinished] » 2020-08-18 08:14:13

A new function name, and proper descriptions would also be needed for a proper submission to the math's section of scripts. The inputs should be self explanatory to most, and the output is the distance between the px, py, and the border of the box. Theoretically one would be able to convert this to work with shape although that's a LOT more work to be able to make it dynamic.

#11 GML Code Help » Rectangle Point Direction [unfinished] » 2020-08-18 08:10:24

redeyesmaster
Replies: 1

This is a bit of code I do not plan on finishing but the part that is finished works extremely well.

Expand/// rect_point_dir(x1,y1,x2,y2,px,py,dir)


var x1,y1,x2,y2,px,py,dir;
x1 = argument0
y1 = argument1
x2 = argument2
y2 = argument3
px = argument4
py = argument5
dir = argument6

var rect_width  = x2-x1
var rect_height = y2-y1

if point_in_rectangle(px,py,x1,y1,x2,y2)
{
      var vx = cos(degtorad(dir))
      var vy = sin(degtorad(dir))
      var trav = rect_width*rect_height
      
      if (vx != 0) {
        t = (x1-px)/vx;
          if (t > 0) trav = min(t,trav);
          draw_text(0,16,"left = "+string(t))
        t = (x2-px)/vx; 
          if (t > 0) trav = min(t,trav);
          draw_text(0,32,"right = "+string(t))
      }
      
      if (vy != 0) {
        t = (py-y1)/vy; 
          if (t > 0) trav = min(t,trav);
          draw_text(0,48,"top = "+string(t))
        t = (py-y2)/vy; 
          if (t > 0) trav = min(t,trav);
          draw_text(0,64,"bottom = "+string(t))
      }
      draw_text(0,0,"travel = "+string(trav))
      draw_set_color(c_red)
      draw_circle(px+lengthdir_x(trav,dir),py+lengthdir_y(trav,dir),3,false)
      draw_set_color(c_white)

      return trav
      
}else{
  return -1
}

Feel free to edit and change this how ever you would like. The code which needs to be added before a proper submission would be to allow the px and py to be outside of the rectangle, currently it only supports when it is inside. Here is a short video demonstrating it.
https://i.gyazo.com/879caa9518b896f9870 … 5cb92b.mp4

There are still draw functions to help with debugging in this script if you would like to check out how it works further.

[Edit]: I found a bug with an offset square and the y system, since it's using sin() you want to use (py-y1)/vy. Thebug has been fixed in the code above. Here is a short video showing off offset px, py
https://i.gyazo.com/5a0c93e2230f593c28b … 8fdf2f.mp4

#12 Re: GML Code Help » Xot's Collision normal [optimizing] » 2020-08-18 04:04:44

hmm, we may need to make use of circle checks instead of point checks for the precise checking. It seems sub pixels cause issues between sprites.

45dbf3566787245da20deb05ea79e346.png

#13 Re: GML Code Help » Xot's Collision normal [optimizing] » 2020-08-18 03:06:52

Of course, if you only wanted the option for non precise checking you could simply mix the two scripts, as Xot's script does work quite well. In his demonstration program it takes about 2000 objects before it drops below the desired fps.

After all, just having the option for non-precise checking allows for roughly 2x fps.

#14 GML Code Help » Xot's Collision normal [optimizing] » 2020-08-18 03:04:10

redeyesmaster
Replies: 3

Xot Made a wonderful Collision normal script found here: https://www.gmlscripts.com/script/collision_normal

Although I would imagine the script could be updated to improve the efficiency.

Some points of note:

I've noticed that the script is calculating points then seeing if they are even in the circle. This area could definitely be improved by doing the calculations algorithmicly. Making sure there is no point in which a point would be outside the circle.

I've also noticed that the script has no precision argument. Most always this argument would be used to simply check the bounding boxes instead of the precise mask, although for this instance I would imagine we could simply check the outer circle instead. Which would save tons of performance.


I've made a quick mock up of what I would imagine this system would look like.
c77f6fccdfa01f821834f5574a6dd9e9.png

This image actually shows both methods at once, The blue arrow depicts my method, and the purple arrow shows Xot's method. As you can see both arrows are with in 1 degree of each other. Which is precisely what we want. Although an optimization which Xot's version is making use of is only doing the point calculations 1/4 of the time and using those calculations to interpret the other locations to check. Trying this method with my method shows undesirable results.

4b54cdba0a87baa03531017e2cd60fbb.png

If we're able to make this a more uniform shape which could be perfectly expanded to the other quadrons then we would have the (ideally) most efficient method.

Here is an example with the precise collision set to false using my method. Comparing with the vanilla collision normal script.
a46e36d4f786d60a50437a424dc4a246.png
af14922fd049870718f9aa334bb18975.png

Since the collision is only checking the outer ring, and the resolution is set to 8 I would say this is a huge success. Although could still use a ton of optimization.

Here is the current code for the non-quadron version I've made.

Expand/// scr_draw_circle(x, y, radius, resolution, prec)

// x
// y
// radius
// resolution - how many pixels of the radius to draw
// prec - (false) = outerring check only; (true) = entire circle check

var cx, cy, xx, yy, radius, res, prec, radius_i, degrees, degrees_i, rads, nx, ny;

cx = argument0
cy = argument1
xx = cx
yy = cy
radius = argument2
radius_i = radius
res = argument3
prec = argument4
degrees = 0
nx = 0
ny = 0

if (res > radius*2){
  res = radius*2;
  show_debug_message("Error: resolution is larger then the circle")
}

if (collision_circle(cx, cy, radius, obj_solid, true, true)) {
  while (radius_i > 0)
  {
    //pi method
    degrees_i = (res/((radius_i*2)*pi))*360
    degrees_i =  360/round(360/degrees_i)
    
    while (degrees < 360)
    {
      rads = degtorad(degrees)
      xx = cos(rads) * radius_i
      yy = sin(rads) * radius_i 
      
      if (collision_point(cx+xx,cy+yy,obj_solid,true,false)){
        draw_set_color(c_red);
      }else{
        draw_set_color(c_green);
        nx += xx
        ny += yy
      }
      draw_circle(cx+xx,cy+yy,res/2,0)
      degrees += degrees_i
    }
    degrees = 0
    radius_i -= res
    if (!prec) radius_i = 0;
  }
  draw_set_color(c_white)
  
  if (nx == 0 && ny == 0) return (-1);
  return point_direction(0,0,nx,ny);
  
}else{
  return (-1);
}

#15 Re: Script Submission » ds_grid_shuffle_adv » 2020-08-18 02:01:39

xot wrote:

I might split these into ds_grid_shuffle_rows() and ds_grid_shuffle_columns() variants.

I thought there was already a shuffle function for rows, but looking into it I guess not. Maybe i'm thinking another data structure. I actually found a bug with it before I posted it where i was returning (ending the script) before I was destroying the temporary structures. I would highly suggest looking into this before pushing it any further forward. My debug has been broken for years so I'm not able to see if it's creating extra grids with out an unreasonable amount of effort.

Edit: Oh yeah I remember why I didn't make it two separate scripts, it's because the GMS documentation pages refer to the two words as if they are interchangeable for some reason. The X of a grid is not the same thing as the X of a graph, it's more like the Y, then when you get into grid heights and lengths this makes even less sense because they work as you suspect they would, then when you're handling specifically rows and columns they are reversed again. Which is why the X argument shuffles the columns and the Y shuffles the rows. Those arguments should probably be changed to sufffleX, shuffleY.

#16 Re: Script Submission » generate a random cave for a ds_grid (Update 9/2/20) » 2020-08-18 01:56:29

Ideally the genoration/perlin and physic's scripts should have a place of their own in the sripts page. Since they dont follow any of the other categories that well, and are frequently used. Similarly to chuck handling codes, and unique camera, and deactivate/activate codes.

I'll probably make something with this script if lostdarkwolf isnt on in a while. I would post it here if I do.

#17 Re: Script Submission » Bundle of string functions » 2020-08-18 01:51:44

Yeah feel free to get in contact with me when ever. You have my discord if you wish to get replies a bit faster. We could discuss there, and post important details here for documentation's sake.

#18 Re: Script Submission » collision_cone_list » 2020-08-18 01:50:05

xot wrote:

You have really been busy! I'm sorry I dropped out of the conversation for a couple of days. I'll try to check these out tonight.

Lol, busy is an understatement. When I'm building code for others to use I try my best to get the most efficient code possible, as it's unlikely it'll ever be updated. Also the use of o_sensor is annoying to me as it doesn't allow a drop in an use experience. really wish the creation of objects wasn't removed.

Speaking of we should probably make sure all the collision scripts which use objects are all using the same object name. I never checked what the others were using.

#19 Re: Script Submission » generate a random cave for a ds_grid (Update 9/2/20) » 2020-08-16 07:07:45

I would love to see an example of the code to use this script and a visual representation would be great as well. But from what I can tell this is quite impressive.

#20 Script Submission » ds_grid_shuffle_adv » 2020-08-16 07:02:08

redeyesmaster
Replies: 2
Expand///ds_grid_shuffle_adv(DSGridIndex, x, y)
// This script will not "randomize()" you must set that your self,
// that way you can use a seed if you want.

/**
 * Shuffles around the grid based on row or column
 *
 * @param   DSMapIndex  The input DS map, DSMap
 * @param   x           true = shuffles by columns
 * @param   y           true = shuffles by rows
 *
 * @return  nothing
 */

/// GMLscripts.com/license


var _grid, _width, widthmax, _height, heightmax;


_grid     = argument[0];
_width    = ds_grid_width(_grid);
widthmax  = _width
_height   = ds_grid_height(_grid);
heightmax = _height
_gridTemp = ds_grid_create(_width,_height)

if (argument[1] = 1) && (argument[2] = 0)
{
    for (var _i=0; _i < widthmax; _i++)
    {
        _width = ds_grid_width(_grid)
        var xrandom = irandom(_width-1)
        ds_grid_set_grid_region(_gridTemp, _grid, xrandom, 0, xrandom, _height-1, _i, 0)
        ds_grid_set_grid_region(_grid, _grid, xrandom+1, 0, _width-1, _height-1, xrandom, 0);
        ds_grid_resize(_grid,_width-1,_height);
        if (_width = 1) break;
    }
    ds_grid_resize(_grid, widthmax, heightmax)
    ds_grid_copy(_grid, _gridTemp)
}


if (argument[1] = 0) && (argument[2] = 1)
{
    for (var _i=0; _i < heightmax; _i++)
    {
        _height = ds_grid_height(_grid)
        var yrandom = irandom(_height-1)
        ds_grid_set_grid_region(_gridTemp, _grid, 0, yrandom, _width-1, yrandom, 0, _i)
        ds_grid_set_grid_region(_grid, _grid, 0, yrandom+1, _width-1, _height-1, 0, yrandom);
        ds_grid_resize(_grid,_width,_height-1);
        if (_height = 1) break;
    }
    ds_grid_resize(_grid, widthmax, heightmax)
    ds_grid_copy(_grid, _gridTemp)
}

if  (argument[1] = 1) && (argument[2] = 1)
{
    ds_grid_shuffle(_grid)
}
ds_grid_destroy(_grid)
ds_grid_destroy(_gridTemp)
return _grid;

This adds more options for shuffling your ds grids then the vanilla function.

Board footer

Powered by FluxBB