Today's Agenda
4:30 - 4:45PM: Log on & Ice breakers: when did you get your first cell phone?
4:45 - 5:05PM: Definitions
Turtle: turtle is a pre-installed Python library that enables users to create pictures and shapes by providing them with a virtual canvas.
Global variable: Variables that are created outside of a function (as in all of the examples above) are known as global variables.
Friction: Friction is opposite to the direction of push applied on the body to make it move.
5:05 - 5:10 PM: Bio Break & Guided Python instruction
5:10 - 5:30PM: Guided Python instruction
5:30 - 6:00 PM: Save & Share!
In this course, you will learn the basics of Python programming. We will meet every Tuesday at 4:30pm to 6:00pm. You don't need any previous programming experiences and all you need to code in Python is a web browser (www.replit.com). Mr. Steven will teach you all the core aspects of the Python programming and I will simplify the more complex topics.
Today we will be creating our simple python game!
The goal is to create your game character and be able to move around the area. Next week we will add more features.
import turtle
#setting up canvas
wn = turtle.Screen()
wn.bgcolor('black')
wn.title('TKU Python Game!')
#setting up the player
player = turtle.Turtle()
player.speed(0)
player.penup()
# examples: green, blue, red
player.color('lime')
# examples: Square, Arrow, Circle, Turtle, Triangle, Classic
player.shape('turtle')
speed = 0
#speed up forward
def speed_up():
global speed
speed += 2
if speed > 2:
speed = 2
#slow-down backward
def slow_down():
global speed
speed -= 2
if speed < -2:
speed = -2
def right():
player.rt(30) #rt means right
def left():
player.lt(30) #lt means left
#friction!
def friction():
global speed
player.friction = 0.97
speed *= player.friction
#Now, we are going to configure with keys
turtle.listen()
turtle.onkeypress(speed_up, 'Up')
turtle.onkey(left, 'Left')
turtle.onkey(right, 'Right')
turtle.onkeypress(slow_down, 'Down')
#friction
while True:
player.forward(speed)
friction()
import turtle
#setting up canvas
wn = turtle.Screen()
wn.bgcolor('black')
wn.title('TKU Python Game!')
#setting up the player
player = turtle.Turtle()
player.speed(0)
player.penup()
# examples: green, blue, red
player.color('lime')
# examples: Square, Arrow, Circle, Turtle, Triangle, Classic
player.shape('turtle')
speed = 0
#speed up forward
def speed_up():
global speed
speed += 2
if speed > 2:
speed = 2
#slow-down backward
def slow_down():
global speed
speed -= 2
if speed < -2:
speed = -2
def right():
player.rt(30) #rt means right
def left():
player.lt(30) #lt means left
#friction!
def friction():
global speed
player.friction = 0.97
speed *= player.friction
#Now, we are going to configure with keys
turtle.listen()
turtle.onkeypress(speed_up, 'Up')
turtle.onkey(left, 'Left')
turtle.onkey(right, 'Right')
turtle.onkeypress(slow_down, 'Down')
#friction
while True:
player.forward(speed)
friction()