Object Oriented Programming; Fall 2016
latest
Getting Started
Course Information
Installing Python
Installing PyGame
Hello PyGame
[Week 1] Hello PyGame
Using Objects
[Week 2] Introducing State
[Week 3] Encapsulating code
[Week 4] Our First Object
[Week 5] Multiple Objects
Mastering Objects
[Week 6] Designing Objects
[Week 7] Object Ecosystems
[Week 8] Object Practice and Projects
[Week 9] Project Discussions
Supplementary
Exercises
Cookbooks
Classes Cookbook
Colors!
Heroes Cookbook
Cookbook
Cookbook
Object Oriented Programming; Fall 2016
Docs
»
Cookbooks
Edit on GitHub
Cookbooks
ΒΆ
Classes Cookbook
Defining a class
Instantiating an object
Writing a method
Using the self variable
Using the property decorator
Inheriting properties and methods
Using the classmethod decorator
Colors!
Heroes Cookbook
Numbers
Integers
Floats
Basic math operations
Advanced math operations
Use the math library
Strings
Add two strings together
Repeat a string
Index into a string
Slice a string
String’s inner functions
Built-in Functions
Boolean algebra
Create a literal boolean variable
Create a boolean variable from comparisons
Combine two boolean variables with ‘and’ and ‘or’
If, elif, and else
Use an if to test for something
Create conditional logic
Nest one if inside another if
Lists
Create an empty list
Create a list with items
Add onto a list
Index into a list
Slice a list into a new list
Test if a value is inside a list
Sets
Create a set or convert a list to a set
Add an item to a set
Using sets to enforce uniqueness
For Loops
Write a for loop
Use the for loop’s loop variable
Use range inside a for loop
Use a list inside a for loop
Nest one for loop inside another for loop
While Loops
Use a comparison
Use a boolean variable
Loop forever
Special Loop Commands
Skip the rest of the current cycle in the loop
Break out of the loop entirely
Functions
No arguments and returns nothing
Takes one argument
Returns a value
Takes two arguments
Takes keyword arguments
Time module
Using time.time() to count how long something takes
Using time.sleep(n) to wait for n seconds
Random Module
Generate a random number between 0 and 1
Generate a random number between two integers
Select a random item from a list
Cookbook
Game Loop
Basic Sprites
Basic Sprite
Adding the drawing function to the basic sprite
Moving a sprite
Colliding with one other sprite
Using Groups of sprites
Colliding with many sprites
Adding an image to your sprite
Adding event handling to your sprite
Making an animated sprite
Basic Game Physics
Handling Keyboard Input
Scoreboards
Menus
Cookbook
Game Loop
Drawing
Using Rect to draw
Bouncing off obstacles
Basic collision detection with screen boundaries
Changing direction based on screen boundary collision
Colliding with another Rect
Read the Docs
v: latest
Versions
latest
Downloads
pdf
htmlzip
epub
On Read the Docs
Project Home
Builds
Free document hosting provided by
Read the Docs
.