1 of 23

Make a Tiny Game

WoCCode 2023

2 of 23

Some Recent Popular Online PC Games

League of Legends

Apex Legends

Minecraft

Valorant

Fortnite

World of Warcraft

CS : GO

3 of 23

Some Classics

Tetris

Minesweeper

Solitaire

Battle City

Snake

4 of 23

Still No Idea? Let’s play together!

5 of 23

Design - Framing

  • Previous experience with video games
  • Regardless of Technical Challenges: How will you design your own game?
    • Type: Action? Adventure? Simulation?
    • Theme? Story?
    • More Details

6 of 23

Design - Coding Ideas

  • Environment vs. Characters
  • Simultaneous Multi-process
  • Position: Coordinate Systems
  • Control & Events
    • Keyboard/Mouse Action Detections
    • If (Pt. reaches 10/ have done XXX/ get to position XXX)
  • Visual Image vs. ‘’Existence’’

7 of 23

Tooling

  • ‘’Game Engines’’
  • Development w/ Python: Graphic Libraries
    • e.g. Turtle, Tkinter
    • Graphics by John Zelle

8 of 23

Watching Game Demo!

https://drive.google.com/drive/folders/1L8x1ZN5IxyfHcjfWuPhvYCAdAxBxX6GA?usp=sharing

  • Download all the files into the same folder
  • PNGs: Icons/ Visual Images
  • graphics.py: the graphic library file (written by expert, leave it as it is)
  • main.py: written by me
  • main_scratch.py: a scratch for you to start

9 of 23

Install the Library

  • Just leave the file in your same working folder and make sure your IDE recognize it!
  • (99% chances won’t happen but) If not: add the path manually.
  • Specific procedures vary on IDEs.
  • Spyder: Tools ->

PYTHONPATHmanager -> add

10 of 23

Coding Structure

  • Class of “Character”
  • Class of “Dart”
  • Class of “endPoint”
  • Utility Function: show_message()
  • main()

11 of 23

“Character” Class - Parameters

  • Location Info (x coordinate, y coordinate, window),
  • Shape (Invisible, for animation contro),
  • Image (~Your Favorite Visual~)

12 of 23

“Character” Class - Functions

  • Move(self, key) <line 19-31>
  • Take in keyboard commands and move your character!
  • If [Press Key ↑\↓\←\→]:

Move the image by [measured by coordinate]�Move the shape by [measured by coordinate]

  • E.g. (1, -10) means move up 1 pixel and 10 pixels to the left�

13 of 23

“Character” Class - Functions

  • Overlap(self, (X,Y) coordinate) <line 34-36>
  • Check if the character overlap/crush with another object at the given coordinate
  • Return true if our character’s center is within a range of the given coordinate; false otherwise
  • Return true if X-25 < our X coordinate < X+25 AND

Y-25 < our Y coordinate < Y+25

14 of 23

“Character” Class - Functions

  • GetCenter(self) <line 32-33>
  • Get OUR coordinate with shorter code!
  • Return [our coordinate]

15 of 23

“Dart” Class - Parameters

  • Location Info (Just Y coordinate (Why?), window)

16 of 23

“Dart” Class - Functions

  • Move(self) <line 59-61>
  • Move the dart with fixed length (For continuous movements later)
  • Move the image & shape[measured by coordinate]

17 of 23

“Dart” Class - Functions

  • getX/Y(self) <line 62-65>
  • Get the dart’s coordinate with shorter code!
  • Return [the dart’s X/Y coordinate]

18 of 23

show_message Function

  • show_message(window, text)
  • Create a colored box with the message centering on the window.
  • Create the box object

Fill the box with [color (RGB)] so that it covers all stuffs below

Draw the box on window

Capture the given text and center it on the screen by setting [coordinate]

Set font size, color

Draw the text on window

19 of 23

Main Function

  • Set up an open window
  • Display welcome message (show_message)
  • Capture mouse action and start the game loop after receiving click
  • Initialize all “static” objects needed for the game: the main character, an destination point

20 of 23

Main Function

  • While the game is not over, repeat:
    • Generate a “dart”, with a random Y coordinate within the window range
    • Takes off from left of the screen and disappear after reaching the right.
  • If the character hits the dart: End the game and alert “You Lose”

If the character hits the end point: End the game and alert “You Win”

  • Close the window

21 of 23

Improvements

  • Alter to your own favorite icons!/ Change parameters
  • Validation: Prevent moving outside of the window
  • More Challenges : Obstacles? Puzzles? Enemies?
  • Ammos? HP/MP/EXP?
  • Scoring
  • Threading

22 of 23

Inspiration

  • Your Own Ultimate Game:
    • Add-ons?
    • How much can you achieve now?
    • What remain to be major challenges? (I expect most but just name a few)

23 of 23

Thank you