8. Python Game Development in Hindi - Continuous Motion PART 2
import pygame
pygame.init()
white = (255,255,255)
black = (0,0,0)
red = (255,0,0)
green = (0,255,0)
blue = (0,0,255)
gameWindow = pygame.display.set_mode((800,600))
pygame.display.set_caption('Snake Game')
pygame.display.update()
gameClose = False
start_x = 400
start_y = 300
background_image = pygame.image.load("background.jpg").convert()
while not gameClose:
for event in pygame.event.get():
if event.type == pygame.QUIT:
gameClose = True
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
start_x -= 25
if event.key == pygame.K_RIGHT:
start_x += 25
gameWindow.blit(background_image,[0,0])
pygame.draw.rect(gameWindow,blue,[start_x,start_y,25,25])
pygame.display.update()
pygame.quit()
quit()
YouTube :
0 Comments