Computer Science Canada is it possible |
| Author: | susan_101 [ Sun Jan 16, 2005 3:49 pm ] |
| Post subject: | is it possible |
hi i was wondering if i could make different coloured circles fly around while the user has to click on them to earn point sor sumthing. th ekey thing is that the different coloured balls equals different points. is this possible? |
|
| Author: | Bacchus [ Sun Jan 16, 2005 3:54 pm ] |
| Post subject: | |
yes it is possible and i am pretty sure ive seen a similar looking one like you described on these forums (but they were squares). i would do a check to see if the mouse is down (Mouse.Where) and then check the color of that spot(whatdotcolor) then just use randint to get the starting positions and colors of the blocks |
|
| Author: | susan_101 [ Sun Jan 16, 2005 4:17 pm ] |
| Post subject: | |
hmm how would i get random number of different dots to fly across? i have to make each dot first, then wat? |
|
| Author: | Leftover [ Sun Jan 16, 2005 5:19 pm ] | ||
| Post subject: | |||
to generate them randomly:
the 10 is the number of circles to draw, it will create random locations for those 10 circles and make them random sizes. |
|||
| Author: | susan_101 [ Sun Jan 16, 2005 6:10 pm ] |
| Post subject: | |
so i have to loop them or something to get them moving? |
|
| Author: | Leftover [ Sun Jan 16, 2005 6:26 pm ] |
| Post subject: | |
How many do you need? |
|
| Author: | susan_101 [ Sun Jan 16, 2005 7:02 pm ] |
| Post subject: | |
well i want six different circles to move, bu ti dun care how many come onto the screen |
|
| Author: | Cervantes [ Sun Jan 16, 2005 7:03 pm ] |
| Post subject: | |
susan_101 wrote: so i have to loop them or something to get them moving?
You're going to have a main loop, as most programs do. Inside that main loop, you'll have a for loop. This for loop will move and draw all your circles. The thing is, you need to keep information on your circles. Do this with an array. |
|
| Author: | susan_101 [ Sun Jan 16, 2005 7:38 pm ] |
| Post subject: | |
cervantes how can i put all the information about the colour and where the circles goes in an array? |
|
| Author: | Cervantes [ Sun Jan 16, 2005 7:52 pm ] | ||
| Post subject: | |||
I'm assuming the colour of the square is related to it's location and is not random. If so, find some mathematical method to allocate colours. If that fails, hardcode it or get information from a file. "Where the circle goes" is most definately linked to the location. Actually, after thinking about your question, I've discovered another question from that sentance, which may or may not be what you originally intended. Do you mean, "how can I store lots of information in an array? It's difficult because I can only assign each element of the array one value." If so, records will help you.
As for x and y: element (1,1) of your array should have an x value of 1 and a y value of 1. Element (4, 2) of your array should have an x value of 4 and a y value of 2. Do all your manipulation and such with incriments of 1 between the grid squares of your board. Mind you, when it comes time to draw it, multiply everything by a constant (say, 50); if you don't, things will be mighty small Hope you understood that, -Cervantes |
|||
| Author: | susan_101 [ Sun Jan 16, 2005 8:03 pm ] |
| Post subject: | |
can yu show me a simple program of 3 different coloured circles flying across the screen cervantes? |
|
| Author: | Cervantes [ Sun Jan 16, 2005 8:25 pm ] | ||
| Post subject: | |||
Sure, how about an overly complicated version, though? They're always good for the learning!
Things get really fun when we start to work with collision between the circles. -Cervantes |
|||
| Author: | susan_101 [ Sun Jan 16, 2005 8:34 pm ] |
| Post subject: | |
wow ur amazing mousewhere (mX, mY, btn) if mX > objX and mX < objX + objWidth and mY > objY and mY < objY + objHeight and btn not= 0 then flag := false end if if flag then drawobject end if ? |
|
| Author: | Cervantes [ Sun Jan 16, 2005 8:45 pm ] |
| Post subject: | |
Close. First, if you're going to use obj instead of circle, remember that you're going to have to do it in a procedure, similar to the move and draw procedures. Second, right now, we've got ovals, not boxes. Ovals are drawn with their centre at (x,y), whereas boxes are drawn with their bottom left corner at (x,y). So, you're mouse detection would be a little off. That's, easily fixed, mind you. But, even if you fixed that up, you'd really be detecting for a box, not a circle. To detect with a circle, use Math.Distance (mX, mY, obj.x, obj.y). Check if that Math.Distance returns a value that is less than or equal to the radius of the circle. If it has, the mouse is over top of the circle. (note that if you don't have Turing 4.0.5, you can make your own distance function). Lastly, don't for get the period '.' between obj and any of it's fields (such as x, y, vx, etc.). Lastly, if you want to go even further over the top, you could make your type object a flexible array and remove elements when they are clicked. That's better than just not drawing them. If you use a flag and simply don't draw them, they are still there, and their movement is still being calculated. Consider if we got the balls bouncing off of each other. When you click on a ball, you stop drawing it, but it would still affect the ball's around it when they collide. Of course, we could wrap the collision code in an if flag then statement, but having these if flag then statements all through your program has got to be annoying! -Cervantes |
|
| Author: | susan_101 [ Sun Jan 16, 2005 8:51 pm ] |
| Post subject: | |
lol ok flexy arrays are liek out of my league im only 1st yr turing user |
|