• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Draw lines that collides

T

tolga_cakir

Guest
Hello,
I would like to draw a line as sprites between dots. For example a dot appears somewhere in room another appears, a line automatically connects these dots, then another dot appears another new line connects this new dot to previousy connected dots It goes in this way. And we need to take these lines only one and collide with other object.
I hope I explained myself.
Thnks in advance
 
Ok, so dots are "appearing", and there is a line between these dots and if an object touches that line, something happens?

When each dot appears, add it's coords to an array (this should go in the place where you are creating the dots):
Code:
var _rx = irandom(room_width);
var _ry = irandom(room_height);
instance_create_layer(_rx,_ry,layer,obj_dot); // This line and the above code are just my substitutions for however you are creating the dot
array_push(dot_array,_rx,_ry); // Dot_array needs to be initialised in the Create Event of whatever object is running this code.
(As a note, in reality you don't even need to create the obj_dot if it is simply a visual indicator, you can just use the array, but we'll use objects for simplicity sake for now.)

Then, in the Step Event, loop through the array and check for a line collision between each dot:
Code:
var _arrlen = array_length(dot_array);
if (_arrlen > 2) {
   for (var i=0;i<_arrlen-2;i+=2) {
      var _x = dot_array[i];
      var _y = dot_array[i+1];
      var _x2 = dot_array[i+2];
      var _y2 = dot_array[i+3];
      var _inst = collision_line(_x,_y,_x2,_y2,collision_object,false,false));
      if (instance_exists(_inst)) {
          // Code for what happens when collision_object intersects with the lines goes here
      }
   }
}
(Also, this topic should have gone in the Programming section, just so you know).
 
Last edited:
T

tolga_cakir

Guest
Thank you for your kind support. I am goint to try it. It looks a bit complicated in my case I think. Thank you again.
 
T

tolga_cakir

Guest
I think I need to explain what I want to do exactly.
When player clicks an object will be created, every time player creates an object(dot), a line collidable with other object created between these two objects. First created object will do nothing, after second object is created, a collidable line will be created between these two objects. After third object is created another collidable line will connect this newly created object. This goes in this way.
I hope I could explain myself.
Thank you
 

Yal

šŸ§ *penguin noises*
GMC Elder
If you need to be able to collide with it, do this:
  1. create a "line" object with a 1x1 pixel sprite
  2. Put the code you want to happen when you touch a line into its collision event
  3. when a dot is created, create a line object
  4. set its image_xscale to the distance to the other dot (e.g. with point_distance) - this stretches it
  5. set its image_angle to the direction to the other dot (e.g. with point_direction) - this rotates it
  6. Congrats, now you have a line.
 
T

tolga_cakir

Guest
If you need to be able to collide with it, do this:
  1. create a "line" object with a 1x1 pixel sprite
  2. Put the code you want to happen when you touch a line into its collision event
  3. when a dot is created, create a line object
  4. set its image_xscale to the distance to the other dot (e.g. with point_distance) - this stretches it
  5. set its image_angle to the direction to the other dot (e.g. with point_direction) - this rotates it
  6. Congrats, now you have a line.
Thanks for your reply,
I was looking for this. I did it with your help.
Now I am trying to make it online turn based game.
Thanks again.
 
Top