Computer Science Canada

Question about dragging a picture:

Author:  Eulogy [ Mon Mar 29, 2004 10:59 am ]
Post subject:  Question about dragging a picture:

Hello everyone,
It's my first post, so I'm a little nervous.
I'm trying to create my first game, and I've encountered a problem.
My game idea is simple, a puzzle that the user reassembles.
My problem: I have the puzzle pieces in bitmaps, but I don't know how to implement them into my game.

What I need to happen:
The puzzle pieces need to be able to be clicked, and dragged around the screen freely. Can anyone reply with the source code needed to for 1 bitmap? I can do the rest.

Thank you.

Author:  Paul [ Mon Mar 29, 2004 11:55 am ]
Post subject: 

I'd say put the picture variables in arrays, make it so that you don't have to hold the mouse button to move it, like once you click it, you have to click it again to drop it. Update the position of the picture everytime the mouse button is clicked and the x and y is different, then when the user clicks again, it stays in the last recorded position.

Author:  guruguru [ Mon Mar 29, 2004 11:58 am ]
Post subject: 

Heres an idea...


setscreen ("nobuttonbar; offscreenonly; graphics")

var piece1 : int := Pic.FileNew (puzzlepiece1)     % Load your picutre
var height : int := Pic.Height (piece1)
var width : int := Pic.Width (piece1)
var x, y, button : int                             % The mouse variables

Pic.Draw (piece1, 50, 50, picMerger)               % Display your picture
View.Update                                        % Put pic on screen

    Mouse.Where (x, y, button)                     % Test where the mouse is
    if button = 1 and whatdotcolor not= 0 then     % If mouse is pressed and your not clicking white
        Pic.Draw (piece1, x + width div 2, y + height div 2)    % Draw the picutre again at mouse
        View.Update                                % Update the screen...
    end if
end loop

% And done...

Hope it helped... but I thinck that would only work for one piece, just put the x and y coordinates of the piece in an array, then update them when you move the pic.

Author:  Tony [ Mon Mar 29, 2004 3:07 pm ]
Post subject: 

I imagine it being something like

if b=1 then %button pressed
//ID what picture is picked up
   exit when b=0 %drag picture around while mouse is down
   picture(picID).x = x
   picture(picID).y = y
   end loop
end loop

I also sujest implementing a snap - that is, if the picture is within certain distance of the square, it gets snaped into it, so that user doesn't have to make per pixel adjustments in positioning