Match objects with drawing lines (Bingo! Solved)

Started by Amir, Mon 06/06/2022 07:43:06

Previous topic - Next topic

Amir

Aha this TestLines(); function probably makes a big difference but it doesn't work for me  ???
I have to import the 2 new functions, right?
Truly, truly, I say to you, blessed are those who play adventure games, for theirs is the kingdom of heaven.

Crimson Wizard

#41
Quote from: Amir on Fri 10/06/2022 20:39:33
Aha this TestLines(); function probably makes a big difference but it doesn't work for me  ???
I have to import the 2 new functions, right?

It's not only 2 new functions, there are other differences, compared to the last code you posted above. I guess you could compare the code side by side to see what is different. Or simply paste full code over, and then adjust to your needs.

Amir

#42
Quote from: Crimson Wizard on Fri 10/06/2022 20:56:08
Quote from: Amir on Fri 10/06/2022 20:39:33
Aha this TestLines(); function probably makes a big difference but it doesn't work for me  ???
I have to import the 2 new functions, right?

It's not only 2 new functions, there are other differences, compared to the last code you posted above. I guess you could compare the code side by side to see what is different. Or simply paste full code over, and then adjust to your needs.

Yes it works now. Thank u so much.  ;-D
Truly, truly, I say to you, blessed are those who play adventure games, for theirs is the kingdom of heaven.

Amir

Quote from: Crimson Wizard on Fri 10/06/2022 20:56:08
Quote from: Amir on Fri 10/06/2022 20:39:33
Aha this TestLines(); function probably makes a big difference but it doesn't work for me  ???
I have to import the 2 new functions, right?

It's not only 2 new functions, there are other differences, compared to the last code you posted above. I guess you could compare the code side by side to see what is different. Or simply paste full code over, and then adjust to your needs.

Please forgive me, I have one last question since you have the code. I want to make it so that if you click the OK button and haven't dragged anything yet, nothing happens. I mean if there are no lines there nothing happens when you click OK. It doesn't work like that

Code: ags

else if (event == 2) // lines ok
  {
  // test all lines and save bools
    TestLines();
    // now final test(s)
    
   if ((line_count == 0) && (VBaer == false) && (Grim == false) && (Fenster == false) && (Vase == false))
    {}  // do nothing
    
   else if ((VBaer == true) && (Grim == true) && (Fenster == true) && (Vase == true))
   {
     // Bingo
     
   } 
   
  else
{
 // wrong answer
}

Truly, truly, I say to you, blessed are those who play adventure games, for theirs is the kingdom of heaven.

Crimson Wizard

Quote from: Amir on Sat 11/06/2022 00:49:40I want to make it so that if you click the OK button and haven't dragged anything yet, nothing happens. I mean if there are no lines there nothing happens when you click OK.

I think it might work if you simply move the "line_count" check up and merge with "if (event == 2)":
Code: ags
if (event == 2 && line_count > 0)

as if there are no lines drawn, then no need to also call TestLines and other things.

Amir

#45
Quote from: Crimson Wizard on Sat 11/06/2022 01:34:54
Quote from: Amir on Sat 11/06/2022 00:49:40I want to make it so that if you click the OK button and haven't dragged anything yet, nothing happens. I mean if there are no lines there nothing happens when you click OK.

I think it might work if you simply move the "line_count" check up and merge with "if (event == 2)":
Code: ags
if (event == 2 && line_count > 0)

as if there are no lines drawn, then no need to also call TestLines and other things.

Good morning, it doesn't work, I've tried many things, like this for example.
Code: ags

  else if (event == 2) // lines ok
  {
  // test all lines and save bools
    TestLines();
    // now final test(s)
  if (line_count == 0) {} // do nothing

  else if ((line_count > 0) && (VBaer == true) && (Grim == true) && (Fenster == true) && (Vase == true))
  {
    // Bingo
  }  
  else
{
 // wrong answer
}    
  }


The result is wrong answer. Something doesn't let it be. The loop? for (int i = 0; i < line_count; i++)

Edit: I'll try to do it with gverbinden.Clickable = false; That is the Gui of the OK button.
Truly, truly, I say to you, blessed are those who play adventure games, for theirs is the kingdom of heaven.

Crimson Wizard

#46
Quote from: Amir on Sat 11/06/2022 08:20:09
Good morning, it doesn't work, I've tried many things, like this for example.

This may be because the line drawing code draws lines even when you click on buttons. So when you click on a button, it draws a small line anyway.
The solution may be to either restrict drawing to certain coordinates, or coordinates of gui that you put sprites on, if you make it not cover whole screen but only area where it is allowed to draw.
Or use ZOrder to put gGuiLine below other controls and test GUI.GetAtScreenXY to see if the mouse is above it before starting to draw.

Code: ags

  bool mouse_down = Mouse.IsButtonDown(eMouseLeft);
  //if the left mouse button is down and the game accepts input, 
  //store x and y of the current mouse position
  if (mouse_down && accept_input){
    if (GUI.GetAtScreenXY(mouse.x, mouse.y) != gGuiLine) // <--------- add this
      return;// <--------- 
   <...>

Amir

QuoteThe solution may be to either restrict drawing to certain coordinates, or coordinates of gui that you put sprites on, if you make it not cover whole screen but only area where it is allowed to draw.

It's not on the whole screen, otherwise the buttons would not be clickable. It's there where the hotspots are. But apparently it still draws invisible lines outside the gui.

Quoteuse ZOrder to put gGuiLine below other controls and test GUI.GetAtScreenXY to see if the mouse is above it before starting to draw.

Ok, i'll test it.
Truly, truly, I say to you, blessed are those who play adventure games, for theirs is the kingdom of heaven.

Amir

Yes with if (GUI.GetAtScreenXY(mouse.x, mouse.y) != gGuiLine) return;// I can click on OK gui but not gGuiline, gGuiline is gone. That's good, but when I change ZOrder and put gGuiline behind the other and click on OK gui, wrong answer, like I said, like I'm drawing an invisible line outside of the gui and that's why it doesn't work.
Truly, truly, I say to you, blessed are those who play adventure games, for theirs is the kingdom of heaven.

Crimson Wizard

Quote from: Amir on Sat 11/06/2022 13:12:18
Yes with if (GUI.GetAtScreenXY(mouse.x, mouse.y) != gGuiLine) return;// I can click on OK gui but not gGuiline, gGuiline is gone. That's good, but when I change ZOrder and put gGuiline behind the other and click on OK gui, wrong answer, like I said, like I'm drawing an invisible line outside of the gui and that's why it doesn't work.

That should not happen. What are zorder values of these guis?
There's also gGuiAllLines, it should perhaps be made non-clickable to not interfere with anything.

Amir

#50
Quote from: Crimson Wizard on Sat 11/06/2022 14:02:34
Quote from: Amir on Sat 11/06/2022 13:12:18
Yes with if (GUI.GetAtScreenXY(mouse.x, mouse.y) != gGuiLine) return;// I can click on OK gui but not gGuiline, gGuiline is gone. That's good, but when I change ZOrder and put gGuiline behind the other and click on OK gui, wrong answer, like I said, like I'm drawing an invisible line outside of the gui and that's why it doesn't work.

That should not happen. What are zorder values of these guis?
There's also gGuiAllLines, it should perhaps be made non-clickable to not interfere with anything.

They are already both unclickable.

Code: ags

  gGuiLine.ZOrder = -100;
 gGuiAllLines.ZOrder = -100;
 
  gverbinden.ZOrder = 100;  // Ok button
 gReset.ZOrder = 100;    // Reset Button


Both Guis left 0 and width 540 and the button OK width 100 and left 700. I tried moving the Gui OK to the far right edge 1100 left but // wrong answer, as if it were inside the gGuiline.

Is it really only drawn in GUI and not outside?
Truly, truly, I say to you, blessed are those who play adventure games, for theirs is the kingdom of heaven.

Amir

I added if (mouse.x < 505) and it seems to be working now.

Code: ags

if (mouse.x < 505)
  {
  
  if ((object[0].Visible == true) || (object[3].Visible == true)) {}  // nicht malen
  
  else if (mouse_down && accept_input) 
  {
    accept_input = false;
    draw = true;
    sx = mouse.x;
    sy = mouse.y;
    ex = sx;
    ey = sy;
    spriteForLine = DynamicSprite.Create(Room.Width, Room.Height);
    gGuiLine.BackgroundGraphic = spriteForLine.Graphic;
  //draw line from the place where the mouse was pressed to the current position of the mouse
  } 
  else if (mouse_down && draw)
  { 
    DrawingSurface *surface = spriteForLine.GetDrawingSurface();
    // first erase old line by repainting it with a transparent color
    surface.DrawingColor = COLOR_TRANSPARENT;
    surface.DrawLine(sx, sy, ex, ey, LINE_WIDTH);
    ex = mouse.x;
    ey = mouse.y;
    surface.DrawingColor = line_color;
    surface.DrawLine(sx, sy, ex, ey, LINE_WIDTH);
    surface.Release();
    
  // if the mouse button is released and input set to false, reset accept_input and stop drawing lines
  } 
  else if (!mouse_down && !accept_input)
  {
    accept_input = true;
    draw = false;
    // paste resulting line onto the final sprite with many lines
    DrawingSurface *surface = spriteForAll.GetDrawingSurface();
    surface.DrawImage(0, 0, spriteForLine.Graphic);
    surface.Release();
    // don't display single-line sprite anymore
    gGuiLine.BackgroundGraphic = 0;
    spriteForLine.Delete();
         // save line
     Lines[line_count].sx = sx;
     Lines[line_count].sy = sy;
     Lines[line_count].ex = ex;
     Lines[line_count].ey = ey;
     line_count++; // increase line counter 
  }
  
  } 
Truly, truly, I say to you, blessed are those who play adventure games, for theirs is the kingdom of heaven.

Crimson Wizard

Quote from: Amir on Sat 11/06/2022 15:27:37
They are already both unclickable.

Note that if gGuiLine is also unclickable, then " if (GUI.GetAtScreenXY(mouse.x, mouse.y) != gGuiLine)" won't work, as GUI.GetAtScreenXY only looks for clickable guis.

Amir

Quote from: Crimson Wizard on Sat 11/06/2022 20:10:32
Quote from: Amir on Sat 11/06/2022 15:27:37
They are already both unclickable.

Note that if gGuiLine is also unclickable, then " if (GUI.GetAtScreenXY(mouse.x, mouse.y) != gGuiLine)" won't work, as GUI.GetAtScreenXY only looks for clickable guis.

Yes, you're right. That's why it didn't work. I forgot that I made both Guis unclickable. No matter now. It works now after I restricted mouse activation. Thank u.
Truly, truly, I say to you, blessed are those who play adventure games, for theirs is the kingdom of heaven.

SMF spam blocked by CleanTalk