@ -0,0 +1,3 @@
|
||||
# 默认忽略的文件
|
||||
/shelf/
|
||||
/workspace.xml
|
@ -0,0 +1,6 @@
|
||||
<component name="InspectionProjectProfileManager">
|
||||
<settings>
|
||||
<option name="USE_PROJECT_PROFILE" value="false" />
|
||||
<version value="1.0" />
|
||||
</settings>
|
||||
</component>
|
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Black">
|
||||
<option name="sdkName" value="Python 3.12 (pythonProject重生版)" />
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.12 (pythonProject重生版)" project-jdk-type="Python SDK" />
|
||||
</project>
|
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/pythonProject重生版.iml" filepath="$PROJECT_DIR$/.idea/pythonProject重生版.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="PYTHON_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
@ -0,0 +1,63 @@
|
||||
import time
|
||||
|
||||
import pygame
|
||||
from pygame.constants import *
|
||||
|
||||
|
||||
def main():
|
||||
"""完成整个程序的控制"""
|
||||
# 1. 创建一个窗口,用来显示内容
|
||||
screen = pygame.display.set_mode((480, 852), 0, 32)
|
||||
# 2. 创建一个和窗口大小的图片,用来充当背景
|
||||
background = pygame.image.load("./feiji/background.png")
|
||||
# 4.创建一个玩家飞机图片,当做真正的飞机
|
||||
player = pygame.image.load("./feiji/hero1.png")
|
||||
|
||||
# 定义飞机的坐标
|
||||
x = 480 / 2 - 100 / 2
|
||||
y = 600
|
||||
|
||||
# 飞机速度
|
||||
speed = 10
|
||||
|
||||
# 设定需要显示的背景图
|
||||
while True:
|
||||
# 3将背景图片贴到窗口中
|
||||
screen.blit(background, (0, 0))
|
||||
# 5将飞机图片贴到窗口中
|
||||
screen.blit(player, (x, y))
|
||||
|
||||
# 遍历所有的事件
|
||||
for event in pygame.event.get():
|
||||
# 判断事件类型如果是pygame的退出
|
||||
if event.type == QUIT:
|
||||
# 执行pygame退出
|
||||
pygame.quit()
|
||||
# python程序的退出
|
||||
exit()
|
||||
|
||||
# 监听键盘事件
|
||||
key_pressed = pygame.key.get_pressed()
|
||||
|
||||
if key_pressed[K_w] or key_pressed[K_UP]:
|
||||
print("上")
|
||||
y -= speed
|
||||
if key_pressed[K_s] or key_pressed[K_DOWN]:
|
||||
print("下")
|
||||
y += speed
|
||||
if key_pressed[K_a] or key_pressed[K_LEFT]:
|
||||
print("左")
|
||||
x -= speed
|
||||
if key_pressed[K_d] or key_pressed[K_RIGHT]:
|
||||
print("右")
|
||||
x += speed
|
||||
if key_pressed[K_SPACE]:
|
||||
print("空格")
|
||||
|
||||
# 更新需要显示的内容
|
||||
pygame.display.update()
|
||||
time.sleep(0.01)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
@ -0,0 +1,78 @@
|
||||
import random
|
||||
import time
|
||||
import pygame
|
||||
from pygame.constants import *
|
||||
|
||||
|
||||
class HeroPlane(object):
|
||||
def __init__(self, screen):
|
||||
# 4.创建一个玩家飞机图片,当做真正的飞机
|
||||
self.player = pygame.image.load("./feiji/hero1.png")
|
||||
|
||||
# 定义飞机的坐标
|
||||
self.x = 480 / 2 - 100 / 2
|
||||
self.y = 600
|
||||
|
||||
# 飞机速度
|
||||
self.speed = 15
|
||||
|
||||
# 记录当前的窗口对象
|
||||
self.screen = screen
|
||||
|
||||
|
||||
|
||||
def key_control(self):
|
||||
# 监听键盘事件
|
||||
key_pressed = pygame.key.get_pressed()
|
||||
|
||||
if key_pressed[K_w] or key_pressed[K_UP]:
|
||||
self.y -= self.speed
|
||||
if key_pressed[K_s] or key_pressed[K_DOWN]:
|
||||
self.y += self.speed
|
||||
if key_pressed[K_a] or key_pressed[K_LEFT]:
|
||||
self.x -= self.speed
|
||||
if key_pressed[K_d] or key_pressed[K_RIGHT]:
|
||||
self.x += self.speed
|
||||
if key_pressed[K_SPACE]:
|
||||
pass
|
||||
|
||||
def display(self):
|
||||
# 5将飞机图片贴到窗口中
|
||||
self.screen.blit(self.player, (self.x, self.y))
|
||||
|
||||
def main():
|
||||
# 1. 创建一个窗口,用来显示内容
|
||||
screen = pygame.display.set_mode((480, 852), 0, 32)
|
||||
# 2. 创建一个和窗口大小的图片,用来充当背景
|
||||
background = pygame.image.load("./feiji/background.png")
|
||||
# 创建一个飞机的对象,注意不要忘记传窗口
|
||||
player = HeroPlane(screen)
|
||||
|
||||
|
||||
# 设定需要显示的背景图
|
||||
while True:
|
||||
# 3将背景图片贴到窗口中
|
||||
screen.blit(background, (0, 0))
|
||||
|
||||
# 遍历所有的事件
|
||||
for event in pygame.event.get():
|
||||
# 判断事件类型如果是pygame的退出
|
||||
if event.type == QUIT:
|
||||
# 执行pygame退出
|
||||
pygame.quit()
|
||||
# python程序的退出
|
||||
exit()
|
||||
|
||||
# 执行飞机的按键监听
|
||||
player.key_control()
|
||||
# 飞机的显示
|
||||
player.display()
|
||||
|
||||
|
||||
# 更新需要显示的内容
|
||||
pygame.display.update()
|
||||
time.sleep(0.01)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
After Width: | Height: | Size: 7.3 KiB |
After Width: | Height: | Size: 36 KiB |
After Width: | Height: | Size: 418 KiB |
After Width: | Height: | Size: 2.6 KiB |
After Width: | Height: | Size: 2.0 KiB |
After Width: | Height: | Size: 5.5 KiB |
After Width: | Height: | Size: 8.7 KiB |
After Width: | Height: | Size: 122 B |
After Width: | Height: | Size: 151 B |
After Width: | Height: | Size: 401 B |
After Width: | Height: | Size: 23 KiB |
After Width: | Height: | Size: 490 B |
After Width: | Height: | Size: 498 B |
After Width: | Height: | Size: 29 KiB |
After Width: | Height: | Size: 28 KiB |
After Width: | Height: | Size: 1.6 KiB |
After Width: | Height: | Size: 2.8 KiB |
After Width: | Height: | Size: 14 KiB |
After Width: | Height: | Size: 2.9 KiB |
After Width: | Height: | Size: 3.3 KiB |
After Width: | Height: | Size: 3.8 KiB |
After Width: | Height: | Size: 5.2 KiB |
After Width: | Height: | Size: 1.7 KiB |
After Width: | Height: | Size: 7.9 KiB |
After Width: | Height: | Size: 10 KiB |
After Width: | Height: | Size: 11 KiB |
After Width: | Height: | Size: 13 KiB |
After Width: | Height: | Size: 3.3 KiB |
After Width: | Height: | Size: 9.0 KiB |
After Width: | Height: | Size: 42 KiB |
After Width: | Height: | Size: 47 KiB |
After Width: | Height: | Size: 52 KiB |
After Width: | Height: | Size: 59 KiB |
After Width: | Height: | Size: 66 KiB |
After Width: | Height: | Size: 74 KiB |
After Width: | Height: | Size: 8.8 KiB |
After Width: | Height: | Size: 44 KiB |
After Width: | Height: | Size: 42 KiB |
After Width: | Height: | Size: 2.8 KiB |
After Width: | Height: | Size: 4.9 KiB |
After Width: | Height: | Size: 6.2 KiB |
After Width: | Height: | Size: 96 B |
After Width: | Height: | Size: 2.1 KiB |
After Width: | Height: | Size: 2.0 KiB |
After Width: | Height: | Size: 1.7 KiB |
After Width: | Height: | Size: 1.9 KiB |
After Width: | Height: | Size: 58 KiB |
After Width: | Height: | Size: 35 KiB |
After Width: | Height: | Size: 3.8 KiB |
After Width: | Height: | Size: 12 KiB |
After Width: | Height: | Size: 12 KiB |
After Width: | Height: | Size: 15 KiB |
After Width: | Height: | Size: 16 KiB |
After Width: | Height: | Size: 18 KiB |
After Width: | Height: | Size: 3.3 KiB |
After Width: | Height: | Size: 17 KiB |
After Width: | Height: | Size: 18 KiB |
After Width: | Height: | Size: 19 KiB |
After Width: | Height: | Size: 12 KiB |
After Width: | Height: | Size: 388 KiB |
After Width: | Height: | Size: 190 KiB |
After Width: | Height: | Size: 358 KiB |
After Width: | Height: | Size: 55 KiB |
After Width: | Height: | Size: 74 KiB |
After Width: | Height: | Size: 154 KiB |
After Width: | Height: | Size: 32 KiB |
After Width: | Height: | Size: 24 KiB |
After Width: | Height: | Size: 28 KiB |
After Width: | Height: | Size: 6.9 KiB |
After Width: | Height: | Size: 7.4 KiB |
After Width: | Height: | Size: 1.7 KiB |
After Width: | Height: | Size: 1.7 KiB |
After Width: | Height: | Size: 1.7 KiB |
After Width: | Height: | Size: 1.7 KiB |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 1.1 KiB |