• pygame---制作一只会转弯的小乌龟


    Pygame

    Pygame是跨平台Python模块,专为电子游戏设计,包含图像、声音。建立在SDL基础上,允许实时电子游戏研发而无需被低级语言(如机器语言汇编语言)束缚。
    包含图像、声音。
    pygame
    建立在SDL基础上,允许实时电子游戏研发而无需被低级语言(如机器语言汇编语言)束缚。基于这样一个设想,所有需要的游戏功能和理念都(主要是图像方面)都完全简化为游戏逻辑本身,所有的资源结构都可以由高级语言提供,如Python
    Pygame 原为代替突然停止的 pySDL
    Pygame 作者是 Pete Shinners 协议为 GNU Lesser General Public License
     
    代码实例:
    # -*- coding: utf-8 -*-
    import pygame
    import sys
    
    # 初始化pygame
    pygame.init()
    
    size = width, height = 600, 400
    speed = [-2,1]
    bg = (0,191,255)
    # 创建指定大小窗口
    screen = pygame.display.set_mode(size)
    
    # 创建窗口标题
    pygame.display.set_caption("鄙视小乌龟")
    
    # 加载图片
    turtle = pygame.image.load("turtle.png")
    
    # 获取图像的位置矩阵
    position = turtle.get_rect()
    
    while True:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                sys.exit()
    
        # 移动图像
        position = position.move(speed)
    
        if position.left < 0 or position.right > 
            # 翻转图像
            tuple = pygame.transform.flip(turtle, True, False)
            # 反方向移动
            speed[0] = - speed[0]
    
        if position.top < 0 or position.bottom > height:
            speed[1] = -speed[1]
    
        #填充背景
        screen.fill(bg)
    
        #更新图像
        screen.blit(turtle,position)
    
        #更新界面
        pygame.display.flip()
    
        #延迟10毫秒
        pygame.time.delay(10)
        
    效果:

    ----------------------------------------------------------------------------------来自一只网络上的小懒虫

     
  • 相关阅读:
    BufferedOutputStream
    BufferedInputStream
    IO异常 的处理
    FileOutStream
    FileInputStream
    File常用的方法
    IO流
    枚举
    jdk1.5新特性之-----自动装箱与自动拆箱
    jdk1.5新特性之------->可变参数
  • 原文地址:https://www.cnblogs.com/xweiqing/p/9106130.html
Copyright © 2020-2023  润新知