Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 is it possible
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
susan_101




PostPosted: 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?
Sponsor
Sponsor
Sponsor
sponsor
Bacchus




PostPosted: Sun Jan 16, 2005 3:54 pm   Post subject: (No 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
susan_101




PostPosted: Sun Jan 16, 2005 4:17 pm   Post subject: (No subject)

hmm how would i get random number of different dots to fly across?
i have to make each dot first, then wat?
Leftover




PostPosted: Sun Jan 16, 2005 5:19 pm   Post subject: (No subject)

to generate them randomly:

code:

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




PostPosted: Sun Jan 16, 2005 6:10 pm   Post subject: (No subject)

so i have to loop them or something to get them moving?
Leftover




PostPosted: Sun Jan 16, 2005 6:26 pm   Post subject: (No subject)

How many do you need?
susan_101




PostPosted: Sun Jan 16, 2005 7:02 pm   Post subject: (No subject)

well i want six different circles to move, bu ti dun care how many come onto the screen
Cervantes




PostPosted: Sun Jan 16, 2005 7:03 pm   Post subject: (No 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.
Sponsor
Sponsor
Sponsor
sponsor
susan_101




PostPosted: Sun Jan 16, 2005 7:38 pm   Post subject: (No subject)

cervantes how can i put all the information about the colour and where the circles goes in an array?
Cervantes




PostPosted: Sun Jan 16, 2005 7:52 pm   Post subject: (No 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. Razz

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.
Turing:

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 Laughing
Hope you understood that,
-Cervantes
susan_101




PostPosted: Sun Jan 16, 2005 8:03 pm   Post subject: (No subject)

can yu show me a simple program of 3 different coloured circles flying across the screen cervantes? Wink
Cervantes




PostPosted: Sun Jan 16, 2005 8:25 pm   Post subject: (No subject)

Sure, how about an overly complicated version, though? They're always good for the learning! Very Happy

Turing:

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




PostPosted: Sun Jan 16, 2005 8:34 pm   Post subject: (No subject)

wow ur amazing Very Happy 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




PostPosted: Sun Jan 16, 2005 8:45 pm   Post subject: (No 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
susan_101




PostPosted: Sun Jan 16, 2005 8:51 pm   Post subject: (No subject)

lol ok flexy arrays are liek out of my league im only 1st yr turing user Crying or Very sad
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 15 Posts ]
Jump to:   


Style:  
Search: