
-----------------------------------
susan_101
Sun Jan 16, 2005 3:49 pm

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?

-----------------------------------
Bacchus
Sun Jan 16, 2005 3:54 pm


-----------------------------------
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

-----------------------------------
susan_101
Sun Jan 16, 2005 4:17 pm


-----------------------------------
hmm how would i get random number of different dots to fly across?
i have to make each dot first, then wat?

-----------------------------------
Leftover
Sun Jan 16, 2005 5:19 pm


-----------------------------------
to generate them randomly:


var x, x2, y, y2 : int

for i : 1 .. 10
    randint (x, 0, 400)
    randint (x2, 0, 25)
    randint (y, 0, 400)
    randint (y2, 0, 25)
    Draw.FillOval (x, y, x2, y2, 255)
end for


the 10 is the number of circles to draw, it will create random locations for those 10 circles and make them random sizes.

-----------------------------------
susan_101
Sun Jan 16, 2005 6:10 pm


-----------------------------------
so i have to loop them or something to get them moving?

-----------------------------------
Leftover
Sun Jan 16, 2005 6:26 pm


-----------------------------------
How many do you need?

-----------------------------------
susan_101
Sun Jan 16, 2005 7:02 pm


-----------------------------------
well i want six different circles to move, bu ti dun care how many come onto the screen

-----------------------------------
Cervantes
Sun Jan 16, 2005 7:03 pm


-----------------------------------
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 [url=http://www.compsci.ca/v2/viewtopic.php?t=366]array.

-----------------------------------
susan_101
Sun Jan 16, 2005 7:38 pm


-----------------------------------
cervantes how can i put all the information about the colour and where the circles  goes in an array?

-----------------------------------
Cervantes
Sun Jan 16, 2005 7:52 pm


-----------------------------------
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. :P  

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, 
var grid : array 1 .. 8, 1 .. 8 of
  record
    colour : int
    other_information : string
    even_more_information : real
  end record

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 :lol:
Hope you understood that,
-Cervantes

-----------------------------------
susan_101
Sun Jan 16, 2005 8:03 pm


-----------------------------------
can yu show me a simple program of 3 different coloured circles flying across the screen cervantes?  :wink:

-----------------------------------
Cervantes
Sun Jan 16, 2005 8:25 pm


-----------------------------------
Sure, how about an overly complicated version, though?  They're always good for the learning! :D


setscreen ("offscreenonly")
type object : array 1 .. 3 of
    record
        x : int
        y : int
        vx : int
        vy : int
        radius : int
        clr : int
    end record


proc initObj (var obj : object, i, x, y, vx, vy, radius, clr : int)
    obj (i).x := x
    obj (i).y := y
    obj (i).vx := vx
    obj (i).vy := vy
    obj (i).radius := radius
    obj (i).clr := clr
end initObj

proc moveObj (var obj : object, i, boundaryLeft, boundaryBottom, boundaryRight, boundaryTop : int)
    obj (i).x += obj (i).vx
    obj (i).y += obj (i).vy
    if obj (i).x + obj (i).radius > boundaryRight or obj (i).x - obj (i).radius < boundaryLeft then
        obj (i).vx *= -1
    end if
    if obj (i).y + obj (i).radius > boundaryTop or obj (i).y - obj (i).radius < boundaryBottom then
        obj (i).vy *= -1
    end if
end moveObj

proc drawObj (var obj : object, i : int)
    drawfilloval (obj (i).x, obj (i).y, obj (i).radius, obj (i).radius, obj (i).clr)
end drawObj

var circle : object
for i : 1 .. upper (object)
    initObj (circle, i, Rand.Int (0, maxx), Rand.Int (0, maxy), Rand.Int (-3, 3), Rand.Int (-3, 3), Rand.Int (5, 25), Rand.Int (1, 15))
end for

loop
    for i : 1 .. upper (object)
        moveObj (circle, i, 0, 0, maxx, maxy)
    end for

    cls
    for i : 1 .. upper (object)
        drawObj (circle, i)
    end for
    View.Update
    delay (10)

end loop


Things get really fun when we start to work with collision between the circles.
-Cervantes

-----------------------------------
susan_101
Sun Jan 16, 2005 8:34 pm


-----------------------------------
wow ur amazing :D  so if i wanted the mouse to be able to click these circles i woudl put 



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 


?

-----------------------------------
Cervantes
Sun Jan 16, 2005 8:45 pm


-----------------------------------
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

-----------------------------------
susan_101
Sun Jan 16, 2005 8:51 pm


-----------------------------------
lol ok flexy arrays are liek out of my league im only 1st yr turing user  :cry:
