**** 飞机循环飞行(飞机动)

1
# -*- coding:utf-8 -*- 2 # Author:Sure Feng 3 import pygame 4 5 # 游戏初始化 6 pygame.init() 7 # 创建游戏窗口 8 screen = pygame.display.set_mode((480, 700)) 9 # 绘制背景 10 bg = pygame.image.load("./images/background.png") 11 screen.blit(bg, (0, 0)) 12 # 绘制英雄 13 hero = pygame.image.load("./images/me1.png") 14 screen.blit(hero, (150, 300)) 15 # 绘制英雄rect对象 16 hero_rect = pygame.Rect(150, 300, 102, 126) 17 # 创建clock对象 18 clock = pygame.time.Clock() 19 20 # 游戏循环 21 while True: 22 23 # 设置游戏刷新频率 24 clock.tick(60) 25 # 事件监听 26 for event in pygame.event.get(): 27 if event.type == pygame.QUIT: 28 print("GAME OVER") 29 pygame.quit() 30 exit() 31 # 判断英雄位置 32 if hero_rect.y <= -126: 33 hero_rect.y = 700 34 # 修改英雄位置 35 hero_rect.y -= 2 36 # 绘制背景 37 screen.blit(bg, (0, 0)) 38 # 绘制英雄 39 screen.blit(hero, hero_rect) 40 # 更新游戏窗口 41 pygame.display.update() 42 43 # 游戏卸载 44 pygame.quit()

 


**** 飞机循环飞行(背景动)
 1 # -*- coding:utf-8 -*-
 2 # Author:Sure Feng
 3 import pygame
 4 
 5 # 游戏初始化
 6 pygame.init()
 7 # 创建游戏窗口
 8 screen = pygame.display.set_mode((480, 700))
 9 # 绘制背景
10 bg1 = pygame.image.load("./images/background.png")
11 bg2 = pygame.image.load("./images/background.png")
12 screen.blit(bg1, (0, 0))
13 # 绘制英雄
14 hero = pygame.image.load("./images/me1.png")
15 screen.blit(hero, (150, 300))
16 # 绘制背景rect对象
17 bg1_rect = pygame.Rect(0, 0, 480, 700)
18 bg2_rect = pygame.Rect(0, -700, 480, 700)
19 # 创建clock对象
20 clock = pygame.time.Clock()
21 
22 # 游戏循环
23 while True:
24 
25     # 设置游戏刷新频率
26     clock.tick(60)
27     # 事件监听
28     for event in pygame.event.get():
29         if event.type == pygame.QUIT:
30             print("GAME OVER")
31             pygame.quit()
32             exit()
33     # 判断英雄位置
34     if bg1_rect.y >= 700:
35         bg1_rect.y = -700
36     if bg2_rect.y >=700:
37         bg2_rect.y = -700
38     # 修改背景位置
39     bg1_rect.y += 3
40     bg2_rect.y += 3
41     # 绘制背景
42     screen.blit(bg1, bg1_rect)
43     screen.blit(bg1, bg2_rect)
44     # 绘制英雄
45     screen.blit(hero, (150, 300))
46     # 更新游戏窗口
47     pygame.display.update()
48 
49 # 游戏卸载
50 pygame.quit()

 

posted on 2018-11-04 16:34  sure_feng  阅读(346)  评论(0编辑  收藏  举报