Commit c98d4347 by BellCodeEditor

auto save

parent c6188a1e
Showing with 79 additions and 2 deletions
import pygame
from pygame import locals
# 初始化pygame,为使用pygame做准备
pygame.init()
# 创建一个窗口
screen = pygame.display.set_mode((660,480))
bg = pygame.image.load("bg.png")
right = pygame.image.load("right.png")
body = pygame.image.load("body.png")
food = pygame.image.load("apple.png")
while True:
for event in pygame.event.get():
if event.type == locals.QUIT:
exit()
screen.blit(bg,(0,0))
screen.blit(right,(240,60))
screen.blit(body,(210,60))
screen.blit(body,(180,60))
screen.blit(body,(180,30))
screen.blit(food,(300,180))
pygame.display.update()
C:\Users\bell\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Python 3.9
\ No newline at end of file
#导入pygame模块
import pygame import pygame
from pygame import locals
'''
1.设置窗口
pygame.display.set_mode(size)
2.size是一个元组类型的参数,使用小括号标志
3.元组是一个一经创建就无法修改的数据类型
4.如果只使用一个模块中的某一个方法/函数 导入时可以只导入这一部分 from 模块名 import 函数名
5.在游戏进行的过程中会发生各种的事件
6.窗口关闭 locals.QUIT 点击窗口右上角的关闭即可触发
7.获取发生的事件 pygame.event.get()
8.pygame坐标起始点(0,0)在左上角 在pygame中横轴用x表示,越向右,x坐标越大;竖轴用y表示,越向下,y坐标越大。
9.将一个图片显示在窗口上叫做 渲染
10.如果想要渲染一张图片,就需要导入 导入的格式: pygame.image.load("图片名.后缀名"),为了方便操作可以赋值给一个变量
11.导入图片算做pygame的初始化内容,要放到while True 的上边 while True 里边的内容叫做游戏逻辑
12. 渲染的格式: screen.blit(要渲染的对象,(x,y)) 归属于游戏逻辑 放到while True的里边
13. 先渲染的内容会被后渲染的内容所覆盖 背景图 --> 贪吃蛇的头 --> 贪吃蛇的身体 --> 苹果
14.渲染是从左上角开始渲染
15.刷新画面 pygame.display.update()
'''
# 初始化pygame,为使用pygame做准备 # 初始化pygame,为使用pygame做准备
pygame.init() pygame.init()
# 创建一个窗口 # 创建一个窗口
?? screen = pygame.display.set_mode((660,480))
\ No newline at end of file
#导入图片
bg = pygame.image.load("bg.png")
#1.导入背景图bg,导入贪吃蛇朝右的头right,贪吃蛇的身体body,苹果food
while True:
#遍历事件/遍历发生的事件
for event in pygame.event.get():
if event.type == locals.QUIT:
exit()
#渲染背景图,和贪吃蛇的头
#渲染三个身体,身体要呈L形
#渲染苹果,苹果只要在格子里就可以
pygame.display.update()
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment