Last active
July 18, 2018 20:17
-
-
Save topherPedersen/504d79b77dc3600339e52112cb36d272 to your computer and use it in GitHub Desktop.
Object Oriented Sprite Example in Python using the Turtle Graphics Library
This file contains hidden or 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
| # Example of how to create a player sprite object that inherits from the object | |
| # turtle.Turtle in Python using the 2D Turtle Graphics Module. Code posted to | |
| # my personal github for reference teaching students at theCoderSchool in | |
| # Flower Mound, TX | |
| # Launch Window using Turtle Graphics/Tkinter | |
| import turtle | |
| screen = turtle.Screen() | |
| screen.setup(635, 355) | |
| # Create Turtle Object | |
| myTurtle = turtle.Turtle() | |
| # Add Background | |
| screen.bgpic("DuckHuntBackgroundBlank.jpg") | |
| # Create Duck Sprite | |
| class Duck(turtle.Turtle): | |
| def __init__(self): | |
| turtle.Turtle.__init__(self) | |
| screen.addshape("DuckFlapUp.png") # Load Image Into Python Program | |
| duck = Duck() | |
| duck.hideturtle() | |
| duck.shape("DuckFlapUp.png") # Show Image on Screen | |
| duck.speed(0) | |
| duck.penup() # prevent duck object from drawing on screen as it moves | |
| duck.left(90) # rotate duck sprite for proper placement on screen | |
| duck.shape("DuckFlapUp.png") # Show Image on Screen | |
| duck.showturtle() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment