Remember that if you modify the value of a global variable within the local scope of a function, you need to include global variable_name within that function. Otherwise, your program might run but not work as intended.
Make sure to save your work frequently in a .py file in case your web browser closes or gets refreshed. To do this, press the βSaveβ button then the βDownloadβ button on the Codeskulptor 3 main web page.
Remove the message variable and add two global variables; one to hold the time and one to hold the increment value (how fast the timer changes). Set both of these to 0 initially.
Edit the draw function so that it will draw the time variable on the canvas. Use the round() function so your time variable only prints to 2 decimal places. In addition to displaying the time, you will also need to update the time in draw, using the increment variable.
one list to hold the targetβs current location (stored as a 2 item list of x and y coordinates). Assign its initial value to 250,150 (the center of the canvas) for now.
Draw four circles using the global list variable for coordinates, a line width of 1, a line colour of black, and various fill colours, as shown below. The largest circle should have a radius of 30, the other circles should have radii of 22, 15 and 8.
Next, draw two lines (look at the same documentation, but the section on drawing a line segment). The lines should intersect the circle centers horizontally and vertically.
Lastly, at the bottom of your program, add the frame.set_draw_handler() and frame.start() commands. When you run this, the canvas should look like the image (below) after the start button is pressed.
Create two global integer variables, one to increment the x direction of the target and one to increment the y direction (assign them number values between 0 and 5).
Inside the conditional in the draw() function, after you draw the target, add code to increment the targetβs x and y coordinates stored in the coordinate list.
Now we need to make sure the target stays on the canvas. Add if statements that check if the targetβs x or y coordinate has gone outside the canvas width or height.
Write an if statement that checks whether the current x coordinate is less than the radius of the target OR greater than the width of the window minus the radius. If either of these conditions is true, reverse the direction of the x increment variable by multiplying it by -1.
Repeat the above sub-step for the y coordinate, checking to see if the current y is less than the radius or greater than the height of the window minus the radius. If either condition is true, multiply the y increment variable by -1.
We want to check if the mouse has clicked on the target. To do this, you need to check if the x click location is between target_x - radius and target_x + radius, and if the y click location is between target_y - radius and target_y + radius. If so, change the global boolean flag so the game stops and print out a winning message.
Below is a video of a similar program that prints a message to the console based on the position of a mouse click. You are NOT required to include these changes.