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

Username:   Password: 
 RegisterRegister   
 Need Quick Help...
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Piro24




PostPosted: Mon Oct 16, 2006 6:43 pm   Post subject: Need Quick Help...

Well, there are obviously much better ways of doing this (or so I would assume), but we are doing a lesson in Mouse.Where in my class, and so I am trying to apply some knowledge...I want help in how to make the scope to follow the mouse better...As of now it lags behind if I move the mouse too fast.

Quote:

var Maxx : int := maxx div 2
var Maxy : int := maxy div 2
var MaxxD2A6 : int := maxx div 2 + 6
var MaxxD2S6 : int := maxx div 2 - 6
var MaxxD2A40 : int := maxx div 2 + 35
var MaxxD2S40 : int := maxx div 2 - 35
var MaxyD2A6 : int := maxy div 2 + 6
var MaxyD2S6 : int := maxy div 2 - 6
var MaxyD2A40 : int := maxy div 2 + 35
var MaxyD2S40 : int := maxy div 2 - 35
var x, y, b : int
loop
Draw.FillOval (Maxx, Maxy, 28, 28, black)
Draw.FillOval (Maxx, Maxy, 24, 24, white)
Draw.ThickLine (MaxxD2A6, Maxy, MaxxD2A40, Maxy, 2, black)
Draw.ThickLine (MaxxD2S6, Maxy, MaxxD2S40, Maxy, 2, black)
Draw.ThickLine (Maxx, MaxyD2A6, Maxx, MaxyD2A40, 2, black)
Draw.ThickLine (Maxx, MaxyD2S6, Maxx, MaxyD2S40, 2, black)
Draw.FillOval (Maxx, Maxy, 3, 3, brightred)
Draw.Oval (Maxx, Maxy, 6, 6, black)
Mouse.Where (x, y, b)
setscreen ("offscreenonly")
View.Update
if b = 0 and x > Maxx then
Maxx := Maxx + 1
MaxxD2A6 := MaxxD2A6 + 1
MaxxD2A40 := MaxxD2A40 + 1
MaxxD2S6 := MaxxD2S6 + 1
MaxxD2S40 := MaxxD2S40 + 1
cls
end if
if b = 0 and x < Maxx then
Maxx := Maxx - 1
MaxxD2A6 := MaxxD2A6 - 1
MaxxD2A40 := MaxxD2A40 - 1
MaxxD2S6 := MaxxD2S6 - 1
MaxxD2S40 := MaxxD2S40 - 1
cls
end if
if b = 0 and y > Maxy then
Maxy := Maxy + 1
MaxyD2A6 := MaxyD2A6 + 1
MaxyD2A40 := MaxyD2A40 + 1
MaxyD2S6 := MaxyD2S6 + 1
MaxyD2S40 := MaxyD2S40 + 1
cls
end if
if b = 0 and y < Maxy then
Maxy := Maxy - 1
MaxyD2A6 := MaxyD2A6 - 1
MaxyD2A40 := MaxyD2A40 - 1
MaxyD2S6 := MaxyD2S6 - 1
MaxyD2S40 := MaxyD2S40 - 1
cls
end if
end loop
Sponsor
Sponsor
Sponsor
sponsor
Windsurfer




PostPosted: Mon Oct 16, 2006 7:03 pm   Post subject: (No subject)

Well, to begin with, if you want it to follow "better" why not just always be where the mouse is?
And press F2 on the keyboard. It makes it easier to read.
And make your variables names better. It makes it easier to read for us people.
And make variables that are always going to be a certain distance from other variables... well, not variables. Make them constants, and then use them in your code like "x + LINE_X_DISTANCE"
And if you're testing the same thing for a bunch of if statements, make a parent if statement that tests that one thing once:
code:

if b=0 then
 if this then
 end if
 if that then
end if

And good job for using the OO Draw.Oval and such Laughing
Piro24




PostPosted: Mon Oct 16, 2006 7:10 pm   Post subject: (No subject)

Thanks for the reply...I didn't want to make the variables and such like that, infact, I think it was pretty dumb. But I was in a hurry, so just made a little system out of naming the variables for my self.

Quote:
Well, to begin with, if you want it to follow "better" why not just always be where the mouse is?

That's where I'm having some problems...After messing around some more, I got this...It seems to work better Surprised

It's probablly terrible in the 'coding world' but I was just messging around for a game I plan on making the the future...

code:

