Python

From Mario Fan Games Galaxy Wiki
 Stub.png This article or section is in need of expansion.

Please add further information.


Python
Python logo.svg.png
Basics
Intermediate
- none
Advanced
- none

Python is a high-level programming and scripting language. Its syntax is well designed and it's meant to be powerful yet readable. There are some people using Python at MFGG.

There are some game libraries for Python, for example Pygame (SDL based) and Pyglet (OpenGL based).

Examples

Hello World

print("Hello world!")

Hello World with Pygame

This example requires Pygame.

 #! /usr/bin/env python
 # -*- coding: utf-8 -*-
 
 import sys
 
 import pygame
 from pygame.locals import *
 pygame.init()
 
 
 # This creates a screen with resolution
 # 320x240. Try changing it!
 screen = pygame.display.set_mode((320, 240))
 
 
 # Loads a font. Since None was specified,
 # it loads a built-in font.
 font = pygame.font.Font(None, 25) 
 
 
 # <fontname>.render arguments: (text, (red, green, blue, alpha))
 # Try changing them!
 text1 = font.render("Hello, World of Pygame!", 1, (12, 34, 56, 255))
 text2 = font.render("Press Enter to Exit!", 1, (65, 43, 21, 255))
 
 
 while 1:
     screen.fill((255, 255, 255))
     
     # Blitting means preparing things for drawing them on screen.
     # That is, setting up the coordinates.
     screen.blit(text1, (10, 10))
     screen.blit(text2, (40, 40))
     
     # Flipping updates the screen.
     pygame.display.flip()
     
     # This gets the latest event that happened.
     event = pygame.event.poll()
     
     if event.type == KEYDOWN:
         if event.key == K_RETURN:
             pygame.quit()
             sys.exit()