Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

basic games to code in python

import turtle as t
playerAscore=0
playerBscore=0
 
#create a window and declare a variable called window and call the screen()
window=t.Screen()
window.title("The Pong Game")
window.bgcolor("green")
window.setup(width=800,height=600)
window.tracer(0)
 
#Creating the left paddle
leftpaddle=t.Turtle()
leftpaddle.speed(0)
leftpaddle.shape("square")
leftpaddle.color("white")
leftpaddle.shapesize(stretch_wid=5,stretch_len=1)
leftpaddle.penup()
leftpaddle.goto(-350,0)
 
#Creating the right paddle
rightpaddle=t.Turtle()
rightpaddle.speed(0)
rightpaddle.shape("square")
rightpaddle.color("white")
rightpaddle.shapesize(stretch_wid=5,stretch_len=1)
rightpaddle.penup()
rightpaddle.goto(-350,0)
 
#Code for creating the ball
ball=t.Turtle()
ball.speed(0)
ball.shape("circle")
ball.color("red")
ball.penup()
ball.goto(5,5)
ballxdirection=0.2
ballydirection=0.2
 
#Code for creating pen for scorecard update
pen=t.Turtle()
pen.speed(0)
pen.color("Blue")
pen.penup()
pen.hideturtle()
pen.goto(0,260)
pen.write("score",align="center",font=('Arial',24,'normal'))
 
#code for moving the leftpaddle
def leftpaddleup():
    y=leftpaddle.ycor()
    y=y+90
    leftpaddle.sety(y)
 
def leftpaddledown():
    y=leftpaddle.ycor()
    y=y+90
    leftpaddle.sety(y)
 
#code for moving the rightpaddle
def rightpaddleup():
    y=rightpaddle.ycor()
    y=y+90
    rightpaddle.sety(y)
 
def rightpaddledown():
    y=rightpaddle.ycor()
    y=y+90
    rightpaddle.sety(y)
 
#Assign keys to play
window.listen()
window.onkeypress(leftpaddleup,'w')
window.onkeypress(leftpaddledown,'s')
window.onkeypress(rightpaddleup,'Up')
window.onkeypress(rightpaddledown,'Down')
 
while True:
    window.update()
 
    #moving the ball
    ball.setx(ball.xcor()+ballxdirection)
    ball.sety(ball.ycor()+ballxdirection)
 
    #border set up
    if ball.ycor()>290:
        ball.sety(290)
        ballydirection=ballydirection*-1
    if ball.ycor()<-290:
        ball.sety(-290)
        ballydirection=ballydirection*-1
         
    if ball.xcor() > 390:
        ball.goto(0,0)
        ball_dx = ball_dx * -1
        player_a_score = player_a_score + 1
        pen.clear()
        pen.write("Player A: {}                    Player B: {} ".format(player_a_score,player_b_score),align="center",font=('Monaco',24,"normal"))
        os.system("afplay wallhit.wav&")
 
 
 
    if(ball.xcor()) < -390: # Left width paddle Border
        ball.goto(0,0)
        ball_dx = ball_dx * -1
        player_b_score = player_b_score + 1
        pen.clear()
        pen.write("Player A: {}                    Player B: {} ".format(player_a_score,player_b_score),align="center",font=('Monaco',24,"normal"))
        os.system("afplay wallhit.wav&")
 
     # Handling the collisions with paddles.
 
    if(ball.xcor() > 340) and (ball.xcor() < 350) and (ball.ycor() < paddle_right.ycor() + 40 and ball.ycor() > paddle_right.ycor() - 40):
        ball.setx(340)
        ball_dx = ball_dx * -1
        os.system("afplay paddle.wav&")
 
    if(ball.xcor() < -340) and (ball.xcor() > -350) and (ball.ycor() < paddle_left.ycor() + 40 and ball.ycor() > paddle_left.ycor() - 40):
        ball.setx(-340)
        ball_dx = ball_dx * -1
        os.system("afplay paddle.wav&")
Comment

games made with python

Python games are fun. But a lot of people don't know you can make games on python.
1. Battlefield 2 uses Python for all of its add-ons and a lot of its functionality.
2. Bridge Commander
3. Civilization IV uses Python for most of its tasks
4. Disney's Toontown Online is written in Python and uses Panda3D for graphics.
5. Doki Doki Literature Club!, a psychological horror visual novel using the Ren'Py engine
6. Eve Online uses Stackless Python.
7. Freedom Force
8. Frets on Fire is written in Python and uses Pygame
9. Mount & Blade is written in Python.
10. Pirates of the Caribbean Online is written in Python and uses Panda3D for graphics.
11. The Sims 4 uses Python
12. The Temple of Elemental Evil, a computer role-playing game based on the classic Greyhawk Dungeons & Dragons campaign setting
13. Unity of Command (video game) is an operational-level wargame about the 1942/43 Stalingrad Campaign on the Eastern Front.
14. Vampire: The Masquerade – Bloodlines, a computer role-playing game based on the World of Darkness campaign setting
15. Vega Strike, an open source space simulator, uses Python for internal scripting
16. World of Tanks uses Python for most of its tasks.
Thank you @Ankur who published the original on may 30th 2020 this is a re-upload
Thank you for reading!
This is remade!
I will keep updating the list to make sure that the games on the list are up to date
Comment

PREVIOUS NEXT
Code Example
Python :: unique_together what is used of it in django 
Python :: matplotlib point labels 
Python :: python gui drag and drop 
Python :: pdf to csv python 
Python :: pandas datetime from date month year columns 
Python :: python functions 
Python :: python tuple vs list 
Python :: how to remove a tuple from a list python 
Python :: get dataframe column names 
Python :: generate random token or id in django 
Python :: create app in django 
Python :: find index of values greater than python 
Python :: python save dictionary 
Python :: get the length of an array python 
Python :: matplotlib dateformatter x axis 
Python :: current date and time into timestamp 
Python :: levenshtein distance 
Python :: how to find an element in a list python 
Python :: def function in python 
Python :: pyplot new figure 
Python :: python multiline comment 
Python :: How to take total count of words in the list python 
Python :: catch error data with except python 
Python :: how to logout in django 
Python :: python password with special characters 
Python :: django install 
Python :: To visualize the correlation between any two columns | scatter plot graph 
Python :: find sum of factors of a number python 
Python :: how to run django in jupyter 
Python :: progress bar python 
ADD CONTENT
Topic
Content
Source link
Name
8+9 =