var Maxx : int := maxx div 2
var Maxy : int := maxy div 2
var MaxxD2A6 : int := maxx div 2 + 6
var MaxxD2S6 : int := maxx div 2 - 6
var MaxxD2A40 : int := maxx div 2 + 35
var MaxxD2S40 : int := maxx div 2 - 35
var MaxyD2A6 : int := maxy div 2 + 6
var MaxyD2S6 : int := maxy div 2 - 6
var MaxyD2A40 : int := maxy div 2 + 35
var MaxyD2S40 : int := maxy div 2 - 35
var x, y, b : int
loop
    Draw.FillOval (Maxx, Maxy, 28, 28, black)
    Draw.FillOval (Maxx, Maxy, 24, 24, white)
    Draw.ThickLine (MaxxD2A6, Maxy, MaxxD2A40, Maxy, 2, black)
    Draw.ThickLine (MaxxD2S6, Maxy, MaxxD2S40, Maxy, 2, black)
    Draw.ThickLine (Maxx, MaxyD2A6, Maxx, MaxyD2A40, 2, black)
    Draw.ThickLine (Maxx, MaxyD2S6, Maxx, MaxyD2S40, 2, black)
    Draw.FillOval (Maxx, Maxy, 3, 3, brightred)
    Draw.Oval (Maxx, Maxy, 6, 6, black)
    Mouse.Where (x, y, b)
    setscreen ("offscreenonly")
    View.Update
    if b = 0 and x > Maxx then
        Maxx := x
        MaxxD2A6 := x + 6
        MaxxD2A40 := x + 40
        MaxxD2S6 := x - 6
        MaxxD2S40 := x - 40
        cls
    end if
    if b = 0 and x < Maxx then
        Maxx := x
        MaxxD2A6 := x + 6
        MaxxD2A40 := x + 40
        MaxxD2S6 := x - 6
        MaxxD2S40 := x - 40
        cls
    end if
    if b = 0 and y > Maxy then
        Maxy := y
        MaxyD2A6 := y + 6
        MaxyD2A40 := y + 40
        MaxyD2S6 := y - 6
        MaxyD2S40 := y - 40
        cls
    end if
    if b = 0 and y < Maxy then
        Maxy := y
        MaxyD2A6 := y + 6
        MaxyD2A40 := y + 40
        MaxyD2S6 := y - 6
        MaxyD2S40 := y - 40
        cls
    end if
end loop
[/quote]
Windsurfer




PostPosted: Mon Oct 16, 2006 7:22 pm   Post subject: (No subject)

you know what? you're fine. I was worse than that the year before last. Everyone can learn, as long as they have a little passion.
Anyways, here's an upgraded version of yours:
code:

var Maxx : int := maxx div 2
var Maxy : int := maxy div 2
var MaxxD2A6 : int := maxx div 2 + 6
var MaxxD2S6 : int := maxx div 2 - 6
var MaxxD2A40 : int := maxx div 2 + 35
var MaxxD2S40 : int := maxx div 2 - 35
var MaxyD2A6 : int := maxy div 2 + 6
var MaxyD2S6 : int := maxy div 2 - 6
var MaxyD2A40 : int := maxy div 2 + 35
var MaxyD2S40 : int := maxy div 2 - 35
var x, y, b : int
loop
    Draw.FillOval (Maxx, Maxy, 28, 28, black)
    Draw.FillOval (Maxx, Maxy, 24, 24, white)
    Draw.ThickLine (MaxxD2A6, Maxy, MaxxD2A40, Maxy, 2, black)
    Draw.ThickLine (MaxxD2S6, Maxy, MaxxD2S40, Maxy, 2, black)
    Draw.ThickLine (Maxx, MaxyD2A6, Maxx, MaxyD2A40, 2, black)
    Draw.ThickLine (Maxx, MaxyD2S6, Maxx, MaxyD2S40, 2, black)
    Draw.FillOval (Maxx, Maxy, 3, 3, brightred)
    Draw.Oval (Maxx, Maxy, 6, 6, black)
    Mouse.Where (x, y, b)
    setscreen ("offscreenonly")
    View.Update
    if b = 0 then
        Maxx := x
        MaxxD2A6 := x + 6
        MaxxD2A40 := x + 35
        MaxxD2S6 := x - 6
        MaxxD2S40 := x - 35
        Maxy := y
        MaxyD2A6 := y + 6
        MaxyD2A40 := y + 35
        MaxyD2S6 := y - 6
        MaxyD2S40 := y - 35
        cls
    end if
end loop
Piro24




PostPosted: Mon Oct 16, 2006 7:33 pm   Post subject: (No subject)

Ok, thanks for the help. Much appreciated.

I guess this thread can be closed.
neufelni




PostPosted: Mon Oct 16, 2006 8:32 pm   Post subject: (No subject)

You really don't need all of those variables. Here is a better version of it, much shorter.
code:

setscreen ("offscreenonly")
var x, y, b : int
loop
    Mouse.Where (x, y, b)
    Draw.FillOval (x, y, 28, 28, black)
    Draw.FillOval (x, y, 24, 24, white)
    Draw.ThickLine (x + 6, y, x + 40, y, 2, black)
    Draw.ThickLine (x - 6, y, x - 40, y, 2, black)
    Draw.ThickLine (x, y + 6, x, y + 40, 2, black)
    Draw.ThickLine (x, y - 6, x, y - 40, 2, black)
    Draw.FillOval (x, y, 3, 3, brightred)
    Draw.Oval (x, y, 6, 6, black)
    View.Update
    cls
end loop
Piro24




PostPosted: Mon Oct 16, 2006 9:46 pm   Post subject: (No subject)

Wow Nick...That just put a lot into perspective to me...I didn't get that first time, and I started overthinking...Thanks a lot.
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  [ 7 Posts ]
Jump to:   


Style:  
Search: