Computer Science Canada

Help with Game!

Author:  R2D2 [ Thu Jan 19, 2017 1:05 pm ]
Post subject:  Help with Game!

Hey guys so i need help with pong game that i am making. How can i make it when the ball hits sides it resets in middle and starts again. And also how can i add a timer, for example after 5 sec the game will start. Thanks Very Happy


Here are the codes:


View.Set ("graphics:400;300,nobuttonbar")
colorback (white)

var key : array char of boolean
var p1pad, p2pad, ballx, bally, p1dir, p2dir, balldir, ballny, ballnx, speed, winner, win, snd : int

p1pad := maxy div 2
p2pad := maxx div 2
ballx := maxx div 2
bally := maxy div 2
ballnx := 5
ballny := 5
speed := 5
snd := 0

loop
Input.KeyDown (key)
if key (KEY_UP_ARROW) and p1pad <= 270 then
p1dir := 1
elsif key (KEY_DOWN_ARROW) and p1pad >= 25 then
p1dir := 2
else
p1dir := 0
end if

if key ('w') and p2pad <= 270 then
p2dir := 1
elsif key ('s') and p2pad >= 25 then
p2dir := 2
else
p2dir := 0
end if

if p1dir = 1 then
p1pad := p1pad + 10
elsif p1dir = 2 then
p1pad := p1pad - 5
end if

if p2dir = 1 then
p2pad := p2pad + 5
elsif p2dir = 2 then
p2pad := p2pad - 5
end if

if ballx <= 10 then
winner := 1
exit
elsif bally <= 10 then
ballny := speed
end if

if ballx >= maxx - 10 then
winner := 2
exit
elsif bally >= maxy - 10 then
ballny := -speed
end if

if ballx >= maxx - 25 then
if p1pad + 20 >= bally + 5 and p1pad - 20 <= bally + 5 then
ballnx := -speed
speed := speed + 1
end if
end if

if ballx <= 25 then
if p2pad + 20 >= bally - 5 and p2pad - 20 <= bally - 5 then
ballnx := speed
speed := speed + 1
end if
end if

ballx += ballnx
bally += ballny

cls

for count : 1 .. 300
drawfillbox (maxx - 20, p1pad - 20, maxx - 10, p1pad + 20, black)
drawbox (4, 4, 395, 295, black)
drawfillbox (10, p2pad - 20, 20, p2pad + 20, black)
drawfilloval (ballx, bally, 5, 5, black)
end for

end loop

Author:  5c0r910n [ Thu Jan 19, 2017 3:30 pm ]
Post subject:  RE:Help with Game!

For the timer, try researching the delay function.
As for the ball reset, try having a piece of code checking for when the balls coordinates are past where the walls are, then run a procedure to set the ball back to the middle coordinates.
Oh, and for starting again have the main part as a procedure you call(this is like the easiest thing to research)
And if you are to continue posting n this forum, do me the grand favor of using code tags.
For example:

[code]
var name:string
get name
put name
[/code]


code:

var name:string
get name
put name



or replace "code" with "syntax="programming language"
like this:

[syntax="turing"]
var name:string
get name
put name
[/syntax]

Turing:

var name:string
get name
put name



it helps people who are used to editing in turing and also helps everyone focus on the code and separate from your own words

Author:  R2D2 [ Thu Jan 19, 2017 5:39 pm ]
Post subject:  RE:Help with Game!

Will look into those things thanks for help. And sorry new to this site not really sure how to post properly

Author:  5c0r910n [ Thu Jan 19, 2017 7:21 pm ]
Post subject:  RE:Help with Game!

its okay, i've been here for like a month or something

Author:  R2D2 [ Sat Jan 21, 2017 2:45 pm ]
Post subject:  RE:Help with Game!

Also i am trying to add music to my program i know what the code for it is

Music.PlayFile ("filename")

but it only starts to play music not the rest of the program any idea how i can fix it

Author:  Insectoid [ Sat Jan 21, 2017 3:23 pm ]
Post subject:  RE:Help with Game!

Music.PlayFileLoop() will play the sound in the background, and let your code execute as it plays. Music.PlayFileStop() will end playback.

Author:  R2D2 [ Sat Jan 21, 2017 3:38 pm ]
Post subject:  RE:Help with Game!

Thanks! it worked

Author:  R2D2 [ Sat Jan 21, 2017 4:40 pm ]
Post subject:  RE:Help with Game!

How can make the music stop at a certain place for example in main menu i want have different music and in game different music i tried Music.PlayFileStop() didnt work

Author:  Insectoid [ Sat Jan 21, 2017 6:55 pm ]
Post subject:  RE:Help with Game!

Did you get an error message?

Author:  R2D2 [ Sat Jan 21, 2017 9:38 pm ]
Post subject:  RE:Help with Game!

Call to 'PlayFileStop' has too many parameters.

Author:  Insectoid [ Sat Jan 21, 2017 9:47 pm ]
Post subject:  RE:Help with Game!

What do you think that error message means?

Author:  R2D2 [ Sat Jan 21, 2017 10:17 pm ]
Post subject:  RE:Help with Game!

Not sure what that means

Author:  Insectoid [ Sun Jan 22, 2017 10:05 am ]
Post subject:  RE:Help with Game!

Think about it. What is a parameter? Parameters are the arguments you pass to a function.

Draw.FillBox (x1, y1, x2, y2, color)

x1, y1, etc. Are all parameters. The error message says you have too many of them. How do you think you might fix that?

Error messages are Turing's way of telling you that you did something wrong. They aren't there just because they're pretty. If you read them, they will tell you where you messed up.

Furthermore, at the top centre of this web page, there's a 'Turing' button. Click that, and you'll see a link to the Turing 4.1 Online Documentation, which explains in detail how to use any function or keyword in Turing. You might wanna take a look there before trying to use functions you don't know.

Author:  R2D2 [ Sun Jan 22, 2017 3:17 pm ]
Post subject:  RE:Help with Game!

Okay i got that, but i want to know how i can play music at different stages of my game i tried
Music.PlayFileStop() but is stops all the music.

Author:  Insectoid [ Sun Jan 22, 2017 3:29 pm ]
Post subject:  RE:Help with Game!

There is no way to stop a specific song in Turing.

Music.PlayFileReturn() looks like it plays a file in the background once, without looping it. It still won't let you stop individual files. This is a limitation of Turing with no workaround.

Author:  R2D2 [ Sun Jan 22, 2017 3:51 pm ]
Post subject:  RE:Help with Game!

Okay i see thanks for your help, I got everything i needed. Is there a way i can remove this tread since i don't need further assistance.

Author:  Insectoid [ Sun Jan 22, 2017 5:19 pm ]
Post subject:  RE:Help with Game!

Nope. It stays here for all eternity, so that this doesn't happen.


: