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

Username:   Password: 
 RegisterRegister   
 RAYS AND ATOMS
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
fdsafdsa




PostPosted: Sat Feb 18, 2006 11:52 pm   Post subject: RAYS AND ATOMS

I AM MAKING A RAY AND ATOM PROGRAM THAT ON A GRID SHOOTS RAYS OUT AND THE WHEN AN ATOM IS INFRONT OF IT IT STOP IF IT IS BESIDE IT AND UP 1 THEN IT BEND TO THE RIGHT OR LEFT BUT ITS CONFUSING I CANT SEEM TO BEND THE RAY IM USING A DRAWFILL BOX AND IT JUST GOES THROUGH THE ATOM THE ATOMS A PICTURES AND ARE RANDOMLY DISPLAYED IN A GRID USING A 2-D ARRAY THE PICS ARE STORED IN THE SECTION OF THE 2-D ARRAY THE GRID IS ALSO MADE BY THE 2-D ARRAY HERE IS MY CODE YOU CANT USE THE PIC CAUSE I HAVE IT







code:


setscreen ("graphics:600;600,title:Laser Atoms KABOOM")
const pic := Pic.FileNew ("/Computer Science/Turing Pcitures/atom.jpg")
const pic2 := Pic.FileNew ("/Computer Science/Turing Pcitures/raygun.jpg")
const pic3 := Pic.FileNew ("/Computer Science/Turing Pcitures/raygun2.jpg")
const pic4 := Pic.FileNew ("/Computer Science/Turing Pcitures/raygun3.jpg")
const pic5 := Pic.FileNew ("/Computer Science/Turing Pcitures/raygun4.jpg")
var g : int := 145
var h : int := 145
cls

var typeatom : array 1 .. 25 of int
var num : int := 1
var num2 := 100
var num3 := 100
var grid : array 1 .. 10, 1 .. 10 of int
for a : 1 .. 10
    for b : 1 .. 10
        grid (a, b) := num2
        num2 := num2 + 40
        drawbox (num3, grid (a, b), num3 + 40, grid (a, b) + 40, black)
    end for
    num2 := 100
    num3 += 40
end for

var a : int
var b : int
var num6 : int := 1
loop
    randint (a, 2, 9)
    randint (b, 2, 9)
    grid (a, b) := pic
    var num4, num5 : int := 143
    for c : 2 .. 10
        for d : 2 .. 10
            if a = c and b = d then
                Pic.Draw (grid (a, b), num4, num5, picCopy)
            elsif a = c and b not= d then
                num5 += 40
            elsif a not= c and b = d then
                num4 += 40
            end if
        end for
    end for
    num6 += 1
    exit when num6 = 11
end loop

var count := 0
Pic.Draw (pic2, -150, 85, picCopy)
var picount : int := 0
var cdist : int := 100
var x, y, button : int

var mx2, my2, btn : int
var dist : int := 100
var dist1 : int := 100
var dist2 : int := 40
var dist3 : int := 120
var dist4 : int := 40
var count2 := 0
var col : int := 10
proc BottomLasers


    if mx2 >= dist and mx2 <= dist2 + dist and my2 <= 100 and btn = 1 then
        for a : 1 .. 10
            randint (col, 1, 250)
            drawfillbox (dist3, 100, dist3 + 1, dist1, red)
            dist1 := dist1 + 1
            count2 := 1
        end for
    else
        if count2 = 1 then
            dist := dist + dist2
            dist3 := dist3 + dist4
            dist1 := 100
            count2 := 0
        elsif mx2 >= dist and mx2 <= dist + 40 then
            loop
                dist := dist + dist2
                dist3 := dist3 + dist4
                count2 := 0
                exit when dist3 = 500
            end loop
        end if
    end if

    if mx2 <= dist and mx2 <= dist - dist2 and btn = 1 then
        loop
            dist := dist - dist2
            dist3 := dist3 - dist4
            exit when mx2 >= dist and mx2 <= dist2 + dist

        end loop
    end if



end BottomLasers

proc RightLasers
    loop
        if my2 >= dist and my2 <= dist2 + dist and mx2 >= 500 and btn = 1 then
            for a : 1 .. 10
                randint (col, 1, 250)
                drawfillbox (500, dist3, dist1, dist3 - 1, red)
                dist1 := dist1 - 1
                count2 := 1
            end for
        else
            if count2 = 1 then
                dist := dist + dist2
                dist3 := dist3 + dist4
                dist1 := 500
                count2 := 0
            elsif mx2 >= dist and mx2 <= dist + 40 then
                loop
                    dist := dist + dist2
                    dist3 := dist3 + dist4
                    count2 := 0
                    exit when dist3 = 500
                end loop
            end if
        end if

        if my2 <= dist and my2 <= dist - dist2 and btn = 1 then
            loop
                dist := dist - dist2
                dist3 := dist3 - dist4
                exit when my2 >= dist and my2 <= dist2 + dist
            end loop
        end if
        if dist = 500 then
            dist := 100
            dist1 := 100
            dist2 := 40
            dist3 := 120
            dist4 := 40
            count2 := 0
            col := 0
        end if
        exit when btn = 1
    end loop

end RightLasers

proc TopLasers

    loop
        if mx2 <= dist + 400 and mx2 >= dist + 400 - dist2 and my2 >= 500 and btn = 1 then
            for a : 1 .. 10
                randint (col, 1, 250)
                drawfillbox (dist3 + 360, 500, dist3 + 360 - 1, dist1, red)
                dist1 := dist1 - 1
                count2 := 1
            end for
        else
            if count2 = 1 then
                dist := dist - dist2
                dist3 := dist3 - dist4
                dist1 := 500
                count2 := 0
            elsif mx2 <= dist and mx2 <= dist + 40 then
                loop
                    dist := dist + dist2
                    dist3 := dist3 + dist4
                    count2 := 0
                    exit
                end loop
            end if
        end if

        if mx2 >= dist + 400 and mx2 >= dist + 400 + dist2 and btn = 1 then
            loop
                dist := dist + dist2
                dist3 := dist3 + dist4
                exit when mx2 >= dist and mx2 <= dist2 + dist
            end loop
        end if
        exit when btn = 1
    end loop
    if dist1 = 100 and mx2 >= 100 and mx2 <= 140 then
        dist := 100
        dist1 := 100
        dist2 := 40
        dist3 := 120
        dist4 := 40
        count2 := 0
        col := 0
    end if
end TopLasers

proc LeftLasers

    loop
        if my2 <= dist + 400 and my2 >= dist + 400 - dist2 and mx2 <= 400 and btn = 1 then
            for a : 1 .. 10
                randint (col, 1, 250)
                drawfillbox (100, dist3 + 360, dist1, dist3 + 360 - 1, red)
                dist1 := dist1 + 1
                count2 := 1
            end for
        else
            if count2 = 1 then
                dist := dist - dist2
                dist3 := dist3 - dist4
                dist1 := 100
                count2 := 0
            elsif mx2 <= dist and mx2 <= dist + 40 then
                loop
                    dist := dist + dist2
                    dist3 := dist3 + dist4
                    count2 := 0
                    exit
                end loop
            end if
        end if

        if my2 >= dist + 400 and my2 >= dist + 400 + dist2 and btn = 1 then
            loop
                dist := dist + dist2
                dist3 := dist3 + dist4
                exit when my2 >= dist and my2 <= dist2 + dist
            end loop
        end if
        exit when btn = 1
    end loop
end LeftLasers

proc Check




end Check



View.Set ("offscreenonly")
loop
    delay (10)
    mousewhere (mx2, my2, btn)
    locate (1, 1)

    if mx2 <= 100 then
        if btn = 1 then
            LeftLasers
        end if

        drawfillbox (0, 0, 99, 600, white)
        drawfillbox (0, 0, 600, 100, white)
        drawfillbox (501, 0, 600, 600, white)
        drawfillbox (0, 500, 600, 600, white)
        drawfillbox (100, 100, 100, 500, black)
        drawfillbox (500, 100, 500, 500, black)
        drawfillbox (100, 100, 500, 100, black)
        drawfillbox (100, 500, 500, 500, black)
        Pic.Draw (pic2, mx2 - 90, my2 - 38, picCopy)

        if btn = 0 then
            put mx2 : 4, "  ", my2 : 4
        else
            put mx2 : 4, "  ", my2 : 4
        end if

    elsif mx2 >= 100 and mx2 <= 500 and my2 <= 100 then
        drawfillbox (0, 0, 99, 600, white)
        drawfillbox (0, 0, 600, 100, white)
        if btn = 1 then
            BottomLasers
        end if
        drawfillbox (501, 0, 600, 600, white)
        drawfillbox (0, 500, 600, 600, white)
        drawfillbox (100, 100, 100, 500, black)
        drawfillbox (500, 100, 500, 500, black)
        drawfillbox (100, 100, 500, 100, black)
        drawfillbox (100, 500, 500, 500, black)
        Pic.Draw (pic3, mx2 - 19, my2 - 90, picCopy)
        if btn = 0 then
            put mx2 : 4, "  ", my2 : 4
        else
            put mx2 : 4, "  ", my2 : 4
        end if
    elsif mx2 >= 502 then
        if btn = 1 then
            RightLasers
        end if
        drawfillbox (0, 0, 99, 600, white)
        drawfillbox (0, 0, 600, 100, white)
        drawfillbox (501, 0, 600, 600, white)
        drawfillbox (0, 500, 600, 600, white)
        drawfillbox (100, 100, 100, 500, black)
        drawfillbox (500, 100, 500, 500, black)
        drawfillbox (100, 100, 500, 100, black)
        drawfillbox (100, 500, 500, 500, black)
        Pic.Draw (pic4, mx2, my2 - 35, picCopy)
        if btn = 0 then
            put mx2 : 4, "  ", my2 : 4
        else
            put mx2 : 4, "  ", my2 : 4
        end if
    elsif mx2 <= 500 and my2 >= 501 then
        if btn = 1 then
            TopLasers
        end if
        drawfillbox (0, 0, 99, 600, white)
        drawfillbox (0, 0, 600, 100, white)
        drawfillbox (501, 0, 600, 600, white)
        drawfillbox (0, 500, 600, 600, white)
        drawfillbox (100, 100, 100, 500, black)
        drawfillbox (500, 100, 500, 500, black)
        drawfillbox (100, 100, 500, 100, black)
        drawfillbox (100, 500, 500, 500, black)
        Pic.Draw (pic5, mx2 - 15, my2, picCopy)
        if btn = 0 then
            put mx2 : 4, "  ", my2 : 4
        else
            put mx2 : 4, "  ", my2 : 4
        end if
    else
        drawfillbox (0, 0, 99, 600, white)
        drawfillbox (0, 0, 600, 100, white)
        drawfillbox (501, 0, 600, 600, white)
        drawfillbox (0, 500, 600, 600, white)
        drawfillbox (100, 100, 100, 500, black)
        drawfillbox (500, 100, 500, 500, black)
        drawfillbox (100, 100, 500, 100, black)
        drawfillbox (100, 500, 500, 500, black)
        if btn = 0 then
            put mx2 : 4, "  ", my2 : 4
        else
            put mx2 : 4, "  ", my2 : 4
        end if
    end if
    View.Update

end loop[code][/code]
Sponsor
Sponsor
Sponsor
sponsor
Andy




PostPosted: Sun Feb 19, 2006 1:44 am   Post subject: (No subject)

LETS BE LIEK COOL AND SHIET AND POST In CAPS SO THAT WHEN PEOPLE LIEK COME BY ANS SHEIT, THEY DONT BOTHER READING IT. OOO AND LETS ALSO POST OUR 5 HUNDRED LINE PROGRAM SO THAT INSTEAD OF FIGURING OUT WHATS WROUNG OURSELVES, HOPE SOMEONE ELSE WILL LIKE US ENOUGH TO DO IT FOR US

point is, dont post in caps if you want response, and post the pictures required in a zip so the program will actually work, also when asking for help, dont just give ur whole program, isolate the error, then do it. we dont have time to figure out what you did from scratch especially without any comments
Cervantes




PostPosted: Sun Feb 19, 2006 8:50 am   Post subject: (No subject)

Your code is way bigger than it needs to be. The rules for a ray bouncing off an atom are the same no matter which way the ray comes from, or where the atom is in relation to the ray. You don't (and shouldn't) have separate code to deal with the laser coming from each of four directions.
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  [ 3 Posts ]
Jump to:   


Style:  
Search: