Python gaming with pygame

in #technology6 years ago

Pygame is the future of gaming with the python.

Pygame provides the Graphical User Interface

GUI vs. CLI

The Python programs that you can write with Python’s built-in functions only deal with text through the print() and input() functions. Your program can display text on the screen and let the user type in text from the keyboard. This type of program has a command line interface, or CLI (which is pronounced like the first part of ―climb‖ and rhymes with ―sky‖). These programs are somewhat limited because they can’t display graphics, have colors, or use the mouse. These CLI programs only get input from the keyboard with the input() function and even then the user must press Enter before the program can respond to the input. This means real-time (that is, continuing to run code without waiting for the user) action games are impossible to make.
Pygame provides functions for creating programs with a graphical user interface, or GUI (pronounced, ―gooey‖). Instead of a text-based CLI, programs with a graphics-based GUI can show a window with images and colors.


The simple Hello world with Pygame

  1. import pygame, sys
  2. from pygame.locals import *
  3. pygame.init()
  4. DISPLAYSURF = pygame.display.set_mode((400, 300))
  5. pygame.display.set_caption('Hello World!')
  6. while True: # main game loop
  7. for event in pygame.event.get():
  8. if event.type == QUIT:
  9. pygame.quit()
  10. sys.exit()
  11. pygame.display.update()

OutPut

Capture.PNG

Pygame Modules


pygame.BufferProxypygame.cdrompygame.Color
pygame.displaypygame.drawpygame.cursors
pygame.eventpygame.eventpygame.font
pygame.imagepygame.keypygame.freetype
pygame.examplepygame.gfxdrawpygame.joystick
pygame.localspygame.mixerpygame.mouse
pygame.mixer.musicpygame.overlaypygame.Rect
pygame.Surfacepygame.timepygame.tests
pygame.transformpygame.spritepygame.scrap

Sort:  

Congratulations @zohaibtahir! You received a personal award!

Happy Birthday! - You are on the Steem blockchain for 1 year!

You can view your badges on your Steem Board and compare to others on the Steem Ranking

Do not miss the last post from @steemitboard:

Are you a DrugWars early adopter? Benvenuto in famiglia!
Vote for @Steemitboard as a witness to get one more award and increased upvotes!

Congratulations @zohaibtahir! You received a personal award!

Happy Steem Birthday! - You are on the Steem blockchain for 2 years!

You can view your badges on your Steem Board and compare to others on the Steem Ranking

Vote for @Steemitboard as a witness to get one more award and increased upvotes!

Coin Marketplace

STEEM 0.18
TRX 0.16
JST 0.029
BTC 75902.83
ETH 2895.60
USDT 1.00
SBD 2.58