pong, hope you like, it has some music in it too!!
Author |
Message |
- IzAk -
|
Posted: Tue Jun 13, 2006 1:19 pm Post subject: pong, hope you like, it has some music in it too!! |
|
|
code: |
% J Jesse James Knudsen
% June 7,2006
% TIK 2
var stopIt : int
stopIt := 0
process playMyMusic
loop
Music.Play (">dbdbefdbdbef 4aaacbacbac 1efgefgefg 4bbbad 2gbgbacefefefab 8efefgbgbefefgbgbefagbccc 8abcdabcddefdefabcdabcddefdef ")
exit when stopIt = 10
end loop
end playMyMusic
%--------------------------------------------------------------------------
var winMain : int := Window.Open ("Graphics:781;541") % window for main menu
setscreen ("nocursor")
var col1 : int := 7 % color numbers for text, backround, paddles and ball
var col2 : int := 0
var delaytime : int := 10
var diff : string (1)
var stop : int := 250
var leave : int := 0
var x, y, movex, movey : int % Ball size & movement variables
var size : int := 10
x := maxx div 2
randint (y, 20, maxy - 20)
movex := 2
movey := 2
var padx1, pady1, padsizey, padsizex : int % paddle 1 size & movement variables
var move1 : string (1)
var movey1 : int
padx1 := 1
pady1 := (maxy div 2) - (110 div 2)
movey1 := 40
var padx2, pady2, padsizey2, padsizex2 : int % paddle 2 size & movement variables
var movey2 : int
padx2 := maxx - 2
pady2 := (maxy div 2) - (110 div 2)
movey2 := 20
var usescore, compscore : int := 0
fork playMyMusic
%---------------------------------------------------------------- main menu
put " *****************************************************"
delay (stop)
put " * Welcome To Pong *"
delay (stop)
put " *Please enter the diffuculty your would like to play*"
delay (stop)
put " * 1.Easy *"
delay (stop)
put " * 2.Medium *"
delay (stop)
put " * 3.Hard *"
delay (stop)
put " * 4.Impossible *"
delay (stop)
put " *****************************************************"
delay (stop)
getch (diff)
loop
if ord (diff) = 49 then % Selection of speed
put "Your Choose ", diff, ".Easy"
stop := 81
exit
elsif ord (diff) = 50 then % Selection of speed
put "Your Choose ", diff, ".Medium"
stop := 50
exit
elsif ord (diff) = 51 then % Selection of speed
put "Your Choose ", diff, ".Hard"
stop := 30
exit
elsif ord (diff) = 52 then % Selection of speed
put "Your Choose ", diff, ".Impossible"
stop := 2
exit
else % if an asked number is not selected
put "Invaild Entry"
put "Please enter the diffuculty your would like to play"
getch (diff)
end if
end loop
put "Press Any Key to Continue"
getch (diff)
setscreen ("offscreenonly")
% Ball Movement & speed
process ball
loop
delay (100)
loop
delay (delaytime)
x := x + movex
y := y + movey
% Ball bouncing off paddle2
if x - size <= padsizex then
if y - size <= padsizey and y + size >= pady1 then
movex := -movex
movex := movex + 1
else
leave := 1
end if
end if
% Ball bouncing off paddle2
if x + size >= padx2 then
if y - size <= padsizey2 and y + size >= pady2 then
movex := -movex
movex := movex - 1
else
leave := 2
end if
end if
% Ball bouncing of Y-Axis
if y >= maxy - 1 - 5 then
movey := -movey
movey := movey - 1
elsif y <= 1 + 5 then
movey := -movey
movey := movey + 1
end if
if leave = 1 or leave = 2 then
exit
end if
end loop
delay (1000)
exit when usescore = 5 or compscore = 5
end loop
end ball
% Paddle 1 movment
process paddle1
loop
loop
padsizex := padx1 + 5
padsizey := pady1 + 110
getch (move1)
if ord (move1) = 200 and padsizey <= maxy then
pady1 := pady1 + movey1
elsif ord (move1) = 208 and pady1 >= 0 then
pady1 := pady1 - movey1
end if
if leave = 1 or leave = 2 then
exit
end if
end loop delay (1000)
exit when usescore = 5 or compscore = 5
end loop
end paddle1
% Paddle 2 movement
process paddle2
loop
loop
padsizex2 := padx2 + 5
padsizey2 := pady2 + 110
delay (stop)
if y < pady2 + 55 then
pady2 := pady2 - movey2
elsif y > padsizey2 - 55 then
pady2 := pady2 + movey2
end if
if leave = 1 or leave = 2 then
exit
end if
end loop
delay (1000)
exit when usescore = 5 or compscore = 5
end loop
end paddle2
% Programed in user score and computer score
% Player score
process pics
loop
loop
drawfill (5,5,col1,col1)
Text.LocateXY (maxx div 2 - 4, 40)
Text.ColourBack (col1)
Text.Colour (col2)
put "SCORE!!!"
Text.LocateXY (maxx div 2 - 4, 30)
Text.ColourBack (col1)
Text.Colour (col2)
put "USER. - ", usescore
Text.LocateXY (maxx div 2 - 10, 20)
Text.ColourBack (col1)
Text.Colour (col2)
put " COMP. - ", compscore
drawfilloval (x, y, size, size, col2)
drawfillbox (padx1, pady1, padsizex, padsizey, col2)
drawfillbox (padx2, pady2, padsizex2, padsizey2, col2)
View.Update
if leave = 1 or leave = 2 then
exit
end if
cls
end loop
delay (999)
exit when usescore = 5 or compscore = 5
end loop
end pics
% Computer score
process score
loop
loop
if leave = 1 then
compscore := compscore + 1
delay (1000)
leave := 0
elsif leave = 2 then
usescore := usescore + 1
delay (1000)
leave := 0
end if
exit when usescore = 5 or compscore = 5
end loop
exit when usescore = 5 or compscore = 5
end loop
end score
process reset
loop
delay (500)
if leave = 1 or leave = 2 then
var size : int := 10
x := maxx div 2
randint (y, 20, maxy - 20)
movex := 2
movey := 2
padx1 := 1
pady1 := (maxy div 2) - (110 div 2)
padx2 := maxx - 2
pady2 := (maxy div 2) - (110 div 2)
end if
exit when usescore = 5 or compscore = 5
end loop
end reset
% Fork's for loops
fork ball
fork paddle1
fork paddle2
fork pics
fork score
fork reset
%Post text for score
Text.LocateXY (maxx div 2 - 4, 40)
put "SCORE!!!"
Text.LocateXY (maxx div 2 - 4, 30)
put "USER - ", usescore
Text.LocateXY (maxx div 2 - 10, 20)
put "COMP. - ", compscore
View.Update
%------------------------------
stopIt := 10 %end music |
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
BenLi
|
Posted: Thu Jun 15, 2006 8:45 pm Post subject: (No subject) |
|
|
you know that think in breakout where if you hit the ball on the side of the paddle it changes the angle and speeds it up?
that'd be a cool feature on this
and nice music? composer in the making? |
|
|
|
|
|
Reality Check
|
Posted: Thu Jun 15, 2006 9:04 pm Post subject: (No subject) |
|
|
Nice Program. I really like the music. Also, doing what the above poster suggested would be great using your code. It shouldn't be too hard to implement. Making different coloured tiles is obviously simple and using whatdotcolour, you can drop a power up item according to which box was hit. I'd give you bits if I knew how... |
|
|
|
|
|
Clayton
|
Posted: Thu Jun 15, 2006 9:16 pm Post subject: (No subject) |
|
|
/me starts to cry
why are you using processes???? pong certainly doesnt need them, the only real use they have in your program is for your music but thats it. also, look into some optimization in there |
|
|
|
|
|
xtremehacker
|
Posted: Thu Sep 07, 2006 6:03 pm Post subject: (No subject) |
|
|
cool game it would be better though if u could move the paddle with the mouse and not just the arrow keys. |
|
|
|
|
|
[Gandalf]
|
Posted: Thu Sep 07, 2006 6:19 pm Post subject: (No subject) |
|
|
Please stop posting in dead/old topics. This is called necro posting and is against [The Rules] which you should definately read before posting further. |
|
|
|
|
|
Foundation
|
Posted: Mon Sep 18, 2006 8:23 pm Post subject: (No subject) |
|
|
Is it still necro posting after someone already necro posted for it to get up again? I made a pong game, it required 270 some lines, and I have no idea what he did in his pong game. ex. fork? When I played it it's a good game though. Maybe I will understand more as I learn more turing.
Thanks for the game! |
|
|
|
|
|
[Gandalf]
|
Posted: Mon Sep 18, 2006 10:38 pm Post subject: (No subject) |
|
|
Only if you're necro posting the necro post. Either way, you should only be posting if you really have something useful to contribute. These things aren't set in stone, but it's good to generally follow the guidelines.
fork is related to processes, which you most probably won't be needing in your Turing programs. Do a search for "process" in the Turing sections and you'll see nothing but "DONT USE PROCESSES!!11!!!". So at best read the tutorials on them and follow that advice. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Foundation
|
Posted: Tue Sep 19, 2006 7:44 am Post subject: (No subject) |
|
|
Okay, thanks for the explaination. I was wondering how you would whatdotcolour for pong. How would you use whatdotcolour as a collision detector? You would need n ifs for n whatdotcolour (x,y)? That would take a long time... |
|
|
|
|
|
[Gandalf]
|
Posted: Tue Sep 19, 2006 2:33 pm Post subject: (No subject) |
|
|
The search button is there to help you for such questions which have most likely been asked hundreds of times.
A very simple pseudo-code-ish example:
code: | if whatdotcolour (paddle.x, paddle.y) = ball.colour then
ball.deflect
end if |
It should be noted that this very thing is do-able, not having to depend on Turing's fairly limited colour system:
code: | if Math.Distance(paddle.x, paddle.y, ball.x, ball.y) <= ball.radius then
ball.deflect
end if |
Also note that this idea won't work in reality, unless your paddle is one pixel wide by one pixel high. |
|
|
|
|
|
blaster009
|
Posted: Tue Sep 19, 2006 6:30 pm Post subject: (No subject) |
|
|
<BEN> casts <LIFE> on target <THISPOST>. Un-necroed! In addition to using the Math.Distance, try to think: The paddle is a rectangle...How could you make the ball not pass through said rectangle? (I suggest using simple comparisons between the ball's center position, which will be [ballX + radius, ballY + radius], and the maximum/minimum possible positions of the paddle (all four corners). |
|
|
|
|
|
|
|