به خاطر این که در ادامه آموزش فانکشن اصلی بازی شلوغ نشود فعالیت های مربوط به هر قسمت در فانکشن مربوط به خودش نوشته میشود که فایل main.py به صورت زیر در می آید:

#main.py

import pygame
from settings import WIN_HEIGHT,WIN_WIDTH,CAPTION
from models import Player
win = pygame.display.set_mode((WIN_WIDTH,WIN_HEIGHT))
pygame.display.set_caption(CAPTION)
player = Player(WIN_WIDTH//2)


def player_control():
	player.draw(win)
	player.move()

def redraw():
	win.fill((0,0,0))

	player_control()

	pygame.display.update()

#main_loop
def main_loop():
	clock = pygame.time.Clock()
	running = True
	while running:
		for event in pygame.event.get():
			if event.type == pygame.QUIT:
				running = False

			if event.type == pygame.KEYDOWN:
				if event.key == pygame.K_RIGHT:
					player.vel = 7
				if event.key == pygame.K_LEFT:
					player.vel = -7

			if event.type == pygame.KEYUP:
				player.vel = 0
		clock.tick(60)
		
		redraw()

main_loop()
#settings.py

#display
WIN_WIDTH = 600
WIN_HEIGHT = 750

CAPTION = "pygame tutorial"
#models.py

from settings import WIN_HEIGHT,WIN_WIDTH
from pygame import image

class Player(object):
	def __init__(self,x):
		self.x = x - 32
		self.y = WIN_HEIGHT - 100
		self.img = image.load("player.png")
		self.vel = 0

	def draw(self,screen):
		screen.blit(self.img,(self.x,self.y))

	def move(self):
		if (self.x >= 0 or self.vel > 0) and (self.x <= WIN_WIDTH - 64 or self.vel < 0):
			self.x += self.vel

سایر قسمت ها :

آموزش بازی سازی با زبان برنامه نویسی پایتون قسمت اول

آموزش بازی سازی با زبان برنامه نویسی پایتون قسمت دوم