Pong

Raspberrypi
Posts: 6
Joined: Thu Jun 30, 2016 9:43 pm
My devices: iPad
Flag: United States of America

Pong

Post by Raspberrypi »

Code: Select all

playerScore = 0 ! comScore = 0 ! startSpeed = 0.1
SPRITE 0 LOAD "Paddle@2x.png" ! SPRITE 0 SHOW
SPRITE 1 LOAD "Paddle@2x.png" ! SPRITE 1 SHOW
SPRITE 2 LOAD "white_box.png" ! SPRITE 2 SHOW
init:
GRAPHICS 
REFRESH
GRAPHICS CLEAR 0, 0.4, 0
OPTION SPRITE POS CENTRAL
OPTION ANGLE DEGREES
RANDOMIZE
DRAW FONT NAME "AppleColorEmoji"
DRAW FONT SIZE 50
DRAW TEXT playerScore AT SCREEN_WIDTH()/4, 100
DRAW TEXT comScore AT SCREEN_WIDTH()/1.5, 100
FOR y = 0 TO SCREEN_HEIGHT() STEP 40
FILL RECT SCREEN_WIDTH()/2, y SIZE 2, 5
NEXT y
player_x = 100 ! player_y = SCREEN_HEIGHT()/2
com_x = SCREEN_WIDTH() - 100 ! com_y = SCREEN_HEIGHT()/2
ball_x = SCREEN_WIDTH()/2 ! ball_y = SCREEN_HEIGHT()/2
ballSpeed_x = 0 ! ballSpeed_y = 0 ! 
IF startSpeed < 0.5 THEN
startSpeed+= 0.05
ENDIF
DIM touches(3) ! game = 0

DEF constrain(v, x, y)
var = v
IF var < x THEN
var = x
ENDIF
IF var > y THEN
var = y
ENDIF
RETURN var
ENDDEF

DEF range(var, x, y)
bool = 0
IF var >= x THEN
IF var < y THEN
bool = 1
ENDIF
ENDIF
RETURN bool
ENDDEF

DEF hitPaddle(x, y)
IF range(.ball_x, x - 15, x + 15) = 1 THEN
IF range(.ball_y, y - 64, y + 64) = 1 THEN
.ballSpeed_x *= -1
.ballSpeed_y = (.ball_y - y) / 300
ENDIF
ENDIF
ENDDEF

1 SPRITE 0 AT player_x, player_y SCALE 2, 0.5 ANGLE 90
SPRITE 1 AT com_x, com_y SCALE 2, 0.5 ANGLE 90
SPRITE 2 AT ball_X, ball_y SCALE 0.5
touches(0) = touches(1)
touches(1) = touches(2)
GET TOUCH 0 AS x, y
touches(2) = y
delta = touches(2) - touches(1) 
IF touches(1) > 0 AND touches(2) > 0 THEN 
player_y += delta
ENDIF
IF ball_y < com_y - 40 THEN ! com_y -= startSpeed / 3 ! ENDIF
IF ball_y > com_y + 40 THEN ! com_y += startSpeed / 3 ! ENDIF
IF game = 0 THEN 
IF y <> -1 THEN 
game = 1 
IF RND(2) = 0 THEN
ballSpeed_x = -startSpeed 
ELSE
ballSpeed_x = startSpeed
ENDIF
ENDIF
ENDIF
player_y = constrain(player_y, 50, SCREEN_HEIGHT() - 50)
com_y = constrain(com_y, 50, SCREEN_HEIGHT() - 50)
IF game = 1 THEN
ball_x += ballSpeed_x
ball_y += ballSpeed_y
ENDIF
CALL hitPaddle(player_x, player_y) ! CALL hitPaddle(com_x, com_y)
IF ball_y < 10 OR ball_y > SCREEN_HEIGHT() - 10 THEN
ballSpeed_y *= -1
ENDIF
IF ball_x < -10 THEN
comScore +=1 
GOTO init
ENDIF
IF ball_x > SCREEN_WIDTH() + 10 THEN
playerScore +=1
GOTO init
ENDIF
GOTO 1

User avatar
rbytes
Posts: 1338
Joined: Sun May 31, 2015 12:11 am
My devices: iPhone 11 Pro Max
iPad Pro 11
MacBook
Dell Inspiron laptop
CHUWI Plus 10 convertible Windows/Android tablet
Location: Calgary, Canada
Flag: Canada
Contact:

Re: Pong

Post by rbytes »

This should be fun. But it won't run without the graphic images - the paddle and the white box. I hope you will post them. :D
The only thing that gets me down is gravity...

User avatar
Dutchman
Posts: 851
Joined: Mon May 06, 2013 9:21 am
My devices: iMac, iPad Air, iPhone
Location: Netherlands
Flag: Netherlands

Re: Pong

Post by Dutchman »

I think that the code is copied from https://books.google.nl/books?id=o2X0ui ... ng&f=false
But where are the images :?: :D

User avatar
rbytes
Posts: 1338
Joined: Sun May 31, 2015 12:11 am
My devices: iPhone 11 Pro Max
iPad Pro 11
MacBook
Dell Inspiron laptop
CHUWI Plus 10 convertible Windows/Android tablet
Location: Calgary, Canada
Flag: Canada
Contact:

Re: Pong

Post by rbytes »

It has been almost a month since I asked Raspberrypi to post them. I think we will have to supply them ourselves.

You are good with game graphics. We just need a paddle and a ball :lol:
The only thing that gets me down is gravity...

User avatar
Dutchman
Posts: 851
Joined: Mon May 06, 2013 9:21 am
My devices: iMac, iPad Air, iPhone
Location: Netherlands
Flag: Netherlands

Re: Pong

Post by Dutchman »

I have stolen my graphics from internet, that's why they look so good. :lol:
I will try to make 'Pong' complete. It remembers me of long ago.

User avatar
rbytes
Posts: 1338
Joined: Sun May 31, 2015 12:11 am
My devices: iPhone 11 Pro Max
iPad Pro 11
MacBook
Dell Inspiron laptop
CHUWI Plus 10 convertible Windows/Android tablet
Location: Calgary, Canada
Flag: Canada
Contact:

Re: Pong

Post by rbytes »

Same here. I started with a Commodore Vic 20, moved to a C64, then an Atari ST and then a couple of Amiga computers. Even today I marvel at what the professional Amiga artists could create with fewer, larger pixels and a fraction of the colors we have now.

Here is a self-portrait by Jim Sachs - one of the best of that elite group.
Attachments
image.gif
image.gif (25.5 KiB) Viewed 3731 times
The only thing that gets me down is gravity...

User avatar
Dutchman
Posts: 851
Joined: Mon May 06, 2013 9:21 am
My devices: iMac, iPad Air, iPhone
Location: Netherlands
Flag: Netherlands

Pong brought to life

Post by Dutchman »

I have brought Pong to life: ;)
https://www.dropbox.com/sh/ntucli2k8nql ... Ev_2a?dl=0
With 'large' ball it was easy to win, with smaller ball it will need some training. :lol:
Who will add sound? :D
won with large ball.PNG
won with large ball.PNG (84.39 KiB) Viewed 3723 times
tie played with small ball.PNG
tie played with small ball.PNG (82.67 KiB) Viewed 3723 times
Last edited by Dutchman on Wed Aug 10, 2016 2:04 pm, edited 2 times in total.

User avatar
Dutchman
Posts: 851
Joined: Mon May 06, 2013 9:21 am
My devices: iMac, iPad Air, iPhone
Location: Netherlands
Flag: Netherlands

Re: Pong, fit for launcher

Post by Dutchman »

I have improved the structure of pong and adapted for use with 'Launcher'
See viewtopic.php?f=20&t=1499
There is still no sound. Who cares? :D
new Pong during run.PNG
new Pong during run.PNG (16.51 KiB) Viewed 3718 times
Last edited by Dutchman on Fri Jan 20, 2023 12:25 pm, edited 1 time in total.

User avatar
rbytes
Posts: 1338
Joined: Sun May 31, 2015 12:11 am
My devices: iPhone 11 Pro Max
iPad Pro 11
MacBook
Dell Inspiron laptop
CHUWI Plus 10 convertible Windows/Android tablet
Location: Calgary, Canada
Flag: Canada
Contact:

Re: Pong

Post by rbytes »

Looks like fun! I will see if I can find some good sound effects.
The only thing that gets me down is gravity...

User avatar
Dutchman
Posts: 851
Joined: Mon May 06, 2013 9:21 am
My devices: iMac, iPad Air, iPhone
Location: Netherlands
Flag: Netherlands

Pong with conditional launcher

Post by Dutchman »

I corrected an error if the program was started with the device in vertical position. :oops:
Furthermore the launcher will be called conditionally.
The variable 'Launcher' at the beginning of the program sets the condition.

Post Reply