pygame游戏之旅 载入小车图片、更新窗口

作者:观月执白 时间:2022-08-06 18:12:39 

本文为大家分享了pygame游戏之旅的第3篇,供大家参考,具体内容如下

载入car图片(我自己画的),需要用到pygame.image模块,定义carImg用于接收载入的图片


carImg = pygame.image.load('car.png')

定义一个car函数绑定car的位置


def car(x, y):
 gameDisplay.blit(carImg,(x,y))

为窗口填充白色并调用car函数,更新窗口


gameDisplay.fill(white)
car(x,y)
pygame.display.update()

完整代码是:


import pygame

pygame.init()

white = (255,255,255)

display_width = 800
display_height = 600

gameDisplay = pygame.display.set_mode( (display_width,display_height) )
pygame.display.set_caption('A bit Racey')
clock = pygame.time.Clock()

carImg = pygame.image.load('car.png')

def car(x, y):
 gameDisplay.blit(carImg,(x,y))

x = display_width * 0.45
y = display_height * 0.8

crashed = False

while not crashed:
 for event in pygame.event.get():
   if event.type == pygame.QUIT:
     crashed = True
   print(event)
 gameDisplay.fill(white)
 car(x,y)
 pygame.display.update()
 clock.tick(60)

pygame.quit()
quit()

结果图:

pygame游戏之旅 载入小车图片、更新窗口

来源:https://blog.csdn.net/pianzang5201/article/details/78294415

标签:pygame,窗口,游戏
0
投稿

猜你喜欢

  • Django实现文件上传和下载功能

    2022-04-02 15:19:34
  • python虚拟环境的安装和配置(virtualenv,virtualenvwrapper)

    2021-05-13 17:40:35
  • python爬虫基础之urllib的使用

    2022-02-10 19:01:18
  • 关于pytorch中网络loss传播和参数更新的理解

    2023-08-06 05:29:09
  • 深入透析样式表滤镜(下)

    2011-06-14 09:49:19
  • 深入研究PHP中的preg_replace和代码执行

    2023-11-22 07:36:55
  • python读取和保存图片5种方法对比

    2022-05-27 23:54:32
  • 支持鼠标拖拽的简单目录树代码

    2011-07-01 12:34:09
  • 对python同一个文件夹里面不同.py文件的交叉引用方法详解

    2023-12-24 00:54:27
  • Python实现批量读取图片并存入mongodb数据库的方法示例

    2021-03-25 01:51:53
  • PHP实现web socket长链接流程详解

    2023-05-27 23:44:39
  • 如何在python中使用selenium的示例

    2023-07-15 20:52:09
  • 视觉设计的一致性与用户体验

    2010-01-06 13:38:00
  • JavaScript创建可维护幻灯片效果

    2008-06-21 16:42:00
  • 如何列出我所需要数据视图?

    2010-01-12 20:00:00
  • Dreamweaver快速编辑网页标签

    2009-05-29 18:35:00
  • 如何在Frontpage中定义CSS样式

    2008-08-02 12:32:00
  • Python实现的读取文件内容并写入其他文件操作示例

    2021-10-11 02:27:02
  • python实现csv格式文件转为asc格式文件的方法

    2021-10-12 19:10:37
  • Python的string模块中的Template类字符串模板用法

    2023-02-02 10:53:05
  • asp之家 网络编程 m.aspxhome.com