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

Username:   Password: 
 RegisterRegister   
 Emergency Help With School Summative
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
pizzajack1




PostPosted: Mon Jun 02, 2014 11:23 pm   Post subject: Emergency Help With School Summative

What is it you are trying to achieve?
Successfully Re-Run my game


What is the problem you are having?
After the first successful run through, if chosen to play again the title page loads fine, however when it gets to moving actual players
the whole thing freezes, and it also doesn't display any players + incoming 'missiles' on the re-run
by freezes, I mean I must restart turing, becomes non-responsive

Describe what you have tried to solve this problem
Reset all players
Reset all variables
View.Update
Removing title page

Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
Turing:

%defining variables
var player1x : int := 148 %player1's x position
var player2x : int := 502 %player2's x position
var player1y, player2y : int := 8 %players' y position
var crossthescreen : int := 8 %setting bullet positions across the screen
var bullets, bulletx, bullety, bulleta : array 1 .. 600 of int %bullet positions
var bulleto : array 1 .. 600 of boolean %if bullets are onscreen, then true
var move : array char of boolean %get keyboard input
var response : string
var active : int %num of bullets onscreen
var chars : array char of boolean
var window : int := Window.Open ("graphics:800;600")
var endGame : boolean := false
var name1, name2 : string
%==========================================================================
%===================bullet types and players' images=======================
%==========================================================================

%-----------------players------------------
var playerPic, player1s, player2s, player1w, player1h : int %players' hitbox images
playerPic := Pic.FileNew ("playerblack.bmp") %player 1 pic
player1w := Pic.Width (playerPic)
player1h := Pic.Height (playerPic)

procedure playersready
    player1s := Sprite.New (playerPic) %player 1 sprite
    Sprite.SetHeight (player1s, 2)
    Sprite.Show (player1s)
    Sprite.SetPosition (player1s, player1x, player1y, true)

    player2s := Sprite.New (playerPic) %player 2 sprite
    Sprite.SetHeight (player2s, 2)
    Sprite.Show (player2s)
    Sprite.SetPosition (player2s, player2x, player2y, true)
end playersready

%-----------------bullets------------------
var rringedp, rringedw, rringedh : int %ringed red circle
rringedp := Pic.FileNew ("rringed.bmp")
rringedw := Pic.Width (rringedp)
rringedh := Pic.Height (rringedp)

var vringedp, vringedw, vringedh : int %ringed violet circle
vringedp := Pic.FileNew ("vringed.bmp")
vringedw := Pic.Width (vringedp)
vringedh := Pic.Height (vringedp)

var blueshinep, blueshinew, blueshineh : int
blueshinep := Pic.FileNew ("blueshine.bmp")
blueshinew := Pic.Width (blueshinep)
blueshineh := Pic.Height (blueshinep)

var leftbluepointedp, leftbluepointedw, leftbluepointedh : int
leftbluepointedp := Pic.FileNew ("darkbluepointedleft.bmp")
leftbluepointedw := Pic.Width (leftbluepointedp)
leftbluepointedh := Pic.Height (leftbluepointedp)

var rightbluepointedp, rightbluepointedw, rightbluepointedh : int
rightbluepointedp := Pic.FileNew ("darkbluepointedright.bmp")
rightbluepointedw := Pic.Width (rightbluepointedp)
rightbluepointedh := Pic.Height (rightbluepointedp)
%=======================================================================
%=====================BULLET PATTERNS(use sprites.)====================
%=======================================================================

%pattern 1 is on permanent hiatus.

%-----------------------------------------------------------------------------
%bullet pattern 2: 5 spread circles, 2 colors
%----------------------------------------------------------------------------
procedure p1pattern2pos (var shoty, shotx, shotA : int, var shoto : boolean, xmin, xmax, ymin, ymax : int) %generates xy loc of center of burst
    View.Update
    var offset : int
    randint (offset, ymin, ymax)
    shoty := round (maxy / 4 * 3) + offset
    randint (offset, xmin, xmax)
    shotx := round (maxx / 4) + offset
    shoto := true
    randint (offset, -15, 15)
    shotA := shotA + offset
    View.Update
end p1pattern2pos

procedure p2pattern2pos (var shoty, shotx, shotA : int, var shoto : boolean, xmin, xmax, ymin, ymax : int) %generates xy loc of center of burst
    var offset : int
    randint (offset, ymin, ymax)
    shoty := round (maxy / 4 * 3) + offset
    randint (offset, xmin, xmax)
    shotx := round (maxx / 4 * 3) + offset
    shoto := true
    randint (offset, -15, 15)
    shotA := shotA + offset
    View.Update
end p2pattern2pos

procedure pattern2ready %Setting up
    %P1///////////////////////////////////////////////////////////////////////
    %burst 1 - center burst
    for i : 1 .. 20
        bullets (i) := Sprite.New (rringedp)
        Sprite.SetHeight (bullets (i), 3) %will go over player sprite
        Sprite.Show (bullets (i))
        bullety (i) := (maxy div 4) * 3
        bulletx (i) := maxx div 4 - 25
        bulleta (i) := i - 1
        bulleto (i) := true
        Sprite.SetPosition (bullets (i), bulletx (i), bullety (i), true)
        View.Update
    end for

    %burst num 2 bottom right burst
    for i : 21 .. 40
        bullets (i) := Sprite.New (rringedp)
        Sprite.SetHeight (bullets (i), 3) %will go over player sprite
        Sprite.Show (bullets (i))
        bullety (i) := (maxy div 4) * 3 - 50
        bulletx (i) := (maxx div 4) + 18
        bulleta (i) := i - 21
        bulleto (i) := true
        Sprite.SetPosition (bullets (i), bulletx (i), bullety (i), true)
        View.Update
    end for

    %burst num 3 -top right burst
    for i : 41 .. 60
        bullets (i) := Sprite.New (rringedp) %create sprites
        Sprite.SetHeight (bullets (i), 3) %will go over player sprite
        Sprite.Show (bullets (i))
        bullety (i) := (maxy div 4) * 3 + 25
        bulletx (i) := (maxx div 4)
        bulleta (i) := i - 20
        bulleto (i) := true
        Sprite.SetPosition (bullets (i), bulletx (i), bullety (i), true)
        View.Update
    end for

    %burst 4 - low purple
    for i : 61 .. 90
        bullets (i) := Sprite.New (vringedp)
        Sprite.SetHeight (bullets (i), 4)
        Sprite.Show (bullets (i))
        bullety (i) := maxy div 2
        bulletx (i) := maxx div 4
        bulleta (i) := 0 - (i + 151)
        bulleto (i) := true
        Sprite.SetPosition (bullets (i), bulletx (i), bullety (i), true)
        View.Update
    end for

    %burst 5- high purple
    for i : 91 .. 120
        bullets (i) := Sprite.New (vringedp)
        Sprite.SetHeight (bullets (i), 4)
        Sprite.Show (bullets (i))
        bullety (i) := (maxy div 4) * 3
        bulletx (i) := (maxx div 4)
        bulleta (i) := i + 150
        bulleto (i) := true
        View.Update
    end for
    %P2///////////////////////////////////////////////////////////////////////
    %burst 1 - center burst
    for i : 121 .. 140
        bullets (i) := Sprite.New (rringedp)
        Sprite.SetHeight (bullets (i), 3) %will go over player sprite
        Sprite.Show (bullets (i))
        bullety (i) := (maxy div 4) * 3
        bulletx (i) := (maxx div 4) * 3 - 25
        bulleta (i) := i - 1
        bulleto (i) := true
        Sprite.SetPosition (bullets (i), bulletx (i), bullety (i), true)
        View.Update
    end for

    %burst num 2 bottom right burst
    for i : 141 .. 160
        bullets (i) := Sprite.New (rringedp)
        Sprite.SetHeight (bullets (i), 3) %will go over player sprite
        Sprite.Show (bullets (i))
        bullety (i) := (maxy div 4) * 3 - 50
        bulletx (i) := (maxx div 4) * 3 + 20
        bulleta (i) := i - 21
        bulleto (i) := true
        Sprite.SetPosition (bullets (i), bulletx (i), bullety (i), true)
        View.Update
    end for

    %burst num 3 -top right burst
    for i : 161 .. 180
        bullets (i) := Sprite.New (rringedp) %create sprites
        Sprite.SetHeight (bullets (i), 3) %will go over player sprite
        Sprite.Show (bullets (i))
        bullety (i) := (maxy div 4) * 3 + 25
        bulletx (i) := (maxx div 4) * 3
        bulleta (i) := i - 20
        bulleto (i) := true
        Sprite.SetPosition (bullets (i), bulletx (i), bullety (i), true)
        View.Update
    end for

    %burst 4 - low purple
    for i : 181 .. 210
        bullets (i) := Sprite.New (vringedp)
        Sprite.SetHeight (bullets (i), 4)
        Sprite.Show (bullets (i))
        bullety (i) := maxy div 2
        bulletx (i) := maxx div 4 * 3
        bulleta (i) := 0 - (i + 31)
        bulleto (i) := true
        Sprite.SetPosition (bullets (i), bulletx (i), bullety (i), true)
        View.Update
    end for

    %burst 5- high purple
    for i : 211 .. 240
        bullets (i) := Sprite.New (vringedp)
        Sprite.SetHeight (bullets (i), 4)
        Sprite.Show (bullets (i))
        bullety (i) := (maxy div 4) * 3
        bulletx (i) := (maxx div 4) * 3
        bulleta (i) := i + 30
        bulleto (i) := true
    end for
    %changesamount of active bullets (used for collision)
    active := 240

end pattern2ready

%procedure pattern2draw: moves bullets for p2
procedure pattern2draw (var waveLeft : int, player1dead, player2dead : boolean, var p1score, p2score : int)
    View.Update
    var speed := 3 %speed of bullet- try to avoid decimals
    for i : 1 .. 240
        var alloffscreen : boolean := true %all bullets are offscreen

        %if a bullet is still onscreen
        for z : 1 .. 120
            if bulleto (z) = true and player1dead = false
                    then
                alloffscreen := false
            end if
        end for
        for z : 121 .. 240
            if bulleto (z) = true and player2dead = false
                    then
                alloffscreen := false
            end if
        end for

        %if onscreen       and  went past boundaries
        if bulleto (i) = true and ((bulletx (i) >= maxx div 2 - 19 and bulletx (i) <= maxx div 2 + 19) or (bulletx (i) <= -5) or (bullety (i) >= maxy + 5) or (bullety (i) <= -5) or (bulletx (i) >=
                maxx + 5))
                then
            bulleto (i) := false
            Sprite.SetPosition (bullets (i), maxx + 50, maxy + 50, true)
        end if

        %if onscreen,      move bullet
        if bulleto (i) and bulletx (i) < maxx div 2 and player1dead = false then
            bulletx (i) := round (cos (bulleta (i)) + cos (bulleta (i)) * speed) + bulletx (i)
            bullety (i) := round (sin (bulleta (i)) + sin (bulleta (i)) * speed) + bullety (i)
            Sprite.SetPosition (bullets (i), bulletx (i), bullety (i), true)
        end if
        if bulleto (i) and bulletx (i) > maxx div 2 and player2dead = false then
            bulletx (i) := round (cos (bulleta (i)) + cos (bulleta (i)) * speed) + bulletx (i)
            bullety (i) := round (sin (bulleta (i)) + sin (bulleta (i)) * speed) + bullety (i)
            Sprite.SetPosition (bullets (i), bulletx (i), bullety (i), true)
        end if

        %if all bullets are offscreen reset positions
        if alloffscreen = true then
            waveLeft -= 1 %waves
            if player1dead = false then %
                p1score += 1     %
            end if               % scoring
            if player2dead = false then %
                p2score += 1     %
            end if
            locate (3, maxcol div 2 + 1)
            case waveLeft of %wave labels
                label 0 :
                    put "0" ..
                label 1 :
                    put "1" ..
                label 2 :
                    put "2" ..
                label 3 :
                    put "3" ..
                label 4 :
                    put "4" ..
                label 5 :
                    put "5" ..
                label 6 :
                    put "6" ..
                label 7 :
                    put "7" ..
                label 8 :
                    put "8" ..
                label 9 :
                    put "9 " ..
                label 10 :
                    put "10" ..
            end case
            exit when waveLeft = 0
            for z : 1 .. 20 %center burst
                p1pattern2pos (bullety (z), bulletx (z), bulleta (z), bulleto (z), -30, -20, -5, 5)
                Sprite.SetPosition (bullets (z), bulletx (z), bullety (z), true)
            end for
            for z : 21 .. 40 %bottom right burst
                p1pattern2pos (bullety (z), bulletx (z), bulleta (z), bulleto (z), 15, 25, -55, -45)
                Sprite.SetPosition (bullets (z), bulletx (z), bullety (z), true)
            end for
            for z : 41 .. 60 %top right burst
                p1pattern2pos (bullety (z), bulletx (z), bulleta (z), bulleto (z), -5, 5, 20, 30)
                Sprite.SetPosition (bullets (z), bulletx (z), bullety (z), true)
            end for
            for z : 61 .. 90 %low purple burst
                bullety (z) := maxy div 2
                bulletx (z) := maxx div 4
                bulleto (z) := true
                Sprite.SetPosition (bullets (z), bulletx (z), bullety (z), true)
            end for
            for z : 91 .. 120 %highburst
                bullety (z) := (maxy div 4) * 3
                bulletx (z) := maxx div 4
                bulleto (z) := true
            end for
            %P2 BULLETS/////////////////////////////////////////////////////////
            for z : 121 .. 140 %center burst
                p2pattern2pos (bullety (z), bulletx (z), bulleta (z), bulleto (z), -30, -20, -5, 5)
                Sprite.SetPosition (bullets (z), bulletx (z), bullety (z), true)
            end for
            for z : 141 .. 160 %bottom right burst
                p2pattern2pos (bullety (z), bulletx (z), bulleta (z), bulleto (z), 15, 25, -55, -45)
                Sprite.SetPosition (bullets (z), bulletx (z), bullety (z), true)
            end for
            for z : 161 .. 180 %top right burst
                p2pattern2pos (bullety (z), bulletx (z), bulleta (z), bulleto (z), -5, 5, 20, 30)
                Sprite.SetPosition (bullets (z), bulletx (z), bullety (z), true)
            end for
            for z : 181 .. 210 %low purple burst
                bullety (z) := maxy div 2
                bulletx (z) := maxx div 4 * 3
                bulleto (z) := true
                Sprite.SetPosition (bullets (z), bulletx (z), bullety (z), true)
            end for
            for z : 211 .. 240 %highburst
                bullety (z) := (maxy div 4) * 3
                bulletx (z) := maxx div 4 * 3
                bulleto (z) := true
            end for
        end if
    end for

end pattern2draw

%--------------------------------------------------------------------
%pattern 3: vertical fall bullets with horizontal shoot bullets
%--------------------------------------------------------------------

%pattern3spawn:spawning the bullets for pattern 3
procedure pattern3spawn (var active : int, var whichDirection : array 1 .. * of string)
    var location : int
    active += 60
    var random : int
    %verticals
    for i : 1 .. 10 %player 1's side
        randint (location, 1, maxx div 2 - 25)
        bulletx (i) := location
        bullets (i) := Sprite.New (blueshinep)
        Sprite.SetHeight (bullets (i), 4)
        Sprite.Show (bullets (i))
        whichDirection (i) := "down"
        Sprite.SetPosition (bullets (i), bulletx (i), bullety (i), true)
    end for
    for i : 11 .. 20 %player 2's side
        randint (location, maxx div 2 + 25, maxx - 1)
        bulletx (i) := location
        bullets (i) := Sprite.New (blueshinep)
        Sprite.SetHeight (bullets (i), 4)
        Sprite.Show (bullets (i))
        whichDirection (i) := "down"
        Sprite.SetPosition (bullets (i), bulletx (i), bullety (i), true)
    end for
    for i : 1 .. 10
        bullety (i) := maxy - 14 + ((i - 1) * maxy div 10)
    end for
    for i : 11 .. 20
        bullety (i) := maxy - 14 + ((i - 11) * maxy div 10)
    end for

    %horizontals
    for i : 21 .. 30 %l p1
        bullets (i) := Sprite.New (leftbluepointedp)
        Sprite.SetHeight (bullets (i), 3)
        whichDirection (i) := "left"
        bulletx (i) := maxx div 2 - 10
        randint (random, 7, maxy - 7)
        bullety (i) := random
        Sprite.Show (bullets (i))
    end for
    for i : 31 .. 40 %l p2
        bullets (i) := Sprite.New (leftbluepointedp)
        Sprite.SetHeight (bullets (i), 3)
        whichDirection (i) := "left"
        bulletx (i) := maxx + 8
        randint (random, 8, maxy - 8)
        bullety (i) := random
        Sprite.Show (bullets (i))
    end for
    for i : 41 .. 50 %r p1
        bullets (i) := Sprite.New (rightbluepointedp)
        Sprite.SetHeight (bullets (i), 3)
        whichDirection (i) := "right"
        bulletx (i) := -8
        randint (random, 8, maxy - 8)
        bullety (i) := random
        Sprite.Show (bullets (i))
    end for
    for i : 51 .. 60 %r p2
        bullets (i) := Sprite.New (rightbluepointedp)
        Sprite.SetHeight (bullets (i), 3)
        whichDirection (i) := "right"
        bulletx (i) := maxx div 2 + 17
        randint (random, 8, maxy - 8)
        bullety (i) := random
        Sprite.Show (bullets (i))
    end for
end pattern3spawn

procedure pattern3verticalreposition (i : int, var bulletx, bullety : int, var waveLeft : int, player1dead, player2dead : boolean, var p1score, p2score : int)
    var randomizer : int
    if i = 10 or i = 20 then
        waveLeft -= 1
        if player1dead = false then
            p1score += 1
        end if
        if player2dead = false then
            p2score += 1
        end if
        locate (3, maxcol div 2 + 1)
        case waveLeft of
            label 0 :
                put "0" ..
            label 1 :
                put "1" ..
            label 2 :
                put "2" ..
            label 3 :
                put "3" ..
            label 4 :
                put "4" ..
            label 5 :
                put "5" ..
            label 6 :
                put "6" ..
            label 7 :
                put "7" ..
            label 8 :
                put "8" ..
            label 9 :
                put "9 " ..
            label 10 :
                put "10" ..
        end case
    end if
    if bulletx < maxx div 2 - 11 then %p1's side verticals
        randint (randomizer, 14, maxx div 2 - 39)
        bulletx := randomizer
        bullety := bullety + maxy
    end if
    if bulletx > maxx div 2 + 11 then %p2 verticals
        randint (randomizer, maxx div 2 + 39, maxx - 15)
        bulletx := randomizer
        bullety := bullety + maxy
    end if
end pattern3verticalreposition

%repositioning horizontal bullets
procedure pattern3horizontalreposition (var bulletx, bullety : int, var whichDirection : string)
    var random : int
    if whichDirection = "left" then
        if bulletx < maxx div 2 then %p1 left
            bulletx := maxx div 2 - 10
            randint (random, 8, maxy - 8)
            bullety := random
        end if
        if bulletx > maxx div 2 then %p2 left
            bulletx := maxx + 8
            randint (random, 8, maxy - 8)
            bullety := random
        end if
    end if
    if whichDirection = "right" then
        if bulletx < maxx div 2 then
            bulletx := -8
            randint (random, 8, maxy - 8)
            bullety := random
        end if
        if bulletx > maxx div 2 then
            bulletx := maxx div 2 + 17
            randint (random, 8, maxy - 8)
            bullety := random
        end if
    end if
end pattern3horizontalreposition

%pattern3move: moving the bullets for pattern 3
procedure pattern3move (active : int, var whichDirection : array 1 .. * of string, var waveLeft : int, player1dead, player2dead : boolean, var p1score, p2score : int)
    if player1dead = false then
        for i : 1 .. 10 %verticals p1
            if bullety (i) < -15 then
                pattern3verticalreposition (i, bulletx (i), bullety (i), waveLeft, player1dead, player2dead, p1score, p2score)
                bulletx (i + 20) -= 1
                bulletx (i + 30) -= 1
                bulletx (i + 40) += 2
                bulletx (i + 50) += 1
            end if
            bullety (i) -= 1
            Sprite.SetPosition (bullets (i), bulletx (i), bullety (i), true)
        end for
    end if
    if player2dead = false then
        for i : 11 .. 20 %verticals p2
            if bullety (i) < -15 then
                pattern3verticalreposition (i, bulletx (i), bullety (i), waveLeft, player1dead, player2dead, p1score, p2score)
                bulletx (i + 20) -= 1
                bulletx (i + 30) -= 1
                bulletx (i + 40) += 2
                bulletx (i + 50) += 1
            end if
            bullety (i) -= 1
            Sprite.SetPosition (bullets (i), bulletx (i), bullety (i), true)
        end for
    end if
    if player1dead = false then
        for i : 21 .. 30 %lefts p1 side
            if bulletx (i) < -7 then %repositioning
                pattern3horizontalreposition (bulletx (i), bullety (i), whichDirection (i))
            end if
            %moving
            if (bulletx (i) <= maxx div 2 - 11 and bulletx (i) >= -7) then
                bulletx (i) -= 1
                Sprite.SetPosition (bullets (i), bulletx (i), bullety (i), true)
            end if
        end for
        for i : 41 .. 50 %rights for p1
            if bulletx (i) > maxx div 2 - 18 then
                pattern3horizontalreposition (bulletx (i), bullety (i), whichDirection (i))
            end if
            if bulletx (i) >= -7 and bulletx (i) <= maxx div 2 - 18 then
                bulletx (i) += 1
                Sprite.SetPosition (bullets (i), bulletx (i), bullety (i), true)
            end if
        end for
    end if

    if player2dead = false then
        for i : 31 .. 40 %lefts p2 side
            %repositioning if past boundaries
            if bulletx (i) < maxx div 2 + 18 then
                pattern3horizontalreposition (bulletx (i), bullety (i), whichDirection (i))
            end if
            %moving
            if (bulletx (i) >= maxx div 2 + 18 and bulletx (i) <= maxx + 7) then
                bulletx (i) -= 1
                Sprite.SetPosition (bullets (i), bulletx (i), bullety (i), true)
            end if
        end for
        for i : 51 .. 60 %rights for p2
            if bulletx (i) > maxx + 7 then
                pattern3horizontalreposition (bulletx (i), bullety (i), whichDirection (i))
            end if
            if bulletx (i) >= maxx div 2 + 18 and bulletx (i) <= maxx + 7 then
                bulletx (i) += 1
                Sprite.SetPosition (bullets (i), bulletx (i), bullety (i), true)
            end if
        end for
    end if
end pattern3move
%===================================================================
%==========================MOVING THE PLAYER========================
%===================================================================
procedure playermove (player1dead, player2dead : boolean)
    Input.KeyDown (move)
    if player1dead = false then
        %PLAYER 1-----------------------------------------------------------
        %focused (slower movement)
        if move ('y') then
            if player1y < maxy - 8 then
                if move ('w') then %move up
                    player1y := player1y + 1
                end if
            end if
            if move ('a') then %move left
                if player1x - 1 < 11 then
                    player1x := 11
                else
                    player1x := player1x - 1
                end if
            end if
            if move ('d') then %move right
                if player1x + 1 > maxx div 2 - 31 then
                    player1x := maxx div 2 - 31
                else
                    player1x := player1x + 1
                end if
            end if
            if player1y > 8 then
                if move ('s') then %move down
                    player1y := player1y - 1
                end if
            end if
        else %unfocused (faster movement)
            if move ('w') then %up
                if player1y + 5 > maxy - 8 then
                    player1y := maxy - 8
                else
                    player1y := player1y + 5
                end if
            end if
            if move ('a') then %left
                if player1x - 5 < 11 then
                    player1x := 8
                else
                    player1x := player1x - 5
                end if
            end if
            if move ('d') then %right
                if player1x + 5 > maxx div 2 - 31 then
                    player1x := maxx div 2 - 31
                else
                    player1x := player1x + 5
                end if
            end if
            if move ('s') then %down
                if player1y - 5 < 13 then
                    player1y := 8
                else
                    player1y := player1y - 5
                end if
            end if
        end if
    end if
    %player2------------------------------------------------------------------
    %focused (slower movement)
    if player2dead = false then
        if move (KEY_SHIFT) then
            if player2y < maxy - 8 then
                if move (KEY_UP_ARROW) then %move up
                    player2y := player2y + 1
                end if
            end if
            if move (KEY_LEFT_ARROW) then %move left
                if player2x - 1 < maxx div 2 + 32 then
                    player2x := maxx div 2 + 32
                else
                    player2x := player2x - 1
                end if
            end if
            if move (KEY_RIGHT_ARROW) then %move right
                if player2x + 1 > maxx - 7 then
                    player2x := maxx - 7
                else
                    player2x := player2x + 1
                end if
            end if
            if player2y > 8 then
                if move (KEY_DOWN_ARROW) then %move down
                    player2y := player2y - 1
                end if
            end if
        else %unfocused (faster movement)
            if move (KEY_UP_ARROW) then %up
                if player2y + 5 > maxy - 8 then
                    player2y := maxy - 8
                else
                    player2y := player2y + 5
                end if
            end if
            if move (KEY_LEFT_ARROW) then %left
                if player2x - 5 < maxx div 2 + 32 then
                    player2x := maxx div 2 + 32
                else
                    player2x := player2x - 5
                end if
            end if
            if move (KEY_RIGHT_ARROW) then %right
                if player2x + 5 > maxx - 7 then
                    player2x := maxx - 7
                else
                    player2x := player2x + 5
                end if
            end if
            if move (KEY_DOWN_ARROW) then %down
                if player2y - 5 < 13 then
                    player2y := 8
                else
                    player2y := player2y - 5
                end if
            end if
        end if
    end if
    %draw sprites
    Sprite.SetPosition (player1s, player1x, player1y, true)
    Sprite.SetPosition (player2s, player2x, player2y, true)
end playermove
%============================================================================
%=======================TITLE PAGE==============================
%============================================================================

procedure scores
    loop
        Input.KeyDown (chars)     % If key down is = 'ESC' exit the game
        if chars (KEY_ESC) then
            exit
        end if
    end loop
end scores
procedure title
    % Music Plays
    Music.PlayFileReturn ("Star wars.mp3")
    var pic : int := Pic.FileNew ("spaceship.jpg")
    pic := Pic.Scale (pic, 800, 600)     % Set screen size
    Pic.Draw (pic, 0, 0, picMerge)
    var font : int     % Variables
    var continue : string (1)
    drawfillbox (maxx div 2 - 260, 510, maxx div 2 + 260, 190, 55)     % Draws box
    drawfillbox (maxx div 2 - 250, 500, maxx div 2 + 250, 200, 54)
    font := Font.New ("Algerian:40")     % Set font and size
    Draw.Text ("Bullet Hell", maxx div 2 - 155, 450, font, white)     % Displays
    font := Font.New ("Algerian:30")
    Draw.Text ("---Menu---", maxx div 2 - 90, 350, font, white)
    font := Font.New ("Algerian:20")
    Draw.Text ("1. Start Game", maxx div 2 - 100, 320, font, white)
    Draw.Text ("2. High Scores", maxx div 2 - 100, 290, font, white)
    Draw.Text ("", 20, 160, font, white)     % Blank
    Draw.Text ("", 20, 130, font, white)
    Draw.Text ("", 20, 100, font, white)
    Draw.Text ("OPTIONS : 1 / 2 ", 20, 20, font, white)
    View.Update
    loop
        Input.KeyDown (chars)     % If key down is = 'ESC' exit the game
        if chars ('2') then
            cls
            scores
        end if
        if chars ('1') then     % If '1'
            View.Set ("graphics:800;600,offscreenonly")
            setscreen ("nocursor")
            pic := Pic.Scale (pic, 800, 600)
            Pic.Draw (pic, 0, 0, picMerge)
            drawfillbox (maxx div 2 - 260, 510, maxx div 2 + 260, 190, 55)
            drawfillbox (maxx div 2 - 250, 500, maxx div 2 + 250, 200, 54)
            font := Font.New ("Algerian:40")
            Draw.Text ("Instructions", maxx div 2 - 180, 450, font, white)
            font := Font.New ("Algerian:15")
            Draw.Text ("Move with the respective keys", maxx div 2 - 165, 430, font, white)
            Draw.Text ("Player 1 --------------------- Player 2", maxx div 2 - 165, 410, font, white)
            font := Font.New ("Algerian:20")
            Draw.Text ("W-------------UP-----------UP", maxx div 2 - 145, 360, font, white)
            Draw.Text ("S-----------DOWN-------DOWN", maxx div 2 - 142, 330, font, white)
            Draw.Text ("A-----------LEFT--------LEFT", maxx div 2 - 145, 300, font, white)
            Draw.Text ("D-----------RIGHT------RIGHT", maxx div 2 - 145, 270, font, white)
            Draw.Text ("Press Anything To Continue...", 20, 20, font, white)
            View.Update
            Input.Pause
            exit
        end if
    end loop
    View.Set ("nooffscreenonly")     % Back to text mode
    cls
    put "Please enter PLAYER 1's name(ENTER FIRST NAME ONLY): " ..    % require name1
    get name1
    put " "
    put "Please enter PLAYER 2's name(ENTER FIRST NAME ONLY): " ..    % require name2
    get name2
    cls
    Music.PlayFileStop
    locate (20, 40)
    put "STARTING IN 3." ..
    delay (300)
    put "." ..
    delay (300)
    put "." ..
    delay (300)
    cls
    locate (20, 40)
    put "STARTING IN 2." ..
    delay (300)
    put "." ..
    delay (300)
    put "." ..
    delay (300)
    cls
    locate (20, 40)
    put "STARTING IN 1." ..
    delay (300)
    put "." ..
    delay (300)
    put "." ..
    delay (300)
    cls
    locate (20, 50)
    put "GO!!"
    delay (300)
    Music.PlayFileReturn ("During.wav")
    View.Set ("graphics:639;399,offscreenonly")
    View.Update
end title
%===================================================================
%==========================GAME FUNCTIONS===========================
%===================================================================
%showLives- displays players' lives
procedure showLives (var p1Life, p2Life : int)
    View.Update
    locate (4, maxcol div 2 - 1)
    put "P1: " ..
    locate (5, maxcol div 2)
    put p1Life ..
    locate (8, maxcol div 2 - 1)
    put "P2: " ..
    locate (9, maxcol div 2)
    put p2Life ..
    View.Update
end showLives

%waver- shows how long the pattern is going to last for
procedure waver (var waveLeft : int)
    locate (1, maxcol div 2 - 1)
    put "Waves" ..
    locate (2, maxcol div 2)
    put "Left:" ..
    View.Update
end waver

%isPlayerDead- checks if a player has run out of lives
procedure isPlayerDead (var p1life, p2life : int, var player1dead, player2dead : boolean)
    if p1life = 0
            then
        player1dead := true
        locatexy (maxx div 4, maxy div 2)
        put "DEAD" ..
    end if
    if p2life <= 0
            then
        player2dead := true
        locatexy (maxx div 4 * 3, maxy div 2)
        put "DEAD" ..
    end if
    View.Update
end isPlayerDead

%isPlayerHit1- checks if player has been hit by a bullet for pattern 1
procedure isPlayerHit1 (var active, player1x, player1y, player1Lives, player2x, player2y, player2Lives : int, var bulletx, bullety : array 1 .. * of int)
    for i : 1 .. active div 2     %decrease player1's life if hit
        if abs (bulletx (i) - player1x) < 8 and abs (bullety (i) - player1y) < 8 then
            player1Lives -= 1
            player1x := 148
            player1y := 8
            View.Update
        end if
    end for
    for i : active div 2 .. active     %decrease player2's life if hit
        if abs (bulletx (i) - player2x) < 8 and abs (bullety (i) - player2y) < 8 then
            player2Lives -= 1
            player2x := 502
            player2y := 8
        end if
    end for
    View.Update
end isPlayerHit1

%isPlayerHit2- checks if player has been hit by a bullet for pattern 2
procedure isPlayerHit2 (var active, player1x, player1y, player1Lives, player2x, player2y, player2Lives : int, var bulletx, bullety : array 1 .. * of int, var whichDirection : array 1 .. * of
        string,
        player1dead, player2dead : boolean)
    for i : 1 .. 20     %verts
        %player 1 hit
        if player1dead = false then
            if abs (bulletx (i) - player1x) < 18 and abs (bullety (i) - player1y) < 18 then
                player1Lives -= 1
                player1x := 148
                player1y := 8
                View.Update
            end if
        end if
        %p2 hit
        if player2dead = false then
            if abs (bulletx (i) - player2x) < 18 and abs (bullety (i) - player2y) < 18 then
                player2Lives -= 1
                player2x := 502
                player2y := 8
            end if
        end if
    end for
    %p1 horzntal
    if player1dead = false then
        for i : 21 .. 30
            if player1x > bulletx (i) - 7 and player1y > bullety (i) - 6 and player1x < bulletx (i) + 7 and player1y < bullety (i) + 6 then
                player1Lives -= 1
                player1x := 148
                player1y := 8
                View.Update
            end if
        end for
        for i : 41 .. 50
            if player1x > bulletx (i) - 7 and player1y > bullety (i) - 6 and player1x < bulletx (i) + 7 and player1y < bullety (i) + 6 then
                player1Lives -= 1
                player2x := 502
                player2y := 8
            end if
        end for
    end if
    %p2 horzntl
    if player2dead = false then
        for i : 31 .. 40
            if player2x > bulletx (i) - 7 and player2y > bullety (i) - 6 and player2x < bulletx (i) + 7 and player2y < bullety (i) + 6 then
                player2Lives -= 1
                player2x := 502
                player2y := 8
            end if
        end for
        for i : 51 .. 60
            if player2x > bulletx (i) - 7 and player2y > bullety (i) - 6 and player2x < bulletx (i) + 7 and player2y < bullety (i) + 6 then
                player2Lives -= 1
                player2x := 502
                player2y := 8
            end if
        end for
    end if
    View.Update
end isPlayerHit2
%============================================================================
%=======================RUNNING THE ACTUAL GAME==============================
%============================================================================
loop
    View.Update
    %defining more variables
    var player1dead, player2dead : boolean := false     %if player gets hit
    var player1Lives, player2Lives : int := 5
    var waveLeft := 1     %how many waves the pattern will last
    var p1score, p2score : int := 0
    var name, highName : string
    var highscore : int
    var winner : int := 0
    var stream : int

    %title
    endGame := false
    title
    exit when endGame = true
    cls
    View.Set ("graphics:639;399,offscreenonly")
    View.Update

    %drawing the player boundaries
    color (black)
    drawbox (1, 1, maxx div 2 - 25, maxy - 1, black)
    drawbox (maxx div 2 + 25, 1, maxx - 1, maxy - 1, black)
    View.Update
    %setups
    playersready     %initialize player positions
    View.Update
    loop
        %initialize pattern 2 bullets and waves
        pattern2ready
        waveLeft := 1
        locate (3, maxcol div 2 + 1)
        put "10" ..
        View.Update
        %pattern 2
        loop

            exit when (player1dead and player2dead) or waveLeft = 0
            playermove (player1dead, player2dead)     %moving players
            pattern2draw (waveLeft, player1dead, player2dead, p1score, p2score)     %moving bullets
            delay (3)
            waver (waveLeft)
            showLives (player1Lives, player2Lives)     %life counter
            isPlayerHit1 (active, player1x, player1y, player1Lives, player2x, player2y, player2Lives, bulletx, bullety)
            isPlayerDead (player1Lives, player2Lives, player1dead, player2dead)
            View.Update
        end loop

        %reset waves
        waveLeft := 10
        locate (3, maxcol div 2 + 1)
        put waveLeft ..
        %pattern 3 whether bullet moves right or left or down
        var whichDirection : array 1 .. 600 of string
        %free pattern 1 sprites
        for i : 1 .. active
            Sprite.Free (bullets (i))
        end for
        %reset amount of active bullets
        active := 1

        %spawning bullets for pattern 3
        pattern3spawn (active, whichDirection)
        active := active - 1

        %pattern 3
        loop
            View.Update
            exit when (player1dead and player2dead) or waveLeft = 0
            playermove (player1dead, player2dead)
            pattern3move (active, whichDirection, waveLeft, player1dead, player2dead, p1score, p2score)
            delay (10)
            waver (waveLeft)
            showLives (player1Lives, player2Lives)
            isPlayerHit2 (active, player1x, player1y, player1Lives, player2x, player2y, player2Lives, bulletx, bullety, whichDirection, player1dead, player2dead)
            isPlayerDead (player1Lives, player2Lives, player1dead, player2dead)
        end loop
        for i : 1 .. active
            Sprite.Free (bullets (i))
        end for
        exit when player1dead and player2dead
    end loop

    cls
    % RUN AGAIN//////////////////////////////////////////////////////
    cls
    Sprite.Hide (player1s)
    Sprite.Hide (player2s)
    Music.PlayFileStop
    locate (maxrow div 2, maxcol div 2)
    put "GAME OVER."
    delay (3000)

    %reset player positions
    player1x := 148     %player1's x position
    player2x := 502     %player2's x position
    player1y := 8     %player1 y position
    player2y := 8     %player2 y position

    %hide bullets
    for i : 1 .. active
        bulletx (i) := maxx + 20
        bullety (i) := maxy + 20
    end for
    cls

    View.Set ("nooffscreenonly")
    Music.PlayFileReturn ("Death.mp3")
    put name1, " survived ", p1score, " waves."
    put name2, " survived ", p2score, " waves."
    put " "

    % who won?
    if p1score > p2score then
        put name1, " won!"
        winner := 1
    elsif p2score > p1score then
        put name2, " won!"
        winner := 2
    else
        put "The two players tied!"
        winner := 3
    end if

    put " "
    %highscoring
    open : stream, "highscore.txt", get
    get : stream, highscore, highName : *
    close (stream)
    type Highscore :
        record
            name : string
            score : int
        end record

    var score : Highscore
    if (p1score or p2score) > highscore then
        if winner = 1 then     %p1 highscore
            score.name := highName
            score.score := highscore
            name := name1
            open : stream, "highscore.txt", write, seek, mod
            seek : stream, *
            write : stream, score
            %put : stream, p1score, " ", name
            close (stream)
        elsif winner = 2 then     %p2 highscore
            put name2, " beat ", highName, "'s highscore of ", highscore, "!"
            name := name2
            open : stream, "highscore.txt", put
            put : stream, p2score, " ", name
            close (stream)
        elsif winner = 3 then     %tied highscore
            put "Both players tied, but you both beat ", highName, "'s highscore of ", highscore, "!"
            put "Input the team's name: " ..
            get name : *
            open : stream, "highscore.txt", put
            put : stream, p2score, " ", name
            close (stream)
        end if
    end if
    put "Run again? Enter anything to continue, 'no' to exit"     %try again?
    get response : *
    if response = "no" or response = "No" or response = "NO" then     % get response
        endGame := true
    end if
    if endGame = true
            then
        Window.Close (window)                  %Exits window
        exit
    end if
    if response not= "no" or response not= "No" or response not= "NO" then     % reset players
        player1x := 148
        player2x := 502
        player1y := 8
        player2y := 8
        crossthescreen := 8
        cls
    end if
    View.Set ("graphics:800;600")
end loop
Music.PlayFileStop




Please specify what version of Turing you are using
Turing 4.1.1



BULLETHELL.t
 Description:
Just cause it's kind of long, it won't run due to unuploaded pics + sound

Download
 Filename:  BULLETHELL.t
 Filesize:  35.12 KB
 Downloaded:  61 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Tue Jun 03, 2014 12:15 am   Post subject: Re: Emergency Help With School Summative

pizzajack1 @ Mon Jun 02, 2014 11:23 pm wrote:

Describe what you have tried to solve this problem
Removing title page

Good approach, but there's still too much left. What is the smallest example that you can make that will demonstrates this behaviour?

Alternatively, you can write some markers (commonly "entering/leaving procedure") to screen or file to see what part of the code the program is in and what it was doing before the problem. Knowing that "the problem is somewhere in this 10 line function" is much more useful than "the problem is somewhere in those 1100+ lines of code".
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
pizzajack1




PostPosted: Wed Jun 04, 2014 11:05 am   Post subject: Re: Emergency Help With School Summative

So the error IS inside the title page part? Do you potentially know what's causing the freezing?
Tony




PostPosted: Wed Jun 04, 2014 11:53 am   Post subject: Re: Emergency Help With School Summative

pizzajack1 @ Wed Jun 04, 2014 11:05 am wrote:
So the error IS inside the title page part?

I don't know, because this is a 1100+ line post. You'd need to find the parts of the code that are relevant to the problem observed.

What exactly do you mean by "freezing" anyway? If you add in code that prints text to screen/file, does that not happen?
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
pizzajack1




PostPosted: Wed Jun 04, 2014 5:03 pm   Post subject: Re: Emergency Help With School Summative

Freezing as in Turing itself becomes non-responsive, must shut it down and restart in order to run the program again
Tony




PostPosted: Wed Jun 04, 2014 5:44 pm   Post subject: RE:Emergency Help With School Summative

That's just the first part of the question. How about identifying the furthest responsive point?
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
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: