Skip to content

Commit 338d5c4

Browse files
authored
Add files via upload
1 parent 6caaf93 commit 338d5c4

File tree

10 files changed

+121
-0
lines changed

10 files changed

+121
-0
lines changed
1.43 KB
Binary file not shown.
1.47 KB
Binary file not shown.
1.33 KB
Binary file not shown.
1.37 KB
Binary file not shown.
1.43 KB
Binary file not shown.
1.46 KB
Binary file not shown.

Famous Arcade Game/generateball.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from turtle import Turtle
2+
import random
3+
4+
class Ball(Turtle):
5+
def __init__(self):
6+
super().__init__()
7+
self.shape("circle")
8+
# self.shapesize(3, 3)
9+
self.penup()
10+
self.bounce_x = 10
11+
self.bounce_y = 10
12+
def move(self):
13+
new_xcor = self.xcor() + self.bounce_x
14+
new_ycor = self.ycor() + self.bounce_y
15+
self.goto(new_xcor, new_ycor)
16+
17+
def bounce(self):
18+
self.bounce_y *= -1
19+
20+
def bounce1(self):
21+
self.bounce_x *= -1

Famous Arcade Game/main.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import turtle
2+
3+
import score
4+
from paddle import Paddle
5+
from generateball import Ball
6+
import time
7+
8+
screen = turtle.Screen()
9+
screen.setup(800, 600)
10+
screen.title("Arcade")
11+
screen.tracer(0)
12+
# paddle_class = Paddle(position)
13+
14+
l_paddle = Paddle((380, 0))
15+
r_paddle = Paddle((-385, 0))
16+
17+
ball = Ball()
18+
19+
screen.listen()
20+
screen.onkeypress(fun=l_paddle.fow, key="Up")
21+
screen.onkeypress(fun=l_paddle.bow, key="Down")
22+
23+
screen.onkeypress(fun=r_paddle.fow, key="w")
24+
screen.onkeypress(fun=r_paddle.bow, key="s")
25+
26+
27+
game_is_on = True
28+
while game_is_on:
29+
time.sleep(0.1)
30+
screen.update()
31+
ball.move()
32+
if ball.ycor() < -270 or ball.ycor() > 270:
33+
ball.bounce()
34+
35+
if ball.xcor() > 300 and ball.distance(l_paddle) < 25 or ball.xcor() < -300 and ball.distance(r_paddle) < 25:
36+
ball.bounce1()
37+
score.Score()
38+
# elif ball.distance(r_paddle) < 25 and ball.xcor() < -290:
39+
# ball.bounce1()
40+
41+
if ball.xcor() > 375 or ball.xcor() < -385:
42+
game_is_on = False
43+
screen.exitonclick()

Famous Arcade Game/paddle.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
from turtle import Turtle
2+
3+
4+
class Paddle(Turtle):
5+
def __init__(self, position):
6+
super().__init__()
7+
self.speed(20000)
8+
self.shape("square")
9+
self.shapesize(4, 1)
10+
self.penup()
11+
self.goto(position)
12+
13+
14+
def fow(self):
15+
new_y = self.ycor() + 15
16+
self.goto(self.xcor(), new_y)
17+
18+
def bow(self):
19+
new_y = self.ycor() - 15
20+
self.goto(self.xcor(), new_y)
21+
22+
23+
24+
25+
# def paddle2(self):
26+
# self.arcade.shape("square")
27+
# self.arcade.shapesize(4, 1)
28+
# self.arcade.penup()
29+
# self.arcade.goto(-370, 0)
30+
#
31+
# def paddle1(self):
32+
# self.arcade1.shape("square")
33+
# self.arcade1.shapesize(4, 1)
34+
# self.arcade1.penup()
35+
# self.arcade1.goto(370, 0)

Famous Arcade Game/score.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from turtle import Turtle
2+
3+
4+
class Score(Turtle):
5+
6+
def __init__(self):
7+
super().__init__()
8+
self.score = 0
9+
self.color("orchid")
10+
self.penup()
11+
self.goto(0, 270)
12+
self.hideturtle()
13+
self.generate_score()
14+
15+
def generate_score(self):
16+
# noinspection PyTypeChecker
17+
self.write(f'Score : {self.score}', align="center", font=('bold', 15, 'italic', 'underline'))
18+
19+
def clear_score(self):
20+
self.score += 1
21+
self.clear()
22+
self.generate_score()

0 commit comments

Comments
 (0)