
-----------------------------------
ezoeeeeet
Tue Jun 04, 2019 3:18 am

game wont work :(
-----------------------------------
What is it you are trying to achieve?
I took a code from this website and im trying to make a game with it for practice, but i don't understand what i am doing wrong with it 


What is the problem you are having?
It wont loop when i type in yes to restart the game, i can't transition from the instruction screen to the actual game



%variables
import GUI
setscreen ("graphics:500;500")
colourback (103)
for i : 1 .. 45
    put ""
end for
const radius := 5
const paddley1 := 10
const paddley2 := 20
var key : string (1)
var name, answer, resp : string
var iFont := Font.New ("serif:50")
var iFont2 := Font.New ("serif:30")
var iFont3 := Font.New ("serif:20")
var iFont4 := Font.New ("serif:13")
var chars : array char of boolean
var ballx, bally, xchange, ychange : int
var paddlex1, paddlex2 : int
var blockx1, blocky1, blockx2, blocky2 : int
var alreadyhit : array 1 .. 44 of boolean
var boxx1 : array 1 .. 44 of int
var boxy1 : array 1 .. 44 of int
var boxx2 : array 1 .. 44 of int
var boxy2 : array 1 .. 44 of int
var holding : boolean := true
var mousex, mousey, button : int
paddlex1 := (maxx div 2) - 40
paddlex2 := (maxx div 2) + 40
ballx := paddlex1 + 40
bally := paddley2 + 5
xchange := 0
ychange := 0
boxx1 (1) := 20
boxy1 (1) := maxy - 20
boxx2 (1) := 60
boxy2 (1) := maxy - 10
%Quit procedure
procedure QuitGame
    loop
        cls
        drawfilloval (500, 500, 140, 90, 0)
        drawfilloval (500, 450, 120, 95, 0)
        drawfilloval (0, 0, 100, 185, 0)
        drawfilloval (0, 10, 170, 145, 0)
        drawfilloval (20, 10, 160, 120, 0)
        Draw.Text ("Thank you for playing!", 120, 290, iFont3, 16)
        exit
    end loop
end QuitGame
proc makeboxes
    for i : 1 .. 43
        if i = 9 then
            boxx1 (9) := 20
            boxx2 (9) := 60
            boxy1 (9) := maxy - 40
            boxy2 (9) := maxy - 30
        elsif i = 18 then
            boxx1 (18) := 20
            boxx2 (18) := 60
            boxy1 (18) := maxy - 60
            boxy2 (18) := maxy - 50
        elsif i = 27 then
            boxx1 (27) := 20
            boxx2 (27) := 60
            boxy1 (27) := maxy - 80
            boxy2 (27) := maxy - 70
        elsif i = 36 then
            boxx1 (36) := 20
            boxx2 (36) := 60
            boxy1 (36) := maxy - 100
            boxy2 (36) := maxy - 90
        end if
        boxx1 (i + 1) := boxx1 (i) + 60
        boxy1 (i + 1) := boxy1 (i)
        boxx2 (i + 1) := boxx2 (i) + 60
        boxy2 (i + 1) := boxy2 (i)

        alreadyhit (i) := false
    end for
end makeboxes
proc game
    setscreen ("offscreenonly")
    loop
        Mouse.Where (mousex, mousey, button)
        Input.KeyDown (chars)
        ballx += xchange
        bally += ychange
        if ballx > (maxx - 5) then
            xchange *= -1
        elsif bally > (maxy - 5) then
            ychange := -2
        elsif bally < 0 then
            exit
        elsif ballx < 5 then
            xchange *= -1
        elsif bally < (paddley2 + 5) and bally > (paddley1) and ballx > paddlex1 and ballx < paddlex2 then
            if ballx < paddlex1 + 40 then
                ychange := 2
                xchange -= round (Math.Distance (paddlex1 + 40, bally, ballx, bally) / 10)
            elsif ballx > paddlex2 - 40 then
                ychange := 2
                xchange += round (Math.Distance (paddlex2 - 40, bally, ballx, bally) / 10)
            end if
        end if
        paddlex1 := mousex - 40
        paddlex2 := mousex + 40
        if button = 1 and holding = true then
            holding := false
            xchange := 2
            ychange := 2
        end if
        if holding = true then
            ballx := paddlex1 + 40
            bally := paddley2 + 5
        end if
        if paddlex1 < 0 then
            paddlex1 := 0
            paddlex2 := 80
        elsif paddlex2 > maxx then
            paddlex2 := maxx
            paddlex1 := maxx - 80
        end if
        for i : 1 .. 43
            drawfillbox (boxx1 (i), boxy1 (i), boxx2 (i), boxy2 (i), 82)
            if (bally > boxy1 (i) - 5 and bally < boxy2 (i) and ballx > boxx1 (i) and ballx < boxx2 (i)) and alreadyhit (i) = false then
                alreadyhit (i) := true
                if ychange = 2 then
                    ychange := -2
                elsif ychange = -2 then
                    ychange := 2
                end if
            end if
            if alreadyhit (i) = true then
                drawfillbox (boxx1 (i), boxy1 (i), boxx2 (i), boxy2 (i), 103)
            end if
        end for
        drawfilloval (ballx, bally, radius, radius, 34)
        drawfillbox (paddlex1, paddley1, paddlex2, paddley2, 97)
        delay (5)
        View.Update
        cls
    end loop
end game
procedure menu
    Font.Draw ("Welcome to Breakout!", 80, 340, iFont2, 16)
    Font.Draw ("By: Eleni", 190, 300, iFont3, 16)
    drawfilloval (500, 500, 140, 90, 0)
    drawfilloval (500, 450, 120, 95, 0)
    drawfilloval (0, 0, 100, 185, 0)
    drawfilloval (0, 10, 170, 145, 0)
    drawfilloval (20, 10, 160, 120, 0)
    locate (16, 20)
    put "Please enter your name!"
    get name
end menu
proc instructions
    cls
    drawfilloval (500, 500, 140, 90, 0)
    drawfilloval (500, 450, 120, 95, 0)
    drawfilloval (0, 0, 100, 185, 0)
    drawfilloval (0, 10, 170, 145, 0)
    drawfilloval (20, 10, 160, 120, 0)
    Draw.Text ("How to play!", 85, 370, iFont3, 16)
    drawfilloval (85, 320, 3, 3, 16)
    Draw.Text ("Control platform with mouse", 93, 315, iFont4, 16)
    drawfilloval (85, 290, 3, 3, 16)
    Draw.Text ("Left click on mouse to start game", 93, 285, iFont4, 16)
    drawfilloval (85, 260, 3, 3, 16)
    Draw.Text ("Only one life, be careful!", 93, 255, iFont4, 16)
end instructions
loop
menu
var StartButton : int := GUI.CreateButton (200, 180, 0, "Start Game", instructions)
var ExitButton : int := GUI.CreateButton (200, 150, 0, "Quit Game", QuitGame)
loop
    exit when GUI.ProcessEvent
end loop
cls
instructions
var GameButton : int := GUI.CreateButton (100, 150, 0, "Begin!", makeboxes)
loop
    exit when GUI.ProcessEvent
end loop
makeboxes
loop
    game
    if bally < 0 then 
    drawfilloval (500, 500, 140, 90, 0)
    drawfilloval (500, 450, 120, 95, 0)
    drawfilloval (0, 0, 100, 185, 0)
    drawfilloval (0, 10, 170, 145, 0)
    drawfilloval (20, 10, 160, 120, 0)
    Font.Draw ("Would you like to play again?", 85, 420, iFont3, 16)
    Draw.Text (" 'Yes' or 'No' answers only :)", 90, 390, iFont3, 16)
    locate (10, 10)
    get answer
    if answer = "no" or answer = "No" then
        exit when answer = "no" or answer = "No"
    end if
    end if
end loop
end loop
cls
drawfilloval (500, 500, 140, 90, 0)
drawfilloval (500, 450, 120, 95, 0)
drawfilloval (0, 0, 100, 185, 0)
drawfilloval (0, 10, 170, 145, 0)
drawfilloval (20, 10, 160, 120, 0)
Draw.Text ("Thank you for playing!", 90, 390, iFont3, 16)
View.Update

-----------------------------------
Insectoid
Tue Jun 04, 2019 5:55 am

RE:game wont work :(
-----------------------------------
When you restart the game, what is the value of bally?
