Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Aircraft Wars/hm_01_pygame入门.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import pygame

pygame.init()

# 编写游戏的代码
print("游戏的代码...")

pygame.quit()
7 changes: 7 additions & 0 deletions Aircraft Wars/hm_02_使用Rect描述英雄.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import pygame

hero_rect = pygame.Rect(100, 500, 120, 125)

print("英雄的原点 %d %d" % (hero_rect.x, hero_rect.y))
print("英雄的尺寸 %d %d" % (hero_rect.width, hero_rect.height))
print("%d %d" % hero_rect.size)
11 changes: 11 additions & 0 deletions Aircraft Wars/hm_03_创建游戏窗口.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import pygame

pygame.init()

# 创建游戏的窗口
screen = pygame.display.set_mode((480, 700))

while True:
pass

pygame.quit()
19 changes: 19 additions & 0 deletions Aircraft Wars/hm_04_绘制图像.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import pygame

pygame.init()

# 创建游戏的窗口
screen = pygame.display.set_mode((480, 700))

# 绘制背景图像
# 1> 加载图像数据
bg = pygame.image.load("./images/background.png")
# 2> blit 绘制图像
screen.blit(bg, (0, 0))
# 3> update 更新屏幕显示
pygame.display.update()

while True:
pass

pygame.quit()
24 changes: 24 additions & 0 deletions Aircraft Wars/hm_05_绘制英雄图像.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import pygame

pygame.init()

# 创建游戏的窗口
screen = pygame.display.set_mode((480, 700))

# 绘制背景图像
# 1> 加载图像数据
bg = pygame.image.load("./images/background.png")
# 2> blit 绘制图像
screen.blit(bg, (0, 0))
# 3> update 更新屏幕显示
pygame.display.update()

# 绘制英雄的飞机
hero = pygame.image.load("./images/me1.png")
screen.blit(hero, (150, 300))
pygame.display.update()

while True:
pass

pygame.quit()
23 changes: 23 additions & 0 deletions Aircraft Wars/hm_06_update方法.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import pygame

pygame.init()

# 创建游戏的窗口
screen = pygame.display.set_mode((480, 700))

# 绘制背景图像
bg = pygame.image.load("./images/background.png")
screen.blit(bg, (0, 0))
# pygame.display.update()

# 绘制英雄的飞机
hero = pygame.image.load("./images/me1.png")
screen.blit(hero, (150, 300))

# 可以在所有绘制工作完成之后,统一调用update方法
pygame.display.update()

while True:
pass

pygame.quit()
38 changes: 38 additions & 0 deletions Aircraft Wars/hm_07_认识游戏循环.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import pygame

# 游戏的初始化
pygame.init()

# 创建游戏的窗口
screen = pygame.display.set_mode((480, 700))

# 绘制背景图像
bg = pygame.image.load("./images/background.png")
screen.blit(bg, (0, 0))
# pygame.display.update()

# 绘制英雄的飞机
hero = pygame.image.load("./images/me1.png")
screen.blit(hero, (150, 300))

# 可以在所有绘制工作完成之后,统一调用update方法
pygame.display.update()

# 创建时钟对象
clock = pygame.time.Clock()

# 游戏循环 -> 意味着游戏的正式开始!
i = 0

while True:

# 可以指定循环体内部的代码执行的频率
clock.tick(1)

print(i)

i += 1

pass

pygame.quit()
43 changes: 43 additions & 0 deletions Aircraft Wars/hm_08_更新英雄位置.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import pygame

# 游戏的初始化
pygame.init()

# 创建游戏的窗口
screen = pygame.display.set_mode((480, 700))

# 绘制背景图像
bg = pygame.image.load("./images/background.png")
screen.blit(bg, (0, 0))
# pygame.display.update()

# 绘制英雄的飞机
hero = pygame.image.load("./images/me1.png")
screen.blit(hero, (150, 300))

# 可以在所有绘制工作完成之后,统一调用update方法
pygame.display.update()

# 创建时钟对象
clock = pygame.time.Clock()

# 1. 定义rect记录飞机的初始位置
hero_rect = pygame.Rect(150, 300, 102, 126)

# 游戏循环 -> 意味着游戏的正式开始!
while True:

# 可以指定循环体内部的代码执行的频率
clock.tick(60)

# 2. 修改飞机的位置
hero_rect.y -= 1

# 3. 调用blit方法绘制图
screen.blit(bg, (0, 0))
screen.blit(hero, hero_rect)

# 4. 调用update方法更新显示
pygame.display.update()

pygame.quit()
47 changes: 47 additions & 0 deletions Aircraft Wars/hm_09_英雄循环飞行.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import pygame

# 游戏的初始化
pygame.init()

# 创建游戏的窗口
screen = pygame.display.set_mode((480, 700))

# 绘制背景图像
bg = pygame.image.load("./images/background.png")
screen.blit(bg, (0, 0))
# pygame.display.update()

# 绘制英雄的飞机
hero = pygame.image.load("./images/me1.png")
screen.blit(hero, (150, 300))

# 可以在所有绘制工作完成之后,统一调用update方法
pygame.display.update()

# 创建时钟对象
clock = pygame.time.Clock()

# 1. 定义rect记录飞机的初始位置
hero_rect = pygame.Rect(150, 300, 102, 126)

# 游戏循环 -> 意味着游戏的正式开始!
while True:

# 可以指定循环体内部的代码执行的频率
clock.tick(60)

# 2. 修改飞机的位置
hero_rect.y -= 1

# 判断飞机的位置
if hero_rect.y <= -102:
hero_rect.y = 700

# 3. 调用blit方法绘制图
screen.blit(bg, (0, 0))
screen.blit(hero, hero_rect)

# 4. 调用update方法更新显示
pygame.display.update()

pygame.quit()
52 changes: 52 additions & 0 deletions Aircraft Wars/hm_10_事件监听.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import pygame

# 游戏的初始化
pygame.init()

# 创建游戏的窗口
screen = pygame.display.set_mode((480, 700))

# 绘制背景图像
bg = pygame.image.load("./images/background.png")
screen.blit(bg, (0, 0))
# pygame.display.update()

# 绘制英雄的飞机
hero = pygame.image.load("./images/me1.png")
screen.blit(hero, (150, 300))

# 可以在所有绘制工作完成之后,统一调用update方法
pygame.display.update()

# 创建时钟对象
clock = pygame.time.Clock()

# 1. 定义rect记录飞机的初始位置
hero_rect = pygame.Rect(150, 300, 102, 126)

# 游戏循环 -> 意味着游戏的正式开始!
while True:

# 可以指定循环体内部的代码执行的频率
clock.tick(60)

# 捕获事件
event_list = pygame.event.get()
if len(event_list) > 0:
print(event_list)

# 2. 修改飞机的位置
hero_rect.y -= 1

# 判断飞机的位置
if hero_rect.y <= -102:
hero_rect.y = 700

# 3. 调用blit方法绘制图
screen.blit(bg, (0, 0))
screen.blit(hero, hero_rect)

# 4. 调用update方法更新显示
pygame.display.update()

pygame.quit()
60 changes: 60 additions & 0 deletions Aircraft Wars/hm_11_监听退出事件.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import pygame

# 游戏的初始化
pygame.init()

# 创建游戏的窗口
screen = pygame.display.set_mode((480, 700))

# 绘制背景图像
bg = pygame.image.load("./images/background.png")
screen.blit(bg, (0, 0))
# pygame.display.update()

# 绘制英雄的飞机
hero = pygame.image.load("./images/me1.png")
screen.blit(hero, (150, 300))

# 可以在所有绘制工作完成之后,统一调用update方法
pygame.display.update()

# 创建时钟对象
clock = pygame.time.Clock()

# 1. 定义rect记录飞机的初始位置
hero_rect = pygame.Rect(150, 300, 102, 126)

# 游戏循环 -> 意味着游戏的正式开始!
while True:

# 可以指定循环体内部的代码执行的频率
clock.tick(60)

# 监听事件
for event in pygame.event.get():

# 判断事件类型是否是退出事件
if event.type == pygame.QUIT:
print("游戏退出...")

# quit 卸载所有的模块
pygame.quit()

# exit() 直接终止当前正在执行的程序
exit()

# 2. 修改飞机的位置
hero_rect.y -= 1

# 判断飞机的位置
if hero_rect.y <= -102:
hero_rect.y = 700

# 3. 调用blit方法绘制图
screen.blit(bg, (0, 0))
screen.blit(hero, hero_rect)

# 4. 调用update方法更新显示
pygame.display.update()

pygame.quit()
Loading