[Help] How to make objects move with mouse.
Author |
Message |
razrdude
|
Posted: Sun Oct 29, 2006 12:14 pm Post subject: [Help] How to make objects move with mouse. |
|
|
Hey Im making a shooter game for comp engineering class and i need some help in making this scope movable with the mouse.
code: |
%Scope casing
Draw.FillOval (55, 55, 55, 55, black)
Draw.FillOval (55, 55, 50, 50, white)
%Thick crosshair threads
Draw.ThickLine (55 - 50, 55, 55 - 35, 55, 3, black)
Draw.ThickLine (55 + 50, 55, 55 + 35, 55, 3, black)
Draw.ThickLine (55, 55 - 50, 55, 55 - 35, 3, black)
Draw.ThickLine (55, 55 + 50, 55, 55 + 35, 3, black)
%Thin threads
Draw.Line (35, 55, 45 + 30, 55, red)
Draw.Line (55, 55 - 20, 55, 40 + 35, red)
|
Any Help will be appreciated. So this object should move around with the mouse, ive seen this work before but didn't understand the coding behind it. Thanks  |
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
Tony

|
Posted: Sun Oct 29, 2006 12:21 pm Post subject: (No subject) |
|
|
First step is to draw it in terms of variables X and Y, instead of your static 55,55 center. This way if I change the variable's value, I'll be able to draw the scope anywhere.
Second is to put that all incide a procedure to make everything so much easier.
Lastly we grab our mouse position with Mouse.Where and pass values along to the procedure we've made above. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
 |
razrdude
|
Posted: Sun Oct 29, 2006 12:25 pm Post subject: (No subject) |
|
|
sorry to sound stupid, but i understood the first part, where they become variables, so you assign then to the mouse x, y? can you further explain the second part with the mouse position. idk if theres any other tut for this, if so please guide me |
|
|
|
|
 |
richcash
|
Posted: Sun Oct 29, 2006 1:37 pm Post subject: (No subject) |
|
|
Well, after you change everything you're drawing to x and y rather than (55, 55), you put it in a procedure.
code: | procedure draw (x, y : int)
%Put all your drawing here. Make sure it's in terms of x and y.
end draw |
Then, you make a loop and use the Mouse.Where (x, y, button) command to make the variables x and y the position of the mouse on the screen. Then call the draw procedure you made.
code: | loop
Mouse.Where (x, y, button) %button is a variable that checks if mouse is clicked
draw (x, y)
end loop |
And just remember to make your variables -- x, y and button -- which should be of type int. |
|
|
|
|
 |
razrdude
|
Posted: Sun Oct 29, 2006 1:52 pm Post subject: (No subject) |
|
|
umm I tried what you said, and the scope follows the mouse, but it leaves a imprint and is flashing like crazy.
Try this and explain?
code: | import GUI
setscreen("graphics:1000;600")
var x, y, button : int
procedure draw (x, y : int)
%Scope casing
Draw.FillOval (x, y, 55, 55, black)
Draw.FillOval (x, y, 50, 50, white)
%Thick crosshair threads
Draw.ThickLine (x - 50, y, x - 35, y, 3, black)
Draw.ThickLine (x + 50, y, x + 35, y, 3, black)
Draw.ThickLine (x, y - 50, x, y - 35, 3, black)
Draw.ThickLine (x, y + 50, x, y + 35, 3, black)
%Thin threads
Draw.Line (x, y, x + 30, y, red)
Draw.Line (x, y - 20, x, y + 35, red)
end draw
loop
Mouse.Where (x, y, button) %button is a variable that checks if mouse is clicked
draw (x, y)
end loop |
|
|
|
|
|
 |
Ultrahex
|
Posted: Sun Oct 29, 2006 1:55 pm Post subject: (No subject) |
|
|
First Of All, Your Not Clearing the Screen
command to clear screen is CLS
second of all, there is no second buffer, so it draws each line directly to screen, you need to do a buffer frame,
See View.Update
and View.Set("offscreenonly")
Hopefully that helps (there is tutorials on these in Turing Tutorials) |
|
|
|
|
 |
razrdude
|
Posted: Sun Oct 29, 2006 2:00 pm Post subject: (No subject) |
|
|
Really sorry about double posting, but I figured out the trail part, I added a cls but now to get the flickering away I know I need to use View.Set ("offscreenonly") and View.Update but I don't know how to properly incorporate them.
Yet again thanks for all the help
code: | import GUI
setscreen("graphics:1000;600")
var x, y, button : int
procedure draw (x, y : int)
%Scope casing
Draw.FillOval (x, y, 55, 55, black)
Draw.FillOval (x, y, 50, 50, white)
%Thick crosshair threads
Draw.ThickLine (x - 50, y, x - 35, y, 3, black)
Draw.ThickLine (x + 50, y, x + 35, y, 3, black)
Draw.ThickLine (x, y - 50, x, y - 35, 3, black)
Draw.ThickLine (x, y + 50, x, y + 35, 3, black)
%Thin threads
Draw.Line (x, y, x + 30, y, red)
Draw.Line (x, y - 20, x, y + 35, red)
end draw
loop
Mouse.Where (x, y, button) %button is a variable that checks if mouse is clicked
draw (x, y)
cls
end loop |
|
|
|
|
|
 |
Ultrahex
|
Posted: Sun Oct 29, 2006 2:05 pm Post subject: (No subject) |
|
|
Well when you do..
View.Set("offscreenonly")
It Makes all the draw commands go to and offscreen buffer.
and when you do View.Update
it draws the offscreen buffer to the screen.
Hopefully you can take this information and figure out the rest  |
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
razrdude
|
Posted: Sun Oct 29, 2006 2:17 pm Post subject: (No subject) |
|
|
YESS, I got it, I fixed the lengths of the thin threads and now it seems perfect, Now to make targets of somewhat add a background and get my buttons working. Imma look around
Btw heres the latest code
code: | import GUI
setscreen("graphics:1000;600")
var x, y, button : int
procedure draw (x, y : int)
View.Set("offscreenonly")
%Scope casing
Draw.FillOval (x, y, 55, 55, black)
Draw.FillOval (x, y, 50, 50, white)
%Thick crosshair threads
Draw.ThickLine (x - 50, y, x - 35, y, 3, black)
Draw.ThickLine (x + 50, y, x + 35, y, 3, black)
Draw.ThickLine (x, y - 50, x, y - 35, 3, black)
Draw.ThickLine (x, y + 50, x, y + 35, 3, black)
%Thin threads
Draw.Line (x - 20, y, x + 20, y, red)
Draw.Line (x, y - 20, x, y + 20, red)
View.Update
end draw
loop
Mouse.Where (x, y, button) %button is a variable that checks if mouse is clicked
draw (x, y)
cls
end loop
|
|
|
|
|
|
 |
|
|