Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Clickable images which will give points

Author
Message
RhysClarke
12
Years of Service
User Offline
Joined: 21st Jun 2012
Location:
Posted: 21st Jun 2012 13:37


Hello im trying to make a little game which i want a red square to appear in random places and you have to click it but im stuck how to do this. The first step is to load the image then the user has 5 seconds to click it then another red square to appear how would i do this?
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 21st Jun 2012 21:21 Edited at: 21st Jun 2012 21:32
Hello,

Basically, you need 2 things:

1. A timer of some sort to wait for the click
2. The screen position and dimensions of the square

The code that follows has the idea. It uses 2 subroutines (blocks of code that can be jumped to and returned from) to control the drawing and placement of the square. The Subroutines are basically psuedocode so you will have to put in the "real" code to get them to work.



_place_square gets the new screen position of the square whenever you want to change it's location.

_draw_square draws the image with the new coordinates created by _place_square.

In the main loop, there is a While Endwhile loop that checks if a certain amount of time has passed (5 secs). If you click the LEFT button of the mouse, the next check is to see if the click occurs within the screen dimensions that were set up when _place_square was last called. If it was, and it was within the 5 secs, then it jumps to the _get_points routine and increases the points, exits out of the While loop and then chooses another screen location for the block.

The framework is there, it's up to you to fill in the blanks.

And just an extra note, random screen positions can be gotten using the rnd() command and the screen sizes:

randomx = rnd(screen width())
randomy = rnd(screen height())

Enjoy your day.

Login to post a reply

Server time is: 2024-11-24 19:11:42
Your offset time is: 2024-11-24 19:11:42