找回密码
 中文实名注册
查看: 186|回复: 3

【python】俞吕敬 六年级

[复制链接]

5

主题

67

帖子

1103

积分

金牌会员

Rank: 6Rank: 6

积分
1103
发表于 2022-8-13 15:19:47 | 显示全部楼层 |阅读模式
本帖最后由 俞吕敬 于 2022-8-13 15:24 编辑

【python】俞吕敬 六年级
回复

使用道具 举报

5

主题

67

帖子

1103

积分

金牌会员

Rank: 6Rank: 6

积分
1103
 楼主| 发表于 2022-8-13 15:34:28 | 显示全部楼层
[Python] 纯文本查看 复制代码
import pygame
# 导入游戏环境
from game import *
import sys

# 初始化
pygame.init()  # pygame 初始化
screen = pygame.display.set_mode((800, 600))  # 创建屏幕
clock = pygame.time.Clock()  # 生成游戏时钟

# 初始化炮台里的能量球
ball = spaceship.new_ball()
# 反应仓列表
ball_list = []

# 加载背景图片
background = pygame.image.load('image/星海背景.png')

# 添加警报器
alarm = pygame.image.load('image/警报器.png')
alarm_rect = alarm.get_rect()
alarm_rect.left = 300
alarm_rect.top = 450

# 添加反应仓及获取反应仓的矩形区域
storage = pygame.image.load('image/反应仓.png')
storage_rect = storage.get_rect()
print(storage_rect)
storage_rect.left = 12
storage_rect.top = 115
print(storage_rect)
# 添加弹出按钮及获取弹出按钮的矩形区域
push = pygame.image.load('image/弹出按钮.png')
push_rect = push.get_rect()
push_rect.left = -4
push_rect.top = 388

# 主循环
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()
            if storage_rect.collidepoint(mouse_position)and len(ball_list)<4:
               ball_list.append(ball)
               ball = spaceship.new_ball()
            else:
            # 【在这里编写代码,完成弹出反应仓的代码】
                spaceship.fire_ball(ball ,mouse_position)
                ball = spacechip.new_ball()



        # 鼠标移动事件
        if event.type == pygame.MOUSEMOTION:
            # 让炮台跟着鼠标转动
            spaceship.rotate_to_mouse()

    # 绘制背景
    screen.blit(background, (0, 0))
    # 绘制飞船
    spaceship.draw(screen)
    # 绘制反应仓
    screen.blit(storage, storage_rect)
    # 绘制弹出按钮
    screen.blit(push, push_rect)
    # 绘制警报器
    screen.blit(alarm, (300, 450))
    ball_rect = get_firstball()
    center = ball_rect.center
    if alarm_rect.collidepoint(center):
        ring_alarm()

    # 检测终极武器有没有触发
    spaceship.master_stroke(screen, ball_list)
    # 更新屏幕
    pygame.display.update()
    # 设置游戏速度
    clock.tick(12)
回复

使用道具 举报

5

主题

67

帖子

1103

积分

金牌会员

Rank: 6Rank: 6

积分
1103
 楼主| 发表于 2022-9-10 15:25:42 | 显示全部楼层
[Python] 纯文本查看 复制代码
import pygame

import sys

pygame.init()
scree = pygame.display.set_mode((800,600))
background = pygame.image.load('image\星海背景.png')
alarm = pygame.image.load('image\警报器.png')
alarm2 = pygame.image.load('image\蓝色能量球.png')
site=[0,0]
site2 = [0, 0]
while True:
    for event in pygame.event.get(): 
        if event.type == pygame.QUIT:
            pygame.quit()
            sys.exit()
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_UP:
                site[1] -= 100
            if event.key == pygame.K_DOWN:
                site[1] += 100
            if event.key == pygame.K_LEFT:
                site[0] -= 100
            if event.key == pygame.K_RIGHT:
                site[0] += 100

        if event.type == pygame.MOUSEBUTTONDOWN:
            print('**',event.pos)
            site2 = event.pos
            print(site2)

    scree.blit(background, (0, 0))
    scree.blit(alarm2, site2)
    scree.blit(alarm, site)

    

    pygame.display.update()
回复

使用道具 举报

5

主题

67

帖子

1103

积分

金牌会员

Rank: 6Rank: 6

积分
1103
 楼主| 发表于 2022-9-10 15:37:07 | 显示全部楼层
[Python] 纯文本查看 复制代码
import pygame
import sys
pygame.init()
scree = pygame.display.set_mode((800, 600))
background = pygame.image.load('image\星海背景.png')

while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            sys.exit()

    scree.blit(background, (0, 0))

    pygame.display.update()
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-5-9 19:03 , Processed in 0.042529 second(s), 28 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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