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

Username:   Password: 
 RegisterRegister   
 Need help with collision, and shooting!
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
TW iz Rippin




PostPosted: Thu Feb 28, 2013 7:07 pm   Post subject: Need help with collision, and shooting!

Here is my code:

Turing:


setscreen ("nocursor, noecho, nobuttonbar")

colourback (green)
cls

var chars : string (1)
var boxx1 : int := 35
var boxy1 : int := 15
var locationx, locationy, x1, y1 : int
var dot : array 1 .. 10, 1 .. 2 of int
var font1, font2, font3, font4 : int
var random : int
font1 := Font.New ("serif:20")
font2 := Font.New ("serif:15")

%Draws the white background and the lines for the box
proc box
    Draw.FillBox (25, 25, 275, 275, white)
    for x : 1 .. 11
        for y : 1 .. 11
            drawline (25, (x * 25), 275, (x * 25), black)
            drawline ((x * 25), 25, (x * 25), 275, black)
        end for
    end for
end box

%Randomizes the location of the dots and randomizes the amount of dots
proc dots
    var randomdot : int := Rand.Int (1, 10)
    for a : 1 .. randomdot
        locationx := Rand.Int (2, 9)
        locationy := Rand.Int (2, 9)
        if locationx = 2 then
            x1 := 62
        elsif locationx = 3 then
            x1 := 87
        elsif locationx = 4 then
            x1 := 112
        elsif locationx = 5 then
            x1 := 137
        elsif locationx = 6 then
            x1 := 162
        elsif locationx = 7 then
            x1 := 187
        elsif locationx = 8 then
            x1 := 212
        elsif locationx = 9 then
            x1 := 237
        end if
        if locationy = 2 then
            y1 := 63
        elsif locationy = 3 then
            y1 := 88
        elsif locationy = 4 then
            y1 := 113
        elsif locationy = 5 then
            y1 := 138
        elsif locationy = 6 then
            y1 := 163
        elsif locationy = 7 then
            y1 := 188
        elsif locationy = 8 then
            y1 := 213
        elsif locationy = 9 then
            y1 := 238
        end if
        Draw.FillOval (x1, y1, 5, 5, red)
        dot (a, 1) := x1
        dot (a, 2) := y1
        random := randomdot
    end for
end dots

proc lazer
    if chars = 'E' or chars = 'e' and boxx1 = 10 then
        drawline (boxx1 + 15, boxy1 - 2, boxx1 + 265, boxy1 - 2, red)
    elsif chars = 'E' or chars = 'e' and boxy1 = 290 then
        drawline (boxx1 + 2, boxy1 - 15, boxx1 + 2, boxy1 - 265, red)
    elsif chars = 'E' or chars = 'e' and boxx1 >= 275 then
        drawline (boxx1 - 14, boxy1 - 2, boxx1 - 260, boxy1 - 2, red)
    elsif chars = 'E' or chars = 'e' and boxy1 = 15 then
        drawline (boxx1 + 2, boxy1 + 15, boxx1 + 2, boxy1 + 260, red)
    end if
end lazer

box
dots
drawfilloval (boxx1, boxy1, 5, 5, blue)

%allows movement of the circle
loop
    getch (chars)
    if boxx1 >= 50 and boxx1 <= 250 and chars = 'w' then
        locate (20, 50)
        put ""
    elsif boxx1 <= 25 and boxy1 >= 250 and chars = 'w' then
        locate (20, 50)
        put ""
    elsif boxx1 >= 275 and boxy1 >= 263 and chars = 'w' then
        locate (20, 50)
        put ""
    elsif boxx1 >= 25 and boxx1 <= 275 and boxy1 = 15 and chars = 's' then
        locate (20, 50)
        put ""
    elsif boxx1 >= 50 and boxx1 <= 250 and chars = 's' then
        locate (20, 50)
        put ""
    elsif boxx1 <= 25 and boxy1 = 40 and chars = 's' then
        locate (20, 50)
        put ""
    elsif boxx1 <= 25 and boxy1 >= 50 and boxy1 <= 250 and chars = 'd' then
        locate (20, 50)
        put ""
    elsif boxx1 >= 250 and boxy1 > 275 and chars = 'd' then
        locate (20, 50)
        put ""
    elsif boxx1 > 275 and boxy1 >= 25 and chars = 'd' then
        locate (20, 50)
        put ""
    elsif boxx1 = 260 and boxy1 = 15 and chars = 'd' then
        locate (20, 50)
        put ""
    elsif boxx1 = 35 and boxy1 >= 287 and chars = 'a' then
        locate (20, 50)
        put ""
    elsif boxx1 = 35 and boxy1 = 15 and chars = 'a' then
        locate (20, 50)
        put ""
    elsif boxx1 <= 25 and boxy1 >= 25 and boxy1 <= 275 and chars = 'a' then
        locate (20, 50)
        put ""
    elsif boxx1 >= 275 and boxy1 >= 25 and boxy1 <= 250 and chars = 'a' then
        locate (20, 50)
        put ""
    else
        if chars = 'W' or chars = 'w' and boxy1 = 15 and boxx1 = 35 then
            boxy1 += 25
            boxx1 -= 25
            drawfilloval (boxx1 + 25, boxy1 - 25, 5, 5, green)
        elsif chars = 'W' or chars = 'w' and boxy1 = 15 and boxx1 = 260 then
            boxy1 += 25
            boxx1 += 25
            drawfilloval (boxx1 - 25, boxy1 - 25, 5, 5, green)
        elsif chars = 'W' or chars = 'w' and boxy1 = 15 and boxy1 + 25 < 35 then
            boxy1 += 25
            drawfilloval (boxx1, boxy1 - 25, 5, 5, green)
        elsif chars = 'W' or chars = 'w' and boxy1 >= 40 and boxy1 + 25 < 300 then
            boxy1 += 25
            drawfilloval (boxx1, boxy1 - 25, 5, 5, green)
        else
            if chars = 'A' or chars = 'a' and boxx1 = 10 and boxx1 - 25 > 5 then
                boxx1 -= 25
                drawfilloval (boxx1 + 25, boxy1, 5, 5, green)
            elsif chars = 'A' or chars = 'a' and boxx1 >= 275 and boxy1 >= 40 then
                boxx1 -= 25
                boxy1 += 25
                drawfilloval (boxx1 + 25, boxy1 - 25, 5, 5, green)
            elsif chars = 'A' or chars = 'a' then
                boxx1 -= 25
                drawfilloval (boxx1 + 25, boxy1, 5, 5, green)
            else
                if chars = 'S' or chars = 's' and boxx1 = 35 and boxy1 >= 285 then
                    boxy1 -= 25
                    boxx1 -= 25
                    drawfilloval (boxx1 + 25, boxy1 + 25, 5, 5, green)
                elsif chars = 'S' or chars = 's' and boxx1 = 260 and boxy1 >= 40 then
                    boxy1 -= 25
                    boxx1 += 25
                    drawfilloval (boxx1 - 25, boxy1 + 25, 5, 5, green)
                elsif chars = 'S' or chars = 's' and boxx1 = 285 and boxy1 = 40 then
                    boxy1 -= 25
                    boxx1 -= 25
                    drawfilloval (boxx1 + 25, boxy1 + 25, 5, 5, green)
                elsif chars = 'S' or chars = 's' and boxx1 > 34 and boxx1 < 285 and boxy1 = 15 and boxy1 - 25 > 10 then
                    boxy1 -= 25
                    drawfilloval (boxx1, boxy1 + 25, 5, 5, green)
                elsif chars = 'S' or chars = 's' then
                    boxy1 -= 25
                    drawfilloval (boxx1, boxy1 + 25, 5, 5, green)
                else
                    if chars = 'D' or chars = 'd' and boxx1 = 10 and boxy1 >= 260 then
                        boxx1 += 25
                        boxy1 += 25
                        drawfilloval (boxx1 - 25, boxy1 - 25, 5, 5, green)
                    elsif chars = 'D' or chars = 'd' and boxx1 < 25 and boxy1 >= 40 and boxx1 + 25 < 25 then
                        boxx1 += 25
                        drawfilloval (boxx1 - 25, boxy1, 5, 5, green)
                    elsif chars = 'D' or chars = 'd' and boxx1 = 10 and boxy1 = 40 then
                        boxx1 += 25
                        boxy1 -= 25
                        drawfilloval (boxx1 - 25, boxy1 + 25, 5, 5, green)
                    elsif chars = 'D' or chars = 'd' then
                        boxx1 += 25
                        drawfilloval (boxx1 - 25, boxy1, 5, 5, green)
                    else
                    end if
                end if
            end if
        end if
    end if
    lazer
    drawfilloval (boxx1, boxy1, 5, 5, blue)
    View.Update
end loop


There are randomized red dots (atoms) in the middle. The blue dot around the edge is what you are controlling, it must shoot lazers (rays) into the grid. It does this but does not meet certain criteria that I do not understand how to do and have been trying to do for days.

If a ray hits an atom it is absorbed. (Stops at the atom)

If a ray is about to pass through a square next to an atom, it is deflected 90 degrees away
from the atom.

A ray that would pass between two atoms one square apart is reflected.

Any help would be appreciated.
Sponsor
Sponsor
Sponsor
sponsor
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  [ 1 Posts ]
Jump to:   


Style:  
Search: