How to save Score
Author |
Message |
uknowhoiam
|
Posted: Mon May 04, 2009 12:14 pm Post subject: How to save Score |
|
|
What is it you are trying to achieve?
I am trying to save score, so the next i play i can see the best score
What is the problem you are having?
I dont know how to save score, i searched through the website but couldnt find anything
Describe what you have tried to solve this problem
I searched trough the website
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
Here is my game (not finshed yet)
Turing: |
import GUI
View.Set ("graphics:300;400,offscreenonly")
var ballx, bally, xpos, xpos2, ypos, gravity : real
var line, Colour, face, brick_colour, brickx, bricky, brickx2, bricky2, brickx3, bricky3, brickx4, bricky4, brickx5, bricky5, brickx6, bricky6, brickx7, bricky7, brickx8, bricky8, dotx, doty, dotx2,
doty2, dotx3, dotx4, doty3, doty4, doty5, doty6, doty7, doty8, score, picID, destination, speed, level, back : int
var keys : array char of boolean
var fail, die : boolean := false
var Score : boolean := true
var fontID, height, ascent, descent, internalLeading : int
Colour := 119
face := 255
line := 50
ballx := line + maxx - 100
bally := line
xpos := 1
xpos2 := - 1
ypos := 8
gravity := . 25
brickx := Rand.Int (0, 250 - 40)
bricky := Rand.Int (50, 90)
brickx2 := brickx + 40
bricky2 := bricky + 15
brickx3 := Rand.Int (0, 250 - 40)
bricky3 := Rand.Int (130, 200)
brickx4 := brickx3 + 40
bricky4 := bricky3 + 15
brickx5 := Rand.Int (0, 250 - 40)
bricky5 := Rand.Int (245, 275)
brickx6 := brickx5 + 40
bricky6 := bricky5 + 15
brickx7 := Rand.Int (0, 250 - 40)
bricky7 := Rand.Int (305, 350)
brickx8 := brickx7 + 40
bricky8 := bricky7 + 15
brick_colour := brown
dotx := maxx div 4
doty := 10
dotx2 := dotx + 3
doty2 := doty + 15
dotx3 := maxx div 2 + dotx
dotx4 := dotx3 + 3
doty3 := 110
doty4 := doty3 + 15
doty5 := 210
doty6 := doty5 + 15
doty7 := 310
doty8 := doty7 + 15
score := 0
destination := 500
speed := 17
level := 1
colourback (103)
cls
procedure Player
drawfilloval (round (ballx ), round (bally ), 10, 10, Colour ) %body
drawoval (round (ballx ), round (bally ), 10, 10, face ) %body outline
drawfilloval (round (ballx ) - 3, round (bally ) + 2, 1, 1, face ) %left eye
drawfilloval (round (ballx ) + 3, round (bally ) + 2, 1, 1, face ) %right eye
drawfillarc (round (ballx ), round (bally ) - 2, 2, 4, 180, 360, face ) %smile
end Player
procedure background
colourback (103)
drawfillbox (dotx, doty, dotx2, doty2, black)
drawfillbox (dotx, doty3, dotx2, doty4, black)
drawfillbox (dotx, doty5, dotx2, doty6, black)
drawfillbox (dotx, doty7, dotx2, doty8, black)
drawfillbox (dotx3, doty, dotx4, doty2, black)
drawfillbox (dotx3, doty3, dotx4, doty4, black)
drawfillbox (dotx3, doty5, dotx4, doty6, black)
drawfillbox (dotx3, doty7, dotx4, doty8, black)
end background
procedure game
loop
background
drawfillbox (brickx, bricky, brickx2, bricky2, brick_colour )
drawfillbox (brickx3, bricky3, brickx4, bricky4, brick_colour )
drawfillbox (brickx5, bricky5, brickx6, bricky6, brick_colour )
drawfillbox (brickx7, bricky7, brickx8, bricky8, brick_colour )
Player
View.Update
delay (speed )
cls
ballx - = xpos
bally + = ypos
ypos - = gravity
if bally <= bricky2 + 10 and bally >= bricky + 10 and ballx <= brickx2 and ballx + 10 >= brickx then %%i assume 10 is the size of the ball?
ypos := 10 - gravity
elsif bally <= bricky4 + 10 and bally >= bricky3 + 10 and ballx <= brickx4 and ballx + 10 >= brickx3 then
ypos := 10 - gravity
elsif bally <= bricky6 + 10 and bally >= bricky5 + 10 and ballx <= brickx6 and ballx + 10 >= brickx5 then
ypos := 10 - gravity
elsif bally <= bricky8 + 10 and bally >= bricky7 + 10 and ballx <= brickx8 and ballx + 10 >= brickx7 then
ypos := 10 - gravity
fail := true
end if
if bally <= bricky2 + 10 and bally >= bricky + 10 and ballx <= brickx2 and ballx + 10 >= brickx and Score = true then %%i assume 10 is the size of the ball?
score + = 10
elsif bally <= bricky4 + 10 and bally >= bricky3 + 10 and ballx <= brickx4 and ballx + 10 >= brickx3 and Score = true then
score + = 10
elsif bally <= bricky6 + 10 and bally >= bricky5 + 10 and ballx <= brickx6 and ballx + 10 >= brickx5 and Score = true then
score + = 10
elsif bally <= bricky8 + 10 and bally >= bricky7 + 10 and ballx <= brickx8 and ballx + 10 >= brickx7 and Score = true then
score + = 10
end if
if bally >= 230 then
doty - = 2
doty2 - = 2
doty3 - = 2
doty4 - = 2
doty5 - = 2
doty6 - = 2
doty7 - = 2
doty8 - = 2
bally - = 2
bricky - = 2
bricky2 - = 2
bricky3 - = 2
bricky4 - = 2
bricky5 - = 2
bricky6 - = 2
bricky7 - = 2
bricky8 - = 2
end if
if bally > maxy then
score + = 5
doty - = 2
doty2 - = 2
doty3 - = 2
doty4 - = 2
doty5 - = 2
doty6 - = 2
doty7 - = 2
doty8 - = 2
bally - = 2
bricky - = 2
bricky2 - = 2
bricky3 - = 2
bricky4 - = 2
bricky5 - = 2
bricky6 - = 2
bricky7 - = 2
bricky8 - = 2
end if
if doty2 <= 0 then
doty := maxy
doty2 := doty + 15
end if
if doty4 <= 0 then
doty3 := maxy
doty4 := doty3 + 15
end if
if doty6 <= 0 then
doty5 := maxy
doty6 := doty5 + 15
end if
if doty8 <= 0 then
doty7 := maxy
doty8 := doty7 + 15
end if
if bricky2 <= 0 then
brickx := Rand.Int (0, 250 - 40)
bricky := Rand.Int (maxy, maxy + 10)
brickx2 := brickx + 40
bricky2 := bricky + 15
Score := true
end if
if bricky4 <= 0 then
brickx3 := Rand.Int (0, 250 - 40)
bricky3 := Rand.Int (maxy, maxy + 10)
brickx4 := brickx3 + 40
bricky4 := bricky3 + 15
Score := true
end if
if bricky6 <= 0 then
brickx5 := Rand.Int (0, 250 - 40)
bricky5 := Rand.Int (maxy, maxy + 10)
brickx6 := brickx5 + 40
bricky6 := bricky5 + 15
Score := true
end if
if bricky8 <= 0 then
brickx7 := Rand.Int (0, 250 - 40)
bricky7 := Rand.Int (maxy, maxy + 10)
brickx8 := brickx7 + 40
bricky8 := bricky7 + 15
Score := true
end if
if bally <= 15 and fail = true then
die := true
doty + = 4
doty2 + = 4
doty3 + = 4
doty4 + = 4
doty5 + = 4
doty6 + = 4
doty7 + = 4
doty8 + = 4
bricky + = 4
bricky2 + = 4
bricky3 + = 4
bricky4 + = 4
bricky5 + = 4
bricky6 + = 4
bricky7 + = 4
bricky8 + = 4
end if
if doty2 >= maxy and die = true then
doty := 0
doty2 := doty + 15
end if
if doty4 >= maxy and die = true then
doty3 := 0
doty4 := doty3 + 15
end if
if doty6 >= maxy and die = true then
doty5 := 0
doty6 := doty5 + 15
end if
if doty8 >= maxy and die = true then
doty7 := 0
doty8 := doty7 + 15
end if
if bricky2 >= maxy and die = true then
brickx := Rand.Int (0, 250 - 40)
bricky := 0
brickx2 := brickx + 40
bricky2 := bricky + 15
end if
if bricky4 >= maxy and die = true then
brickx3 := Rand.Int (0, 250 - 40)
bricky3 := 0
brickx4 := brickx3 + 40
bricky4 := bricky3 + 15
end if
if bricky6 >= maxy and die = true then
brickx6 := Rand.Int (0, 250 - 40)
bricky5 := 0
brickx6 := brickx5 + 40
bricky6 := bricky5 + 15
end if
if bricky8 >= maxy and die = true then
brickx7 := Rand.Int (0, 250 - 40)
bricky7 := 0
brickx8 := brickx7 + 40
bricky8 := bricky7 + 15
end if
if bally <= 15 and die = false then
ypos := 10 - gravity
end if
if ballx > maxx + 10 then
ballx := - 10
end if
if ballx < - 10 then
ballx := maxx + 10
end if
if xpos >= 3 then
xpos := 2
end if
if xpos <= - 3 then
xpos := - 2
end if
if score >= destination then
destination + = 525
speed - = 2
level + = 1
end if
locate (3, maxcol div 2)
colour (105)
put "LVL: ", level
locate (1, 1)
colour (105)
put "Next Level: ", destination
locate (1, maxcol - 11)
colour (105)
put "Score: ", score
Input.KeyDown (keys )
if keys (KEY_RIGHT_ARROW) then
xpos - = 2. 5
end if
if keys (KEY_LEFT_ARROW) then
xpos + = 2. 5
end if
end loop
end game
procedure instruction %instruction procedure
cls
colour (105)
put repeat ("%", maxcol)
locate (2, maxcol div 2 - 6)
put "Instructions"
locate (4, 1)
put "Move Happy Ball with the Left and Right arrows"
put repeat ("%", maxcol)
var Play2 : int := GUI.CreateButton (maxx div 2 - 20, maxy div 2, 0, "Play", %Creating a button called play
game )
View.Update %avoiding the flicker
loop
exit when GUI.ProcessEvent %exiting when pressed
end loop
end instruction
procedure menu %the menu procedure
fontID := Font.New ("Ariel:25:bold") %The font
Font.Sizes (fontID, height, ascent, descent, internalLeading ) %font size
Font.Draw ("Happy Ball", 43, 350, fontID, black)
drawfilloval (round (ballx ), round (bally + 130), 10, 10, Colour ) %body
drawoval (round (ballx ), round (bally + 130), 10, 10, face ) %body outline
drawfilloval (round (ballx ) - 3, round (bally + 130) + 2, 1, 1, face ) %left eye
drawfilloval (round (ballx ) + 3, round (bally + 130) + 2, 1, 1, face ) %right eye
drawfillarc (round (ballx ), round (bally + 130) - 2, 2, 4, 180, 360, face ) %smile
drawfillbox (brickx, bricky, brickx2, bricky2, brick_colour )
var Instruc : int := GUI.CreateButton (maxx div 2, maxy div 2, 0, "Instructions", %Creating a button called instructions
instruction )
View.Update
var Play : int := GUI.CreateButton (maxx div 2 - 70, maxy div 2, 0, "Play", %Creating a button called play
game )
View.Update
loop
exit when GUI.ProcessEvent %exiting when pressed
end loop
end menu
menu
|
Please specify what version of Turing you are using
<Answer Here> |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Tony
|
Posted: Mon May 04, 2009 12:57 pm Post subject: RE:How to save Score |
|
|
The game itself isn't relevant; you are just looking to read/write something from a file. There are tutorials for that + documentation on open, get and put |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
tjmoore1993
|
Posted: Mon May 04, 2009 4:14 pm Post subject: Re: RE:How to save Score |
|
|
Tony @ Mon May 04, 2009 12:57 pm wrote: The game itself isn't relevant; you are just looking to read/write something from a file. There are tutorials for that + documentation on open, get and put
Check out my load / saving system in tutorials section FIRST PAGE |
|
|
|
|
|
uknowhoiam
|
Posted: Fri May 08, 2009 10:26 am Post subject: RE:How to save Score |
|
|
i still dont get it... and i want to make the ball to not bouce off when it is under the brick.. i tried everything but cant come up with anything
can anyone help me?? |
|
|
|
|
|
Kharybdis
|
Posted: Fri May 08, 2009 10:45 am Post subject: Re: How to save Score |
|
|
You need to look up how to do I/O of files.
Example of Opening a file:
Turing: |
var fileName : string := "Master" % Name of file
var fileNo : int % Number of file
var inputVariable : string ( 100 )
open : fileNo, fileName, read %This opens the file to be read
read : fileNo, inputVariable
close : fileNo
|
That is just an example of opening a file, reading it, and closing. (This is taken directly from Turing's Documentation)
The commands to look up would be: close, get, put, read, write, seek, mod, tell.
Read some tutorials to understand all the particular elements.
As to your brick problem, you have to code in the fact that if the ball is below a brick, then that brick has no collision detection implemented, and it's above a brick, then collision may equal true.
Also, try not to use Turing's GUI... i find it very poor and primarily uncustomizable. You would do better creating your own buttons. |
|
|
|
|
|
|
|