Computer Science Canada Having a 'Click to continue' inside a loop |
Author: | awesomenesss22 [ Sun Jan 06, 2019 4:18 pm ] |
Post subject: | Having a 'Click to continue' inside a loop |
I'm creating a game and at the beginning title screen there are 2 buttons which can be pressed that take you to 2 different screens, as seen down below: setscreen ("graphics:1000;1000") var BoxX, BoxY, Clicks : int loop mousewhere (BoxX, BoxY, Clicks) locate (10, 10) if Clicks = 1 and BoxX >= 550 and BoxX <= 650 and BoxY >= 500 and BoxY <= 550 then drawfillbox (0, 0, 1000, 1000, 103) Draw.Text ("Shutting Down...", 250, 700, font, 7) delay (2000) for decreasing tran1 : 29 .. 16 drawfillbox (0, 0, 1000, 1000, tran1) delay (100) end for exit %Click Start elsif Clicks = 1 and BoxX >= 350 and BoxX <= 450 and BoxY >= 500 and BoxY <= 550 then for decreasing tran3 : 31 .. 16 drawfillbox (0, 0, 1000, 1000, tran3) delay (50) end for delay (500) for tran4 : 16 .. 17 drawfillbox (0, 0, 1000, 1000, tran4) delay (50) end for After this, I want to create a 'click to continue' screen. The main character finishes talking and after they finish the user clicks on the screen anywhere and the next piece of dialog happens. However when I put clicks=1 it doesn't work because I believe that the clicks=1 is already being used to exit the game as shown in the title screen. Down below is my whole code : %GUI Import import GUI %Screen Dimensions setscreen ("graphics:1000;1000") %Sky Background drawfillbox (0, 0, 1000, 1000, 103) %Hills drawfilloval (100, 200, 300, 400, 48) drawfilloval (850, 200, 300, 375, 48) drawfilloval (500, 200, 300, 300, 47) %Cloud Left drawfilloval (20, 890, 100, 85, 0) drawfilloval (100, 865, 105, 80, 0) %Cloud Right drawfilloval (765, 875, 120, 80, 0) drawfilloval (700, 910, 100, 80, 0) drawfilloval (610, 875, 100, 80, 0) %Fonts var font, font2, font3, font4 : int font := Font.New ("Comic Sans MS:50:bold") font2 := Font.New ("Arial Black:70:bold") font3 := Font.New ("Comic Sans MS:20:bold") font4 := Font.New ("Comic Sans MS:30") %Welcome Screen Draw.Text ("Welcome to", 300, 725, font, 7) delay (1500) %Title Draw.Text ("Chick-A-Mania!", 150, 625, font2, 7) delay (500) Draw.Text ("Chick-A-Mania!", 150, 625, font2, 41) delay (500) %Start Button drawfillbox (360, 510, 450, 560, 8) drawbox (360, 510, 450, 560, 7) Draw.Text ("Start", 369, 525, font3, 7) %Exit Button drawfillbox (560, 510, 650, 560, 8) drawbox (560, 510, 650, 560, 7) Draw.Text ("Exit", 578, 525, font3, 7) %ClickExit var BoxX, BoxY, Clicks : int loop mousewhere (BoxX, BoxY, Clicks) locate (10, 10) if Clicks = 1 and BoxX >= 550 and BoxX <= 650 and BoxY >= 500 and BoxY <= 550 then drawfillbox (0, 0, 1000, 1000, 103) Draw.Text ("Shutting Down...", 250, 700, font, 7) delay (2000) for decreasing tran1 : 29 .. 16 drawfillbox (0, 0, 1000, 1000, tran1) delay (100) end for exit %Click Start elsif Clicks = 1 and BoxX >= 350 and BoxX <= 450 and BoxY >= 500 and BoxY <= 550 then for decreasing tran3 : 31 .. 16 drawfillbox (0, 0, 1000, 1000, tran3) delay (50) end for delay (500) for tran4 : 16 .. 17 drawfillbox (0, 0, 1000, 1000, tran4) delay (50) end for %Barn Transition drawfillbox (0, 0, 1000, 1000, 184) drawfillbox (420, 700, 580, 870, 52) drawfilloval (500, 870, 80, 80, 52) Draw.Arc (500, 870, 80, 80, 0, 90, 7) Draw.Arc (500, 870, 80, 80, 0, 180, 7) drawline (420, 700, 420, 870, 7) drawline (420, 700, 580, 700, 7) drawline (580, 700, 580, 870, 7) drawfillbox (0, 0, 1000, 510, 208) delay (15) drawfillbox (0, 0, 1000, 1000, 112) drawfillbox (420, 700, 580, 870, 53) drawfilloval (500, 870, 80, 80, 53) Draw.Arc (500, 870, 80, 80, 0, 90, 7) Draw.Arc (500, 870, 80, 80, 0, 180, 7) drawline (420, 700, 420, 870, 7) drawline (420, 700, 580, 700, 7) drawline (580, 700, 580, 870, 7) drawfillbox (0, 0, 1000, 510, 208) delay (15) drawfillbox (0, 0, 1000, 1000, 4) drawfillbox (420, 700, 580, 870, 54) drawfilloval (500, 870, 80, 80, 54) Draw.Arc (500, 870, 80, 80, 0, 90, 7) Draw.Arc (500, 870, 80, 80, 0, 180, 7) drawline (420, 700, 420, 870, 7) drawline (420, 700, 580, 700, 7) drawline (580, 700, 580, 870, 7) drawfillbox (0, 0, 1000, 510, 137) %Chicken drawfilloval (90, 515, 20, 20, 0) drawfilloval (100, 530, 20, 20, 4) drawfilloval (110, 495, 25, 15, 0) Draw.ThickLine (120, 440, 100, 450, 2, 42) Draw.ThickLine (120, 450, 100, 450, 2, 42) Draw.ThickLine (120, 445, 100, 450, 2, 42) Draw.ThickLine (130, 500, 100, 450, 2, 7) Draw.ThickLine (160, 450, 180, 440, 2, 42) Draw.ThickLine (160, 450, 180, 445, 2, 42) Draw.ThickLine (160, 450, 180, 450, 2, 42) Draw.ThickLine (160, 450, 130, 500, 2, 7) var BeakX : array 1 .. 3 of int := init (220, 140, 140) var BeakY : array 1 .. 3 of int := init (570, 600, 550) drawfillpolygon (BeakX, BeakY, 3, 42) drawfilloval (143, 608, 4, 10, 40) drawfilloval (143, 617, 10, 13, 40) drawfilloval (154, 612, 4, 10, 40) drawfilloval (154, 621, 10, 13, 40) drawfilloval (150, 540, 55, 65, 0) drawoval (175, 572, 10, 17, 7) drawfilloval (178, 577, 3, 3, 7) drawfilloval (120, 490, 26, 16, 0) drawfilloval (133, 488, 27, 16, 0) drawfilloval (87, 498, 8, 7, 0) drawfilloval (205, 545, 7, 10, 40) drawfilloval (205, 552, 5, 8, 40) drawoval (150, 525, 18, 27, 7) drawfillbox (120, 534, 180, 552, 0) drawline (150, 498, 150, 537, 7) drawline (140, 503, 140, 530, 7) drawline (160, 503, 160, 530, 7) %Text delay (1000) drawfillbox (50, 740, 950, 950, 0) drawbox (50, 740, 950, 950, 7) delay (115) Draw.Text ("O", 55, 900, font4, 7) delay (115) Draw.Text ("h", 84, 900, font4, 7) delay (115) Draw.Text (",", 105, 900, font4, 7) delay (115) Draw.Text ("n", 125, 900, font4, 7) delay (115) Draw.Text ("o", 145, 900, font4, 7) delay (115) Draw.Text ("!", 165, 900, font4, 7) delay (115) Draw.Text ("M", 185, 900, font4, 7) delay (115) Draw.Text ("r", 220, 900, font4, 7) delay (115) Draw.Text ("s", 240, 900, font4, 7) delay (115) Draw.Text (".", 258, 900, font4, 7) delay (115) Draw.Text ("C", 280, 900, font4, 7) delay (115) Draw.Text ("l", 305, 900, font4, 7) delay (115) Draw.Text ("u", 315, 900, font4, 7) delay (115) Draw.Text ("c", 335, 900, font4, 7) delay (115) Draw.Text ("k", 355, 900, font4, 7) delay (115) Draw.Text ("l", 375, 900, font4, 7) delay (115) Draw.Text ("e", 385, 900, font4, 7) delay (115) Draw.Text ("s", 409, 900, font4, 7) delay (115) Draw.Text ("'", 425, 900, font4, 7) delay (115) Draw.Text ("e", 450, 900, font4, 7) delay (115) Draw.Text ("g", 473, 900, font4, 7) delay (115) Draw.Text ("g", 495, 900, font4, 7) delay (115) Draw.Text ("s", 517, 900, font4, 7) delay (115) Draw.Text ("h", 555, 900, font4, 7) delay (115) Draw.Text ("a", 578, 900, font4, 7) delay (115) Draw.Text ("v", 598, 900, font4, 7) delay (115) Draw.Text ("e", 618, 900, font4, 7) delay (115) Draw.Text ("a", 655, 900, font4, 7) delay (115) Draw.Text ("l", 675, 900, font4, 7) delay (115) Draw.Text ("l", 685, 900, font4, 7) delay (115) Draw.Text ("g", 710, 900, font4, 7) delay (115) Draw.Text ("o", 730, 900, font4, 7) delay (115) Draw.Text ("n", 750, 900, font4, 7) delay (115) Draw.Text ("e", 770, 900, font4, 7) delay (115) Draw.Text ("m", 55, 850, font4, 7) delay (115) Draw.Text ("i", 85, 850, font4, 7) delay (115) Draw.Text ("s", 95, 850, font4, 7) delay (115) Draw.Text ("s", 115, 850, font4, 7) delay (115) Draw.Text ("i", 135, 850, font4, 7) delay (115) Draw.Text ("n", 145, 850, font4, 7) delay (115) Draw.Text ("g", 165, 850, font4, 7) delay (115) Draw.Text ("!", 185, 850, font4, 7) delay (115) Draw.Text ("P", 210, 850, font4, 7) delay (115) Draw.Text ("o", 230, 850, font4, 7) delay (115) Draw.Text ("o", 250, 850, font4, 7) delay (115) Draw.Text ("r", 270, 850, font4, 7) delay (115) Draw.Text ("M", 305, 850, font4, 7) delay (115) Draw.Text ("r", 340, 850, font4, 7) delay (115) Draw.Text ("s", 360, 850, font4, 7) delay (115) Draw.Text (".", 378, 850, font4, 7) delay (115) Draw.Text ("C", 400, 850, font4, 7) delay (115) Draw.Text ("l", 425, 850, font4, 7) delay (115) Draw.Text ("u", 435, 850, font4, 7) delay (115) Draw.Text ("c", 455, 850, font4, 7) delay (115) Draw.Text ("k", 475, 850, font4, 7) delay (115) Draw.Text ("l", 495, 850, font4, 7) delay (115) Draw.Text ("e", 505, 850, font4, 7) delay (115) Draw.Text ("s", 528, 850, font4, 7) delay (125) Draw.Text (".", 550, 850, font4, 7) delay (125) Draw.Text (".", 565, 850, font4, 7) delay (125) Draw.Text (".", 580, 850, font4, 7) delay (125) Draw.Text ("(Click to continue)", 700, 760, font3, 7) THE CLICK TO CONTINUE SHOULD BE HERE else end if end if end loop Help me fix the issue. Thanks! ![]() |
Author: | Insectoid [ Wed Jan 09, 2019 1:33 pm ] |
Post subject: | RE:Having a \'Click to continue\' inside a loop |
Mouse.Where returns the state of the mouse only at the time Mouse.Where is called. That information becomes out of date immediately, and the longer you wait to use it, the more wrong that information is, because the mouse is doing things. You've got your Mouse.Where way up at the top of the program, and your 'click to continue' way down at the bottom. That data is useless by the time we need it. So the obvious solution is to just call Mouse.Where again, immediately before we need it. If you are waiting for a specific state, for example the mouse button being depressed, you need to call Mouse.Where over and over again until you find the state you're looking for. |