找回密码
 中文实名注册
查看: 380|回复: 1

第六单元 课程文件

[复制链接]

697

主题

1085

帖子

2万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
22878
发表于 2021-11-14 18:43:18 | 显示全部楼层 |阅读模式





本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?中文实名注册

x
回复

使用道具 举报

3

主题

41

帖子

873

积分

高级会员

Rank: 4

积分
873
发表于 2022-7-31 11:39:54 | 显示全部楼层
import pygame
import sys
# 导入游戏环境
from game import *


# 初始化
pygame.init()  # pygame 初始化
screen = pygame.display.set_mode((800, 600))  # 创建屏幕
clock = pygame.time.Clock()  # 生成游戏时钟
pygame.display.set_caption('星海战舰')  # 创建窗口标题


# 加载背景图片
background = pygame.image.load('pygame/image/星海背景.png')
# 初始化要发射的能量球
shell = 1


# 你需要在这里编写 [加载警报器图片及rect] 的代码
alarm = pygame.image.load('pygame/image/警报器.png')


alarm_rect = alarm.get_rect()
alarm_rect.left = 300
alarm_rect.top = 450


# 主循环
while True:
    # 事件检测
    for event in pygame.event.get():
        # 退出事件
        if event.type == pygame.QUIT:
            pygame.quit()
            sys.exit()
        # 鼠标点击事件
        if event.type == pygame.MOUSEBUTTONDOWN:
            # 获取鼠标坐标
            mouse_position = pygame.mouse.get_pos()
            # 把炮台中的炮弹发射出去
            spaceship.fire_ball(shell, mouse_position)
            # 随机取出一颗新炮弹
            shell = random.choice([1, 2, 3, 4])
            # 装弹
            spaceship.add_ball(shell)
        # 鼠标移动事件
        if event.type == pygame.MOUSEMOTION:
            # 让炮台跟着鼠标转动
            spaceship.rotate_to_mouse()


    # 绘制背景
    screen.blit(background, (0, 0))
    # 绘制飞船
    spaceship.draw(screen)
    # 你需要在这里编写 [绘制警报器和碰撞检测] 的代码
    screen.blit(alarm, (300, 450))
    ball_rest = get_firstball()
    center = ball_rest.center
   

    # 更新屏幕
    pygame.display.update()
    # 设置游戏速度
    clock.tick(12)
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 中文实名注册

本版积分规则

小黑屋|东台市机器人学会 ( 苏ICP备2021035350号-1;苏ICP备2021035350号-2;苏ICP备2021035350号-3 )

GMT+8, 2024-5-18 14:12 , Processed in 0.046244 second(s), 27 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表