Introduction of Pygame ( Basic Commands )
'''
Pygame Introdction and Basic Commands
'''
import pygame
# To initialize the pygame module
x = pygame.init()
# To insert the gaming window or window for game.
# The diamensions are in list.
gamewindow = pygame.display.set_mode((1200,500))
# To set the title to the window following code use:
pygame.display.set_caption ("My First Game")
# Game need the various varible for various command
# Hence following are variable for game.
exit_game = False
game_over = False
# --------------- Game Loop ---------------------------
# Game loop is loop use to run game continuosly
# If loop run continuous we can add keyboard keys
# and any other function to the game
while not exit_game:
for event in pygame.event.get(): # event.get() is
# command use to handle all keys
# and mouse sense in game or handle
# event in the game
if event.type == pygame.QUIT: # This is use for to close
exit_game = True # the game with cross icon on toolbar
# Following code is for to detect which key press and what key press.
# this is command in which key pressed.
if event.type == pygame.KEYDOWN:
#This is for right arrow key press.
if event.key == pygame.K_RIGHT:
print("You have pressed right arrow keys")
pygame.quit()
quit()
Comments
Post a Comment