Skip to content

Commit a486ecc

Browse files
authored
Added a pong game (#92)
* Update README.md * Update README.md * Create README.md * Create main.py * Update README.md * Update README.md * Update main.py * Add files via upload * Update README.md * Update README.md * Update README.md
1 parent 478a798 commit a486ecc

File tree

5 files changed

+189
-1
lines changed

5 files changed

+189
-1
lines changed

Pong Game/README.md

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# PONG GAME
2+
3+
A fun 2D dual Pong game made using Python.
4+
5+
#### Requirements for PC
6+
1. Python3 to be installed
7+
2. An IDE installed
8+
9+
#### To run this on your PC
10+
1. Fork this repository.
11+
2. Clone this repository bby downloading the zip file.
12+
3. Now go for main.py, run the file and ENJOY the game.
13+
14+
15+
##### NB
16+
Make sure that you are accessible to the .wav file.
17+
18+
19+
### Feel free to point out bugs by opening issues on the repository.

Pong Game/S27.wav

7.66 KB
Binary file not shown.

Pong Game/bounce.wav

5.67 KB
Binary file not shown.

Pong Game/main.py

+147
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
# A simple Pong game using Python
2+
3+
4+
import turtle
5+
import winsound
6+
7+
wn = turtle.Screen()
8+
wn.title('Pong Game')
9+
wn.bgcolor('blue')
10+
wn.setup(width=800, height=600)
11+
wn.tracer(0)
12+
13+
14+
# Score
15+
16+
score_a = 0
17+
score_b = 0
18+
19+
20+
# Paddle A
21+
22+
paddle_a = turtle.Turtle()
23+
paddle_a.speed(0)
24+
paddle_a.shape("square")
25+
paddle_a.color("grey")
26+
paddle_a.shapesize(stretch_wid=5, stretch_len=1)
27+
paddle_a.penup()
28+
paddle_a.goto(-350,0)
29+
30+
31+
# Paddle B
32+
33+
paddle_b = turtle.Turtle()
34+
paddle_b.speed(0)
35+
paddle_b.shape("square")
36+
paddle_b.color("grey")
37+
paddle_b.shapesize(stretch_wid=5, stretch_len=1)
38+
paddle_b.penup()
39+
paddle_b.goto(350,0)
40+
41+
42+
# Ball
43+
44+
ball = turtle.Turtle()
45+
ball.speed(0)
46+
ball.shape("circle")
47+
ball.color("red")
48+
ball.penup()
49+
ball.goto(0,0)
50+
ball.dx = 0.2
51+
ball.dy = 0.2
52+
53+
54+
# Pen
55+
56+
pen = turtle.Turtle()
57+
pen.speed(0)
58+
pen.color('White')
59+
pen.penup()
60+
pen.hideturtle()
61+
pen.goto(0, 260)
62+
pen.write("Player A : 0 Player B : 0", align = 'center', font = ('Courier', 24, 'normal'))
63+
64+
65+
# Functions
66+
67+
def paddle_a_up():
68+
y = paddle_a.ycor()
69+
y += 20
70+
paddle_a.sety(y)
71+
72+
def paddle_a_down():
73+
y = paddle_a.ycor()
74+
y -= 20
75+
paddle_a.sety(y)
76+
77+
def paddle_b_up():
78+
y = paddle_b.ycor()
79+
y += 20
80+
paddle_b.sety(y)
81+
82+
def paddle_b_down():
83+
y = paddle_b.ycor()
84+
y -= 20
85+
paddle_b.sety(y)
86+
87+
88+
# Keyboard binding
89+
90+
wn.listen()
91+
wn.onkeypress(paddle_a_up, "w")
92+
wn.onkeypress(paddle_a_down, "s")
93+
wn.onkeypress(paddle_b_up, "Up")
94+
wn.onkeypress(paddle_b_down, "Down")
95+
96+
97+
# Main game loop
98+
99+
while True:
100+
101+
wn.update()
102+
103+
# Move the ball
104+
105+
ball.setx(ball.xcor() + ball.dx)
106+
ball.sety(ball.ycor() + ball.dy)
107+
108+
# Border Checking
109+
110+
if ball.ycor() > 290:
111+
ball.sety(290)
112+
ball.dy *= -1
113+
winsound.PlaySound('bounce.wav', winsound.SND_ASYNC)
114+
115+
if ball.ycor() < -290:
116+
ball.sety(-290)
117+
ball.dy *= -1
118+
winsound.PlaySound('bounce.wav', winsound.SND_ASYNC)
119+
120+
if ball.xcor() < -390:
121+
ball.goto(0, 0)
122+
ball.dx *= -1
123+
score_b += 1
124+
pen.clear()
125+
pen.write("Player A : {} Player B : {}".format(score_a, score_b), align = 'center', font = ('Courier', 24, 'normal'))
126+
127+
if ball.xcor() > 390:
128+
ball.goto(0, 0)
129+
ball.dx *= -1
130+
score_a += 1
131+
pen.clear()
132+
pen.write("Player A : {} Player B : {}".format(score_a, score_b), align = 'center', font = ('Courier', 24, 'normal'))
133+
134+
# Paddle & Ball collision
135+
136+
if (ball.xcor() > 340 and ball.xcor() < 350) and (ball.ycor() < paddle_b.ycor() + 40 and ball.ycor() > paddle_b.ycor() - 40):
137+
ball.setx(340)
138+
ball.dx *= -1
139+
winsound.PlaySound('S27.wav', winsound.SND_ASYNC)
140+
141+
if (ball.xcor() < -340 and ball.xcor() > -350) and (ball.ycor() < paddle_a.ycor() + 40 and ball.ycor() > paddle_a.ycor() - 40):
142+
ball.setx(-340)
143+
ball.dx *= -1
144+
winsound.PlaySound('S27.wav', winsound.SND_ASYNC)
145+
146+
# END
147+
# YAY!

Spaceship-Battle/README.md

+23-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1-
## Spaceship Battle
1+
# Spaceship Battle
22

33
A fun 2D Spaceship dual Battle Game made using Pygame.
4+
5+
## Modules required to be installed:
6+
7+
1. Pygame
8+
2. Files from Assets folder
9+
10+
### Steps to install Pygame:
11+
12+
1. Open New Terminal on Visual Studio Code or PyCharm.
13+
2. Type "pip install pygame".
14+
3. The pygame should install automatically.
15+
4. If already installed, upgrade pygame.
16+
5. Type "pip install --upgrade pygame" to upgrade.
17+
18+
19+
#### To run this on your PC, follow the steps:
20+
1. Fork this repository.
21+
2. Clone this repository by downloading the zip file.
22+
3. Now go for main.py, run the file and ENJOY the game.
23+
24+
25+
### Feel free to point out bugs by opening issues on the repository.

0 commit comments

Comments
 (0)