Computer Science Canada

Single player pong (no a/i)

Author:  Offroadrider [ Fri Apr 01, 2011 4:34 pm ]
Post subject:  Single player pong (no a/i)

this is a simple game of pong

controls are the up and down arrow keys

Code:

View.Set ("offscreenonly")

var ballx, bally : int := 200
var xchange, ychange : int := 1
var paddley : int
var chars : array char of boolean
var score := 0
paddley := 170

loop

Input.KeyDown (chars)
drawfillbox (0, 0, maxx, maxy, black)
drawfilloval (ballx, bally, 5, 5, white)
delay (0)
drawfillbox (10, paddley, 20, paddley + 80, white)


View.Update
ballx += xchange
bally += ychange

if bally > 389 then
ychange := -1
end if

if bally < 5 then
ychange := 1
end if

if ballx > 634 then
xchange := -1
end if

if ballx < 20 and bally > paddley and bally < paddley + 80 then
xchange := 1
score +=1
end if



if ballx < 0 then
ballx := 500
bally := 200
end if


%%%%%%%%%%%%%%%%%%%%%%%paddle movement%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if chars (KEY_UP_ARROW) then
paddley += 1
end if

if chars (KEY_DOWN_ARROW) then
paddley -= 1
end if

if paddley > 319 then
paddley := 319
end if

if paddley < 0 then
paddley := 0
end if



end loop



Try it out and respond with what you guys thought of the program

Author:  apython1992 [ Fri Apr 01, 2011 4:46 pm ]
Post subject:  RE:Single player pong (no a/i)

Not a bad start, the game-play is there. I suggest maybe slowing it down a touch, and using getch to let the user hit a key before it starts. After that, a good next step might be to split the paddle up into segments such that if it bounces off the middle segment, the ball's path can be reflected along the paddle's normal, and segments moving away from the center would reflect the ball at wider angles. Do you have any plans to add AI/an extra player?

Author:  Offroadrider [ Fri Apr 01, 2011 4:56 pm ]
Post subject:  Re: Single player pong (no a/i)

Thanks for the feed back!!!

About the speed, My laptop runs the program slower than others so I don't know by how much to slow it down.
Also I plan on adding an intro screen and an ai/second player in the future. (I just don't know how to program an a/i yet)

I'll post a revised version of the game under this topic.

Thanks for playing!! Very Happy

Author:  Offroadrider [ Sun Apr 03, 2011 12:44 pm ]
Post subject:  2 player pong

As promised, here is the code for the revised (now 2 player) game of pong.

Player 1 is on the left side and the controls are w, and s.
Player 2 is on the right side and the controls are the up and down arrow keys

The game counts the score up to 10 then states who won.



Please post a reply of what you guys thought of the revised game!

Thanks for playing!!! Very Happy

Author:  Raknarg [ Sun Apr 03, 2011 2:49 pm ]
Post subject:  RE:Single player pong (no a/i)

I think a delay (2) or (3) is good enough.
The only things I would like to see:
- an AI
- a menu with choices of AI or 2-P or a 3/4-P, or even a survival game where you constantly ramp the speed or something Razz
- game speed option

Author:  Insectoid [ Sun Apr 03, 2011 5:03 pm ]
Post subject:  RE:Single player pong (no a/i)

A working pong AI is ridiculously easy to make. If the ball is above the AI's paddle, move the paddle up. If it's below, move the paddle down.

Of course, you can make it a bit more fun by determining when the AI makes 'mistakes' and when it doesn't. Maybe it moves in the wrong direction, maybe it moves too fast or too slow.

Author:  Offroadrider [ Sun Apr 03, 2011 6:51 pm ]
Post subject:  Re: Single player pong (no a/i)

Thanks for the feed back.

I like the idea of a survival mode.

Upgrades for the next version:

a/i, survival mode, and hopefully sound fx's

Thanks for playing! Very Happy


: