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

Username:   Password: 
 RegisterRegister   
 Need some advice for my pong game please :)
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
krashnna




PostPosted: Wed Jun 10, 2015 4:18 pm   Post subject: Need some advice for my pong game please :)

What is it you are trying to achieve?
To get some help with my game!


What is the problem you are having?
Putting a max score limit on my game


Describe what you have tried to solve this problem
Not sure where to start


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
----
[syntax="turing"]

<Add your code here>


%Introduction
colourback (black)
colour (black)
cls
colour (12)
locate (3, 22)
put " Welcome to Pong "
locate (10,3)
put "Paddle 1 Controls - w Moves Paddle Up, s moves Paddle Down"
locate (11,3)
put "Paddle 2 Controls - 8 Moves Paddle Up, 2 moves Paddle Down (Use number pad)"
locate (25, 17)
put " By Krishna, ICS 2014/2015 "
delay (5000)
cls

%Variables
setscreen ("graphics : 600; 300")
var x, y, xp, yp, xa, ya : int
var xstep, ystep, radius : int
var key : string (1)
var score1, score2 : int

score1 := 0
score2 := 0

xp := 20
yp := 190
xa := 620
ya := 190
x := round (maxx / 2)
y := round (maxy / 2)
radius := 5
xstep := 1
ystep := 1
%random moving ball
drawfillbox (xp, yp, xp + 7, yp + 70, darkgrey)
drawfillbox (xa, ya, xa - 7, ya + 70, darkgrey)
drawline (0, 375, maxx, 375, grey)
drawline (1, 375, maxx, 375, grey)
drawline (2, 375, maxx, 375, grey)
drawline (3, 375, maxx, 375, grey)
drawline (4, 375, maxx, 375, grey)
loop
drawline (0, 375, maxx, 375, grey)
drawline (1, 375, maxx, 375, grey)
drawline (2, 375, maxx, 375, grey)
drawline (3, 375, maxx, 375, grey)
drawline (4, 375, maxx, 375, grey)

drawfilloval (x, y, radius, radius, white)
delay (3)
drawfilloval (x, y, radius, radius, black)
x := x + xstep
y := y + ystep
if y > maxy - radius or y < radius then
ystep := -ystep
end if
if x > maxx - radius -1 then
xstep := -xstep
score1 := score1 + 1
x := round (maxx / 2)
y := round (maxy / 2)
elsif x < radius + 1 then
xstep := -xstep
score2 := score2 + 1
x := round (maxx / 2)
y := round (maxy / 2)
end if



%Paddle 1 Collison
if whatdotcolour (x - radius + 1, y) not= black then
xstep := -xstep
elsif whatdotcolour (x - radius - 1, y) not= black then
xstep := -xstep
elsif whatdotcolour (x, y - radius + 1) not= black then
ystep := -ystep
elsif whatdotcolour (x, y - radius - 1) not= black then
ystep := -ystep
elsif whatdotcolour (x + radius + 1, y) not= black then
xstep := -xstep
elsif whatdotcolour (x - radius - 1, y) not= black then
xstep := -xstep
elsif whatdotcolour (x, y + radius + 1) not= black then
ystep := -ystep
elsif whatdotcolour (x, y - radius - 1) not= black then
ystep := -ystep
end if

%Paddle 1 Movement

if hasch then
getch (key)
if key = "w" then
drawfillbox (xp, yp, xp + 7, yp + 70, black)
yp += 10
drawfillbox (xp, yp, xp + 7, yp + 70, darkgrey)
elsif key = "s" then
drawfillbox (xp, yp, xp + 7, yp + 70, black)
yp -= 10


%Paddle 2 Movement


drawfillbox (xp, yp, xp + 7, yp + 70, darkgrey)
elsif key = "8" then
drawfillbox (xa, ya, xa - 7, ya + 70, black)
ya += 10
drawfillbox (xa, ya, xa - 7, ya + 70, darkgrey)
elsif key = "2" then
drawfillbox (xa, ya, xa - 7, ya + 70, black)
ya -= 10
drawfillbox (xa, ya, xa - 7, ya + 70, darkgrey)
end if

%Paddle 2 Collison
if whatdotcolour (x + radius + 1, y) not= black then
xstep := -xstep
elsif whatdotcolour (x + radius - 1, y) not= black then
xstep := -xstep
elsif whatdotcolour (x, y + radius + 1) not= black then
ystep := -ystep
elsif whatdotcolour (x, y + radius - 1) not= black then
ystep := -ystep
end if

%Scoring
locate (1, 1)
put "Player 1 Score: ", score1
locate (1, 32)
put "Pong"
locate (1, 63)
put "Player 2 Score: ", score2
end if
end loop


Please specify what version of Turing you are using
<Answer Here>
Sponsor
Sponsor
Sponsor
sponsor
Insectoid




PostPosted: Wed Jun 10, 2015 7:42 pm   Post subject: RE:Need some advice for my pong game please :)

What do you want the game to do when the score limit is reached? There's a few different approaches. You could simply exit the loop using the 'exit when' command, or you could have the game restart, which requires you to reset all variables to their initial state and return to the top of the program, or whatever you want. Ultimately it comes down to detecting if the score limit is reached using either an if statement or an exit when statement and controlling the flow of the program when that statement returns true.
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  [ 2 Posts ]
Jump to:   


Style:  
Search: