top of page

Apple Catch Game With Python

  • Writer: Jackhammer
    Jackhammer
  • Jan 12, 2020
  • 1 min read

import turtle

import time

import random

import sys


# misc

caught = 0

miss = 0


win = turtle.Screen()

win.bgcolor("sky blue")

win.title("Apple Catch")

win.setup(600,600)


char = turtle.Turtle()

char.shape("square")

char.penup()

char.shapesize(2,13)

char.color("dark green")

char.hideturtle()

char.goto(0,-250)

char.showturtle()


pen = turtle.Turtle()

pen.color("red")

pen.penup()

pen.hideturtle()

pen.goto(0 , 200)

pen.speed(0)

pen.pensize(6)


def lt():

char.backward(20)


def rt():

char.fd(20)


def block():

if (char.xcor() <= -250):

char.setx(-250)


def rblock():

if (char.xcor() >= 250):

char.setx(250)


win.listen()


win.onkeypress(lt , "a")

win.onkeypress(rt , "d")

#game loop

while True:

block()

rblock()

posx = (random.randint(-220,220))

app = turtle.Turtle()

app.rt(90)

app.penup()

app.color("red")

app.shape("circle")

app.shapesize(2)

app.hideturtle()

app.goto(posx , 250)

app.showturtle()

app.fd(500)

if(app.xcor() > char.xcor() - 130 and app.xcor() < char.xcor() + 130 and app.ycor() < char.ycor() + 20 and app.ycor() > char.ycor() - 20):

caught += 1

pen.undo()

pen.write("SCORE: " + str(caught) + " " + " MISSED: " + str(miss) , align = "center" , font = ("Arial" , 24 , "bold"))

app.hideturtle()

else:

miss += 1

app.hideturtle()

pen.undo()

pen.write("SCORE: " + str(caught) + " " + " MISSED: " + str(miss) , align = "center" , font = ("Arial" , 24 , "bold"))

if (miss == 5):

pen.undo()

pen.write("GAME OVER", align = "center" , font = ("Arial" , 24 , "bold"))

break

sys.exit(3)



 
 
 

Recent Posts

See All
DODGE Game Source Code

import turtle import time import random #screen a = turtle.Screen() a.setup(600,600) a.bgcolor('orange') a.title('DODGE') # cannon 1 can1...

 
 
 
ENDLESS GAME SOURCE CODE

# imports import time import turtle import random import sys #misc speed = 2.8 rang = 210 charspeed = 3 score = 0 #screen win =...

 
 
 
Python Fotball Game Source Code

# foot ball game import turtle import time # field (screen setup) mscreen = turtle.Screen() mscreen.bgcolor('dark green')...

 
 
 

Kommentare


bottom of page