Giới thiệu sản phẩm
Tìm hiểu chủ đề: Môn thể thao vua - bóng đá
Kiến thức, khái niệm: Tìm hiểu thuộc tính Animate, chèn ảnh vào chương trình, tạo nhân vật với thuộc tính animate. Tạo chuyển động bằng lập trình
Dự án Chiến binh siêu hạng: Vận dụng thuộc tính animate trong thư viện pygame để thiết lập những hành động của nhân vật: chạy, nhảy,...
import pygame
pygame.init()
WIDTH, HEIGHT = 800, 400
FPS = 60
WHITE = (255, 255, 255)
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption(" Game")
sky = pygame.image.load("Sky.png").convert()
ground = pygame.image.load("ground.png").convert()
sky_x = 0
ground_x = 0
scroll_speed_sky = 4
scroll_speed_ground = 2
clock = pygame.time.Clock()
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
screen.fill(WHITE)
sky_x -= scroll_speed_sky
if sky_x <= -WIDTH:
sky_x = 0
screen.blit(sky, (sky_x, 0))
screen.blit(sky, (sky_x + WIDTH, 0))
ground_x -= scroll_speed_ground
if ground_x <= -WIDTH:
ground_x = 0
screen.blit(ground, (ground_x, 300))
screen.blit(ground, (ground_x + WIDTH, 300))
pygame.display.flip()
clock.tick(FPS)
Kiến thức, khái niệm: Tìm hiểu thuộc tính Animate, chèn ảnh vào chương trình, tạo nhân vật với thuộc tính animate. Tạo chuyển động bằng lập trình
Dự án Chiến binh siêu hạng: Vận dụng thuộc tính animate trong thư viện pygame để thiết lập những hành động của nhân vật: chạy, nhảy,...
import pygame
pygame.init()
WIDTH, HEIGHT = 800, 400
FPS = 60
WHITE = (255, 255, 255)
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption(" Game")
sky = pygame.image.load("Sky.png").convert()
ground = pygame.image.load("ground.png").convert()
sky_x = 0
ground_x = 0
scroll_speed_sky = 4
scroll_speed_ground = 2
clock = pygame.time.Clock()
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
screen.fill(WHITE)
sky_x -= scroll_speed_sky
if sky_x <= -WIDTH:
sky_x = 0
screen.blit(sky, (sky_x, 0))
screen.blit(sky, (sky_x + WIDTH, 0))
ground_x -= scroll_speed_ground
if ground_x <= -WIDTH:
ground_x = 0
screen.blit(ground, (ground_x, 300))
screen.blit(ground, (ground_x + WIDTH, 300))
pygame.display.flip()
clock.tick(FPS)
Hình ảnh sản phẩm
Sản phẩm cùng tác giả
Sản phẩm liên quan
Không có sản phẩm nào
Đăng nhập để tham gia bình luận