9. Python Game Development in Hindi - Continuous Motion PART 3
Code :
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
update_x = 0
clk = pygame.time.Clock()
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:
update_x = -25
if event.key == pygame.K_RIGHT:
update_x = +25
start_x += update_x
gameWindow.blit(background_image,[0,0])
pygame.draw.rect(gameWindow,blue,[start_x,start_y,25,25])
pygame.display.update()
clk.tick(13)
pygame.quit()
quit()
YouTube :
0 Comments