pygame游戏开发入门例子
2023-09-27 14:19:37 时间
# *_* coding:utf-8 *_*
# 开发团队:中国软件开发团队
# 开发人员:Administrator
# 开发时间:2019/3/23 11:16
# 文件名称:pygame_demo
# 开发工具:PyCharm
import sys
import pygame
import time
def main():
size=width,height=640,480
pygame.init()
screen=pygame.display.set_mode(size)
color=(0,0,0)
cat=pygame.image.load("cat.ico")
catrect=cat.get_rect()
speed=[5,5]
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit(0)
catrect=catrect.move(speed)
#碰到左右边缘
if catrect.left<0 or catrect.right>width:
speed[0]=-speed[0]
#碰到上下边缘
if catrect.top<0 or catrect.bottom>height:
speed[1]=-speed[1]
#通过延时控制移动速度
time.sleep(0.025)
screen.fill(color)
screen.blit(cat,catrect)
pygame.display.flip()
pygame.quit()
if __name__ == '__main__':
main()
相关文章
- 玩儿游戏也能学编程?12个学习编程的游戏化平台
- OUYA游戏开发核心技术剖析大学霸内部资料
- 华为游戏浮标不显示或显示异常
- 《HTML5游戏编程核心技术与实战》一第1章 游戏和HTML5初探
- 《C++游戏编程入门(第4版)》——2.6 使用while循环
- 《Python和Pygame游戏开发指南》——1.12 图书中的文本折行
- 《Python和Pygame游戏开发指南》——2.7 像素坐标
- 《Python和Pygame游戏开发指南》——2.11 颜色的透明度
- 《Python和Pygame游戏开发指南》——2.12 pygame.Color对象
- 《Python和Pygame游戏开发指南》——2.14 基本的绘制函数
- 《Python和Pygame游戏开发指南》——2.19 用pygame.image.load()和blit()绘制图像
- 《Python和Pygame游戏开发指南》——2.22 播放声音
- 《Python和Pygame游戏开发指南》——导读
- 《Android游戏开发详解》——第2章,第2.19节使用字符串
- 《Android游戏开发详解》——第3章,第3.6节图形
- 《Unity 3.x游戏开发实例》——1.9节技术的神奇之处
- 基于QT(C++)实现的翻金币游戏【100010527】
- ChatGPT 深度解析您真正需要知道的一切(特点和游戏开发中的用途)
- 【Unity3D日常开发】Unity3D中数字网格类游戏Demo实现
- Unity 性能优化 之 优化移动端游戏性能 | 来自Unity顶级工程师的物理、UI和音频设置小贴士
- 致佳音: 推箱子游戏自己主动求解算法设计(四)
- 【loj6191】「美团 CodeM 复赛」配对游戏 概率期望dp