Book Image

NumPy: Beginner's Guide

By : Ivan Idris
Book Image

NumPy: Beginner's Guide

By: Ivan Idris

Overview of this book

Table of Contents (21 chapters)
NumPy Beginner's Guide Third Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
NumPy Functions' References
Index

Time for action – creating a simple game


It's important to notice the so-called main game loop, where all the action happens, and the usage of the Font module to render text. In this program, we will manipulate a Pygame Surface object that is used for drawing, and we will handle a quit event.

  1. First, import the required Pygame modules. If Pygame is installed properly, we should get no errors, otherwise please return to the installation Time for action:

    import pygame, sys
    from pygame.locals import *
  2. Initialize Pygame, create a display of 400 by 300 pixels, and set the window title to Hello world!:

    pygame.init()
    screen = pygame.display.set_mode((400, 300))
    
    pygame.display.set_caption('Hello World!')
  3. Games usually have a game loop, which runs forever until, for instance, a quit event occurs. In this example, only set a label with the text Hello world! at coordinates (100, 100). The text has font size 19 and a red color:

    while True: 
       sysFont = pygame.font.SysFont("None", 19)
       rendered = sysFont...