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

Username:   Password: 
 RegisterRegister   
 delay stacking
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
goroyoshi




PostPosted: Wed May 11, 2011 7:10 pm   Post subject: delay stacking

Turing:

setscreen ("offscreenonly,graphics:600;600,nobuttonbar")
var bullet, bullet2 : flexible array 1 .. 0 of int
var direction, direction2 : string := "up"
var pastx, pasty, pastx2, pasty2 : int
var recoil, recoil2 : boolean := false
var win : int := 0
var chars : array char of boolean
var x1, y1 : int := 100
var x2, y2 : int := 399
process recharge
    delay (600)
    recoil := false
end recharge
process recharge2
    delay (600)
    recoil2 := false
end recharge2
process fire
    if recoil = false then
        pastx := x1
        pasty := y1
        recoil := true
        fork recharge
        if direction = "up" then
            for i : y1 .. upper (bullet)
                drawfilloval (pastx, i, 1, 1, red)
                if whatdotcolour (pastx, i + 2) = 3 then
                    win := 1
                end if
                delay (1)
            end for
        elsif direction = "right" then
            for i : x1 .. upper (bullet)
                drawfilloval (i, pasty, 1, 1, red)
                if whatdotcolour (i + 2, pasty) = 3 then
                    win := 1
                end if
                delay (1)
            end for
        elsif direction = "left" then
            for decreasing i : x1 .. upper (bullet)
                drawfilloval (i - 2, pasty, 1, 1, red)
                if whatdotcolour (i, pasty) = 3 then
                    win := 1
                end if
                delay (1)
            end for
        elsif direction = "down" then
            for decreasing i : y1 .. upper (bullet)
                drawfilloval (pastx, i, 1, 1, red)
                if whatdotcolour (pastx, i - 2) = 3 then
                    win := 1
                end if
                delay (1)
            end for
        end if
    end if
end fire
process fire2
    if recoil2 = false then
        pastx2 := x2
        pasty2 := y2
        recoil2 := true
        fork recharge2
        if direction2 = "up" then
            for i : y2 .. upper (bullet2)
                drawfilloval (pastx2, i, 1, 1, red)
                if whatdotcolour (pastx2, i + 2) = 2 then
                    win := 2
                end if
                delay (1)
            end for
        elsif direction2 = "right" then
            for i : x2 .. upper (bullet2)
                drawfilloval (i, pasty2, 1, 1, red)
                if whatdotcolour (i + 2, pasty2) = 2 then
                    win := 2
                end if
                delay (1)
            end for
        elsif direction2 = "left" then
            for decreasing i : x2 .. upper (bullet2)
                drawfilloval (i, pasty2, 1, 1, red)
                if whatdotcolour (i - 2, pasty2) = 2 then
                    win := 2
                end if
                delay (1)
            end for
        elsif direction2 = "down" then
            for decreasing i : y2 .. upper (bullet2)
                drawfilloval (pastx2, i, 1, 1, red)
                if whatdotcolour (pastx2, i - 2) = 2 then
                    win := 2
                end if
                delay (1)
            end for
        end if
    end if
end fire2
loop
    drawbox (0, 0, maxx, maxy, 1)
    Input.KeyDown (chars)
    if chars (KEY_UP_ARROW) then
        direction := "up"
        y1 += 1
    elsif chars (KEY_RIGHT_ARROW) then
        direction := "right"
        x1 += 1
    elsif chars (KEY_LEFT_ARROW) then
        direction := "left"
        x1 -= 1
    elsif chars (KEY_DOWN_ARROW) then
        direction := "down"
        y1 -= 1
    end if
    if chars ('w') then
        direction2 := "up"
        y2 += 1
    elsif chars ('d') then
        direction2 := "right"
        x2 += 1
    elsif chars ('a') then
        direction2 := "left"
        x2 -= 1
    elsif chars ('s') then
        direction2 := "down"
        y2 -= 1
    end if
    if y1 + 6 >= maxy then     %p1 boundaries
        y1 -= 1
    end if
    if y1 - 6 <= 0 then
        y1 += 1
    end if
    if x1 + 6 >= maxx then
        x1 -= 1
    end if
    if x1 - 6 <= 0 then
        x1 += 1
    end if
    if y2 + 6 >= maxy then     %p2 boundaries
        y2 -= 1
    end if
    if y2 - 6 <= 0 then
        y2 += 1
    end if
    if x2 + 6 >= maxx then
        x2 -= 1
    end if
    if x2 - 6 <= 0 then
        x2 += 1
    end if
    drawfilloval (x1, y1, 5, 5, 2)
    drawfilloval (x2, y2, 5, 5, 3)
    if chars ('/') then
        if direction = "up" then
            for i : y1 .. maxy
                if whatdotcolor (x1, i) = 1 then
                    new bullet, i
                    exit
                end if
                new bullet, 0
            end for
        elsif direction = "right" then
            for i : x1 .. maxx
                if whatdotcolor (i, y1) = 1 then
                    new bullet, i
                    exit
                end if
                new bullet, 0
            end for
        elsif direction = "left" then
            for decreasing i : x1 .. 0
                if whatdotcolor (i, y1) = 1 then
                    new bullet, i
                    exit
                end if
                new bullet, 0
            end for
        elsif direction = "down" then
            for decreasing i : y1 .. 0
                if whatdotcolor (x1, i) = 1 then
                    new bullet, i
                    exit
                end if
                new bullet, 0
            end for
        end if
        fork fire
    end if
    if chars (' ') then
        if direction2 = "up" then
            for i : y2 .. maxy
                if whatdotcolor (x2, i) = 1 then
                    new bullet2, i
                    exit
                end if
                new bullet2, 0
            end for
        elsif direction2 = "right" then
            for i : x2 .. maxx
                if whatdotcolor (i, y2) = 1 then
                    new bullet2, i
                    exit
                end if
                new bullet2, 0
            end for
        elsif direction2 = "left" then
            for decreasing i : x2 .. 0
                if whatdotcolor (i, y2) = 1 then
                    new bullet2, i
                    exit
                end if
                new bullet2, 0
            end for
        elsif direction2 = "down" then
            for decreasing i : y2 .. 0
                if whatdotcolor (x2, i) = 1 then
                    new bullet2, i
                    exit
                end if
                new bullet2, 0
            end for
        end if
        fork fire2
    end if
    delay (3)
    View.Update
    cls
    exit when win > 0
end loop
if win = 1 then
    put "Player one has won."
else
    put "Player two has won."
end if


if you hold the fire button then everyone slows down, why is this? and how do I prevent it?
note: im guessing that it is processes, i'm probably not going to change it because it's realistic for the shooter to slow down to aim
Sponsor
Sponsor
Sponsor
sponsor
Raknarg




PostPosted: Wed May 11, 2011 8:00 pm   Post subject: RE:delay stacking

Its almost definitely processes. I tried another shooting game that used processes, they had the exact same issue.
And this is ok for now, but in the future, I would definitely reccomend procedures.
I would also venture to say that your delay (1) inside your loops are making a difference, but probably not by that much.
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  [ 2 Posts ]
Jump to:   


Style:  
Search: