Computer Science Canada

need help with a "replay" button and a "next level" button

Author:  Justinr666 [ Wed Jan 13, 2010 10:14 pm ]
Post subject:  need help with a "replay" button and a "next level" button

What is it you are trying to achieve?
im trying to have so that when you crash, instead of the game exiting, you get a message asking to try again, and also, when you complete the level, a way for you to go onto the second level


What is the problem you are having?
im not that good with turing code, so i cant figure out how to do it, or even how to start


Describe what you have tried to solve this problem
ive tried one example i found on here for a retry buttons, but had no luck getting it to work with my game


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


Turing:


var checkLeft, checkRight, checkUp, checkDown : boolean := false
var x, xp1, xp2, xp3, xp4, xp5 : int := 345
var y, yp1, yp2, yp3, yp4, yp5 : int := 210

var wacky : int
var chars : array char of boolean
View.Set ("offscreenonly")
wacky := Pic.FileNew ("Wacky Background.jpg")


loop
Pic.Draw (wacky, 0, 0, picCopy)
    if x > maxx - 2 then
        exit
    elsif x < 2 then
        exit
    end if
    if y > maxy - 2 then
        exit
    elsif y < 2 then
        exit
    end if
    drawline (0, 0, 0, 399, 7)
    drawline (0, 0, 639, 0, 7)
    drawline (0, 399, 639, 399, 7)
    drawline (639, 0, 639, 399, 7)

    drawline (50, 50, 150, 50, 3)
    drawline (50, 50, 50, 150, 3)
    drawline (50, 150, 150, 150, 3)
    drawline (150, 150, 150, 50, 3)

    Input.KeyDown (chars)



    if chars (KEY_UP_ARROW) and checkUp = true then
        xp1 := x
        xp2 := x
        yp1 := y
        yp2 := y - 5
        y := y + 5
        checkLeft := false
        checkRight := false
        checkDown := false

    end if
    if chars (KEY_RIGHT_ARROW) and checkRight = true then
        yp1 := y
        yp2 := y
        xp1 := x
        xp2 := x - 5
        x := x + 5
        checkLeft := false
        checkUp := false
        checkDown := false
    end if
    if chars (KEY_LEFT_ARROW) and checkLeft = true then
        yp1 := y
        yp2 := y
        xp1 := x
        xp2 := x + 5
        x := x - 5
        checkRight := false
        checkUp := false
        checkDown := false
    end if
    if chars (KEY_DOWN_ARROW) and checkDown = true then
        xp1 := x
        xp2 := x
        yp1 := y
        yp2 := y + 5
        y := y - 5
        checkLeft := false
        checkUp := false
        checkRight := false
    end if
    if x > 49 and x < 151 and y > 49 and y < 151 then
        exit
    end if


    drawfilloval (x, y, 4, 4, blue)
    drawfilloval (xp1, yp1, 4, 4, blue)
    drawfilloval (xp2, yp2, 4, 4, blue)
    delay (30)
View.Update
    cls

    checkDown := true
    checkUp := true
    checkRight := true
    checkLeft := true

end loop



Please specify what version of Turing you are using
turing 4.1.1

Author:  DemonWasp [ Wed Jan 13, 2010 10:18 pm ]
Post subject:  RE:need help with a "replay" button and a "next level" button

You have it set up so that your gameplay loop exits when you collide with something. You want to do that multiple times, assuming that the user chooses to continue. What does that sound like?

A loop. Put another loop around your existing loop. After your existing loop, have something that asks about whether the player wants to try again, and if not, exits the outer loop. Otherwise, just let it loop back up to the start of your "gameplay loop".

Author:  Justinr666 [ Wed Jan 13, 2010 10:40 pm ]
Post subject:  Re: need help with a "replay" button and a "next level" button

im not sure i quite understand what you mean.. i thought i did have it so it exits after each collison.. ill paste the collsion part of my code again..

% collision detection for the box obsticle
if x > maxx - 2 then
exit
elsif x < 2 then
exit
end if
if y > maxy - 2 then
exit
elsif y < 2 then
exit
end if
-----------------------------
% when you hit the box, the game exits
if x > 49 and x < 151 and y > 49 and y < 151 then
exit
end if

Author:  TheGuardian001 [ Wed Jan 13, 2010 11:03 pm ]
Post subject:  Re: need help with a "replay" button and a "next level" button

The collision part of your code is fine.

What DemonWasp meant was that in order to get the entire game to repeat itself (the stuff inside your current loop), you should add a second loop around the other one, in which you will ask the user if they want to play again.

By having this second loop with the play again option, when your main game loop exits, there is another loop which keeps the program going and asks if they would like to play again. If they answer no, you exit the second loop. Otherwise, you let the loop keep going, and it brings you back to the start and into your main game loop again.

Author:  Turing_Gamer [ Thu Jan 14, 2010 8:38 am ]
Post subject:  Re: need help with a "replay" button and a "next level" button

For example
Turing:
loop
    loop
        %Game code
        exit when gamefinish = true
    end loop
    put "Continue?"
    if answer = 'y' then
        %Reset code
    elsif answer = 'n' then
        exit
    end if
end loop
   

Author:  Justinr666 [ Thu Jan 14, 2010 10:49 am ]
Post subject:  RE:need help with a "replay" button and a "next level" button

oh, ok, thank you, i understand now

Author:  Justinr666 [ Fri Jan 15, 2010 2:09 pm ]
Post subject:  RE:need help with a "replay" button and a "next level" button

so i have a new problem, i have a picture for my title screen with text over it, but where ever the text is, is a ugly white box behind it, so i was wondering if there was a way to make it so the text displays directly over the picture with no white box behind it?

Author:  Zren [ Fri Jan 15, 2010 2:55 pm ]
Post subject:  RE:need help with a "replay" button and a "next level" button

Use Font.Draw instead of put statements. You can look up how to use it in the Turing Walkthrough or in the documentation (F9) or http://compsci.ca/holtsoft/doc/.


: