
-----------------------------------
Prince Pwn
Fri Nov 03, 2006 12:51 pm

Array of Boxes
-----------------------------------
Is there a way so I can make the boxes keep up with my mouse? If you hold down the left mouse button and drag a box to the side really fast it stops holding. 

And how could I fix it so when I drag one box over another, the bottom box doesn't dissapear?


Mouse.ButtonChoose ("multibutton")
View.Set ("graphics:1000,600;offscreenonly")

var x, y, button, rad, col, boxNum : int
boxNum := 15 %number of boxes
rad := 30 %size of boxes

var boxX, boxY : array 1 .. boxNum of int %makes variables for each box
col := Rand.Int (0, 255) %sets default colour

for i : 1 .. boxNum %positions all the boxes
    boxX (i) := 0 + i * rad
    boxY (i) := maxy div 2
end for

loop
    Mouse.Where (x, y, button)

    %makes it so boxes can't go offscreen
    if x = maxx - rad div 2 then
        x := maxx - rad div 2
    end if
    if y = maxy - rad div 2 then
        y := maxy - rad div 2
    end if

    for i : 1 .. boxNum %draws each box and checks their values
        drawfillbox (boxX (i), boxY (i), boxX (i) + rad, boxY (i) + rad, col)
        drawbox (boxX (i), boxY (i), boxX (i) + rad, boxY (i) + rad, black)
        if button = 1 and x > boxX (i) and x < boxX (i) + rad
                and y > boxY (i) and y < boxY (i) + rad then
            %checks if you left click on any of the boxes
            boxX (i) := x - rad div 2
            boxY (i) := y - rad div 2
        elsif button = 10 then
            boxX (i) := x - rad div 2
            boxY (i) := y - rad div 2
        end if
        col := Rand.Int (0, 255) %makes the boxes flash
    end for

    View.Update
    cls
end loop


-----------------------------------
Clayton
Fri Nov 03, 2006 4:40 pm


-----------------------------------
The reason the box doesn't "stick" to the mouse is because your computer can't keep up with so many things working in the background (especially with Turing running :?) and therefore ends up delaying certain things from running while it trys to run everything else, so your turing program ends up lagging, and the box can't keep up with the mouse.

-----------------------------------
Piro24
Fri Nov 03, 2006 5:36 pm


-----------------------------------
If is all you want to do is draw something along with the mouse, it's simple.

Use your Mouse.Where co ords (x,y,b)
and plug them into the variables of the box
ex.

Mouse.Where (x,y,b)
if b = 1 then
drawoval (x,y,20,20black)
end if

-----------------------------------
Prince Pwn
Sat Nov 04, 2006 10:33 am


-----------------------------------
Oh and I realised the reason why the box below the one dragged disappears, it doesn't really dissapear. It just hides ontop or goes underneath the box being dragged due to "if mouse touches box then locate middle of box on mouse pointer", found this out by looking at my updated code... But I wonder how I should solve it...


Mouse.ButtonChoose ("multibutton")
View.Set ("graphics:1000,600;offscreenonly")

var x, y, button, rad, col, boxNum, fSize : int
boxNum := 15 %number of boxes
rad := 50 %size of boxes
View.Set ("title:BoxMove " + intstr (rad))

if rad > 50 then
    fSize := 10
elsif rad > 35 and rad  24 and rad  boxX (i) and x < boxX (i) + 50 and y > boxY (i) and y < boxY (i) + 50 then
                clicked := i
                buttonUp := false
            end if
        end for
    elsif button = 0 then
        clicked := 0
        buttonUp := true
    end if
    if clicked not= 0 then
        boxX (clicked) := x - 25
        boxY (clicked) := y - 25
    end if
    for i : 1 .. 12
        Draw.FillBox (boxX (i), boxY (i), boxX (i) + 50, boxY (i) + 50, Rand.Int (0, 255))
    end for
    View.Update
    delay (5)
    cls
end loop

-----------------------------------
Prince Pwn
Sat Nov 04, 2006 1:06 pm


-----------------------------------
Sweet idea. And yours runs like 10x faster too and it doesn't clear when you overlap =)

-----------------------------------
Prince Pwn
Sat Nov 04, 2006 1:12 pm


-----------------------------------
Wait, what is slowing mine down?

-----------------------------------
richcash
Sat Nov 04, 2006 1:44 pm


-----------------------------------
I don't think mine is any faster, I even delayed it by 5. It's just that your first code only works when you go slow with the mouse (so it gives the illusion of being slow). Your second code has so much text, font and input slowing it down, and it also only works when you go slow. So I just think mine looks faster because it works.

Make sure you understand that code, otherwise it's useless to you! :wink:
