zoukankan      html  css  js  c++  java
  • 基础DAY14-飞机大战-绘制图像

    import pygame
    pygame.init()
    # 创建游戏窗口
    screen = pygame.display.set_mode((480, 700))
    # 加载backgroud.png创建背景
    bg = pygame.image.load("./images/background.png")
    # 将背景绘制在屏幕的(0,0)位置
    screen.blit(bg, (0, 0))
    # 调用屏幕更新显示背景图像
    pygame.display.update()
    while True:
        pass
    pygame.quit()
    绘制图像

    import pygame
    pygame.init()
    # 创建游戏窗口
    screen = pygame.display.set_mode((480, 700))
    # 加载backgroud.png创建背景
    bg = pygame.image.load("./images/background.png")
    # 将背景绘制在屏幕的(0,0)位置
    screen.blit(bg, (0, 0))
    # 调用屏幕更新显示背景图像
    pygame.display.update()
    hero_plane = pygame.image.load("./images/me1.png")
    screen.blit(hero_plane, (150, 400))
    pygame.display.update()
    while True:
        pass
    pygame.quit()
    绘制英雄图像

    import pygame
    pygame.init()
    # 创建游戏窗口
    screen = pygame.display.set_mode((480, 700))
    # 加载backgroud.png创建背景
    bg = pygame.image.load("./images/background.png")
    # 将背景绘制在屏幕的(0,0)位置
    screen.blit(bg, (0, 0))
    # 调用屏幕更新显示背景图像
    # pygame.display.update()
    
    # 绘制英雄的飞机
    hero_plane = pygame.image.load("./images/me1.png")
    screen.blit(hero_plane, (150, 300))
    # 可以在所有绘制工作完成之后,统一调用update方法
    pygame.display.update()
    while True:
        pass
    pygame.quit()
    update()

    import pygame
    pygame.init()
    # 创建游戏窗口
    screen = pygame.display.set_mode((480, 700))
    # 加载backgroud.png创建背景
    bg = pygame.image.load("./images/background.png")
    # 将背景绘制在屏幕的(0,0)位置
    screen.blit(bg, (0, 0))
    # 调用屏幕更新显示背景图像
    pygame.display.update()
    
    # 绘制英雄的飞机
    hero_plane = pygame.image.load("./images/me1.png")
    screen.blit(hero_plane, (150, 300))
    # 调用屏幕更新显示背景图像
    pygame.display.update()
    # 创建时钟对象
    clock = pygame.time.Clock()
    i = 0
    while True:
        # 可以指定循环体内部执行的频率
        clock.tick(6)
        print(i)
        i += 1
        pass
    pygame.quit()
    时钟对象

     

    import pygame
    pygame.init()
    # 创建游戏窗口
    screen = pygame.display.set_mode((480, 700))
    # 加载backgroud.png创建背景
    bg = pygame.image.load("./images/background.png")
    # 将背景绘制在屏幕的(0,0)位置
    screen.blit(bg, (0, 0))
    # 调用屏幕更新显示背景图像
    #pygame.display.update()
    # 绘制英雄的飞机
    hero = pygame.image.load("./images/me1.png")
    # 创建时钟对象
    clock = pygame.time.Clock()
    # 1 在游戏循环外部,定义rect记录飞机的初始位置
    hero_rect = pygame.Rect(150, 300, 102, 126)
    print(hero_rect)
    while True:
        # 可以指定循环体内部执行的频率
        clock.tick(60)
        # 2 修改飞机的位置
        hero_rect.y -= 1
        # 判断飞机的位置
        if hero_rect.y <= 0:
            # 修改飞机的位置到底部
            hero_rect.y = 700
        # 3 调用blit方法修改图像
        screen.blit(bg, (0, 0))
        screen.blit(hero, hero_rect)
        # 4 调用update方法
        pygame.display.update()
    
    pygame.quit()
    英雄循环移动

  • 相关阅读:
    用 ArcMap 发布 ArcGIS Server FeatureServer Feature Access 服务 PostgreSQL 版本
    ArcMap 发布 ArcGIS Server OGC(WMSServer,MapServer)服务
    ArcScene 创建三维模型数据
    ArcMap 导入自定义样式Symbols
    ArcMap 导入 CGCS2000 线段数据
    ArcMap 导入 CGCS2000 点坐标数据
    ArcGis Server manager 忘记用户名和密码
    The view or its master was not found or no view engine supports the searched locations
    python小记(3)操作文件
    pytest(2) pytest与unittest的区别
  • 原文地址:https://www.cnblogs.com/joycezhou/p/11423323.html
Copyright © 2011-2022 走看看