
-----------------------------------
ReCreate
Mon Nov 09, 2009 7:57 pm

Yet another Pong game, Complete, With Beeps, points and tone sweeps!
-----------------------------------
Well...Here it is.
This is my first project...
[code]
/*
 PONG By ReCreate

 (yet another)Remake of the old game PONG
 Made in about 2-3 hours total.
 Why I made it? No reason really, Kind of a competition with someone I know who had to make one for a project.
 */
View.Set ("graphics,nobuttonbar")
var boxx, boxy, xvelocity, yvelocity, xupordown, yupordown, points, p2points : int
var gameover, font, playerpaddlepos, otherplayerpaddlepos, debug : int
var gameovermessage : string
const midx := maxx div 2
const midy := maxy div 2
var chars : array char of boolean

points := 0
p2points := 0
boxx := midx
boxy := midy
xvelocity := Rand.Int (-8 - points, 8 + points)
yvelocity := Rand.Int (-8 - points, 8 + points)
gameover := 0 %0 means game not over, 1 means it is
playerpaddlepos := 10
otherplayerpaddlepos := 0
debug := 0 %0 means not in debug mode, 1 means is in debug mode

%prevents sloooow moving balls
if yvelocity < 4 or xvelocity < 4 or xvelocity = 0 then
    xvelocity := Rand.Int (-8 - points, 8 + points)
    yvelocity := Rand.Int (-8 - points, 8 + points)
end if

loop
    Input.KeyDown (chars) %self explanatory

    if chars ('r') then
        %restarts the game
        boxx := midx
        boxy := midy
        boxy := midy
        xvelocity := Rand.Int (-8 - points, 8 + points)
        yvelocity := Rand.Int (-8 - points, 8 + points)
        gameover := 0
        %prevents sloooow moving balls
        if yvelocity < 4 or xvelocity < 4 or xvelocity = 0 then
            xvelocity := Rand.Int (-8 - points, 8 + points)
            yvelocity := Rand.Int (-8 - points, 8 + points)
        end if
    end if

    if chars ('d') then %debug mode
        if debug = 0 then
            debug := 1
        else
            debug := 0
        end if
        delay (150)
    end if

    if debug = 1 then
        put "Ball X velocity: " + intstr (xvelocity) + " Ball Y Velocity: " + intstr (yvelocity)
    end if

    if gameover = 0 then
        %GAME HAS NOT ENDED!!!

        if chars (KEY_UP_ARROW) then
            if playerpaddlepos < maxy - 95 then
                playerpaddlepos += 5
            end if
        end if

        if chars (KEY_DOWN_ARROW) then
            if playerpaddlepos > 0 then
                playerpaddlepos -= 5
            end if
        end if
        %finds is the box is out of the screen
        if boxx < 0 then
            gameovermessage := "You don't win. Still next level"
            gameover := 1
            p2points += 1
        end if
        if boxy < 0 then
            %bounce!
            yvelocity := -yvelocity
            Music.Sound (440, 50)
        end if

        if boxx > maxx then
            %you win
            gameover := 1
            gameovermessage := "You win! Next level"
            points += 1
        end if
        if boxy > maxy - 20 then
            %bounce!
            Music.Sound (440, 50)
            yvelocity := -yvelocity
        end if

        Time.DelaySinceLast (round (1000 / 30))     %delays to get 30 FPS

        Draw.Cls ()     %clears the screen for this frame
        put "Points: " + intstr (points) + "                                Points: " + intstr (p2points)
        Draw.Line (midx, 0, midx, maxy, black)
        %draws the ball
        Draw.Box (boxx, boxy, boxx + 20, boxy + 20, black)
        %moves the ball
        boxx += xvelocity
        boxy += yvelocity

        %moves the other paddle
        if boxy > otherplayerpaddlepos then
            otherplayerpaddlepos += 3 + points
        else
            otherplayerpaddlepos -= 3 + points
        end if

        %draws your paddle
        Draw.Box (20, playerpaddlepos, 40, playerpaddlepos + 80, black)
        %draws the other player's paddle
        Draw.Box (maxx - 20, otherplayerpaddlepos - 20, maxx - 40, otherplayerpaddlepos + 80 - 20, black)

        %collision checking
        if 619 >= boxx and 599 = boxy and otherplayerpaddlepos  0 then
                xvelocity += 1
            else
                xvelocity -= 1
            end if

            if yvelocity > 0 then
                yvelocity += 1
            else
                yvelocity -= 1
            end if
        end if

        if 40 >= boxx and 20 = boxy and playerpaddlepos  0 then
                xvelocity += 1
            else
                xvelocity -= 1
            end if

            if yvelocity > 0 then
                yvelocity += 1
            else
                yvelocity -= 1
            end if
        end if
    else
        if gameovermessage = "You win! Next level" then
            for i : 100 .. 3000 by 100
                Music.Sound (i, 50)         % Sound note
            end for
            %restarts the game
            boxx := midx
            boxy := midy
            boxy := midy
            xvelocity := Rand.Int (-8 - points, 8 + points)
            yvelocity := Rand.Int (-8 - points, 8 + points)
            gameover := 0
            %prevents sloooow moving balls
            if yvelocity < 4 or xvelocity < 4 or xvelocity = 0 then
                xvelocity := Rand.Int (-8 - points, 8 + points)
                yvelocity := Rand.Int (-8 - points, 8 + points)
            end if
        else
            for decreasing i : 2900 .. 200 by 100
                Music.Sound (i, 50)
            end for
            %restarts the game
            boxx := midx
            boxy := midy
            boxy := midy
            xvelocity := Rand.Int (-8 - points, 8 + points)
            yvelocity := Rand.Int (-8 - points, 8 + points)
            gameover := 0
            %prevents sloooow moving balls
            if yvelocity < 4 or xvelocity < 4 or xvelocity = 0 then
                xvelocity := Rand.Int (-8 - points, 8 + points)
                yvelocity := Rand.Int (-8 - points, 8 + points)
            end if
        end if
    end if
end loop
[/code]
Tell me what you think, Any suggestions, And any ideas to fix the (few) bugs there are.
Thanks
~ReCreate

-----------------------------------
D_homes
Mon Nov 09, 2009 8:41 pm

RE:Yet another Pong game, Complete, With Beeps, points and tone sweeps!
-----------------------------------
Great game considering its your first project.

I ran into trouble a couple of times where after a point is scored, the xvelocity = 0 so the ball just bounces up and down in a straight line. to prevent this you could use :

[code]
if xvelocity >= 0 then 
     xvelocity += 1 
else 
[/code]
instead of:
[code]
if xvelocity > 0 then 
   xvelocity += 1 
else 
[/code]

by adding the = sign you are saying if xvelocity is greater than/less than or equal to 0 then make it + 1 

therefor you would never run into that glitch

-----------------------------------
ReCreate
Mon Nov 09, 2009 9:50 pm

RE:Yet another Pong game, Complete, With Beeps, points and tone sweeps!
-----------------------------------
Thanks!
I updated the first post now.
Edit: Oh crap I can't edit a post that's been replied to...  :oops: 
Well anyways, Here is the Updated version.
[code]
/*
 PONG By ReCreate

 (yet another)Remake of the old game PONG
 Made in about 2-3 hours total.
 Why I made it? No reason really, Kind of a competition with someone I know who had to make one for a project.
 */
View.Set ("graphics,nobuttonbar")
var boxx, boxy, xvelocity, yvelocity, xupordown, yupordown, points, p2points : int
var gameover, font, playerpaddlepos, otherplayerpaddlepos, debug : int
var gameovermessage : string
const midx := maxx div 2
const midy := maxy div 2
var chars : array char of boolean

points := 0
p2points := 0
boxx := midx
boxy := midy
xvelocity := Rand.Int (-8 - points, 8 + points)
yvelocity := Rand.Int (-8 - points, 8 + points)
gameover := 0 %0 means game not over, 1 means it is
playerpaddlepos := 10
otherplayerpaddlepos := 0
debug := 0 %0 means not in debug mode, 1 means is in debug mode

if yvelocity  otherplayerpaddlepos then
            otherplayerpaddlepos += 3 + points
        else
            otherplayerpaddlepos -= 3 + points
        end if

        %draws your paddle
        Draw.Box (20, playerpaddlepos, 40, playerpaddlepos + 80, black)
        %draws the other player's paddle
        Draw.Box (maxx - 20, otherplayerpaddlepos - 20, maxx - 40, otherplayerpaddlepos + 80 - 20, black)

        %collision checking
        if 619 >= boxx and 599 = boxy and otherplayerpaddlepos = 0 then
                xvelocity += 1
            else
                xvelocity -= 1
            end if

            if yvelocity >= 0 then
                yvelocity += 1
            else
                yvelocity -= 1
            end if
        end if

        if 40 >= boxx and 20 = boxy and playerpaddlepos  0 then
                xvelocity += 1
            else
                xvelocity -= 1
            end if

            if yvelocity > 0 then
                yvelocity += 1
            else
                yvelocity -= 1
            end if
        end if
    else
        if gameovermessage = "You win! Next level" then
            for i : 100 .. 3000 by 100
                Music.Sound (i, 50)         % Sound note
            end for
            %restarts the game
            boxx := midx
            boxy := midy
            boxy := midy
            xvelocity := Rand.Int (-8 - points, 8 + points)
            yvelocity := Rand.Int (-8 - points, 8 + points)
            gameover := 0
            %prevents sloooow moving balls
            if yvelocity < 4 or xvelocity < 4 or xvelocity = 0 then
                xvelocity := Rand.Int (-8 - points, 8 + points)
                yvelocity := Rand.Int (-8 - points, 8 + points)
            end if
        else
            for decreasing i : 2900 .. 200 by 100
                Music.Sound (i, 50)
            end for
            %restarts the game
            boxx := midx
            boxy := midy
            boxy := midy
            xvelocity := Rand.Int (-8 - points, 8 + points)
            yvelocity := Rand.Int (-8 - points, 8 + points)
            gameover := 0
            %prevents sloooow moving balls
            if yvelocity < 4 or xvelocity < 4 or xvelocity = 0 then
                xvelocity := Rand.Int (-8 - points, 8 + points)
                yvelocity := Rand.Int (-8 - points, 8 + points)
            end if
        end if
    end if
end loop


[/code]

-----------------------------------
D_homes
Mon Nov 09, 2009 10:09 pm

RE:Yet another Pong game, Complete, With Beeps, points and tone sweeps!
-----------------------------------
Nope, still happened again, keep in mind you need to adjust this part aswell.

[code]
if 40 >= boxx and 20 = boxy and playerpaddlepos  0 then 
                xvelocity += 1 
            else 
                xvelocity -= 1 
            end if 

            if yvelocity > 0 then 
                yvelocity += 1 
            else 
                yvelocity -= 1 
            end if 
        end if 
[/code]

-----------------------------------
ReCreate
Mon Nov 09, 2009 10:56 pm

RE:Yet another Pong game, Complete, With Beeps, points and tone sweeps!
-----------------------------------
Yes I forgot that... The New one.
[code]
/*
 PONG By ReCreate

 (yet another)Remake of the old game PONG
 Made in about 2-3 hours total.
 Why I made it? No reason really, Kind of a competition with someone I know who had to make one for a project.
 */
View.Set ("graphics,nobuttonbar")
var boxx, boxy, xvelocity, yvelocity, xupordown, yupordown, points, p2points : int
var gameover, font, playerpaddlepos, otherplayerpaddlepos, debug : int
var gameovermessage : string
const midx := maxx div 2
const midy := maxy div 2
var chars : array char of boolean

points := 0
p2points := 0
boxx := midx
boxy := midy
xvelocity := Rand.Int (-8 - points, 8 + points)
yvelocity := Rand.Int (-8 - points, 8 + points)
gameover := 0 %0 means game not over, 1 means it is
playerpaddlepos := 10
otherplayerpaddlepos := 0
debug := 0 %0 means not in debug mode, 1 means is in debug mode

if yvelocity  otherplayerpaddlepos then
            otherplayerpaddlepos += 3 + points
        else
            otherplayerpaddlepos -= 3 + points
        end if

        %draws your paddle
        Draw.Box (20, playerpaddlepos, 40, playerpaddlepos + 80, black)
        %draws the other player's paddle
        Draw.Box (maxx - 20, otherplayerpaddlepos - 20, maxx - 40, otherplayerpaddlepos + 80 - 20, black)

        %collision checking
        if 619 >= boxx and 599 = boxy and otherplayerpaddlepos = 0 then
                xvelocity += 1
            else
                xvelocity -= 1
            end if

            if yvelocity >= 0 then
                yvelocity += 1
            else
                yvelocity -= 1
            end if
        end if

        if 40 >= boxx and 20 = boxy and playerpaddlepos = 0 then
                xvelocity += 1
            else
                xvelocity -= 1
            end if

            if yvelocity >= 0 then
                yvelocity += 1
            else
                yvelocity -= 1
            end if
        end if
    else
        if gameovermessage = "You win! Next level" then
            for i : 100 .. 3000 by 100
                Music.Sound (i, 50)         % Sound note
            end for
            %restarts the game
            boxx := midx
            boxy := midy
            boxy := midy
            xvelocity := Rand.Int (-8 - points, 8 + points)
            yvelocity := Rand.Int (-8 - points, 8 + points)
            gameover := 0
            %prevents sloooow moving balls
            if yvelocity < 4 or xvelocity < 4 or xvelocity = 0 then
                xvelocity := Rand.Int (-8 - points, 8 + points)
                yvelocity := Rand.Int (-8 - points, 8 + points)
            end if
        else
            for decreasing i : 2900 .. 200 by 100
                Music.Sound (i, 50)
            end for
            %restarts the game
            boxx := midx
            boxy := midy
            boxy := midy
            xvelocity := Rand.Int (-8 - points, 8 + points)
            yvelocity := Rand.Int (-8 - points, 8 + points)
            gameover := 0
            %prevents sloooow moving balls
            if yvelocity < 4 or xvelocity < 4 or xvelocity = 0 then
                xvelocity := Rand.Int (-8 - points, 8 + points)
                yvelocity := Rand.Int (-8 - points, 8 + points)
            end if
        end if
    end if
end loop
[/code]

-----------------------------------
Turing_Gamer
Wed Nov 11, 2009 4:30 pm

Re: Yet another Pong game, Complete, With Beeps, points and tone sweeps!
-----------------------------------
why don't you put it in a .zip file instead of having to copy paste all that text?

-----------------------------------
petree08
Thu Nov 12, 2009 8:54 am

RE:Yet another Pong game, Complete, With Beeps, points and tone sweeps!
-----------------------------------
Personally I find copying and pasting code easier than downloading and extracting a zip.

I only zip when i am only posting the exe or there are assets other than code

-----------------------------------
Prince Pwn
Thu Nov 12, 2009 2:00 pm

RE:Yet another Pong game, Complete, With Beeps, points and tone sweeps!
-----------------------------------
Yes, it's much easier copying and pasting code. Also, too bad edit doesn't work properly.

As for your code, a trick to make your graphics run smoother, use double buffering. Inside your code at the top, do:

View.Set("graphics;offscreenonly")

Then inside your loop after you draw, use: 

View.Update

-----------------------------------
Turing_Gamer
Wed Nov 18, 2009 3:29 pm

Re: Yet another Pong game, Complete, With Beeps, points and tone sweeps!
-----------------------------------
Ah the beeps is so annoying yet good.
Perfect for 8-bit playing...

-----------------------------------
ReCreate
Sun Nov 11, 2012 10:42 pm

RE:Yet another Pong game, Complete, With Beeps, points and tone sweeps!
-----------------------------------
Whoah. To think. I made this when I was only fourteen? Now that's not impressive by most standards, it's certainly impressive by my own.

I managed this at only fourteen with absolutely no help at all, and yet I'm this complete rubbish today.

(and I'm sorry if this goes against some sort of bumping, or reviving old threads rule, I just needed to write this for the sake of archival on these forums as my program is archived)

Edit: uhh... is my avatar supposed to be that big?

-----------------------------------
QuantumPhysics
Mon Nov 12, 2012 6:46 pm

RE:Yet another Pong game, Complete, With Beeps, points and tone sweeps!
-----------------------------------
Turing is meant to be understood by preschoolers.

Yea, reviving is not allowed on this forums, I don't know why, but you gotta play by the rules or go back to school

-----------------------------------
ReCreate
Mon Nov 12, 2012 7:03 pm

RE:Yet another Pong game, Complete, With Beeps, points and tone sweeps!
-----------------------------------
I don't understand why you seem to be insulting my education, though. I am the same person as the OP, just three years of untreated depression have passed.

Anyways, Please pardon this revival, I won't do it anymore.

-----------------------------------
Insectoid
Mon Nov 12, 2012 7:16 pm

RE:Yet another Pong game, Complete, With Beeps, points and tone sweeps!
-----------------------------------
QuantumPhysics, there's nothing wrong with reviving your own thread, and the logic behind the game is language independent. There's no need to be a dick.

-----------------------------------
Tony
Mon Nov 12, 2012 7:18 pm

RE:Yet another Pong game, Complete, With Beeps, points and tone sweeps!
-----------------------------------
Woah, hostilities. Necroposting is frowned upon, legitimate thread revivals are okay.

http://compsci.ca/v3/viewtopic.php?t=3151

Posting in old topics is generally frowned upon, unless the post is important, relevant or adds new content. If your post is important (for example, say you made a big improvement to an algorithm the original author was using), you may post in an otherwise dead topic. However, bringing up an old game from 
I feel that OP reflecting on their previous work and progress made over the last 3 years is a valid update to this thread.

-----------------------------------
QuantumPhysics
Tue Nov 13, 2012 9:52 am

Re: RE:Yet another Pong game, Complete, With Beeps, points and tone sweeps!
-----------------------------------
Woah, hostilities. Necroposting is frowned upon, legitimate thread revivals are okay.

http://compsci.ca/v3/viewtopic.php?t=3151

Posting in old topics is generally frowned upon, unless the post is important, relevant or adds new content. If your post is important (for example, say you made a big improvement to an algorithm the original author was using), you may post in an otherwise dead topic. However, bringing up an old game from 
I feel that OP reflecting on their previous work and progress made over the last 3 years is a valid update to this thread.

I did not realize you are allowed to revive threads on certain condtions. I thought it was no reviving at all

QuantumPhysics, there's nothing wrong with reviving your own thread, and the logic behind the game is language independent. There's no need to be a dick.

I was only sharing my opinion, just like mirhagk has the right to share his opinion on me.

-----------------------------------
ReCreate
Tue Nov 13, 2012 12:27 pm

RE:Yet another Pong game, Complete, With Beeps, points and tone sweeps!
-----------------------------------
It's best to not share an opinion than to share a degrading and rude opinion.
