-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pong via FreeCodeCamp - Github/IrisDroidology/Python-Learning
- Loading branch information
1 parent
f806190
commit 0362e6f
Showing
3 changed files
with
181 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# Simple Pong Game for Beginners | ||
# Youtube: https://www.youtube.com/watch?v=C6jJg9Zan7w | ||
# Part of Stellarios by ACORD - http://acord.tech/stellarios | ||
|
||
import turtle # module that lets you do basic graphics in Python | ||
|
||
wn = turtle.Screen() | ||
wn.title("Pong by ACORD") | ||
wn.bgcolor(black) | ||
wn.setup(width=800, height=600) | ||
wn.tracer(0) | ||
|
||
""" | ||
wn = turtle.Screen() # creates a variable called "wn" that is the game windows | ||
wn.title("Pong by ACORD") # sets the title that would appear on the window | ||
wn.bgcolor("black") # sets the game window bg color | ||
wn.setup(width=800, height=600) # sets the game window size | ||
wn.tracer(0) # stops the window from updating | ||
# Paddle A | ||
paddle_a = turtle.Turtle() # creates a game object. "turtle" = module, Turtle = class | ||
paddle_a.speed(0) # Speed of animation - maximum possible speed | ||
paddle_a.shape("square") # default - 20px*20px | ||
paddle_a.color("white") | ||
paddle_a.shapesize(stretch_wid=5, stretch_len=1) # Stretches the width and length of "paddle_a" | ||
paddle_a.penup() | ||
paddle_a.goto(-350, 0) # Sets the initial coordinates for the Paddle_A | ||
# Paddle B | ||
paddle_b = turtle.Turtle() # creates a game object. "turtle" = module, Turtle = class | ||
paddle_b.speed(0) # Speed of animation - maximum possible speed | ||
paddle_b.shape("square") # default - 20px*20px | ||
paddle_b.color("white") | ||
paddle_b.shapesize(stretch_wid=5, stretch_len=1) # Stretches the width and length of "paddle_a" | ||
paddle_b.penup() | ||
paddle_b.goto(350, 0) # Sets the initial coordinates for the Paddle_A | ||
# Ball | ||
ball = turtle.Turtle() # creates a game object. "turtle" = module, Turtle = class | ||
ball.speed(0) # Speed of animation - maximum possible speed | ||
ball.shape("square") # default - 20px*20px | ||
ball.color("white") | ||
ball.penup() | ||
ball.goto(0, 0) # Sets the initial coordinates for the Paddle_A | ||
# Main Game Loop | ||
while True: | ||
wn.update() # every time the loop runs, it updates the screen | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import turtle # imports the "turtle" function and asset set, which draws objects on the gameboard | ||
|
||
|
||
|
||
# Gameboard | ||
wn = turtle.Screen() # Utilises Python to create a screen | ||
wn.title("Pong by ACORD") # Sets the title of the menu bar | ||
wn.bgcolor("black") # sets the background colour to black | ||
wn.setup(width=800, height=600) # sets the game window to 800px wide and 600px tall | ||
wn.tracer(0) | ||
|
||
|
||
|
||
# Paddle A | ||
paddle_a = turtle.Turtle() | ||
paddle_a.speed(0) # Sets the initial value of the speed for paddle_a to 0 | ||
paddle_a.shape("square") # this sets the dimensions to 20px*20px, which is too small (see line #15) | ||
paddle_a.color("white") | ||
paddle_a.shapesize(stretch_wid=5, stretch_len=1) # Resizes the paddle | ||
paddle_a.penup() | ||
paddle_a.goto(-350, 0) # sets the coords for the original position for "paddle_a" | ||
|
||
|
||
|
||
# Paddle B | ||
paddle_b = turtle.Turtle() | ||
paddle_b.speed(0) # Sets the initial value of the speed for paddle_b to 0 | ||
paddle_b.shape("square") # this sets the dimensions to 20px*20px, which is too small (see line #15) | ||
paddle_b.color("white") | ||
paddle_b.shapesize(stretch_wid=5, stretch_len=1) # Resizes the paddle | ||
paddle_b.penup() | ||
paddle_b.goto(350, 0) # sets the coords for the original position for "paddle_b" | ||
|
||
|
||
|
||
# Ball | ||
ball = turtle.Turtle() | ||
ball.speed(0) # Sets the initial value of the speed for ball to 0 | ||
ball.shape("square") # this sets the dimensions to 20px*20px, which is too small (see line #15) | ||
ball.color("white") | ||
ball.penup() | ||
ball.goto(0, 0) # sets the coords for the original position for "ball" | ||
|
||
# Moving the paddles | ||
|
||
|
||
# Functions | ||
# Moving the paddles | ||
def paddle_a_up(): # defining function | ||
y = paddle_a.ycor # finding and defining the y coord for paddle_a | ||
y += 20 | ||
paddle_a.sety(y) | ||
# Key Binding | ||
wn.listen() | ||
wn.onkeypress(paddle_a_up, "w") | ||
|
||
|
||
|
||
# Main Game Loop | ||
while True: | ||
wn.update() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters