Created
May 4, 2019 10:03
-
-
Save mohitkh7/cb2a916452e9bdb9f5abd036ffca51a8 to your computer and use it in GitHub Desktop.
Python Game
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
import turtle | |
# set up screen | |
window = turtle.Screen() | |
window.bgcolor("#bbb") | |
# Setting up boundry | |
mypen = turtle.Turtle() | |
mypen.penup() | |
mypen.setposition(-260, -260) | |
mypen.pendown() | |
mypen.speed(5) | |
mypen.shapesize(1) | |
mypen.pensize(4) | |
mypen.hideturtle() | |
# moving boundry | |
for i in range(4): | |
mypen.forward(520) | |
mypen.left(90) | |
# creating a player | |
player = turtle.Turtle() | |
player.shapesize(1) | |
player.color("red") | |
player.shape("triangle") | |
player.speed(0) | |
player.penup() | |
def turn_right(): | |
player.right(30) | |
def turn_left(): | |
player.left(30) | |
def increase_speed(): | |
global speed | |
speed += 1 | |
def decrease_speed(): | |
global speed | |
speed -= 1 | |
# keyboard binding | |
turtle.listen() | |
turtle.onkey(turn_left, "Left") | |
turtle.onkey(turn_right, "Right") | |
turtle.onkey(increase_speed, "Up") | |
turtle.onkey(decrease_speed, "Down") | |
# setting up the speed for turtle | |
speed = 1 | |
while True: | |
player.forward(speed) | |
if player.xcor() < -245 or player.xcor() > 245: | |
player.right(180) | |
if player.ycor() < -245 or player.ycor() > 245: | |
player.right(180) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment