Author Topic: Problems with creating this shape  (Read 3778 times)

infern0man1

  • ~(=^・ω・^)ψ
  • Global Moderator
  • Oatmeal Killer
  • Posts: 1.021
  • Dear sir stroke madam, fire exclamation point
  • OS:
  • Linux Linux
  • Browser:
  • Safari 4.0 Safari 4.0
    • View Profile
    • Twitter
  • Playstyle: Keyboard
Problems with creating this shape
« on: June 19, 2015, 08:27:10 PM »


I'm attempting at making a shape similar to the one above, so I wrote up the code below:

Code: (objBoss - Step Event) [Select]
//stepcounter coding beforehand and bla
xx=room_width/2;
yy=room_height/2;
dist=76;
num=4;
for(i=-num;i<=num;i+=1){
  a=instance_create(xx+i*dist,yy+i*dist,cherry);
}

However, when I run the game, no cherry appears when it's supposed to. I'm thinking that it's just the way I wrote it that GM just doesn't even. Is there a better way or a workaround for this, or am I just completely missing something?

infern0man1

  • ~(=^・ω・^)ψ
  • Global Moderator
  • Oatmeal Killer
  • Posts: 1.021
  • Dear sir stroke madam, fire exclamation point
  • OS:
  • Linux Linux
  • Browser:
  • Safari 4.0 Safari 4.0
    • View Profile
    • Twitter
  • Playstyle: Keyboard
Re: Problems with creating this shape
« Reply #1 on: June 20, 2015, 04:09:03 PM »
The way you were attempting to pull this off isn't exactly what I had in mind; each line in the pic of shape is straight, where the starting point of each line in the first quadrant would be {x+=1,y-=1}, and each quadrant is different. I just now realized that the code I wrote up would create cherries in the shape of a grid.
That method was also based off of a script I found:

Code: [Select]
//argument0=x
//argument1=y
//argument2=distance between 2 points
//argument3=number of points per half of each axis

var i,xx,yy,dist,num;
xx=argument0;
yy=argument1;
dist=argument2;
num=argument3;
for(i=-num;i<=num;i+=1){
  draw_line(xx,yy+i*dist,xx+(num-abs(i))*dist,yy);
  draw_line(xx,yy+i*dist,xx-(num-abs(i))*dist,yy);
}

I thought at first I could convert that into instance_create, but I failed to realize that this only takes into consideration the points on each axis.

I can easily create the axis, but not the lines of cherries going to different coordinates on the axis. How would you do that?

WetWookie

  • Cherry Eater
  • Posts: 90
  • OS:
  • Windows 8.1/Server 2013 Windows 8.1/Server 2013
  • Browser:
  • Firefox 38.0 Firefox 38.0
    • View Profile
  • Playstyle: Keyboard
Re: Problems with creating this shape
« Reply #2 on: June 20, 2015, 10:57:10 PM »


//stepcounter coding beforehand and bla
xx=room_width/2;
yy=room_height/2;
dist=50;
num=4;
for(i=-num;i<=num;i+=1){
    for(j=-num;j<=num;j+=1){
        xp = xx + (i *(abs(abs(j)-num)/num)) *dist;
        yp = yy + (j *(abs(abs(i)-num)/num)) *dist;
        a=instance_create(xp,yp,cherry);
    }
}


WetWookie

  • Cherry Eater
  • Posts: 90
  • OS:
  • Windows 8.1/Server 2013 Windows 8.1/Server 2013
  • Browser:
  • Firefox 38.0 Firefox 38.0
    • View Profile
  • Playstyle: Keyboard
Re: Problems with creating this shape
« Reply #3 on: June 21, 2015, 09:28:01 AM »
I put something together that should be more accurate with larger shapes, gives you more control and should be useful for other things as well. I present to you draw_object_line(x1,x2,y1,y2, NumObjects, ObjectType)

put this in a script called draw_object_line
Code: [Select]
x1 = argument0;
y1 = argument1;
x2 = argument2;
y2 = argument3;
NumObjects = argument4;
Object = argument5

if NumObjects < 2 {NumObjects = 2;}

if x1 == x2
{
    if y2 < y1
    {
        xt = x1;
        yt = y1;
        x1 = x2;
        y1 = y2;
        x2 = xt;
        y2 = yt;
    }
   
    XStep = (x2 - x1)/(NumObjects-1);
    YStep = (y2 - y1)/(NumObjects-1);
   
    tx = x1;
    for (ty = y1; ty <= y2; ty += YStep)
    {
        a = instance_create(tx,ty,Object);
        tx += XStep;
    }   

} else {

    if x2 < x1
    {
        xt = x1;
        yt = y1;
        x1 = x2;
        y1 = y2;
        x2 = xt;
        y2 = yt;
    }
   
    XStep = (x2 - x1)/(NumObjects-1);
    YStep = (y2 - y1)/(NumObjects-1);
   
    ty = y1;
    for (tx = x1; tx <= x2; tx += XStep)
    {
        a = instance_create(tx,ty,Object);
        ty += YStep;
    }   

}

Now your shape drawing code looks pretty much the same as your starting code.
//stepcounter coding beforehand and bla
xx=room_width/2;
yy=room_height/2;
dist=50;
num=4;
for(i=-num;i<=num;i+=1){
    draw_object_line(xx,yy+i*dist,xx+(num-abs(i))*dist,yy,5,cherry);
    draw_object_line(xx,yy+i*dist,xx-(num-abs(i))*dist,yy,5,cherry);
}

This should look familiar


//stepcounter coding beforehand and bla
xx=room_width/2;
yy=room_height/2;
dist=25;
num=10;
for(i=-num;i<=num;i+=1){
    draw_object_line(xx,yy+i*dist,xx+(num-abs(i))*dist,yy,num * 10,bullet);
    draw_object_line(xx,yy+i*dist,xx-(num-abs(i))*dist,yy,num * 10,bullet);
}

« Last Edit: June 21, 2015, 10:10:59 AM by WetWookie »

infern0man1

  • ~(=^・ω・^)ψ
  • Global Moderator
  • Oatmeal Killer
  • Posts: 1.021
  • Dear sir stroke madam, fire exclamation point
  • OS:
  • Windows Vista/Server 2008 Windows Vista/Server 2008
  • Browser:
  • Chrome 43.0.2357.124 Chrome 43.0.2357.124
    • View Profile
    • Twitter
  • Playstyle: Keyboard
Re: Problems with creating this shape
« Reply #4 on: June 21, 2015, 12:31:07 PM »
Thank you so much my man <3

lawatson

  • The Kid
  • Posts: 331
  • I do things and I make things.
  • OS:
  • Windows 7/Server 2008 R2 Windows 7/Server 2008 R2
  • Browser:
  • Chrome 43.0.2357.124 Chrome 43.0.2357.124
    • View Profile
  • Playstyle: Keyboard
Re: Problems with creating this shape
« Reply #5 on: June 21, 2015, 02:25:32 PM »
god damn it that looks nice

edit: whoopsied my other post. ._.
« Last Edit: June 30, 2015, 06:25:37 PM by lawatson »
(click to show/hide)

smoke weed everyday

verveplay

  • Wannabe
  • Posts: 31
  • Hi
  • OS:
  • Windows 7/Server 2008 R2 Windows 7/Server 2008 R2
  • Browser:
  • Firefox 38.0 Firefox 38.0
    • View Profile
  • Playstyle: Keyboard
Re: Problems with creating this shape
« Reply #6 on: June 28, 2015, 09:32:26 AM »
Wookie how do you even... You are a genius

infern0man1

  • ~(=^・ω・^)ψ
  • Global Moderator
  • Oatmeal Killer
  • Posts: 1.021
  • Dear sir stroke madam, fire exclamation point
  • OS:
  • Linux Linux
  • Browser:
  • Safari 4.0 Safari 4.0
    • View Profile
    • Twitter
  • Playstyle: Keyboard
Re: Problems with creating this shape
« Reply #7 on: June 28, 2015, 10:07:55 PM »
Just found put that using a tile for the background image messed something up and hid the apples that were originally supposed to spawn OpieOP

WetWookie

  • Cherry Eater
  • Posts: 90
  • OS:
  • Windows 8.1/Server 2013 Windows 8.1/Server 2013
  • Browser:
  • Firefox 38.0 Firefox 38.0
    • View Profile
  • Playstyle: Keyboard
Re: Problems with creating this shape
« Reply #8 on: June 29, 2015, 07:30:20 AM »
Make sure the tiles have a higher depth value than the object running the code that is creating the fruit.

verveplay

  • Wannabe
  • Posts: 31
  • Hi
  • OS:
  • Windows 7/Server 2008 R2 Windows 7/Server 2008 R2
  • Browser:
  • Firefox 38.0 Firefox 38.0
    • View Profile
  • Playstyle: Keyboard
Re: Problems with creating this shape
« Reply #9 on: June 29, 2015, 07:45:55 AM »
Do that with all the objects that might possibly overlap, the higher depth is,  the further they are from the player (covered by objects with smaller depth)

infern0man1

  • ~(=^・ω・^)ψ
  • Global Moderator
  • Oatmeal Killer
  • Posts: 1.021
  • Dear sir stroke madam, fire exclamation point
  • OS:
  • Windows Vista/Server 2008 Windows Vista/Server 2008
  • Browser:
  • Chrome 43.0.2357.130 Chrome 43.0.2357.130
    • View Profile
    • Twitter
  • Playstyle: Keyboard
Re: Problems with creating this shape
« Reply #10 on: June 29, 2015, 11:13:21 AM »
Make sure the tiles have a higher depth value than the object running the code that is creating the fruit.


I did at the time; the tiles were at a depth of like 1000000 and the apples were at 0. IDK why they didn't show up since the rest of the attacks did, but w/e

WetWookie

  • Cherry Eater
  • Posts: 90
  • OS:
  • Windows 7/Server 2008 R2 Windows 7/Server 2008 R2
  • Browser:
  • Firefox 38.0 Firefox 38.0
    • View Profile
  • Playstyle: Keyboard
Re: Problems with creating this shape
« Reply #11 on: June 29, 2015, 11:17:28 AM »
Keep in mind that objects created in code will use the depth of the object that is running the code and not the depth set in the spawned object properties.