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

Username:   Password: 
 RegisterRegister   
 Lines, and time.
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Prognosis




PostPosted: Sat Jan 21, 2006 11:10 pm   Post subject: Lines, and time.

Well, im new to these forums, but i consider myself a fast learner, and am using turing for my first few months. Ive already made my program so it makes a line from the center of the screen to where you click, and it keeps going. I did this by finding out the equation of the line (using the center point, and where you clicked), and drew the line pixel by pixel. BUT..
There are many bugs, such as:
1. the speed of the line getting drawn changes in comparison to where you click.
2: in some places (when xclick and centerx are closer together), it isnt a line, but a series of dots.
Those 2 errors sound weird now, but they will become more clear when the program is run. Please help me to fix these bugs. Also, help me to enable you to shoot more than one line out at once (this is because these lines are accually lazers for my new game)


code:
var m, b, xl, yl : real
var x, y, button, x2, y2, rol : int
const xm := maxx div 2
const ym := maxy div 2

m := 0
b := 0
xl := xm
yl := ym
x := 0
y := 0
x2 := 0
y2 := 0
%right or left.. right=1, left=2,equal=middle
rol := 0
loop
loop
    mousewhere (x, y, button)
    if button = 1 then
        %putting current values for your mouse into new variables
        x2 := x
        y2 := y
        %finding out the slope(m) and y intercept(b) for your line.
        if x2=xm then
        exit
        else
        m := (y2 - ym) / (x2 - xm)
        end if
        b := - (m * x2) + y2
        %finding out the relation the dot to the middle of the screen
        if x2 > xm then
            rol := 1
        elsif x2 < xm then
            rol := 2
        elsif x2 = xm then
            rol := 3
        end if
        loop
            drawdot (round (xl), round (yl), 7)
            if rol = 1 then
                xl += 1
            elsif rol = 2 then
                xl -= 1
            elsif rol = 3 then
            end if
            yl := m * xl + b
            delay (2)
            if xl>maxx or xl<0 or yl>maxy or yl<0 then
            exit
            end if
        end loop
    end if
    m := 0
b := 0
xl := xm
yl := ym
x := 0
y := 0
x2 := 0
y2 := 0
%right or left.. right=1, left=2,equal=middle
rol := 0
end loop
end loop
Sponsor
Sponsor
Sponsor
sponsor
Delos




PostPosted: Sun Jan 22, 2006 9:23 am   Post subject: (No subject)

Hmm...interesting.

Ever noticed that the changing speeds for some sort of pattern? Well, they do. Those closer to the vertical are drawn faster, simply because they have a larger slope (m). Work around that.
You get a series of dots, partly for the above state reason, and partly because you are using drawdot() Rolling Eyes . Try use a drawline statement instead, where you'll need two coords - the point to be drawn to, and the current point.

Also, you've error proofed against drawing a vertical line (infinite slope, non-diff'able) but you haven't included a clause to draw such a line should it be clicked. That needs fixing!

As for multiple lines - it's possible, but a little more complicated. You'll have to move on to some simple Object Oriented programming first (read the [Tuts] on records, procedures, for a start).

BTW: Thank you for the excellent problem description. And laser has an 's' in it.
Prognosis




PostPosted: Sun Jan 22, 2006 10:19 am   Post subject: (No subject)

Hmm, im really glad that someone understands what im trying to do here... but that didnt quite give me everything i wanted to know.
Of course i knew that the bigger the slope, the faster the line grows. This is simply because... say the slope 10.. then it would go 10 up every time it went through the loop, rather than 1 or less up. But you didnt give me what I needed to do. Can someone give me an idea on how to even out the slope and the delay... thats the only way i can see it being done.

And dude, you said use a drawline instead,,, the whole point of this is so it goes Slowly, not in one motion. I want this because you will be a ship in the middle of the screen, and you need to shoot other ships, using lasers!!!!!!!!Very Happy

So does anyone know how to accually fix this?
Rasta Fella




PostPosted: Sun Jan 22, 2006 12:25 pm   Post subject: (No subject)

code:
Also, help me to enable you to shoot more than one line out at once (this is because these lines are accually lazers for my new game)

Do you mean you want to make the delay slower for the lasers? Or do you want like you shoot one laser and then want it to dissapear after?
Delos




PostPosted: Sun Jan 22, 2006 5:20 pm   Post subject: (No subject)

He means that the User should have the ability to create several instances of the laser, each of which would travel in the specified direction, but all at the same speed.
While one is still travelling, the other should be able to move as well.
Cervantes




PostPosted: Sun Jan 22, 2006 5:36 pm   Post subject: Re: Lines, and time.

Prognosis wrote:
Also, help me to enable you to shoot more than one line out at once (this is because these lines are accually lazers for my new game)


Check the Flexible Array Tutorial. It's got an example of this.
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  [ 6 Posts ]
Jump to:   


Style:  
Search: