mdinfotech.net  



Unit 4: Game Dev in Python

In class lesson on how to run Python hello world in VSCode. print() and input() and basic variables.

Resources
  • Online GDB
  • Python Hello World
  • How to setup Python for VSCode
  • W3 Schools Python Tutorials
  • How are Python variables, typing, and operators are different from Java? Read the tutorials below and complete the exercise.

    Tutorials
  • Variables and Types
  • Basic Operators
  • Programming Exercise 1:

    Create a program that asks the user to enter their name and age. Print a message addressed to them that tells them the year that they will turn 100 years old.

    Read about String Formatting, and String Operations. Complete the exercise below.

    Tutorials
  • Basic String Formatting
  • Basic String Operations
  • Programming Exercise 2:

    Ask the user to enter a phrase, then print the phrase backwards.

    Read about User Input and Random Numbers. Complete the exercise below.

    Tutorials
  • User Input
  • Random Integers in Python
  • Programming Exercise 3:

    Make a Rock-Paper-Scissors game against the computer.

    Read about Lists, Conditions, and Loops. Complete the exercise below.

    Tutorials
  • Conditions
  • Lists
  • Loops
  • Programming Exercise 4:

    Write a program to remove duplicates from a list. Example: if my_list = [ 1, 2, 2, 3, 4, 4, 5, 1, 8, 3] then the result = [ 1, 2, 3, 4, 5, 8] .

    Write an algorithm you know from Java in Python.

  • Closed all.
  • In class lesson on functions (methods).

    Tutorials
  • Functions
  • Programming Exercise 5:

    Write a function that calculates the sum of all numbers in a list. Write a test driver for this function.

    In class lesson on dictionaries.

    1. Watch this video: https://www.youtube.com/watch?v=daefaLgNkw0
    2. Try some dictionary programming exercises.
    3. Additional Tutorial: Dictionaries
    Programming Exercise 6:

    Write a program that asks the user to enter a sentence. Your program should count how many times each word appears and store the results in a dictionary. Then, print out each word followed by its count. Use the skeleton code below to get started. Read pass keyword in Python.

    sentence = input("Enter a sentence: ")
    words = sentence.split()
    
    word_counts = {}
    
    # TODO: Loop through the words and count how many times each appears
    for word in words:
        # Fill in the logic to count each word
        pass
    
    # TODO: Print each word and its count
    for word in word_counts:
        pass                
                    

    Complete the 5 exercises at the end of the video.

    Tutorials
  • Pygame Hello World
  • To fully understand how pygame, and computer games in general, work, read this tutorial:

  • Pygame Primer
  • Below is a list of common errors students get during this unit, along with what it means and how to fix it.

    1. Anything in pygame is "not initialized": You did not initialize pygame. The fix: Call pygame.init() first in main.
    2. pygame anything does not exist: Meaning - you probably named your program "pygame.py" or "import pygame.py" and it is overriding the actual pygame library. The fix: Rename your file "hello.py" or something else.
    3. Your program was working, but now it says you have an error on line 1 and the console prompt looks like this: >>>: Meaning - Your console is in python command line instead of windows command line.The fix: Type exit() and hit enter.
    4. Something is not being drawn: The fix: First draw the background. Then blit/draw the images and text. Then call pygame.display.update() only once at the end of the game loop. Do not put update in an if or another loop. Never call it more than once.
    5. blah is not callable: Meaning - you are calling blah like it is a function, but it is not. ie. Suppose foo is a function that requires two parameters, a blah and a tuple, but you forgot the comma like this: foo(blah (x,y)). This will cause this error. The fix: use the comma to separate the parameters to foo: foo(blah, (x,y)).
    6. Tuples cannot be reassigned: Example
                          foo = (1, 'hello', 9.2)
                          foo1 = 'world' 
      . Meaning - Tuples are immutable, which means once they have been assigned, their values cannot be modified. The fix: Use a list instead.
                          foo =  1, 'hello', 9.2
                          foo1 = 'world' 

    Complete the 4 video lessons on Hangman.

    Tutorials
  • Hangman 1
  • Hangman 2
  • Hangman 3
  • Hangman 4
  • Now make the game yours. Have at least 50 different possible puzzles that are all related to a theme. Redesign the background and images used to reflect the theme.

    Assessment

    6/10 - you finished the tutorial.

    8/10 - you added 50 words related to a theme.

    10/10 - you redesigned the graphics to reflect the theme and it looks professionally done.

    Complete this tutorial on how to do a Platformer Game.

  • PyGame Platformer Tutorial
  • Work with a Partner

    Create a platformer game where the main character is a horse. Your game should reflect real horse challenges (care, feeding, riding, etc.), but you can also include fictional and anthropomorphic elements to make it fun and creative.

    1. Learn About Horses

    Before designing your game, read Horses 101 (includes fun facts, breeds, cost, care, riding, and more) to understand the real-world context of your character..

    2. Build Your Game

    Start with the base code from the YouTube Platformer Tutorials. Then, design your horse-themed platformer with the following requirements. Implement a good UI (User Interface). Watch this video on User Interface Design.

    Basic Criteria (ALL REQUIRED)
    Your game must include:
    1. Lives or Health System:
      • The player (horse) must lose health or lives when hit by enemies or hazards.
      • The game must end when all lives are lost.
    2. Food and Water Collection:
      • Each level must have hay and water.
      • Players must collect both before exiting the level.
    3. Multiple Levels:
      • Teams of 2: Create at least 5 new levels.
      • Teams of 3: Create at least 10 new levels.
      • These levels must be original (not from the tutorial).
      • Each level should have a unique layout and increasing difficulty.
    Advanced Criteria:
    Add as many of the following features as you can:
    1. Power-ups:
      • Temporary abilities like invincibility, speed boost, or high jump.
      • Scatter them throughout levels.
    2. Save/Load Game
      • Allow players to save progress and continue later.
      • Save data using a text file.
    3. Time Limits:
      • Add a timer for each level.
      • Players may hae to complete the level before time runs out OR
      • The time is used in combination with high scores (#6) somehow.
    4. Boss Fight:
      • Create a final boss with unique attacks and strategies.
    5. Customization Options:
      • Let players customize the horse's appearance (colors, skins, accessories).
    6. High Scores
      • Track and display the highest scores.
      • Save data using a text file.
    7. How to Play Tutorial
      • Include player instructions.
      • Ideally, create an interactive tutorial level.
    Assessment
    Assessment Rubric

    Milestones
    1. Start: Thursday June 4
    2. Milestone 1: Monday June 9 - 1 basic criteria met
    3. Milestone 2: Thursday June 12 - All basic criteria met -
    4. Milestone 3: Monday June 16 - Sprites, background, and platform graphics are updated to the ones you want in your final game.
    5. Final Game Due Wednesday June 18: In Class Demos of Final Game
    Resources

    Complete this tutorial on how to do a simple Tetris Game. Tetris with Pygame Tutorial

    Now make it your own by adding any, or all, of the following customizations:

    1. Hard dropping blocks
    2. 3 new custom blocks
    3. speed up as game progresses
    4. easy, medium, hard levels
    5. a preview of the next 3 blocks
    6. high scores saved to a file with user name
    7. save current game to file and be able to reload
    8. put a block on hold

    Assessment

    • Emerging (5/10): Finished video
    • Developing (6/10): 1 customization
    • Proficient (8/10): 2 customizations
    • Extending (10/10): 3 customizations